4#include <ddc/kernels/fft.hpp>
6#include "ddc_alias_inline_functions.hpp"
7#include "ddc_aliases.hpp"
8#include "ddc_helper.hpp"
9#include "directional_tag.hpp"
10#include "ipoisson_solver.hpp"
16 class IdxRangeLaplacian,
17 class IdxRangeFull = IdxRangeLaplacian,
18 class ExecSpace = Kokkos::DefaultExecutionSpace,
19 class LayoutSpace = Kokkos::layout_right>
36template <
class... GridPDEDim1D,
class IdxRangeFull,
class ExecSpace,
class LayoutSpace>
39 IdxRange<GridPDEDim1D...>,
41 typename ExecSpace::memory_space,
46 IdxRange<GridPDEDim1D...>,
48 typename ExecSpace::memory_space,
53 struct GridFourier : ddc::PeriodicSampling<ddc::Fourier<Dim>>
81 = IdxRange<GridFourier<typename GridPDEDim1D::continuous_dimension_type>...>;
93 static constexpr ddc::FFT_Normalization m_norm = ddc::FFT_Normalization::BACKWARD;
102 template <
class... FDim>
103 KOKKOS_FUNCTION
static double get_laplace_operator(Idx<FDim...> index)
105 return (((
double)ddc::coordinate(ddc::select<FDim>(index))
106 * (
double)ddc::coordinate(ddc::select<FDim>(index)))
121 void differentiate_and_invert_fourier_values(
122 DField<laplacian_idx_range_type, memory_space, LayoutSpace> derivative,
123 fourier_field_type fourier_derivative,
124 fourier_field_type values)
const
126 negative_differentiate_equation<Dim>(fourier_derivative, values);
130 get_field(derivative),
131 get_field(fourier_derivative),
132 ddc::kwArgs_fft {m_norm});
143 DField<laplacian_idx_range_type, memory_space, LayoutSpace> gradient,
144 fourier_field_type fourier_derivative,
145 fourier_field_type values)
const
148 typename ddc::type_seq_element_t<0, ddc::to_type_seq_t<laplacian_idx_range_type>>::
149 continuous_dimension_type;
150 using FourierDim = GridFourier<Dim>;
151 differentiate_and_invert_fourier_values<FourierDim>(gradient, fourier_derivative, values);
161 template <
class... Dims>
165 laplacian_idx_range_type,
168 layout_space> gradient,
169 fourier_field_type fourier_derivative,
170 fourier_field_type values)
const
172 ((differentiate_and_invert_fourier_values<
173 GridFourier<Dims>>(ddcHelper::get<Dims>(gradient), fourier_derivative, values)),
177 template <
class Gr
id1D>
178 void init_fourier_space(IdxRange<Grid1D> idx_range)
180 using GridFFT = GridFourier<typename Grid1D::continuous_dimension_type>;
181 ddc::init_discrete_space<GridFFT>(ddc::init_fourier_space<GridFFT>(idx_range));
192 template <
class Layout>
195 DField<laplacian_idx_range_type, memory_space, Layout> rho)
const
198 ddc::fft(ExecSpace(), intermediate_chunk, rho, ddc::kwArgs_fft {m_norm});
204 ddc::parallel_for_each(
208 if (ik != k_mesh.front()) {
209 intermediate_chunk(ik) = intermediate_chunk(ik) / get_laplace_operator(ik);
211 intermediate_chunk(ik) = 0.;
229 Kokkos::complex<double> imaginary_unit(0.0, 1.0);
230 ddc::parallel_for_each(
232 get_idx_range(values),
234 Idx<Dim>
const ikx = ddc::select<Dim>(ik);
235 derivative(ik) = -imaginary_unit * ddc::coordinate(ikx) * values(ik);
249 ((init_fourier_space<GridPDEDim1D>(ddc::select<GridPDEDim1D>(laplacian_idx_range))), ...);
263 Kokkos::Profiling::pushRegion(
"FFTPoissonSolver");
270 GridFourier<typename GridPDEDim1D::continuous_dimension_type>...>(idx_range,
false);
276 solve_poisson_equation(intermediate_chunk, rho[ib]);
282 get_field(intermediate_chunk),
283 ddc::kwArgs_fft {m_norm});
286 Kokkos::Profiling::popRegion();
304 Kokkos::Profiling::pushRegion(
"FFTPoissonSolver");
311 GridFourier<typename GridPDEDim1D::continuous_dimension_type>...>(idx_range,
false);
320 solve_poisson_equation(intermediate_chunk, rho[ib]);
321 get_gradient(E[ib], fourier_efield, intermediate_chunk);
327 get_field(intermediate_chunk),
328 ddc::kwArgs_fft {m_norm});
330 Kokkos::Profiling::popRegion();
IdxRange< GridFourier< typename GridPDEDim1D::continuous_dimension_type >... > fourier_idx_range_type
The type of the Fourier space index range.
Definition fft_poisson_solver.hpp:81
void solve_poisson_equation(fourier_field_type intermediate_chunk, DField< laplacian_idx_range_type, memory_space, Layout > rho) const
A function to solve the Poisson equation in Fourier space This function should be private.
Definition fft_poisson_solver.hpp:193
typename base_type::vector_field_type vector_field_type
The type of the derivative of .
Definition fft_poisson_solver.hpp:64
FFTPoissonSolver(laplacian_idx_range_type laplacian_idx_range)
A constructor for the FFT Poisson solver.
Definition fft_poisson_solver.hpp:247
typename base_type::layout_space layout_space
The layout space of the Fields passed to operator().
Definition fft_poisson_solver.hpp:75
virtual field_type operator()(field_type phi, field_type rho) const final
An operator which calculates the solution to Poisson's equation: .
Definition fft_poisson_solver.hpp:261
typename base_type::batch_index_type batch_index_type
The index type for indexing a batch dimension.
Definition fft_poisson_solver.hpp:69
typename base_type::memory_space memory_space
The space (CPU/GPU) where the Fields passed to operator() are saved.
Definition fft_poisson_solver.hpp:77
typename base_type::field_type field_type
The Field type of the arguments to operator().
Definition fft_poisson_solver.hpp:59
virtual field_type operator()(field_type phi, vector_field_type E, field_type rho) const final
An operator which calculates the solution to Poisson's equation and its derivative: .
Definition fft_poisson_solver.hpp:302
FieldMem< Kokkos::complex< double >, fourier_idx_range_type, memory_space > fourier_field_mem_type
The type of a Field storing the Fourier transform of a function.
Definition fft_poisson_solver.hpp:87
typename base_type::batch_idx_range_type batch_idx_range_type
The index range type describing the batch dimensions.
Definition fft_poisson_solver.hpp:67
typename fourier_idx_range_type::discrete_element_type fourier_index_type
The type of an index of the Fourier space index range.
Definition fft_poisson_solver.hpp:83
typename fourier_field_mem_type::span_type fourier_field_type
The type of a Field storing the Fourier transform of a function.
Definition fft_poisson_solver.hpp:89
void negative_differentiate_equation(fourier_field_type derivative, fourier_field_type values) const
Differentiate and multiply by -1 an expression in Fourier space by multiplying by -i * k This functio...
Definition fft_poisson_solver.hpp:226
typename base_type::const_field_type const_field_type
The const Field type of the arguments to operator().
Definition fft_poisson_solver.hpp:61
typename base_type::laplacian_idx_range_type laplacian_idx_range_type
The type of the index range on which the equation is defined.
Definition fft_poisson_solver.hpp:72
See FFTPoissonSolverImplementation.
Definition fft_poisson_solver.hpp:20
Definition ipoisson_solver.hpp:10
A class which holds multiple (scalar) fields in order to represent a vector field.
Definition vector_field.hpp:64