ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SolveWithMLMG.cpp File Reference
#include "ERF.H"
#include "ERF_Utils.H"
#include "ERF_SolverUtils.H"
#include <AMReX_MLABecLaplacian.H>
#include <AMReX_MLMG.H>
#include <AMReX_MLPoisson.H>
#include <limits>
#include <memory>
#include <string>
Include dependency graph for ERF_SolveWithMLMG.cpp:

Functions

void solve_with_mlmg (int lev, Vector< MultiFab > &rhs, Vector< MultiFab > &phi, Vector< Array< MultiFab, AMREX_SPACEDIM >> &fluxes, const Geometry &geom, const Vector< IntVect > &ref_ratio, Array< std::string, 2 *AMREX_SPACEDIM > domain_bc_type, int mg_verbose, Real reltol, Real abstol)
 

Function Documentation

◆ solve_with_mlmg()

void solve_with_mlmg ( int  lev,
Vector< MultiFab > &  rhs,
Vector< MultiFab > &  phi,
Vector< Array< MultiFab, AMREX_SPACEDIM >> &  fluxes,
const Geometry &  geom,
const Vector< IntVect > &  ref_ratio,
Array< std::string, 2 *AMREX_SPACEDIM >  domain_bc_type,
int  mg_verbose,
Real  reltol,
Real  abstol 
)

Solve the Poisson equation using MLMG Note that the level may or may not be level zero

Important: we solve on the whole level even if there are disjoint regions

Parameters
levLevel index for the solve
rhsRight-hand side MultiFab vector
phiSolution MultiFab vector to fill
fluxesFace-centered gradient fluxes to fill
geomGeometry for the solve level
ref_ratioCoarse-fine refinement ratios
domain_bc_typeDomain boundary-condition names
mg_verboseMLMG verbosity level
reltolRelative solver tolerance
abstolAbsolute solver tolerance
131 {
132  BL_PROFILE("ERF::solve_with_mlmg()");
133 
134  auto const dom_lo = lbound(geom.Domain());
135  auto const dom_hi = ubound(geom.Domain());
136 
137  LPInfo info;
138  // Allow a hidden direction if the domain is one cell wide in any lateral direction
139  if (dom_lo.x == dom_hi.x) {
140  info.setHiddenDirection(0);
141  } else if (dom_lo.y == dom_hi.y) {
142  info.setHiddenDirection(1);
143  }
144 
145  // MLPoisson coarsens every direction by 2 on each MG level, so cells longer in some
146  // direction stay that anisotropic all the way down. Red-black Gauss-Seidel then smooths only
147  // along the short directions, and with piecewise-constant prolongation the coarse-grid
148  // correction overshoots the error left along the long ones: at a cell aspect ratio of 4 the
149  // V-cycle diverges (#5064). For anisotropic cells, coarsen the directions on their own.
150  const bool aniso = cells_are_anisotropic(geom, info);
151  if (aniso) {
152  info.setMaxCoarseningLevel(aniso_max_coarsening_level(geom, rhs[0].boxArray(), info));
153  }
154 
155  // Make sure the solver only sees the levels over which we are solving
156  Vector<BoxArray> ba_tmp; ba_tmp.push_back(rhs[0].boxArray());
157  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(rhs[0].DistributionMap());
158  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom);
159 
160  auto bclo = get_lo_projection_bc(geom,domain_bc_type);
161  auto bchi = get_hi_projection_bc(geom,domain_bc_type);
162 
163  // amrex::Print() << "BCLO " << bclo[0] << " " << bclo[1] << " " << bclo[2] << std::endl;
164  // amrex::Print() << "BCHI " << bchi[0] << " " << bchi[1] << " " << bchi[2] << std::endl;
165 
166  // ****************************************************************************
167  // Multigrid solve
168  // ****************************************************************************
169 
170  std::unique_ptr<MLPoisson> mlpoisson_ptr = aniso
171  ? std::make_unique<MLPoissonAniso>(geom_tmp, ba_tmp, dm_tmp, info)
172  : std::make_unique<MLPoisson>(geom_tmp, ba_tmp, dm_tmp, info);
173  MLPoisson& mlpoisson = *mlpoisson_ptr;
174  mlpoisson.setDomainBC(bclo, bchi);
175  if (lev > 0) {
176  mlpoisson.setCoarseFineBC(nullptr, ref_ratio[lev-1], LinOpBCType::Neumann);
177  }
178  mlpoisson.setLevelBC(0, nullptr);
179 
180  // Use low order for outflow at physical boundaries
181  mlpoisson.setMaxOrder(2);
182 
183  MLMG mlmg(mlpoisson);
184  int max_iter = 100;
185  mlmg.setMaxIter(max_iter);
186 
187  mlmg.setVerbose(mg_verbose);
188  mlmg.setBottomVerbose(0);
189 
190  mlmg.solve(GetVecOfPtrs(phi),
191  GetVecOfConstPtrs(rhs),
192  reltol, abstol);
193  mlmg.getFluxes(GetVecOfArrOfPtrs(fluxes));
194 
195  // ****************************************************************************
196  // Impose bc's on pprime
197  // ****************************************************************************
198  // ImposeBCsOnPhi(lev, phi[0], geom.Domain()));
199 }
Array< LinOpBCType, AMREX_SPACEDIM > get_lo_projection_bc(Geometry const &lev_geom, Array< std::string, 2 *AMREX_SPACEDIM > l_domain_bc_type)
Definition: ERF_SolverUtils.H:20
Array< LinOpBCType, AMREX_SPACEDIM > get_hi_projection_bc(Geometry const &lev_geom, Array< std::string, 2 *AMREX_SPACEDIM > l_domain_bc_type)
Definition: ERF_SolverUtils.H:48
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:176
Here is the call graph for this function: