OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
fft.hpp File Reference

Fast Fourier Transform interface for spectral methods. More...

#include "core/decomposition.hpp"
#include "openpfc/backends/heffte_adapter.hpp"
#include "openpfc/core/backend_tags.hpp"
#include "openpfc/core/databuffer.hpp"
#include "openpfc/core/world.hpp"
#include "openpfc/fft/kspace.hpp"
#include <heffte.h>
#include <iostream>
#include <memory>
#include <mpi.h>
Include dependency graph for fft.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pfc::fft::layout::FFTLayout
 Structure to hold the layout of FFT data. More...
 
struct  pfc::fft::IFFT
 
struct  pfc::fft::FFT_Impl< BackendTag >
 FFT class for distributed-memory parallel Fourier transforms. More...
 

Typedefs

using pfc::fft::layout::box3di = heffte::box3d< int >
 
using pfc::fft::layout::Decomposition = pfc::decomposition::Decomposition
 
using pfc::fft::Decomposition = pfc::decomposition::Decomposition
 
using pfc::fft::RealVector = std::vector< double >
 
using pfc::fft::ComplexVector = std::vector< std::complex< double > >
 
using pfc::fft::box3di = heffte::box3d< int >
 Type alias for 3D integer box.
 
using pfc::fft::RealDataBuffer = core::DataBuffer< backend::CpuTag, double >
 
using pfc::fft::ComplexDataBuffer = core::DataBuffer< backend::CpuTag, std::complex< double > >
 
using pfc::fft::fft_r2c = heffte::fft3d_r2c< heffte::backend::fftw >
 FFTW backend (CPU)
 
using pfc::fft::FFT = FFT_Impl< heffte::backend::fftw >
 
using pfc::FFT = fft::FFT
 Type alias for FFT class.
 
using pfc::FFTLayout = fft::layout::FFTLayout
 Type alias for FFTLayout class.
 

Enumerations

enum class  pfc::fft::Backend { FFTW , CUDA }
 FFT backend selection. More...
 

Functions

const FFTLayout pfc::fft::layout::create (const Decomposition &decomposition, int r2c_direction)
 Creates an FFTLayout object based on the given decomposition and parameters.
 
const autopfc::fft::layout::get_real_box (const FFTLayout &layout, int i)
 
const autopfc::fft::layout::get_complex_box (const FFTLayout &layout, int i)
 
auto pfc::fft::layout::get_r2c_direction (const FFTLayout &layout)
 
template<typename BackendTag >
const autopfc::fft::get_fft_object (const FFT_Impl< BackendTag > &fft) noexcept
 
template<typename BackendTag >
auto pfc::fft::get_inbox (const FFT_Impl< BackendTag > &fft) noexcept
 
template<typename BackendTag >
auto pfc::fft::get_outbox (const FFT_Impl< BackendTag > &fft) noexcept
 
FFT pfc::fft::create (const FFTLayout &fft_layout, int rank_id, plan_options options)
 Creates an FFT object based on the given FFTLayout and rank ID.
 
FFT pfc::fft::create (const Decomposition &decomposition, int rank_id)
 Creates an FFT object based on the given decomposition and rank ID.
 
FFT pfc::fft::create (const Decomposition &decomposition)
 Creates an FFT object based on the given decomposition.
 
std::unique_ptr< IFFTpfc::fft::create_with_backend (const FFTLayout &fft_layout, int rank_id, plan_options options, Backend backend)
 Creates an FFT object with runtime backend selection.
 
std::unique_ptr< IFFTpfc::fft::create_with_backend (const Decomposition &decomposition, int rank_id, Backend backend)
 Creates an FFT object with runtime backend selection.
 

Detailed Description

Fast Fourier Transform interface for spectral methods.

This file defines the FFT class and related utilities for performing distributed parallel FFT operations using HeFFTe. OpenPFC uses spectral methods where derivatives and other spatial operations are efficiently computed in Fourier space.

The FFT class provides:

  • Distributed-memory parallel 3D real-to-complex and complex-to-real transforms
  • Integration with HeFFTe backend (supports FFTW, cuFFT, rocFFT)
  • FFTLayout for managing real/complex data decomposition
  • Helper functions for k-space operations (wavenumbers, Laplacian operators)

Typical usage:

