54 fft_mp->transform(FORWARD, *this->rhs_mp, fieldComplex_m);
56 auto view = fieldComplex_m.getView();
57 const int nghost = fieldComplex_m.getNghost();
59 scalar_type pi = Kokkos::numbers::pi_v<scalar_type>;
60 const mesh_type& mesh = this->rhs_mp->get_mesh();
61 const auto& lDomComplex = layoutComplex_mp->getLocalNDIndex();
62 using vector_type =
typename mesh_type::vector_type;
63 const vector_type& origin = mesh.getOrigin();
64 const vector_type& hx = mesh.getMeshSpacing();
68 for (
size_t d = 0; d < Dim; ++d) {
69 N[d] = domain_m[d].length();
70 rmax[d] = origin[d] + (N[d] * hx[d]);
77 switch (this->params_m.template get<int>(
"output_type")) {
81 KOKKOS_LAMBDA(
const index_array_type& args) {
83 for (
unsigned d = 0; d < Dim; ++d) {
84 iVec[d] += lDomComplex[d].first();
89 for (
size_t d = 0; d < Dim; ++d) {
90 const scalar_type Len = rmax[d] - origin[d];
91 bool shift = (iVec[d] > (N[d] / 2));
92 kVec[d] = 2 * pi / Len * (iVec[d] - shift * N[d]);
96 for (
unsigned d = 0; d < Dim; ++d) {
97 Dr += kVec[d] * kVec[d];
100 bool isNotZero = (Dr != 0.0);
101 scalar_type factor = isNotZero * (1.0 / (Dr + ((!isNotZero) * 1.0)));
103 apply(view, args) *= factor;
106 fft_mp->transform(BACKWARD, *this->rhs_mp, fieldComplex_m);
114 Complex_t imag = {0.0, 1.0};
115 auto tempview = tempFieldComplex_m.getView();
116 auto viewRhs = this->rhs_mp->getView();
117 auto viewLhs = this->lhs_mp->getView();
118 const int nghostL = this->lhs_mp->getNghost();
120 for (
size_t gd = 0; gd < Dim; ++gd) {
122 "Gradient FFTPeriodicPoissonSolver",
getRangePolicy(view, nghost),
123 KOKKOS_LAMBDA(
const index_array_type& args) {
125 for (
unsigned d = 0; d < Dim; ++d) {
126 iVec[d] += lDomComplex[d].first();
131 for (
size_t d = 0; d < Dim; ++d) {
132 const scalar_type Len = rmax[d] - origin[d];
133 bool shift = (iVec[d] > (N[d] / 2));
134 bool notMid = (iVec[d] != (N[d] / 2));
137 kVec[d] = notMid * 2 * pi / Len * (iVec[d] - shift * N[d]);
141 for (
unsigned d = 0; d < Dim; ++d) {
142 Dr += kVec[d] * kVec[d];
147 bool isNotZero = (Dr != 0.0);
148 scalar_type factor = isNotZero * (1.0 / (Dr + ((!isNotZero) * 1.0)));
150 apply(tempview, args) *= -(imag * kVec[gd] * factor);
153 fft_mp->transform(BACKWARD, *this->rhs_mp, tempFieldComplex_m);
156 "Assign Gradient FFTPeriodicPoissonSolver",
158 KOKKOS_LAMBDA(
const index_array_type& args) {
159 apply(viewLhs, args)[gd] =
apply(viewRhs, args);
167 throw IpplException(
"FFTPeriodicPoissonSolver::solve",
"Unrecognized output_type");
KOKKOS_INLINE_FUNCTION constexpr decltype(auto) apply(const View &view, const Coords &coords)
Definition IpplOperations.h:64
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
Definition ParallelDispatch.h:56