OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
pfc::fft::FFT_Impl< BackendTag > Struct Template Reference

FFT class for distributed-memory parallel Fourier transforms. More...

#include <fft.hpp>

Inheritance diagram for pfc::fft::FFT_Impl< BackendTag >:
Collaboration diagram for pfc::fft::FFT_Impl< BackendTag >:

Public Types

using fft_type = heffte::fft3d_r2c< BackendTag >
 
using workspace_type = typename heffte::fft3d_r2c< BackendTag >::template buffer_container< std::complex< double > >
 

Public Member Functions

 FFT_Impl (fft_type fft)
 Constructs an FFT object with the given HeFFTe FFT object.
 
template<typename RealBackendTag , typename ComplexBackendTag , typename RealType >
void forward (const core::DataBuffer< RealBackendTag, RealType > &in, core::DataBuffer< ComplexBackendTag, std::complex< RealType > > &out)
 
void forward (const RealVector &in, ComplexVector &out) override
 Performs the forward FFT transformation.
 
template<typename ComplexBackendTag , typename RealBackendTag , typename RealType >
void backward (const core::DataBuffer< ComplexBackendTag, std::complex< RealType > > &in, core::DataBuffer< RealBackendTag, RealType > &out)
 
void backward (const ComplexVector &in, RealVector &out) override
 Performs the backward (inverse) FFT transformation.
 
void reset_fft_time () override
 Resets the recorded FFT computation time to zero.
 
double get_fft_time () const override
 Returns the recorded FFT computation time.
 
size_t size_inbox () const override
 Returns the associated Decomposition object.
 
size_t size_outbox () const override
 Returns the size of the outbox used for FFT computations.
 
size_t size_workspace () const override
 Returns the size of the workspace used for FFT computations.
 
size_t get_allocated_memory_bytes () const override
 Returns the total memory allocated by HeFFTe in bytes.
 

Public Attributes

const fft_type m_fft
 
double m_fft_time = 0.0
 
workspace_type m_wrk
 

Detailed Description

template<typename BackendTag = heffte::backend::fftw>
struct pfc::fft::FFT_Impl< BackendTag >

FFT class for distributed-memory parallel Fourier transforms.

Provides real-to-complex (R2C) and complex-to-real (C2R) 3D FFT operations using HeFFTe backend. This is the core computational engine for spectral methods in OpenPFC, enabling efficient calculation of derivatives and convolutions in Fourier space.

Key Features

  • Distributed-memory parallelism via MPI
  • Real-to-complex symmetry exploitation (half-space representation)
  • Multiple backend support (FFTW, cuFFT, rocFFT)
  • Automatic workspace management
  • Performance timing capabilities

Memory Layout

  • Real data: Full 3D grid (N_x × N_y × N_z)
  • Complex data: Half-space (N_x × N_y × (N_z/2+1)) due to conjugate symmetry
  • Both use distributed decomposition across MPI ranks

Normalization Convention

  • Forward transform: No normalization
  • Backward transform: Divides by total grid points (1/N)
  • Round-trip: x → forward → backward → x (exact)

Usage Pattern

// Setup
auto world = world::create({256, 256, 256});
auto fft = fft::create(decomp);
// Allocate fields
RealVector real_field(fft.size_inbox());
ComplexVector fourier_field(fft.size_outbox());
// Forward: real space → k-space
fft.forward(real_field, fourier_field);
// Apply operators in k-space
for (size_t k = 0; k < fourier_field.size(); ++k) {
}
// Backward: k-space → real space (normalized)
fft.backward(fourier_field, real_field);
auto create(const World< T > &world, const heffte::box3d< int > &box)
Construct a new World object from an existing one and a box.
Definition decomposition.hpp:62
Describes a static, pure partitioning of the global simulation domain into local subdomains.
Definition decomposition.hpp:182
Represents the global simulation domain (the "world").
Definition world.hpp:91

Performance Notes

  • FFT is O(N log N) operation
  • MPI communication overhead scales with domain decomposition
  • Use reset_fft_time() and get_fft_time() to measure performance
  • Powers of 2 for grid dimensions yield fastest transforms
Note
FFT stores a reference/pointer to Decomposition - ensure lifetime
Warning
Forward and backward are NOT inverses without normalization
Complex array is half the size of real array (conjugate symmetry)
See also
fft::create() for construction
Decomposition for domain decomposition
kspace.hpp for wavenumber and operator helpers

