PSCF v1.5.0
Pscf::FFT< D, CPT > Class Template Reference

Fourier transform wrapper. More...

#include <FFT.h>

Public Member Functions

 FFT ()
 Default constructor.
virtual ~FFT ()
 Destructor.
void setup (IntVec< D > const &meshDimensions)
 Setup grid dimensions, FFT plans and work space.
void forwardTransform (RField< D, CPT > const &in, RFieldDft< D, CPT > &out) const
 Compute forward (real-to-complex) discrete Fourier transform (DFT).
void inverseTransformUnsafe (RFieldDft< D, CPT > &in, RField< D, CPT > &out) const
 Compute inverse (complex-to-real) DFT, overwriting the input.
void inverseTransformSafe (RFieldDft< D, CPT > const &in, RField< D, CPT > &out) const
 Compute inverse (complex-to-real) DFT without overwriting input.
void forwardTransform (CField< D, CPT > const &in, CField< D, CPT > &out) const
 Compute forward (complex-to-complex) discrete Fourier transform.
void inverseTransform (CField< D, CPT > const &in, CField< D, CPT > &out) const
 Compute complex-to-complex inverse Fourier transform.
IntVec< D > const & meshDimensions () const
 Return the dimensions of the grid for which this was setup.
bool isSetup () const
 Has this FFT object been setup?

Static Public Member Functions

static void computeKMesh (IntVec< D > const &rMeshDimensions, IntVec< D > &kMeshDimensions, int &kSize)
 Compute dimensions and size of k-space mesh for DFT of real data.
static bool hasImplicitInverse (IntVec< D > const &wavevector, IntVec< D > const &meshDimensions)
 Does this wavevector have implicit inverse in DFT or real data?

Detailed Description

template<int D>
class Pscf::FFT< D, CPT >

Fourier transform wrapper.

This class is a wrapper for plan creation and discrete Fourier transform (DFT) functions provided by the FFTW library, providing an interface to specializations of the field container templates RField, RFieldDf, and CField with a backend T=CppTp<D>.

Definition at line 41 of file cpp/FFT.h.

Constructor & Destructor Documentation

◆ FFT()

template<int D>
Pscf::FFT< D, CPT >::FFT ( )

◆ ~FFT()

template<int D>
Pscf::FFT< D, CPT >::~FFT ( )
virtual

Destructor.

Definition at line 72 of file cpp/FFT.tpp.

References FFT().

Member Function Documentation

◆ setup()

template<int D>
void Pscf::FFT< D, CPT >::setup ( IntVec< D > const & meshDimensions)

Setup grid dimensions, FFT plans and work space.

Parameters
meshDimensionsDimensions of real-space grid.

Definition at line 92 of file cpp/FFT.tpp.

References FFT(), meshDimensions(), and UTIL_CHECK.

◆ forwardTransform() [1/2]

template<int D>
void Pscf::FFT< D, CPT >::forwardTransform ( RField< D, CPT > const & in,
RFieldDft< D, CPT > & out ) const

Compute forward (real-to-complex) discrete Fourier transform (DFT).

The resulting complex array is the output of FFTW's forward transform method scaled by a factor of 1/N (where N is the number of grid points). The scaling ensures that a round-trip Fourier transform (forward + inverse) reproduces the original input array.

This function does not overwrite or corrupt the input array.

Parameters
inarray of real values on r-space grid
outarray of complex values on k-space grid

Definition at line 151 of file cpp/FFT.tpp.

References FFT(), and UTIL_CHECK.

◆ inverseTransformUnsafe()

template<int D>
void Pscf::FFT< D, CPT >::inverseTransformUnsafe ( RFieldDft< D, CPT > & in,
RField< D, CPT > & out ) const

Compute inverse (complex-to-real) DFT, overwriting the input.

The resulting real array is the unaltered output of FFTW's inverse transform function.

NOTE: The inverse transform generally overwrites and corrupts its input. This is the behavior of the complex-to-real (c2r) transform of the underlying FFTW library. See Sec. 2.3 of the FFTW 3 documentation at https://www.fftw.org/fftw3_doc, One-Dimensional DFTs of Real Data: "...the inverse transform (complex to real) has the side-effect of overwriting its input array, ..."

Parameters
inarray of complex values on k-space grid (overwritten)
outarray of real values on r-space grid

Definition at line 179 of file cpp/FFT.tpp.

