ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
P3MFFTBackend.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <utils/Vector.hpp>
23
24#include <complex>
25#include <type_traits>
26
27/**
28 * @brief Abstract interface for the P3M reciprocal-space FFT.
29 *
30 * P3M only ever touches the FFT through this handful of methods: the k-space
31 * box geometry accessors and the forward/backward transforms. Concrete
32 * backends (heFFTe for the general/distributed case, kokkos-fft for the
33 * single-rank case) implement it, so the solver is agnostic to which one is
34 * active. The transform buffers are flat, contiguous, no-halo arrays; halo
35 * exchange is handled outside the FFT.
36 */
37template <typename FloatType, class FFTConfig> struct P3MFFTBackend {
38 using ComplexType = std::complex<FloatType>;
39 /**
40 * Real-space scalar type. P3M's real-space buffers (charge density, E-field)
41 * are physically real in both configs, so this is always @c FloatType. For a
42 * c2c backend (@c use_r2c=false) the imaginary part is dropped on the
43 * backward transform via heFFTe's real-output convenience overload, matching
44 * the pre-backend-interface behaviour where the templated forward/backward
45 * transforms of @c P3MFFT accepted real pointers for either config.
46 */
47 using RSpaceScalar = FloatType;
48
49 virtual ~P3MFFTBackend() = default;
50
51 /** @brief Lower-left corner of this rank's k-space box (global coords). */
53 /** @brief Upper-right corner (exclusive) of this rank's k-space box. */
55 /** @brief Extent of this rank's k-space box. */
56 virtual Utils::Vector3i ks_local_size() const = 0;
57 /** @brief Extent of this rank's real-space (no-halo) box. */
58 virtual Utils::Vector3i rs_local_size() const = 0;
59 /** @brief Persistent, transform-ready buffer for the caller to fill with the
60 * no-halo real-space input; holds product(rs_local_size()) elements. Passing
61 * it back as @ref forward's @c in lets a backend transform it in place. */
63 /** @brief Forward transform (real/complex charge density to k-space). */
64 virtual void forward(RSpaceScalar const *in, ComplexType *out) = 0;
65 /** @brief Backward transform (k-space field to real space).
66 * The input buffer is non-const by contract: a backend may destroy it
67 * during the transform (FFTW's multi-dimensional c2r has no
68 * preserve-input mode, so the kokkos-fft backend runs it in place).
69 * Callers must recompute the k-space input before reading it again.
70 */
71 virtual void backward(ComplexType *in, RSpaceScalar *out) = 0;
72};
Vector implementation and trait types for boost qvm interoperability.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Abstract interface for the P3M reciprocal-space FFT.
std::complex< FloatType > ComplexType
virtual Utils::Vector3i ks_local_ld_index() const =0
Lower-left corner of this rank's k-space box (global coords).
virtual RSpaceScalar * forward_input_buffer()=0
Persistent, transform-ready buffer for the caller to fill with the no-halo real-space input; holds pr...
virtual void forward(RSpaceScalar const *in, ComplexType *out)=0
Forward transform (real/complex charge density to k-space).
FloatType RSpaceScalar
Real-space scalar type.
virtual Utils::Vector3i ks_local_ur_index() const =0
Upper-right corner (exclusive) of this rank's k-space box.
virtual Utils::Vector3i ks_local_size() const =0
Extent of this rank's k-space box.
virtual void backward(ComplexType *in, RSpaceScalar *out)=0
Backward transform (k-space field to real space).
virtual Utils::Vector3i rs_local_size() const =0
Extent of this rank's real-space (no-halo) box.
virtual ~P3MFFTBackend()=default