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

Functions

SurfaceGrid create_surface_grid (const BoxArray &ba_atm, const DistributionMapping &dm_atm, const Geometry &geom_atm, int C, const SurfaceCouplingNames &names)
 

Function Documentation

◆ create_surface_grid()

SurfaceGrid create_surface_grid ( const BoxArray &  ba_atm,
const DistributionMapping &  dm_atm,
const Geometry &  geom_atm,
int  C,
const SurfaceCouplingNames &  names 
)
14 {
16  (names.tag() + " Building the " + names.grid() + ": " + names.key("grid_ratio")
17  + " must be >= 1").c_str());
18  SurfaceGrid sg;
19  sg.C = C;
20 
21  // Step 1: the k = 0 slab of each atmospheric box, in the order of ba_atm, so
22  // that surface box n refines atmospheric box n. The k index here is the
23  // surface grid's own single layer.
24  Vector<Box> box_list_2d;
25  for (int i = 0; i < ba_atm.size(); ++i) {
26  Box b = ba_atm[i];
27  b.setSmall(2, 0);
28  b.setBig(2, 0);
29  box_list_2d.push_back(b);
30  }
31  BoxList bl_2d(std::move(box_list_2d));
32  BoxArray ba_2d(bl_2d);
33 
34  // Step 2: the region the grid covers, the bounding rectangle of the level's
35  // boxes: the domain on level 0, the refined region on a finer level. The
36  // grid treats the region's edges as its domain edges, so the boxes must
37  // cover it without holes (verify_surface_grid_level says so first with the
38  // inputs to change).
39  const Box region = ba_2d.minimalBox();
40  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(region.numPts() == ba_2d.numPts(),
41  (names.tag() + " Building the " + names.grid()
42  + ": the boxes of the atmospheric level do not form one rectangle").c_str());
43  const IntVect atm_lo(region.smallEnd(0), region.smallEnd(1), 0);
44 
45  // Step 3: shift to the region's corner and refine by {C, C, 1}. The grid's
46  // index space starts at zero there, as every AMReX Geometry does, so
47  // positions from ProbLo + (i + 1/2) dx and the plotfile header are those of
48  // the region as they stand; only the map back to the atmosphere adds
49  // atm_lo. refine() and shift() keep the number and order of the boxes, so
50  // dm_atm maps identically (box n of the grid is owned by the rank of
51  // atmospheric box n).
52  BoxArray ba_surf = ba_2d;
53  ba_surf.shift(-atm_lo);
54  ba_surf.refine(IntVect(C, C, 1));
55 
56  // Step 4: the 2D Geometry over the region. Where the region spans the
57  // domain the domain's own bounds are used; elsewhere the bounds are the
58  // atmospheric cell faces at the region's edges. The grid inherits the
59  // atmospheric periodicity in x and y where the region spans the domain, so
60  // FillBoundary exchanges across a periodic seam; a region narrower than the
61  // domain has edges of its own and is not periodic there.
62  const Box& dom_atm = geom_atm.Domain();
63  Box surf_domain(IntVect(0, 0, 0),
64  IntVect(region.length(0) * C - 1, region.length(1) * C - 1, 0));
65 
66  Array<Real, AMREX_SPACEDIM> lo {geom_atm.ProbLo(0), geom_atm.ProbLo(1), geom_atm.ProbLo(2)};
67  Array<Real, AMREX_SPACEDIM> hi {geom_atm.ProbHi(0), geom_atm.ProbHi(1), geom_atm.ProbLo(2) + Real(1.0)}; // z extent = 1 m (dummy)
68  Array<int, AMREX_SPACEDIM> is_per {0, 0, 0};
69  for (int d = 0; d < 2; ++d) {
70  const bool spans = (region.smallEnd(d) == dom_atm.smallEnd(d)) && (region.bigEnd(d) == dom_atm.bigEnd(d));
71  if (!spans) {
72  lo[d] = geom_atm.ProbLo(d) + Real(region.smallEnd(d) - dom_atm.smallEnd(d)) * geom_atm.CellSize(d);
73  hi[d] = geom_atm.ProbLo(d) + Real(region.bigEnd(d) - dom_atm.smallEnd(d) + 1) * geom_atm.CellSize(d);
74  }
75  is_per[d] = (spans && geom_atm.isPeriodic(d)) ? 1 : 0;
76  }
77  RealBox prob_domain_2d(lo, hi);
78 
79  sg.ba = ba_surf;
80  sg.dm = dm_atm;
81  sg.geom = Geometry(surf_domain, prob_domain_2d, CoordSys::cartesian, is_per);
82  sg.atm_lo = atm_lo;
83  return sg;
84 }
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
std::string tag() const
"[FIRE]"
Definition: ERF_SurfaceCouplingNames.H:24
std::string grid() const
"fire grid"
Definition: ERF_SurfaceCouplingNames.H:28
std::string key(const std::string &k) const
"erf.fire." followed by key
Definition: ERF_SurfaceCouplingNames.H:26
2D horizontal surface grid
Definition: ERF_SurfaceGrid.H:34
amrex::Geometry geom
2D Geometry in physical coordinates [m]
Definition: ERF_SurfaceGrid.H:37
amrex::IntVect atm_lo
Definition: ERF_SurfaceGrid.H:43
amrex::BoxArray ba
2D BoxArray (C*nx x C*ny x 1), box n refines atmospheric box n
Definition: ERF_SurfaceGrid.H:35
amrex::DistributionMapping dm
The atmospheric level's owners.
Definition: ERF_SurfaceGrid.H:36
int C
Definition: ERF_SurfaceGrid.H:38

Referenced by create_fire_grid(), and create_flood_grid().

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