Skip to content

Commit 5cee80d

Browse files
committed
FFT Poisson Solver: Neumann and Dirichlet Boundaries
Add support for Neumann and Dirichlet boundaries in the FFT based Poisson solver. This requires cosine and sine transforms. For CPU builds, we use FFTW for these transforms. But GPU builds, we have implemented cosine and sine transforms using the real-to-complex transform provided by cuFFT, rocFFT and oneMKL.
1 parent dc745bb commit 5cee80d

File tree

14 files changed

+2703
-1069
lines changed

14 files changed

+2703
-1069
lines changed

Docs/sphinx_documentation/source/FFT.rst

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,42 @@ object. Therefore, one should cache it for reuse if possible.
6464
Poisson Solver
6565
==============
6666

67-
AMReX provides FFT based Poisson solvers. :cpp:`FFT::Poisson` supports all
68-
periodic boundaries using purely FFT. :cpp:`FFT::PoissonHybrid` is a 3D only
69-
solver that supports periodic boundaries in the first two dimensions and
70-
Neumann boundary in the last dimension. Similar to :cpp:`FFT::R2C`, the
71-
Poisson solvers should be cached for reuse.
67+
AMReX provides FFT based Poisson solvers. :cpp:`FFT::Poisson` supports
68+
periodic (:cpp:`FFT::Boundary::periodic`), homogeneous Neumann
69+
(:cpp:`FFT::Boundary::even`), and homogeneous Dirichlet
70+
(:cpp:`FFT::Boundary::odd`) boundaries using FFT. Below is an example of
71+
using the solver.
72+
73+
.. highlight:: c++
74+
75+
::
76+
77+
Geometry geom(...);
78+
MultiFab soln(...);
79+
MultiFab rhs(...);
80+
81+
Array<std::pair<FFT::Boundary,FFT::Boundary>,AMREX_SPACEDIM>
82+
fft_bc{...};
83+
84+
bool has_dirichlet = false;
85+
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
86+
has_dirichlet = has_dirichlet ||
87+
fft_bc[idim].first == FFT::Boundary::odd ||
88+
fft_bc[idim].second == FFT::Boundary::odd;
89+
}
90+
if (! has_dirichlet) {
91+
// Shift rhs so that its sum is zero.
92+
auto rhosum = rhs.sum(0);
93+
rhs.plus(-rhosum/geom.Domain().d_numPts(), 0, 1);
94+
}
95+
96+
FFT::Poisson fft_poisson(geom, fft_bc);
97+
fft_poisson.solve(soln, rhs);
98+
99+
:cpp:`FFT::PoissonHybrid` is a 3D only solver that supports periodic
100+
boundaries in the first two dimensions and Neumann boundary in the last
101+
dimension. The last dimension is solved with a tridiagonal solver that can
102+
support non-uniform cell size in the z-direction. For most applications,
103+
:cpp:`FFT::Poisson` should be used.
104+
105+
Similar to :cpp:`FFT::R2C`, the Poisson solvers should be cached for reuse.

0 commit comments

Comments
 (0)