17 template <
typename FieldLHS,
typename FieldRHS>
27 template <
typename FieldLHS,
typename FieldRHS>
41 template <
typename FieldLHS,
typename FieldRHS>
55 template <
typename FieldLHS,
typename FieldRHS>
64 template <
typename FieldLHS,
typename FieldRHS>
66 static_assert(
Dim == 3,
"Dimension other than 3 not supported in FFTTruncatedGreenPeriodicPoissonSolver!");
83 for (
unsigned int i = 0; i <
Dim; ++i) {
88 std::array<bool, Dim> isParallel =
layout_mp->isParallel();
94 unsigned int RCDirection = this->
params_m.template
get<int>(
"r2c_direction");
95 for (
unsigned int i = 0; i <
Dim; ++i) {
103 using mesh_type =
typename lhs_type::Mesh_t;
119 for (
unsigned int d = 0; d <
Dim; ++d) {
125 const auto& ldom =
layout_mp->getLocalNDIndex();
128 const int size =
nr_m[d];
133 Kokkos::parallel_for(
134 "Helper index Green field initialization",
136 KOKKOS_LAMBDA(
const int i,
const int j,
const int k) {
138 const int ig = i + ldom[0].first() - nghost;
139 const int jg = j + ldom[1].first() - nghost;
140 const int kg = k + ldom[2].first() - nghost;
143 const bool outsideN = (ig >= size / 2);
144 view(i, j, k) = (size * outsideN - ig) * (size * outsideN - ig);
147 const bool isOrig = ((ig == 0) && (jg == 0) && (kg == 0));
148 view(i, j, k) += isOrig * 1.0;
152 Kokkos::parallel_for(
153 "Helper index Green field initialization",
155 KOKKOS_LAMBDA(
const int i,
const int j,
const int k) {
157 const int jg = j + ldom[1].first() - nghost;
160 const bool outsideN = (jg >= size / 2);
161 view(i, j, k) = (size * outsideN - jg) * (size * outsideN - jg);
165 Kokkos::parallel_for(
166 "Helper index Green field initialization",
168 KOKKOS_LAMBDA(
const int i,
const int j,
const int k) {
170 const int kg = k + ldom[2].first() - nghost;
173 const bool outsideN = (kg >= size / 2);
174 view(i, j, k) = (size * outsideN - kg) * (size * outsideN - kg);
189 template <
typename FieldLHS,
typename FieldRHS>
200 for (
unsigned int i = 0; i <
Dim; ++i) {
228 const Trhs pi = Kokkos::numbers::pi_v<Trhs>;
229 Kokkos::complex<Trhs> imag = {0.0, 1.0};
232 const int nghost =
rhotr_m.getNghost();
234 auto viewRhs = this->
rhs_mp->getView();
235 auto viewLhs = this->
lhs_mp->getView();
236 const int nghostL = this->
lhs_mp->getNghost();
244 for (
size_t gd = 0; gd <
Dim; ++gd) {
246 "Gradient FFTPeriodicPoissonSolver",
getRangePolicy(view, nghost),
247 KOKKOS_LAMBDA(
const index_array_type& args) {
250 for (
unsigned d = 0; d <
Dim; ++d) {
251 iVec[d] += lDomComplex[d].first();
256 for (
size_t d = 0; d <
Dim; ++d) {
257 const Trhs Len = N[d] * hsize[d];
258 bool shift = (iVec[d] > (N[d] / 2));
259 bool notMid = (iVec[d] != (N[d] / 2));
262 kVec[d] = notMid * 2 *
pi / Len * (iVec[d] - shift * N[d]);
266 for (
unsigned d = 0; d <
Dim; ++d) {
267 Dr += kVec[d] * kVec[d];
272 bool isNotZero = (Dr != 0.0);
274 apply(tempview, args) *= -(isNotZero * imag * kVec[gd]);
280 "Assign Gradient FFTPeriodicPoissonSolver",
getRangePolicy(viewLhs, nghostL),
281 KOKKOS_LAMBDA(
const index_array_type& args) {
282 apply(viewLhs, args)[gd] =
apply(viewRhs, args);
306 template <
typename FieldLHS,
typename FieldRHS>
322 for (
unsigned int i = 0; i <
Dim; ++i) {
327 const int nghost =
grn_m.getNghost();
328 const auto& ldom =
layout_mp->getLocalNDIndex();
331 Kokkos::parallel_for(
333 KOKKOS_LAMBDA(
const int i,
const int j,
const int k) {
335 const int ig = i + ldom[0].first() - nghost;
336 const int jg = j + ldom[1].first() - nghost;
337 const int kg = k + ldom[2].first() - nghost;
339 const bool isOrig = (ig == 0 && jg == 0 && kg == 0);
341 Trhs r = Kokkos::real(Kokkos::sqrt(view(i, j, k)));
342 view(i, j, k) = (!isOrig) * forceConstant * (Kokkos::erf(alpha * r) / r);
ippl::FieldLayout< Dim > FieldLayout_t
KOKKOS_INLINE_FUNCTION constexpr decltype(auto) apply(const View &view, const Coords &coords)
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
void parallel_for(const std::string &name, const ExecPolicy &policy, const FunctorType &functor)
KOKKOS_INLINE_FUNCTION auto & get(Tuple< Ts... > &t)
Accessor function to get an element mutable reference at a specific index from a Tuple.
typename BareField_t::view_type view_type
void setRhs(rhs_type &rhs) override
void setDefaultParameters() override
IField_t grnIField_m[Dim]
Vector< Trhs, Dim > Vector_t
std::unique_ptr< FFT_t > fft_m
typename FieldRHS::value_type Trhs
CxField_t tempFieldComplex_m
NDIndex< Dim > domainComplex_m
std::unique_ptr< mesh_type > meshComplex_m
static constexpr unsigned Dim
Poisson< FieldLHS, FieldRHS > Base
FieldLayout_t * layout_mp
FFTTruncatedGreenPeriodicPoissonSolver()
typename FieldRHS::Mesh_t mesh_type
std::unique_ptr< FieldLayout_t > layoutComplex_m
void setLhs(lhs_type &lhs)
virtual void setRhs(rhs_type &rhs)
::ippl::Vector< index_type, Dim > index_array_type