ORB5X 1.0.0
Performance-portable global electromagnetic gyrokinetic PIC code
orb5x::FFTWrapper Class Reference

Host FFTW transforms and Kokkos/FFTW layout conversion. More...

#include "fft_wrapper.hpp"

Static Public Member Functions

static void bspl2fft_2d (const Kokkos::View< Real ** > &bspl_data, Kokkos::View< Complex ** > &fft_data, int nchi, int nphi)
 Compute an unnormalized full complex 2-D FFT of a real surface.
 
static void bspl2fft_3d (const Kokkos::View< Real *** > &bspl_data, Kokkos::View< Complex ** > &fft_data, int ns, int nchi, int nphi, int neq_f, const Kokkos::View< int *** > *filter=nullptr, const Kokkos::View< Real * > *fftminv=nullptr, const Kokkos::View< int ** > *mmin_f=nullptr, const Kokkos::View< int ** > *mmax_f=nullptr)
 Transform radial B-spline surfaces to packed Fourier coefficients.
 
static std::size_t cached_plan_count_2d_backward ()
 Inspect the number of cached backward 2-D transform sizes.
 
static std::size_t cached_plan_count_2d_forward ()
 Inspect the number of cached forward 2-D transform sizes.
 
static void copy_complex_from_fftw (fftw_complex *fftw_data, const Kokkos::View< Complex ** > &kokkos_data, int neq_f, int nphi)
 Copy FFTW host storage into a packed complex Kokkos View.
 
static void copy_complex_to_fftw (const Kokkos::View< Complex ** > &kokkos_data, fftw_complex *fftw_data, int neq_f, int nphi)
 Copy a packed complex Kokkos View to FFTW host storage.
 
static void copy_from_fftw (fftw_complex *fftw_data, const Kokkos::View< Real *** > &kokkos_data, int ns, int nchi, int nphi)
 Copy real components from FFTW storage into a 3-D Kokkos View.
 
static void copy_to_fftw (const Kokkos::View< Real *** > &kokkos_data, fftw_complex *fftw_data, int ns, int nchi, int nphi)
 Copy a real 3-D Kokkos View to complex FFTW host storage.
 
static void destroy_plan (fftw_plan plan)
 Destroy a caller-owned FFTW plan when non-null.
 
static void execute_backward (fftw_plan plan)
 Execute a previously created FFTW backward plan.
 
static void execute_forward (fftw_plan plan)
 Execute a previously created FFTW forward plan.
 
static void fft2bspl_2d (const Kokkos::View< Complex ** > &fft_data, Kokkos::View< Real ** > &bspl_data, int nchi, int nphi)
 Compute the normalized real inverse of a full 2-D spectrum.
 
static void fft2bspl_3d (const Kokkos::View< Complex ** > &fft_data, Kokkos::View< Real *** > &bspl_data, int ns, int nchi, int nphi, int neq_f, const Kokkos::View< int ** > *mmin_f=nullptr, const Kokkos::View< int ** > *mmax_f=nullptr, bool reconstruct_hermitian_toroidal=false, const char *trace_tag=nullptr)
 Reconstruct real B-spline surfaces from packed Fourier modes.
 
static void init_1d_backward (int n, fftw_plan &plan_backward, fftw_complex *in, fftw_complex *out)
 Create an unnormalized 1-D backward complex FFTW plan.
 
static void init_1d_forward (int n, fftw_plan &plan_forward, fftw_complex *in, fftw_complex *out)
 Create an unnormalized 1-D forward complex FFTW plan.
 
static void init_2d_backward (int nchi, int nphi, fftw_plan &plan_backward, fftw_complex *in, fftw_complex *out)
 Create an unnormalized backward FFT over (chi,phi).
 
static void init_2d_forward (int nchi, int nphi, fftw_plan &plan_forward, fftw_complex *in, fftw_complex *out)
 Create an unnormalized forward FFT over (chi,phi).
 

Detailed Description

Host FFTW transforms and Kokkos/FFTW layout conversion.

ORB5X stores periodic poloidal (chi) and toroidal (phi) data in Kokkos Views but currently executes transforms with double-complex FFTW plans on host buffers. Flattening is row-major with phi fastest. The raw plan helpers follow FFTW's unnormalized convention; the higher-level 2-D and 3-D pairs apply normalization as documented on each function.

Cached 2-D plans are protected by a mutex and released at process shutdown. They remain FFTW host plans and do not provide device-resident transforms.

Member Function Documentation

◆ bspl2fft_2d()

static void orb5x::FFTWrapper::bspl2fft_2d ( const Kokkos::View< Real ** > &  bspl_data,
Kokkos::View< Complex ** > &  fft_data,
int  nchi,
int  nphi 
)
static

Compute an unnormalized full complex 2-D FFT of a real surface.

Parameters
[in]bspl_dataReal input [chi][phi].
[out]fft_dataFull complex spectrum [chi mode][phi mode].
[in]nchiPoloidal extent.
[in]nphiToroidal extent.

Referenced by orb5x::bspl2fft_2d().

◆ bspl2fft_3d()

static void orb5x::FFTWrapper::bspl2fft_3d ( const Kokkos::View< Real *** > &  bspl_data,
Kokkos::View< Complex ** > &  fft_data,
int  ns,
int  nchi,
int  nphi,
int  neq_f,
const Kokkos::View< int *** > *  filter = nullptr,
const Kokkos::View< Real * > *  fftminv = nullptr,
const Kokkos::View< int ** > *  mmin_f = nullptr,
const Kokkos::View< int ** > *  mmax_f = nullptr 
)
static

Transform radial B-spline surfaces to packed Fourier coefficients.

Parameters
[in]bspl_dataReal coefficients [s][chi][phi].
[out]fft_dataPacked complex coefficients [equation][phi mode].
[in]nsNumber of radial surfaces.
[in]nchiRequested poloidal transform extent.
[in]nphiRequested toroidal transform extent.
[in]neq_fNumber of packed radial/poloidal equations; each surface receives neq_f/ns consecutive poloidal slots.
[in]filterOptional integer multiplier [phi][s][wrapped m]; zero suppresses a mode.
[in]fftminvOptional per-phi multiplier, applied only with filter.
[in]mmin_fOptional first retained poloidal-mode metadata [s][phi].
[in]mmax_fMust accompany mmin_f to enable mode-selected packing; currently retained for interface parity, while packed width is determined by neq_f/ns.

The forward coefficients include 1/(nchi_fft*nphi_fft) normalization. Active extents may be reduced to the supplied metadata/filter extents.

Referenced by orb5x::bspl2fft_3d().

◆ cached_plan_count_2d_backward()

static std::size_t orb5x::FFTWrapper::cached_plan_count_2d_backward ( )
static

Inspect the number of cached backward 2-D transform sizes.

Returns
Thread-safe cache entry count for regression/support diagnostics.

◆ cached_plan_count_2d_forward()

static std::size_t orb5x::FFTWrapper::cached_plan_count_2d_forward ( )
static

Inspect the number of cached forward 2-D transform sizes.

Returns
Thread-safe cache entry count for regression/support diagnostics.

◆ copy_complex_from_fftw()

static void orb5x::FFTWrapper::copy_complex_from_fftw ( fftw_complex *  fftw_data,
const Kokkos::View< Complex ** > &  kokkos_data,
int  neq_f,
int  nphi 
)
static

Copy FFTW host storage into a packed complex Kokkos View.

Parameters
[in]fftw_dataSource of at least neq_f*nphi values.
[out]kokkos_dataDestination [equation][phi].
[in]neq_fEquation extent.
[in]nphiToroidal extent and fastest flattened index.

◆ copy_complex_to_fftw()

static void orb5x::FFTWrapper::copy_complex_to_fftw ( const Kokkos::View< Complex ** > &  kokkos_data,
fftw_complex *  fftw_data,
int  neq_f,
int  nphi 
)
static

Copy a packed complex Kokkos View to FFTW host storage.

Parameters
[in]kokkos_dataSource [equation][phi].
[out]fftw_dataDestination of at least neq_f*nphi values.
[in]neq_fEquation extent.
[in]nphiToroidal extent and fastest flattened index.

◆ copy_from_fftw()

static void orb5x::FFTWrapper::copy_from_fftw ( fftw_complex *  fftw_data,
const Kokkos::View< Real *** > &  kokkos_data,
int  ns,
int  nchi,
int  nphi 
)
static

Copy real components from FFTW storage into a 3-D Kokkos View.

Parameters
[in]fftw_dataSource of ns*nchi*nphi complex values.
[out]kokkos_dataDestination [s][chi][phi].
[in]nsRadial extent.
[in]nchiPoloidal extent.
[in]nphiToroidal extent and fastest flattened index.

◆ copy_to_fftw()

static void orb5x::FFTWrapper::copy_to_fftw ( const Kokkos::View< Real *** > &  kokkos_data,
fftw_complex *  fftw_data,
int  ns,
int  nchi,
int  nphi 
)
static

Copy a real 3-D Kokkos View to complex FFTW host storage.

Parameters
[in]kokkos_dataSource [s][chi][phi].
[out]fftw_dataDestination of at least ns*nchi*nphi values; the imaginary component is set to zero.
[in]nsRadial extent.
[in]nchiPoloidal extent.
[in]nphiToroidal extent and fastest flattened index.

◆ destroy_plan()

static void orb5x::FFTWrapper::destroy_plan ( fftw_plan  plan)
static

Destroy a caller-owned FFTW plan when non-null.

Parameters
[in]planPlan to release; cached internal plans must not be passed.

Referenced by orb5x::destroy_plan().

◆ execute_backward()

static void orb5x::FFTWrapper::execute_backward ( fftw_plan  plan)
static

Execute a previously created FFTW backward plan.

Parameters
[in]planValid plan still bound to live planning buffers.

Referenced by orb5x::execute_backward().

◆ execute_forward()

static void orb5x::FFTWrapper::execute_forward ( fftw_plan  plan)
static

Execute a previously created FFTW forward plan.

Parameters
[in]planValid plan still bound to live planning buffers.

Referenced by orb5x::execute_forward().

◆ fft2bspl_2d()

static void orb5x::FFTWrapper::fft2bspl_2d ( const Kokkos::View< Complex ** > &  fft_data,
Kokkos::View< Real ** > &  bspl_data,
int  nchi,
int  nphi 
)
static

Compute the normalized real inverse of a full 2-D spectrum.

Parameters
[in]fft_dataComplex spectrum [chi mode][phi mode].
[out]bspl_dataReal part of the inverse [chi][phi].
[in]nchiPoloidal extent.
[in]nphiToroidal extent.
Note
Applies 1/(nchi*nphi) after FFTW's unnormalized backward transform.

Referenced by orb5x::fft2bspl_2d().

◆ fft2bspl_3d()

static void orb5x::FFTWrapper::fft2bspl_3d ( const Kokkos::View< Complex ** > &  fft_data,
Kokkos::View< Real *** > &  bspl_data,
int  ns,
int  nchi,
int  nphi,
int  neq_f,
const Kokkos::View< int ** > *  mmin_f = nullptr,
const Kokkos::View< int ** > *  mmax_f = nullptr,
bool  reconstruct_hermitian_toroidal = false,
const char *  trace_tag = nullptr 
)
static

Reconstruct real B-spline surfaces from packed Fourier modes.

Parameters
[in]fft_dataPacked coefficients [equation][phi mode] produced by bspl2fft_3d() or an equivalent solver.
[out]bspl_dataReal output [s][chi][phi]; untouched extents are zero.
[in]nsNumber of radial surfaces.
[in]nchiPoloidal inverse-transform extent.
[in]nphiToroidal inverse-transform extent.
[in]neq_fPacked equation count.
[in]mmin_fOptional first poloidal mode [s][phi].
[in]mmax_fCompanion metadata enabling selected-mode unpacking; currently not used to set the packed width.
[in]reconstruct_hermitian_toroidalIf true and the full toroidal extent is active, fill negative (m,n) modes by complex conjugacy so the inverse represents a real field.
[in]trace_tagOptional label enabling pre/post reconstruction traces for radial surface zero.

No scale is applied after FFTW's backward transform because the matching 3-D forward routine already applies the reciprocal transform size.

Referenced by orb5x::fft2bspl_3d().

◆ init_1d_backward()

static void orb5x::FFTWrapper::init_1d_backward ( int  n,
fftw_plan &  plan_backward,
fftw_complex *  in,
fftw_complex *  out 
)
static

Create an unnormalized 1-D backward complex FFTW plan.

Parameters
[in]nTransform length.
[out]plan_backwardNewly allocated plan owned by the caller.
[in,out]inPlanning/execution input buffer of at least n values.
[out]outPlanning/execution output buffer of at least n values.

Referenced by orb5x::init_1d_backward().

◆ init_1d_forward()

static void orb5x::FFTWrapper::init_1d_forward ( int  n,
fftw_plan &  plan_forward,
fftw_complex *  in,
fftw_complex *  out 
)
static

Create an unnormalized 1-D forward complex FFTW plan.

Parameters
[in]nTransform length.
[out]plan_forwardNewly allocated plan owned by the caller.
[in,out]inPlanning/execution input buffer of at least n values.
[out]outPlanning/execution output buffer of at least n values.

Referenced by orb5x::init_1d_forward().

◆ init_2d_backward()

static void orb5x::FFTWrapper::init_2d_backward ( int  nchi,
int  nphi,
fftw_plan &  plan_backward,
fftw_complex *  in,
fftw_complex *  out 
)
static

Create an unnormalized backward FFT over (chi,phi).

Parameters
[in]nchiPoloidal transform length.
[in]nphiToroidal transform length and fastest flattened dimension.
[out]plan_backwardNewly allocated plan owned by the caller.
[in,out]inBuffer of at least nchi*nphi complex values.
[out]outBuffer of at least nchi*nphi complex values.

Referenced by orb5x::init_2d_backward().

◆ init_2d_forward()

static void orb5x::FFTWrapper::init_2d_forward ( int  nchi,
int  nphi,
fftw_plan &  plan_forward,
fftw_complex *  in,
fftw_complex *  out 
)
static

Create an unnormalized forward FFT over (chi,phi).

Parameters
[in]nchiPoloidal transform length.
[in]nphiToroidal transform length and fastest flattened dimension.
[out]plan_forwardNewly allocated plan owned by the caller.
[in,out]inBuffer of at least nchi*nphi complex values.
[out]outBuffer of at least nchi*nphi complex values.

Referenced by orb5x::init_2d_forward().


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