// Create FFT for decomposed domain
pfc::decomposition::Decomposition decomp(world, MPI_COMM_WORLD);
// Transform to Fourier space
std::vector<double> real_data = ...;
std::vector<std::complex<double>> fourier_data = fft.forward(real_data);
// Compute derivatives in k-space, then transform back
// ... modify fourier_data ...
std::vector<double> result = fft.backward(fourier_data);
Describes a static, pure partitioning of the global simulation domain into local subdomains.
Definition decomposition.hpp:182
FFT class for distributed-memory parallel Fourier transforms.
Definition fft.hpp:248
World(const Int3 &lower, const Int3 &upper, const CoordinateSystem< T > &cs)
Constructs a World object.

This file is part of the Core Infrastructure module, providing the foundation for spectral method computations in phase-field simulations.

See also
core/decomposition.hpp for domain decomposition
model.hpp for FFT usage in physics models
backends/heffte_adapter.hpp for HeFFTe integration

Enumeration Type Documentation

◆ Backend

enum class pfc::fft::Backend
strong

FFT backend selection.

Specifies which FFT library backend to use for computations.

  • FFTW: CPU-based FFT (default, always available)
  • CUDA: GPU-based FFT using cuFFT (requires CUDA and OpenPFC_ENABLE_CUDA)
Enumerator
FFTW 

CPU-based FFT using FFTW (default)

CUDA 

GPU-based FFT using cuFFT (requires CUDA support)

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

Function Documentation

◆ create() [1/4]

FFT pfc::fft::create ( const Decomposition decomposition)

Creates an FFT object based on the given decomposition.

Parameters
decompositionThe Decomposition object defining the domain decomposition.
Returns
An FFT object containing the FFT configuration and data.
Exceptions
std::logic_error,ifdecomposition size and rank size do not match.
Note
Precision (float/double) is determined by data types passed to forward/backward methods.

◆ create() [2/4]

const FFTLayout pfc::fft::layout::create ( const Decomposition decomposition,
int  r2c_direction 
)

Creates an FFTLayout object based on the given decomposition and parameters.

Parameters
decompositionThe Decomposition object defining the domain decomposition.
r2c_directionThe direction of real-to-complex symmetry.
Returns
An FFTLayout object containing the layout information.
Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ create() [3/4]

FFT pfc::fft::create ( const Decomposition decomposition,
int  rank_id 
)

Creates an FFT object based on the given decomposition and rank ID.

Parameters
decompositionThe Decomposition object defining the domain decomposition.
rank_idThe rank ID of the current process in the MPI communicator.
Returns
An FFT object containing the FFT configuration and data.
Note
Precision (float/double) is determined by data types passed to forward/backward methods.

◆ create() [4/4]

FFT pfc::fft::create ( const FFTLayout fft_layout,
int  rank_id,
plan_options  options 
)

Creates an FFT object based on the given FFTLayout and rank ID.

Parameters
fft_layoutThe FFTLayout object defining the FFT configuration.
rank_idThe rank ID of the current process in the MPI communicator.
optionsPlan options for configuring the FFT behavior.
Returns
An FFT object containing the FFT configuration and data.
Note
Precision (float/double) is determined by data types passed to forward/backward methods.
Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.

◆ create_with_backend() [1/2]

std::unique_ptr< IFFT > pfc::fft::create_with_backend ( const Decomposition decomposition,
int  rank_id,
Backend  backend 
)

Creates an FFT object with runtime backend selection.

Parameters
decompositionThe Decomposition object defining the domain decomposition.
rank_idThe rank ID of the current process in the MPI communicator.
backendThe FFT backend to use (FFTW, CUDA, etc.)
Returns
A unique_ptr to IFFT interface for the selected backend
Exceptions
std::runtime_errorif backend is not supported or not compiled in
Here is the call graph for this function:

◆ create_with_backend() [2/2]

std::unique_ptr< IFFT > pfc::fft::create_with_backend ( const FFTLayout fft_layout,
int  rank_id,
plan_options  options,
Backend  backend 
)

Creates an FFT object with runtime backend selection.

Parameters
fft_layoutThe FFTLayout object defining the FFT configuration.
rank_idThe rank ID of the current process in the MPI communicator.
optionsPlan options for configuring the FFT behavior.
backendThe FFT backend to use (FFTW, CUDA, etc.)
Returns
A unique_ptr to IFFT interface for the selected backend
Exceptions
std::runtime_errorif backend is not supported or not compiled in
Note
This function provides runtime polymorphism via the IFFT interface. For compile-time selection with zero overhead, use create() directly.
Examples
/home/runner/work/OpenPFC/OpenPFC/include/openpfc/fft.hpp.
Here is the call graph for this function:
Here is the caller graph for this function: