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
26/**
27 * @brief Abstract interface for the P3M reciprocal-space FFT.
28 *
29 * P3M only ever touches the FFT through this handful of methods: the k-space
30 * box geometry accessors and the forward/backward transforms. Concrete
31 * backends (heFFTe for the general/distributed case, kokkos-fft for the
32 * single-rank case) implement it, so the solver is agnostic to which one is
33 * active. The transform buffers are flat, contiguous, no-halo arrays; halo
34 * exchange is handled outside the FFT.
35 */
36template <typename FloatType, class FFTConfig> struct P3MFFTBackend {
37 using ComplexType = std::complex<FloatType>;
38 /**
39 * Real-space scalar type. P3M's real-space buffers (charge density, E-field)
40 * are physically real in both configs, so this is always @c FloatType. For a
41 * c2c backend (@c use_r2c=false) the imaginary part is dropped on the
42 * backward transform via heFFTe's real-output convenience overload, matching
43 * the pre-backend-interface behaviour where the templated forward/backward
44 * transforms of @c P3MFFT accepted real pointers for either config.
45 */
46 using RSpaceScalar = FloatType;
47
48 virtual ~P3MFFTBackend() = default;
49
50 /** @brief Lower-left corner of this rank's k-space box (global coords). */
52 /** @brief Upper-right corner (exclusive) of this rank's k-space box. */
54 /** @brief Extent of this rank's k-space box. */
55 virtual Utils::Vector3i ks_local_size() const = 0;
56 /** @brief Extent of this rank's real-space (no-halo) box. */
57 virtual Utils::Vector3i rs_local_size() const = 0;
58 /** @brief Persistent, transform-ready buffer for the caller to fill with the
59 * no-halo real-space input; holds product(rs_local_size()) elements. Passing
60 * it back as @ref forward's @c in lets a backend transform it in place. */
62 /** @brief Forward transform (real/complex charge density to k-space). */
63 virtual void forward(RSpaceScalar const *in, ComplexType *out) = 0;
64 /** @brief Backward transform (k-space field to real space).
65 * The input buffer is non-const by contract: a backend may destroy it
66 * during the transform (FFTW's multi-dimensional c2r has no
67 * preserve-input mode, so the kokkos-fft backend runs it in place).
68 * Callers must recompute the k-space input before reading it again.
69 */
70 virtual void backward(ComplexType *in, RSpaceScalar *out) = 0;
71 /** @brief Backward transform of @p n fields stored back to back in @p in
72 * (k-space size each) and @p out (real-space size each). Backends that
73 * have a faster batched transform override this default loop.
74 */
75 virtual void backward_batch(unsigned n, ComplexType *in, RSpaceScalar *out) {
76 auto const ks_size = Utils::product(ks_local_size());
77 auto const rs_size = Utils::product(rs_local_size());
78 for (auto i = 0u; i < n; ++i) {
79 backward(in + i * ks_size, out + i * rs_size);
80 }
81 }
82};
Vector implementation and trait types for boost qvm interoperability.
T product(Vector< T, N > const &v)
Definition Vector.hpp:379
VectorXi< 3 > Vector3i
Definition Vector.hpp:216
Abstract interface for the P3M reciprocal-space FFT.
virtual void backward_batch(unsigned n, ComplexType *in, RSpaceScalar *out)
Backward transform of n fields stored back to back in in (k-space size each) and out (real-space size...
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