1#ifndef PRDC_CPU_FFT_TPP
2#define PRDC_CPU_FFT_TPP
75 fftw_destroy_plan(rcfPlan_);
78 fftw_destroy_plan(criPlan_);
81 fftw_destroy_plan(ccfPlan_);
84 fftw_destroy_plan(cciPlan_);
100 for (
int i = 0; i < D; ++i) {
102 meshDimensions_[i] = meshDimensions[i];
103 rSize_ *= meshDimensions[i];
105 kSize_ *= meshDimensions[i];
107 kSize_ *= (meshDimensions[i]/2 + 1);
112 if (!kFieldCopy_.isAllocated()) {
113 kFieldCopy_.allocate(meshDimensions);
115 if (kFieldCopy_.capacity() != kSize_) {
116 kFieldCopy_.deallocate();
117 kFieldCopy_.allocate(meshDimensions);
120 UTIL_CHECK(meshDimensions == kFieldCopy_.meshDimensions());
140 makePlans(rField, kFieldCopy_, cFieldIn, cFieldOut);
163 fftw_execute_dft_r2c(rcfPlan_,
const_cast<double*
>(&rField[0]),
167 double scale = 1.0/double(rSize_);
168 for (
int i = 0; i < kSize_; ++i) {
169 kField[i][0] *= scale;
170 kField[i][1] *= scale;
189 fftw_execute_dft_c2r(criPlan_, &kField[0], &rField[0]);
203 kFieldCopy_ = kField;
204 inverseTransformUnsafe(kFieldCopy_, rField);
225 fftw_execute_dft(ccfPlan_,
const_cast<fftw_complex*
>(&rField[0]),
229 double scale = 1.0/double(rSize_);
230 for (
int i = 0; i < rSize_; ++i) {
231 kField[i][0] *= scale;
232 kField[i][1] *= scale;
252 fftw_execute_dft(cciPlan_,
const_cast<fftw_complex*
>(&kField[0]),
An IntVec<D, T> is a D-component vector of elements of integer type T.
Field of complex double precision values on an FFT mesh.
const IntVec< D > & meshDimensions() const
Return mesh dimensions by constant reference.
void allocate(const IntVec< D > &meshDimensions)
Allocate the underlying C array for an FFT grid.
void inverseTransformUnsafe(RFieldDft< D > &in, RField< D > &out) const
Compute inverse (complex-to-real) DFT, overwriting the input.
FFT()
Default constructor.
void forwardTransform(RField< D > const &in, RFieldDft< D > &out) const
Compute forward (real-to-complex) discrete Fourier transform.
void inverseTransform(CField< D > const &in, CField< D > &out) const
Compute complex-to-complex inverse Fourier transform.
void setup(IntVec< D > const &meshDimensions)
Setup grid dimensions, FFT plans and work space.
virtual ~FFT()
Destructor.
void inverseTransformSafe(RFieldDft< D > const &in, RField< D > &out) const
Compute inverse (complex-to-real) DFT without overwriting input.
Fourier transform of a real field on an FFT mesh.
IntVec< D > const & meshDimensions() const
Return vector of spatial mesh dimensions by constant reference.
Field of real double precision values on an FFT mesh.
void allocate(IntVec< D > const &meshDimensions)
Allocate the underlying C array for an FFT grid.
const IntVec< D > & meshDimensions() const
Return mesh dimensions by constant reference.
int capacity() const
Return allocated size.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
PSCF package top-level namespace.
Utility classes for scientific computation.