Skip to content

Commit 0e1af39

Browse files
committed
Documentation
1 parent 424f704 commit 0e1af39

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. role:: cpp(code)
2+
:language: c++
3+
4+
.. _sec:FFT:r2c:
5+
6+
FFT::R2C Class
7+
==============
8+
9+
Class template `FFT::R2C` supports discrete Fourier transforms between real
10+
and complex data. The name R2C indicates that the forward transform converts
11+
real data to complex data, while the backward transform converts complex
12+
data to real data. It should be noted that both directions of transformation
13+
are supported, not just from real to complex.
14+
15+
The implementation utilizes cuFFT, rocFFT, oneMKL and FFTW, for CUDA, HIP,
16+
SYCL and CPU builds, respectively. Because the parallel communication is
17+
handled by AMReX, it does not need the parallel version of
18+
FFTW. Furthermore, there is no constraint on the domain decomposition such
19+
as one Box per process. This class performs parallel FFT on AMReX's parallel
20+
data containers (e.g., :cpp:`MultiFab` and
21+
:cpp:`FabArray<BaseFab<ComplexData<Real>>>`. For local FFT, the users can
22+
use FFTW, cuFFT, rocFFT, or oneMKL directly.
23+
24+
The scaling follows the FFTW convention, where applying the forward
25+
transform followed by the backward transform scales the original data by the
26+
size of the input array. The layout of the complex data also follows the
27+
FFTW convention, where the complex Hermitian output array has
28+
`(nx/2+1,ny,nz)` elements. Here `nx`, `ny` and `nz` are the sizes of the
29+
real array and the division is rounded down.
30+
31+
Below are examples of using :cpp:`FFT:R2C`.
32+
33+
.. highlight:: c++
34+
35+
::
36+
37+
Geometry geom(...);
38+
MultiFab mfin(...);
39+
MultiFab mfout(...);
40+
41+
auto scaling = 1. / geom.Domain().d_numPts();
42+
43+
FFT::R2C r2c(geom.Domain());
44+
r2c.forwardThenBackward(mfin, mfout,
45+
[=] AMREX_GPU_DEVICE (int, int, int, auto& sp)
46+
{
47+
sp *= scaling;
48+
});
49+
50+
cMultiFab cmf(...);
51+
FFT::R2C<Real,FFT::Direction::forward> r2c_forward(geom.Domain());
52+
r2c_forward(mfin, cmf);
53+
54+
FFT::R2C<Real,FFT::Direction::backward> r2c_backward(geom.Domain());
55+
r2c_backward(cmf, mfout);
56+
57+
Note that using :cpp:`forwardThenBackward` is expected to be more efficient
58+
than separate calls to :cpp:`forward` and :cpp:`backward` because some
59+
parallel communication can be avoided.
60+
61+
62+
Poisson Solver
63+
==============
64+
65+
AMReX provides FFT based Poisson solvers. :cpp:`FFT::Poisson` supports all
66+
periodic boundaries using purely FFT. :cpp:`FFT::PoissonHybrid` is a 3D only
67+
solver that supports periodic boundaries in the first two dimensions and
68+
Neumann boundary in the last dimension.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. _Chap:FFT:
2+
3+
.. _sec:FFT:FFTOverview:
4+
5+
Discrete Fourier Transform
6+
==========================
7+
8+
AMReX provides support for parallel discrete Fourier transform. The
9+
implementation utilizes cuFFT, rocFFT, oneMKL and FFTW, for CUDA, HIP, SYCL
10+
and CPU builds, respectively. It also provides FFT based Poisson
11+
solvers.
12+
13+
.. toctree::
14+
:maxdepth: 1
15+
16+
FFT

Docs/sphinx_documentation/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Documentation on migration from BoxLib is available in the AMReX repository at D
5252
Fortran_Chapter
5353
Python_Chapter
5454
EB_Chapter
55+
FFT_Chapter
5556
TimeIntegration_Chapter
5657
GPU_Chapter
5758
Visualization_Chapter

Src/FFT/AMReX_FFT.H

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public:
4949
MultiFab, FabArray<BaseFab<T> > >;
5050
using cMF = FabArray<BaseFab<GpuComplex<T> > >;
5151

52+
/**
53+
* \brief Constructor
54+
*
55+
* \param domain the forward domain (i.e., the domain of the real data)
56+
* \param info optional information
57+
*/
5258
explicit R2C (Box const& domain, Info const& info = Info{});
5359

5460
~R2C ();
@@ -58,6 +64,25 @@ public:
5864
R2C& operator= (R2C const&) = delete;
5965
R2C& operator= (R2C &&) = delete;
6066

67+
/**
68+
* \brief Forward and then backward transform
69+
*
70+
* This function is available only when this class template is
71+
* instantiated for transforms in both directions. It's more efficient
72+
* than calling the forward function that stores the spectral data in a
73+
* caller provided container followed by the backward function, because
74+
* this can avoid parallel communication between the internal data and
75+
* the caller's data container.
76+
*
77+
* \param inmf input data in MultiFab or FabArray<BaseFab<float>>
78+
* \param outmf output data in MultiFab or FabArray<BaseFab<float>>
79+
* \param post_forward a callable object for processing the post-forward
80+
* data before the backward transform. Its interface
81+
* is `(int,int,int,GpuComplex<T>&)`, where the integers
82+
* are indices in the spectral space, and the reference
83+
* to the complex number allows for the modification of
84+
* the spectral data at that location.
85+
*/
6186
template <typename F, Direction DIR=D,
6287
std::enable_if_t<DIR == Direction::both, int> = 0>
6388
void forwardThenBackward (MF const& inmf, MF& outmf, F const& post_forward)
@@ -67,21 +92,65 @@ public:
6792
this->backward(outmf);
6893
}
6994

95+
/**
96+
* \brief Forward transform
97+
*
98+
* The output is stored in this object's internal data. This function is
99+
* not available when this class template is instantiated for
100+
* backward-only transform.
101+
*
102+
* \param inmf input data in MultiFab or FabArray<BaseFab<float>>
103+
*/
70104
template <Direction DIR=D, std::enable_if_t<DIR == Direction::forward ||
71105
DIR == Direction::both, int> = 0>
72106
void forward (MF const& inmf);
73107

108+
/**
109+
* \brief Forward transform
110+
*
111+
* This function is not available when this class template is
112+
* instantiated for backward-only transform.
113+
*
114+
* \param inmf input data in MultiFab or FabArray<BaseFab<float>>
115+
* \param outmf output data in FabArray<BaseFab<GpuComplex<T>>>
116+
*/
74117
template <Direction DIR=D, std::enable_if_t<DIR == Direction::forward ||
75118
DIR == Direction::both, int> = 0>
76119
void forward (MF const& inmf, cMF& outmf);
77120

121+
/**
122+
* \brief Backward transform
123+
*
124+
* This function is available only when this class template is
125+
* instantiated for transforms in both directions.
126+
*
127+
* \param outmf output data in MultiFab or FabArray<BaseFab<float>>
128+
*/
78129
template <Direction DIR=D, std::enable_if_t<DIR == Direction::both, int> = 0>
79130
void backward (MF& outmf);
80131

132+
/**
133+
* \brief Backward transform
134+
*
135+
* This function is not available when this class template is
136+
* instantiated for forward-only transform.
137+
*
138+
* \param inmf input data in FabArray<BaseFab<GpuComplex<T>>>
139+
* \param outmf output data in MultiFab or FabArray<BaseFab<float>>
140+
*/
81141
template <Direction DIR=D, std::enable_if_t<DIR == Direction::backward ||
82142
DIR == Direction::both, int> = 0>
83143
void backward (cMF const& inmf, MF& outmf);
84144

145+
/**
146+
* \brief Get the internal spectral data
147+
*
148+
* This function is not available when this class template is
149+
* instantiated for backward-only transform. For performance reasons,
150+
* the returned data array does not have the usual ordering of
151+
* `(x,y,z)`. The order is specified in the second part of the return
152+
* value.
153+
*/
85154
template <Direction DIR=D, std::enable_if_t<DIR == Direction::forward ||
86155
DIR == Direction::both, int> = 0>
87156
std::pair<cMF*,IntVect> getSpectralData ();

Src/FFT/AMReX_FFT_Poisson.H

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
namespace amrex::FFT
88
{
99

10+
/**
11+
* \brief Poisson solver for all periodic boundaries using FFT
12+
*/
1013
template <typename MF>
1114
class Poisson
1215
{
@@ -26,6 +29,10 @@ private:
2629
R2C<typename MF::value_type, Direction::both> m_r2c;
2730
};
2831

32+
/**
33+
* \brief 3D Poisson solver for periodic boundaries in the first two
34+
* dimensions and Neumann in the last dimension.
35+
*/
2936
template <typename MF>
3037
class PoissonHybrid
3138
{

0 commit comments

Comments
 (0)