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_MLMG.H>
#include <AMReX_MLPoisson.H>
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 0.

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

23 {
24  BL_PROFILE("ERF::solve_with_mlmg()");
25 
26  auto const dom_lo = lbound(geom.Domain());
27  auto const dom_hi = ubound(geom.Domain());
28 
29  LPInfo info;
30  // Allow a hidden direction if the domain is one cell wide in any lateral direction
31  if (dom_lo.x == dom_hi.x) {
32  info.setHiddenDirection(0);
33  } else if (dom_lo.y == dom_hi.y) {
34  info.setHiddenDirection(1);
35  }
36 
37  // Make sure the solver only sees the levels over which we are solving
38  Vector<BoxArray> ba_tmp; ba_tmp.push_back(rhs[0].boxArray());
39  Vector<DistributionMapping> dm_tmp; dm_tmp.push_back(rhs[0].DistributionMap());
40  Vector<Geometry> geom_tmp; geom_tmp.push_back(geom);
41 
42  auto bclo = get_lo_projection_bc(geom,domain_bc_type);
43  auto bchi = get_hi_projection_bc(geom,domain_bc_type);
44 
45  // amrex::Print() << "BCLO " << bclo[0] << " " << bclo[1] << " " << bclo[2] << std::endl;
46  // amrex::Print() << "BCHI " << bchi[0] << " " << bchi[1] << " " << bchi[2] << std::endl;
47 
48  // ****************************************************************************
49  // Multigrid solve
50  // ****************************************************************************
51 
52  MLPoisson mlpoisson(geom_tmp, ba_tmp, dm_tmp, info);
53  mlpoisson.setDomainBC(bclo, bchi);
54  if (lev > 0) {
55  mlpoisson.setCoarseFineBC(nullptr, ref_ratio[lev-1], LinOpBCType::Neumann);
56  }
57  mlpoisson.setLevelBC(0, nullptr);
58 
59  // Use low order for outflow at physical boundaries
60  mlpoisson.setMaxOrder(2);
61 
62  MLMG mlmg(mlpoisson);
63  int max_iter = 100;
64  mlmg.setMaxIter(max_iter);
65 
66  mlmg.setVerbose(mg_verbose);
67  mlmg.setBottomVerbose(0);
68 
69  mlmg.solve(GetVecOfPtrs(phi),
70  GetVecOfConstPtrs(rhs),
71  reltol, abstol);
72  mlmg.getFluxes(GetVecOfArrOfPtrs(fluxes));
73 
74  // ****************************************************************************
75  // Impose bc's on pprime
76  // ****************************************************************************
77  // ImposeBCsOnPhi(lev, phi[0], geom.Domain()));
78 }
const auto & dom_hi
Definition: ERF_SetupVertDiff.H:2
const auto & dom_lo
Definition: ERF_SetupVertDiff.H:1
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:13
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:34
Here is the call graph for this function: