ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SurfacePrerequisites.cpp File Reference
#include <ERF_SurfacePrerequisites.H>
#include <ERF.H>
#include <AMReX_ParmParse.H>
#include <string>
Include dependency graph for ERF_SurfacePrerequisites.cpp:

Functions

int surface_anchor_level (int anchor_level, int finest_level, const SurfaceCouplingNames &names)
 The level the surface grid refines: anchor_level, or the finest level when it is -1. Aborts, naming erf.<coupling>.anchor_level, when it is above the finest level. More...
 
void verify_surface_precip_source (const std::string &engine_name, const SurfacePrecipAccumulationSources &sources, const std::string &what, const SurfaceCouplingNames &names)
 Aborts, naming erf.moisture_model, when no microphysics surface precipitation accumulator exists for an engine that reads it. More...
 
void verify_surface_grid_level (const ERF &erf, int lev, const SurfaceCouplingNames &names)
 The checks on the level the surface grid refines, each naming the inputs to change. More...
 
void verify_surface_static_refinement (int lev, const std::string &pp_prefix, const SurfaceCouplingNames &names)
 Check 2 of verify_surface_grid_level: above level 0 the level must keep its boxes. More...
 

Function Documentation

◆ surface_anchor_level()

int surface_anchor_level ( int  anchor_level,
int  finest_level,
const SurfaceCouplingNames &  names 
)

The level the surface grid refines: anchor_level, or the finest level when it is -1. Aborts, naming erf.<coupling>.anchor_level, when it is above the finest level.

11 {
12  const int lev = (anchor_level < 0) ? finest_level : anchor_level;
13  if (lev > finest_level) {
14  Abort(names.tag() + " " + names.key("anchor_level") + " = " + std::to_string(anchor_level)
15  + " is above the finest level of this run (" + std::to_string(finest_level)
16  + "). Set it to a level from 0 to " + std::to_string(finest_level)
17  + ", or leave it unset for the finest level.");
18  }
19  return lev;
20 }
std::string tag() const
"[FIRE]"
Definition: ERF_SurfaceCouplingNames.H:24
std::string key(const std::string &k) const
"erf.fire." followed by key
Definition: ERF_SurfaceCouplingNames.H:26

Referenced by fire_anchor_level(), and flood_anchor_level().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_surface_grid_level()

void verify_surface_grid_level ( const ERF &  erf,
int  lev,
const SurfaceCouplingNames &  names 
)

The checks on the level the surface grid refines, each naming the inputs to change.

  1. The level exists (0 to the finest level).
  2. Above level 0, the level keeps its boxes (regrid_int <= 0, read with ERF's own ParmParse prefix): the grid is built once (verify_surface_static_refinement).
  3. Every box spans the level's full height: the grid pairs one surface slab with each box, and reads whole columns.
  4. The boxes cover one rectangle: the grid treats its edges as domain edges.
  5. The level's domain starts at index 0 (the map i / C + atm_lo assumes it).
42 {
43  const std::string tag = names.tag();
44  const std::string grid = names.grid();
45 
46  // Check 1: the level the grid refines exists. surface_anchor_level()
47  // resolves the input and aborts above the finest level; this is the
48  // backstop for any other caller.
49  if (lev < 0 || lev > erf.finestLevel()) {
50  Abort(tag + " Internal error: the " + grid + "'s level " + std::to_string(lev)
51  + " is outside 0.." + std::to_string(erf.finestLevel()));
52  }
53 
54  // Check 2: static refinement, with regrid_int read the way ERF reads it
56 
57  // Check 3: no z decomposition. The grid pairs one surface slab with each
58  // box of the level.
59  const BoxArray& ba = erf.boxArray(lev);
60  const Box& domain = erf.Geom(lev).Domain();
61  const int domain_nz = domain.length(2);
62  for (int i = 0; i < ba.size(); ++i) {
63  if (ba[i].length(2) != domain_nz) {
64  Abort(tag + " Cannot decompose in z direction. Every box on level " + std::to_string(lev)
65  + " must span the level's full height, since the " + grid + " pairs one surface slab "
66  "with each box: leave amr.no_box_split_dir at its default "
67  "of 2, or set amr.max_grid_size_z to at least " + std::to_string(domain_nz)
68  + ", and on a refined level use a refinement box that reaches the domain top "
69  "(erf.<box>.in_box_hi without a z bound)");
70  }
71  }
72 
73  // Check 4: the boxes cover one rectangle. The grid treats the edges of
74  // their bounding rectangle as its domain edges and fills its ghost cells
75  // there; a hole or a second patch would leave cells with no neighbor data.
76  {
77  BoxList bl_2d;
78  for (int i = 0; i < ba.size(); ++i) {
79  Box b = ba[i];
80  b.setSmall(2, 0);
81  b.setBig(2, 0);
82  bl_2d.push_back(b);
83  }
84  const BoxArray ba_2d(std::move(bl_2d));
85  const Box region = ba_2d.minimalBox();
86  if (region.numPts() != ba_2d.numPts()) {
87  Abort(tag + " The boxes of level " + std::to_string(lev) + " cover "
88  + std::to_string(ba_2d.numPts()) + " of the " + std::to_string(region.numPts())
89  + " columns of their bounding rectangle, but the " + grid + " needs one rectangle. "
90  "Refine one rectangle on that level (a single refinement box), or set "
91  + names.key("anchor_level") + " to a level whose boxes form one.");
92  }
93  }
94 
95  // Check 5: a zero-based domain. A surface cell maps back to its
96  // atmospheric cell by i_a = i_s / C + atm_lo (ERF_SurfaceGrid.H), and
97  // create_surface_grid() takes the region's physical position from ProbLo
98  // plus its index offset from the domain's corner. Every AMReX level has a
99  // zero-based domain, so this asserts the convention rather than relying on
100  // it silently.
101  if (domain.smallEnd(0) != 0 || domain.smallEnd(1) != 0 || domain.smallEnd(2) != 0) {
102  Abort(tag + " Internal error: the " + names.lower
103  + " coupling needs a level domain that starts at index 0");
104  }
105 }
const Real length
Definition: ERF_InitCustomPert_AnelasticWallDiffusion.H:16
void verify_surface_static_refinement(int lev, const std::string &pp_prefix, const SurfaceCouplingNames &names)
Check 2 of verify_surface_grid_level: above level 0 the level must keep its boxes.
Definition: ERF_SurfacePrerequisites.cpp:108
std::string pp_prefix
Definition: ERF.H:1259
std::string grid() const
"fire grid"
Definition: ERF_SurfaceCouplingNames.H:28
const char * lower
"fire": input prefix erf.<lower>, "the <lower> grid", "<lower> engine"
Definition: ERF_SurfaceCouplingNames.H:19

Referenced by verify_fire_prerequisites(), and verify_flood_prerequisites().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_surface_precip_source()

void verify_surface_precip_source ( const std::string &  engine_name,
const SurfacePrecipAccumulationSources &  sources,
const std::string &  what,
const SurfaceCouplingNames &  names 
)

Aborts, naming erf.moisture_model, when no microphysics surface precipitation accumulator exists for an engine that reads it.

Parameters
[in]whatWhat the engine takes from the accumulators, for the message ("rain", "precipitation")
27 {
28  if (surface_precip_has_any_source(sources)) { return; }
29  std::string moisture_model = "None";
30  ParmParse pp_erf("erf");
31  pp_erf.query("moisture_model", moisture_model);
32  Abort(names.tag() + " The " + names.lower + " engine \"" + engine_name + "\" takes the " + what
33  + " of every column from the microphysics surface precipitation accumulators, but "
34  "erf.moisture_model = \"" + moisture_model
35  + "\" provides none (Kessler, SAM, Morrison, WSM6 and WDM6 with precipitation do; Kessler_NoRain, "
36  "SatAdj, MoistNoCondensation and None do not). Choose one of those, or set the engine's inputs so "
37  "it does not read the " + what + ".");
38 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool surface_precip_has_any_source(const SurfacePrecipAccumulationSources &src) noexcept
Definition: ERF_SurfacePrecipitation.H:68

Referenced by verify_fire_precip_source(), and verify_flood_precip_source().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_surface_static_refinement()

void verify_surface_static_refinement ( int  lev,
const std::string &  pp_prefix,
const SurfaceCouplingNames &  names 
)

Check 2 of verify_surface_grid_level: above level 0 the level must keep its boxes.

Parameters
[in]levThe level the surface grid refines
[in]pp_prefixThe ParmParse prefix ERF reads regrid_int with (ERF::pp_prefix: "erf", or a MultiBlock block's own)
[in]namesThe coupling's names, for the message
109 {
110  // The grid is built once from the boxes of its level, so the level must
111  // keep its boxes for the whole run. Level 0 never regrids. ERF reads
112  // regrid_int with its own prefix (ERF::ReadParameters), which a MultiBlock
113  // block sets to its own name.
114  if (lev == 0) { return; }
115  ParmParse pp(pp_prefix);
116  int regrid_int = -1;
117  pp.query("regrid_int", regrid_int);
118  if (regrid_int > 0) {
119  const std::string key = pp_prefix + ".regrid_int";
120  Abort(names.tag() + " The " + names.grid() + " on level " + std::to_string(lev)
121  + " is built once from that level's boxes, so the refinement must not change, but "
122  + key + " = " + std::to_string(regrid_int) + " regrids it. Use static refinement "
123  "boxes with " + key + " = -1, or set " + names.key("anchor_level") + " = 0.");
124  }
125 }
ParmParse pp("prob")

Referenced by verify_surface_grid_level().

Here is the call graph for this function:
Here is the caller graph for this function: