Skip to content

Commit

Permalink
FFT-based Poisson solver follow-up (ECP-WarpX#4945)
Browse files Browse the repository at this point in the history
* changed  2

* add assert to check fft compilation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update Source/ablastr/fields/PoissonSolver.H

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>

* Update Source/ablastr/fields/PoissonSolver.H

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
  • Loading branch information
3 people authored May 31, 2024
1 parent b954937 commit bfffedf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Source/FieldSolver/ElectrostaticSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ WarpX::computePhi (const amrex::Vector<std::unique_ptr<amrex::MultiFab> >& rho,
const std::optional<amrex::Vector<amrex::FArrayBoxFactory const *> > eb_farray_box_factory;
#endif

bool const is_solver_multigrid =
WarpX::poisson_solver_id != PoissonSolverAlgo::IntegratedGreenFunction;
bool const is_solver_igf_on_lev0 =
WarpX::poisson_solver_id == PoissonSolverAlgo::IntegratedGreenFunction;

ablastr::fields::computePhi(
sorted_rho,
Expand All @@ -397,7 +397,7 @@ WarpX::computePhi (const amrex::Vector<std::unique_ptr<amrex::MultiFab> >& rho,
this->dmap,
this->grids,
this->m_poisson_boundary_handler,
is_solver_multigrid,
is_solver_igf_on_lev0,
WarpX::do_single_precision_comms,
this->ref_ratio,
post_phi_calculation,
Expand Down
16 changes: 13 additions & 3 deletions Source/ablastr/fields/PoissonSolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace ablastr::fields {
* \param[in] dmap the distribution mapping per level (e.g., from AmrMesh)
* \param[in] grids the grids per level (e.g., from AmrMesh)
* \param[in] boundary_handler a handler for boundary conditions, for example @see ElectrostaticSolver::PoissonBoundaryHandler
* \param[in] is_solver_multigrid boolean to select the Poisson solver: 1 for Multigrid, 0 for FFT
* \param[in] is_solver_igf_on_lev0 boolean to select the Poisson solver: 1 for FFT on level 0 & Multigrid on other levels, 0 for Multigrid on all levels
* \param[in] do_single_precision_comms perform communications in single precision
* \param[in] rel_ref_ratio mesh refinement ratio between levels (default: 1)
* \param[in] post_phi_calculation perform a calculation per level directly after phi was calculated; required for embedded boundaries (default: none)
Expand All @@ -106,7 +106,7 @@ computePhi (amrex::Vector<amrex::MultiFab*> const & rho,
amrex::Vector<amrex::DistributionMapping> const& dmap,
amrex::Vector<amrex::BoxArray> const& grids,
T_BoundaryHandler const boundary_handler,
[[maybe_unused]] bool is_solver_multigrid,
bool is_solver_igf_on_lev0,
bool const do_single_precision_comms = false,
std::optional<amrex::Vector<amrex::IntVect> > rel_ref_ratio = std::nullopt,
[[maybe_unused]] T_PostPhiCalculationFunctor post_phi_calculation = std::nullopt,
Expand Down Expand Up @@ -160,9 +160,19 @@ computePhi (amrex::Vector<amrex::MultiFab*> const & rho,
{{ beta[0], beta[1], beta[2] }};
#endif

#if !defined(WARPX_USE_FFT)
ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE( !is_solver_igf_on_lev0,
"Must compile with -DWarpX_FFT=ON to use the FFT solver!");
#endif

#if !defined(WARPX_DIM_3D)
ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE( !is_solver_igf_on_lev0,
"The FFT Poisson solver is currently only implemented for 3D!");
#endif

#if (defined(WARPX_USE_FFT) && defined(WARPX_DIM_3D))
// Use the Integrated Green Function solver (FFT) on the coarsest level if it was selected
if(!is_solver_multigrid && lev==0){
if(is_solver_igf_on_lev0 && lev==0){
amrex::Array<amrex::Real,AMREX_SPACEDIM> const dx_igf
{AMREX_D_DECL(geom[lev].CellSize(0)/std::sqrt(1._rt-beta_solver[0]*beta_solver[0]),
geom[lev].CellSize(1)/std::sqrt(1._rt-beta_solver[1]*beta_solver[1]),
Expand Down

0 comments on commit bfffedf

Please sign in to comment.