FFT class template for distributed-memory parallel Fourier transforms

Template Parameters
BackendTagHeFFTe backend tag (heffte::backend::fftw or heffte::backend::cufft)
Note
Precision (float/double) is determined by the data types passed to forward() and backward() methods, not by template parameters. HeFFTe automatically handles precision based on input/output types.
Examples
03_simulator_workflow.cpp, 04_diffusion_model.cpp, and 05_simulator.cpp.

Constructor & Destructor Documentation

◆ FFT_Impl()

template<typename BackendTag = heffte::backend::fftw>
pfc::fft::FFT_Impl< BackendTag >::FFT_Impl ( fft_type  fft)
inline

Constructs an FFT object with the given HeFFTe FFT object.

Parameters
fftHeFFTe FFT object (already configured)

Member Function Documentation

◆ backward()

template<typename BackendTag = heffte::backend::fftw>
void pfc::fft::FFT_Impl< BackendTag >::backward ( const ComplexVector &  in,
RealVector &  out 
)
inlineoverridevirtual

Performs the backward (inverse) FFT transformation.

Parameters
inInput vector of complex values.
outOutput vector of real values.

Implements pfc::fft::IFFT.

Here is the call graph for this function:

◆ forward()

template<typename BackendTag = heffte::backend::fftw>
void pfc::fft::FFT_Impl< BackendTag >::forward ( const RealVector &  in,
ComplexVector &  out 
)
inlineoverridevirtual

Performs the forward FFT transformation.

Parameters
inInput vector of real values.
outOutput vector of complex values.

Implements pfc::fft::IFFT.

◆ get_allocated_memory_bytes()

template<typename BackendTag = heffte::backend::fftw>
size_t pfc::fft::FFT_Impl< BackendTag >::get_allocated_memory_bytes ( ) const
inlineoverridevirtual

Returns the total memory allocated by HeFFTe in bytes.

Calculates memory for workspace buffer used by HeFFTe.

Returns
Total allocated memory in bytes

Implements pfc::fft::IFFT.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ get_fft_time()

template<typename BackendTag = heffte::backend::fftw>
double pfc::fft::FFT_Impl< BackendTag >::get_fft_time ( ) const
inlineoverridevirtual

Returns the recorded FFT computation time.

Returns
The FFT computation time in seconds.

Implements pfc::fft::IFFT.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ reset_fft_time()

template<typename BackendTag = heffte::backend::fftw>
void pfc::fft::FFT_Impl< BackendTag >::reset_fft_time ( )
inlineoverridevirtual

Resets the recorded FFT computation time to zero.

Implements pfc::fft::IFFT.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ size_inbox()

template<typename BackendTag = heffte::backend::fftw>
size_t pfc::fft::FFT_Impl< BackendTag >::size_inbox ( ) const
inlineoverridevirtual

Returns the associated Decomposition object.

Returns
Reference to the Decomposition object.

Returns the size of the inbox used for FFT computations.

Returns
Size of the inbox.

Implements pfc::fft::IFFT.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ size_outbox()

template<typename BackendTag = heffte::backend::fftw>
size_t pfc::fft::FFT_Impl< BackendTag >::size_outbox ( ) const
inlineoverridevirtual

Returns the size of the outbox used for FFT computations.

Returns
Size of the outbox.

Implements pfc::fft::IFFT.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ size_workspace()

template<typename BackendTag = heffte::backend::fftw>
size_t pfc::fft::FFT_Impl< BackendTag >::size_workspace ( ) const
inlineoverridevirtual

Returns the size of the workspace used for FFT computations.

Returns
Size of the workspace.

Implements pfc::fft::IFFT.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

Member Data Documentation

◆ m_fft

template<typename BackendTag = heffte::backend::fftw>
const fft_type pfc::fft::FFT_Impl< BackendTag >::m_fft

◆ m_fft_time

template<typename BackendTag = heffte::backend::fftw>
double pfc::fft::FFT_Impl< BackendTag >::m_fft_time = 0.0

Recorded FFT computation time.

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ m_wrk

template<typename BackendTag = heffte::backend::fftw>
workspace_type pfc::fft::FFT_Impl< BackendTag >::m_wrk

Workspace vector for FFT computations (double precision).

Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

The documentation for this struct was generated from the following file: