From bfffedf5862fb180619567559b48d4e8aa7a0c6d Mon Sep 17 00:00:00 2001 From: Arianna Formenti Date: Thu, 30 May 2024 20:09:46 -0700 Subject: [PATCH] FFT-based Poisson solver follow-up (#4945) * 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 * Update Source/ablastr/fields/PoissonSolver.H Co-authored-by: Axel Huebl --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Axel Huebl --- Source/FieldSolver/ElectrostaticSolver.cpp | 6 +++--- Source/ablastr/fields/PoissonSolver.H | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp index a74beae3c91..3860bd55325 100644 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ b/Source/FieldSolver/ElectrostaticSolver.cpp @@ -382,8 +382,8 @@ WarpX::computePhi (const amrex::Vector >& rho, const std::optional > 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, @@ -397,7 +397,7 @@ WarpX::computePhi (const amrex::Vector >& 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, diff --git a/Source/ablastr/fields/PoissonSolver.H b/Source/ablastr/fields/PoissonSolver.H index 6b1cce415b4..e5340e825c9 100644 --- a/Source/ablastr/fields/PoissonSolver.H +++ b/Source/ablastr/fields/PoissonSolver.H @@ -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) @@ -106,7 +106,7 @@ computePhi (amrex::Vector const & rho, amrex::Vector const& dmap, amrex::Vector 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 > rel_ref_ratio = std::nullopt, [[maybe_unused]] T_PostPhiCalculationFunctor post_phi_calculation = std::nullopt, @@ -160,9 +160,19 @@ computePhi (amrex::Vector 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 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]),