References FFT(), and UTIL_CHECK.

Referenced by inverseTransformSafe().

◆ inverseTransformSafe()

template<int D>
void Pscf::FFT< D, CPT >::inverseTransformSafe ( RFieldDft< D, CPT > const & in,
RField< D, CPT > & out ) const

Compute inverse (complex-to-real) DFT without overwriting input.

The resulting real array is the unaltered output of FFTW's inverse transform function.

This function makes a copy of the input data and passes the copy to inverseTransformUnsafe to avoid overwriting the input data.

Parameters
inarray of complex values on k-space grid
outarray of real values on r-space grid

Definition at line 199 of file cpp/FFT.tpp.

References FFT(), inverseTransformUnsafe(), and UTIL_CHECK.

◆ forwardTransform() [2/2]

template<int D>
void Pscf::FFT< D, CPT >::forwardTransform ( CField< D, CPT > const & in,
CField< D, CPT > & out ) const

Compute forward (complex-to-complex) discrete Fourier transform.

The resulting complex array is the output of FFTW's forward transform method scaled by a factor of 1/N (where N is the number of grid points). The scaling ensures that a round-trip Fourier transform (forward + inverse) reproduces the original input array.

This function does not overwrite or corrupt the input array.

Note that, in this transform, the k-space grid is the same size as the r-space grid, which differs from the real-to-complex transform.

Parameters
inarray of complex values on r-space grid
outarray of complex values on k-space grid

Definition at line 216 of file cpp/FFT.tpp.

References FFT(), and UTIL_CHECK.

◆ inverseTransform()

template<int D>
void Pscf::FFT< D, CPT >::inverseTransform ( CField< D, CPT > const & in,
CField< D, CPT > & out ) const

Compute complex-to-complex inverse Fourier transform.

The resulting complex array is the unaltered output of FFTW's inverse transform function.

Note that, in this transform, the k-space grid is the same size as the r-space grid, which differs from the complex-to-real transform.

Parameters
inarray of complex values on k-space grid
outarray of complex values on r-space grid

Definition at line 244 of file cpp/FFT.tpp.

References FFT(), and UTIL_CHECK.

◆ meshDimensions()

template<int D>
IntVec< D > const & Pscf::FFT< D, CPT >::meshDimensions ( ) const
inline

Return the dimensions of the grid for which this was setup.

Definition at line 280 of file cpp/FFT.h.

References FFT().

Referenced by hasImplicitInverse(), and setup().

◆ isSetup()

template<int D>
bool Pscf::FFT< D, CPT >::isSetup ( ) const
inline

Has this FFT object been setup?

Definition at line 273 of file cpp/FFT.h.

References FFT().

◆ computeKMesh()

template<int D>
void Pscf::FFT< D, CPT >::computeKMesh ( IntVec< D > const & rMeshDimensions,
IntVec< D > & kMeshDimensions,
int & kSize )
static

Compute dimensions and size of k-space mesh for DFT of real data.

A corresponding function is not needed for complex-to-complex transforms because the real-space and Fourier-space grids for complex transforms have the same dimensions.

Parameters
rMeshDimensionsdimensions of real space grid (real data)
kMeshDimensionsdimensions of k-space grid (complex data)
kSizenumber of point in k-space grid

Definition at line 267 of file cpp/FFT.tpp.

References FFT().

◆ hasImplicitInverse()

template<int D>
bool Pscf::FFT< D, CPT >::hasImplicitInverse ( IntVec< D > const & wavevector,
IntVec< D > const & meshDimensions )
inlinestatic

Does this wavevector have implicit inverse in DFT or real data?

The inverse of a wavevector within the DFT mesh used for a DFT of real data is "implicit" if its inverse is not equivalent to any wavevector in this mesh. The inverse is not implicit if its inverse is equivalent to a wavevector within this mesh.

To compute a Fourier sum using the DFT of real r-space data, for any summand that has inversion symmetry (i.e., the same value for every vector and its inverse), sum over all vectors in the k-space mesh and multiply each element for each wavevector that has an implicit inverse by 2.0, and all others by 1.0.

Parameters
wavevectorinteger indices of wavevector
meshDimensionsdimensions of real-space mesh

Definition at line 287 of file cpp/FFT.h.

References FFT(), meshDimensions(), and UTIL_CHECK.


The documentation for this class was generated from the following files: