90inline const auto &get_real_box(
const FFTLayout &layout,
int i) {
94inline const auto &get_complex_box(
const FFTLayout &layout,
int i) {
98inline auto get_r2c_direction(
const FFTLayout &layout) {
105using pfc::types::Real3;
108using RealVector = std::vector<double>;
109using ComplexVector = std::vector<std::complex<double>>;
115#if defined(OpenPFC_ENABLE_CUDA)
135#if defined(OpenPFC_ENABLE_CUDA)
141 virtual ~IFFT() =
default;
159 virtual void reset_fft_time() = 0;
160 virtual double get_fft_time()
const = 0;
162 virtual size_t size_inbox()
const = 0;
163 virtual size_t size_outbox()
const = 0;
164 virtual size_t size_workspace()
const = 0;
248template <
typename BackendTag = heffte::backend::fftw>
struct FFT_Impl :
IFFT {
307 template <
typename RealBackendTag,
typename ComplexBackendTag,
typename RealType>
310 static_assert(std::is_same_v<RealBackendTag, ComplexBackendTag>,
311 "Input and output must use the same backend");
316 std::complex<RealType>>(
m_fft.size_workspace());
325 if constexpr (std::is_same_v<BackendTag, heffte::backend::fftw>) {
332 throw std::runtime_error(
333 "GPU FFT requires DataBuffer, not std::vector. Use forward(DataBuffer, "
334 "DataBuffer) instead.");
381 template <
typename ComplexBackendTag,
typename RealBackendTag,
typename RealType>
385 static_assert(std::is_same_v<ComplexBackendTag, RealBackendTag>,
386 "Input and output must use the same backend");
391 std::complex<RealType>>(
m_fft.size_workspace());
400 if constexpr (std::is_same_v<BackendTag, heffte::backend::fftw>) {
407 throw std::runtime_error(
408 "GPU FFT requires DataBuffer, not std::vector. Use backward(DataBuffer, "
409 "DataBuffer) instead.");
461 return m_wrk.size() *
sizeof(
typename workspace_type::value_type);
470template <
typename BackendTag>
475template <
typename BackendTag>
476inline auto get_inbox(
const FFT_Impl<BackendTag> &fft)
noexcept {
477 return get_fft_object(fft).inbox();
480template <
typename BackendTag>
481inline auto get_outbox(
const FFT_Impl<BackendTag> &fft)
noexcept {
482 return get_fft_object(fft).outbox();
485using heffte::plan_options;
486using layout::FFTLayout;
std::array< int, 3 > Int3
Type aliases for clarity.
Definition types.hpp:45
Backend-agnostic memory buffer with tag-based dispatch.
Domain decomposition for parallel MPI simulations.
std::unique_ptr< IFFT > create_with_backend(const FFTLayout &fft_layout, int rank_id, plan_options options, Backend backend)
Creates an FFT object with runtime backend selection.
heffte::box3d< int > box3di
Type alias for 3D integer box.
Definition fft.hpp:110
Backend
FFT backend selection.
Definition fft.hpp:128
@ FFTW
CPU-based FFT using FFTW (default)
@ CUDA
GPU-based FFT using cuFFT (requires CUDA support)
heffte::fft3d_r2c< heffte::backend::fftw > fft_r2c
FFTW backend (CPU)
Definition fft.hpp:134
Adapter functions for HeFFTe library integration.
K-space (Fourier space) helper functions for spectral methods.
Backend-agnostic memory buffer.
Definition databuffer.hpp:68
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
void reset_fft_time() override
Resets the recorded FFT computation time to zero.
Definition fft.hpp:416
size_t size_inbox() const override
Returns the associated Decomposition object.
Definition fft.hpp:437
void forward(const RealVector &in, ComplexVector &out) override
Performs the forward FFT transformation.
Definition fft.hpp:324
size_t size_outbox() const override
Returns the size of the outbox used for FFT computations.
Definition fft.hpp:444
double m_fft_time
Definition fft.hpp:255
size_t size_workspace() const override
Returns the size of the workspace used for FFT computations.
Definition fft.hpp:451
const fft_type m_fft
Definition fft.hpp:254
void backward(const ComplexVector &in, RealVector &out) override
Performs the backward (inverse) FFT transformation.
Definition fft.hpp:399
FFT_Impl(fft_type fft)
Constructs an FFT object with the given HeFFTe FFT object.
Definition fft.hpp:269
double get_fft_time() const override
Returns the recorded FFT computation time.
Definition fft.hpp:423
workspace_type m_wrk
Definition fft.hpp:262
size_t get_allocated_memory_bytes() const override
Returns the total memory allocated by HeFFTe in bytes.
Definition fft.hpp:460
virtual void backward(const ComplexVector &in, RealVector &out)=0
Performs the backward (inverse) FFT transformation.
virtual void forward(const RealVector &in, ComplexVector &out)=0
Performs the forward FFT transformation.
virtual size_t get_allocated_memory_bytes() const =0
Returns the total memory allocated by HeFFTe in bytes.
Structure to hold the layout of FFT data.
Definition fft.hpp:72
const Decomposition m_decomposition
The Decomposition object.
Definition fft.hpp:73
const std::vector< heffte::box3d< int > > m_complex_boxes
Complex boxes for FFT.
Definition fft.hpp:76
const int m_r2c_direction
Real-to-complex symmetry direction.
Definition fft.hpp:74
const std::vector< heffte::box3d< int > > m_real_boxes
Real boxes for FFT.
Definition fft.hpp:75
Represents the global simulation domain (the "world").
Definition world.hpp:91
World(const Int3 &lower, const Int3 &upper, const CoordinateSystem< T > &cs)
Constructs a World object.
World class definition and unified interface.