ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
erf_terrain_file Namespace Reference

Classes

struct  HeightTable
 

Functions

std::string TableProblem (bool is_usgs, int nx, int ny, const Vector< Real > &x, const Vector< Real > &y, const Vector< Real > &z, const GpuArray< Real, AMREX_SPACEDIM > &prob_lo, const GpuArray< Real, AMREX_SPACEDIM > &prob_hi, bool require_domain_coverage)
 
std::string TableSummary (const std::string &fname, bool is_usgs, int nx, int ny, const Vector< Real > &x, const Vector< Real > &y, const Vector< Real > &z)
 
std::string MakeTablePeriodic (HeightTable &t, const GpuArray< Real, AMREX_SPACEDIM > &prob_lo, const GpuArray< Real, AMREX_SPACEDIM > &prob_hi, const Array< bool, 2 > &periodic, std::string &note)
 
const HeightTable & ReadHeightTable (const std::string &fname, bool is_usgs, const GpuArray< Real, AMREX_SPACEDIM > &prob_lo, const GpuArray< Real, AMREX_SPACEDIM > &prob_hi, bool require_domain_coverage, const Array< bool, 2 > &periodic)
 
Array< Real, 4 > FaceBandSlopes (const MultiFab &z_phys_nd, const MultiFab &mf_mx, const MultiFab &mf_my, const Geometry &geom, int band)
 
std::string OpenFaceSlopeWarning (int lev, int band, const Array< Real, 4 > &slopes, const Array< bool, 4 > &open, const Array< std::string, 4 > &bc_names)
 
const HeightTable & ReadHeightTable (const std::string &fname, bool is_usgs, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_lo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_hi, bool require_domain_coverage=true, const amrex::Array< bool, 2 > &periodic={false, false})
 
std::string MakeTablePeriodic (HeightTable &t, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_lo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_hi, const amrex::Array< bool, 2 > &periodic, std::string &note)
 
std::string TableProblem (bool is_usgs, int nx, int ny, const amrex::Vector< amrex::Real > &x, const amrex::Vector< amrex::Real > &y, const amrex::Vector< amrex::Real > &z, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_lo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_hi, bool require_domain_coverage=true)
 
std::string TableSummary (const std::string &fname, bool is_usgs, int nx, int ny, const amrex::Vector< amrex::Real > &x, const amrex::Vector< amrex::Real > &y, const amrex::Vector< amrex::Real > &z)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real CellTerrainSlope (int i, int j, int k, const amrex::Array4< const amrex::Real > &z_nd, amrex::Real mfx, amrex::Real mfy, amrex::Real dxinv, amrex::Real dyinv) noexcept
 
amrex::Array< amrex::Real, 4 > FaceBandSlopes (const amrex::MultiFab &z_phys_nd, const amrex::MultiFab &mf_mx, const amrex::MultiFab &mf_my, const amrex::Geometry &geom, int band)
 
std::string OpenFaceSlopeWarning (int lev, int band, const amrex::Array< amrex::Real, 4 > &slopes, const amrex::Array< bool, 4 > &open, const amrex::Array< std::string, 4 > &bc_names)
 

Variables

constexpr amrex::Real open_face_slope_warn = amrex::Real(0.3)
 

Function Documentation

◆ CellTerrainSlope()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_terrain_file::CellTerrainSlope ( int  i,
int  j,
int  k,
const amrex::Array4< const amrex::Real > &  z_nd,
amrex::Real  mfx,
amrex::Real  mfy,
amrex::Real  dxinv,
amrex::Real  dyinv 
)
noexcept

Physical slope |grad h| of the terrain over cell (i,j,k): the terrain drops of ComputeTerrainCellDrops (the same drops as the diffusive limits and the slope factor) times the map factor over the cell size in each direction.

Parameters
[in]i,j,kcell indices
[in]z_ndnodal heights
[in]mfx,mfymap factors of the cell
[in]dxinv,dyinvinverse horizontal cell sizes
196 {
197  const TerrainCellDrops d = ComputeTerrainCellDrops(i, j, k, z_nd);
198  const amrex::Real hx = mfx * dxinv * d.dx_drop;
199  const amrex::Real hy = mfy * dyinv * d.dy_drop;
200  return std::sqrt(hx*hx + hy*hy);
201 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE TerrainCellDrops ComputeTerrainCellDrops(int i, int j, int k, const amrex::Array4< const amrex::Real > &z_nd) noexcept
Definition: ERF_TerrainDiffusionLimits.H:44
Definition: ERF_TerrainDiffusionLimits.H:29
amrex::Real dy_drop
Definition: ERF_TerrainDiffusionLimits.H:31
amrex::Real dx_drop
Definition: ERF_TerrainDiffusionLimits.H:30

Referenced by FaceBandSlopes().

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

◆ FaceBandSlopes() [1/2]

amrex::Array<amrex::Real,4> erf_terrain_file::FaceBandSlopes ( const amrex::MultiFab &  z_phys_nd,
const amrex::MultiFab &  mf_mx,
const amrex::MultiFab &  mf_my,
const amrex::Geometry &  geom,
int  band 
)

Largest CellTerrainSlope, on one level, over the surface cells within band cells of each lateral domain face, in the order xlo, xhi, ylo, yhi; -1 for a face whose band holds no cell of this level. Reduced over all ranks.

Parameters
[in]z_phys_ndnodal heights of the level (surface at the domain's lowest k)
[in]mf_mxmap factor in x at cell centers (ERF's mapfac m_x, on ba2d)
[in]mf_mymap factor in y at cell centers (m_y)
[in]geomgeometry of the level
[in]bandwidth of the band in cells (>= 1)

◆ FaceBandSlopes() [2/2]

Array<Real,4> erf_terrain_file::FaceBandSlopes ( const MultiFab &  z_phys_nd,
const MultiFab &  mf_mx,
const MultiFab &  mf_my,
const Geometry &  geom,
int  band 
)
462 {
463  AMREX_ALWAYS_ASSERT(band >= 1);
464  const Box& dom = geom.Domain();
465  const int klo = dom.smallEnd(2);
466  const Real dxinv = geom.InvCellSize(0);
467  const Real dyinv = geom.InvCellSize(1);
468 
469  // The bands of cells next to each lateral face, at the surface only
470  Array<Box,4> bands;
471  for (int f = 0; f < 4; ++f) {
472  Box b(dom);
473  b.setRange(2, klo);
474  const int dir = f / 2;
475  if (f % 2 == 0) {
476  b.setBig(dir, amrex::min(dom.smallEnd(dir) + band - 1, dom.bigEnd(dir)));
477  } else {
478  b.setSmall(dir, amrex::max(dom.bigEnd(dir) - band + 1, dom.smallEnd(dir)));
479  }
480  bands[f] = b;
481  }
482 
483  Array<Real,4> smax{Real(-1.), Real(-1.), Real(-1.), Real(-1.)};
484  for (int f = 0; f < 4; ++f) {
485  ReduceOps<ReduceOpMax> reduce_op;
486  ReduceData<Real> reduce_data(reduce_op);
487  using ReduceTuple = typename decltype(reduce_data)::Type;
488  bool any = false;
489  for (MFIter mfi(z_phys_nd); mfi.isValid(); ++mfi) {
490  // z_phys_nd is nodal: its valid cells are the enclosed cells of the nodal box
491  const Box bx = enclosedCells(mfi.validbox()) & bands[f];
492  if (bx.isEmpty()) { continue; }
493  any = true;
494  const Array4<const Real> z_nd = z_phys_nd.const_array(mfi);
495  // the map factors live on the same boxes flattened to one k (ba2d)
496  const Array4<const Real> mfx = mf_mx.const_array(mfi);
497  const Array4<const Real> mfy = mf_my.const_array(mfi);
498  reduce_op.eval(bx, reduce_data, [=] AMREX_GPU_DEVICE (int i, int j, int k) -> ReduceTuple
499  {
500  return {CellTerrainSlope(i, j, k, z_nd, mfx(i,j,0), mfy(i,j,0), dxinv, dyinv)};
501  });
502  }
503  if (any) { smax[f] = amrex::get<0>(reduce_data.value(reduce_op)); }
504  }
505  ParallelDescriptor::ReduceRealMax(smax.data(), 4);
506  return smax;
507 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real CellTerrainSlope(int i, int j, int k, const amrex::Array4< const amrex::Real > &z_nd, amrex::Real mfx, amrex::Real mfy, amrex::Real dxinv, amrex::Real dyinv) noexcept
Definition: ERF_TerrainFileChecks.H:194

Referenced by ERF::WarnSteepTerrainAtOpenFaces().

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

◆ MakeTablePeriodic() [1/2]

std::string erf_terrain_file::MakeTablePeriodic ( HeightTable &  t,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  prob_lo,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  prob_hi,
const amrex::Array< bool, 2 > &  periodic,
std::string &  note 
)

Make an ERF-format height table periodic in each direction where periodic[d] is true, so that the terrain is the same on the two faces of the domain in that direction:

  • a table with points on both faces (to 1e-3 of the table spacing) must hold the same heights on the two faces, to 1e-6 of the largest |height| (at least 1e-6 m);
  • a table with points on one face only is extended to the other face with the heights of the face it has (a table with one height per node starting at prob_lo, say, gets the heights at prob_lo again at prob_hi). A direction with a single value is constant and needs nothing. A table with points on neither face is left as it is, with a note. Returns the problem (heights that differ on the two faces), or an empty string; note describes what was done, or is empty if nothing was.
Parameters
[in,out]ttable (must pass TableProblem with the domain coverage check)
[in]prob_lo,prob_hidomain extent
[in]periodicwhether x and y are periodic
[out]notewhat was done to the table, for the start-up output

◆ MakeTablePeriodic() [2/2]

std::string erf_terrain_file::MakeTablePeriodic ( HeightTable &  t,
const GpuArray< Real, AMREX_SPACEDIM > &  prob_lo,
const GpuArray< Real, AMREX_SPACEDIM > &  prob_hi,
const Array< bool, 2 > &  periodic,
std::string &  note 
)
187 {
188  note.clear();
189  Real zscale = Real(1.);
190  for (const auto& h : t.z) { zscale = amrex::max(zscale, std::abs(h)); }
191  const Real ztol = Real(1.e-6) * zscale;
192 
193  for (int d = 0; d < 2; ++d) {
194  const int n = (d == 0) ? t.nx : t.ny;
195  if (!periodic[d] || n == 1) { continue; }
196  Vector<Real>& v = (d == 0) ? t.x : t.y;
197  const char* name = (d == 0) ? "x" : "y";
198  const char* other = (d == 0) ? "y" : "x";
199  const Real lo = prob_lo[d];
200  const Real hi = prob_hi[d];
201  // A point on a face: within 1e-3 of the table spacing (and a few ulp), as in list_problem
202  const Real ulps = Real(8.) * std::numeric_limits<Real>::epsilon()
203  * amrex::max(std::abs(lo), std::abs(hi));
204  const bool on_lo = std::abs(v[0] - lo) <= Real(1.e-3)*(v[1] - v[0] ) + ulps;
205  const bool on_hi = std::abs(v[n-1] - hi) <= Real(1.e-3)*(v[n-1] - v[n-2]) + ulps;
206 
207  // Index of the height at point m in direction d and point o in the other direction
208  const int n_other = (d == 0) ? t.ny : t.nx;
209  auto idx = [&] (int m, int o) { return (d == 0) ? m*t.ny + o : o*t.ny + m; };
210  auto other_coord = [&] (int o) { return (d == 0) ? t.y[o] : t.x[o]; };
211 
212  std::ostringstream os;
213  if (on_lo && on_hi) {
214  // Heights on both faces: they must be the same
215  Real dmax = Real(0.);
216  int omax = 0;
217  for (int o = 0; o < n_other; ++o) {
218  const Real diff = std::abs(t.z[idx(0,o)] - t.z[idx(n-1,o)]);
219  if (diff > dmax) { dmax = diff; omax = o; }
220  }
221  if (dmax > ztol) {
222  os << name << " is periodic, but the heights on the two " << name << " faces differ: "
223  << t.z[idx(0,omax)] << " at " << name << " = " << v[0] << " and "
224  << t.z[idx(n-1,omax)] << " at " << name << " = " << v[n-1]
225  << " (" << other << " = " << other_coord(omax) << "), a difference of " << dmax
226  << " (allowed: " << ztol << "); a periodic domain needs the same terrain on both faces";
227  return os.str();
228  }
229  os << " " << name << " is periodic: the heights at " << name << " = " << v[0]
230  << " and " << name << " = " << v[n-1] << " agree\n";
231  note += os.str();
232  } else if ((on_lo && v[n-1] < hi) || (on_hi && v[0] > lo)) {
233  // Heights on one face only: give the other face the same heights
234  const int src = on_lo ? 0 : n-1;
235  const int nx_new = (d == 0) ? t.nx + 1 : t.nx;
236  const int ny_new = (d == 1) ? t.ny + 1 : t.ny;
237  Vector<Real> z_new(Long(nx_new) * Long(ny_new));
238  for (int i = 0; i < nx_new; ++i) {
239  for (int j = 0; j < ny_new; ++j) {
240  // the new point in direction d is the last (on_lo) or the first (on_hi)
241  const int m_new = (d == 0) ? i : j;
242  const int m_old = on_lo ? ((m_new == n) ? src : m_new)
243  : ((m_new == 0) ? src : m_new - 1);
244  const int i_old = (d == 0) ? m_old : i;
245  const int j_old = (d == 1) ? m_old : j;
246  z_new[i*ny_new + j] = t.z[i_old*t.ny + j_old];
247  }
248  }
249  t.z = z_new;
250  if (on_lo) {
251  v.push_back(hi);
252  } else {
253  v.insert(v.begin(), lo);
254  }
255  t.nx = nx_new;
256  t.ny = ny_new;
257  os << " " << name << " is periodic: no heights at " << name << " = "
258  << (on_lo ? hi : lo) << ", so the heights at " << name << " = "
259  << (on_lo ? v[0] : v[n]) << " are used there\n";
260  note += os.str();
261  } else {
262  os << " " << name << " is periodic, but the table (" << name << " = " << v[0] << " .. "
263  << v[n-1] << ") has no point on either face, or runs past one, of the domain "
264  << lo << " .. " << hi << "; its heights are used as they are\n";
265  note += os.str();
266  }
267  }
268  return "";
269 }
if(add_bubble)
Definition: ERF_InitCustomPert_ABL.H:60
const GpuArray< Real, AMREX_SPACEDIM > prob_lo
Definition: ERF_InitCustomPert_CloudChamber.H:34
const amrex::Real * prob_hi
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:17
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
@ t
Definition: ERF_WSM6.H:295
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
Here is the call graph for this function:

◆ OpenFaceSlopeWarning() [1/2]

std::string erf_terrain_file::OpenFaceSlopeWarning ( int  lev,
int  band,
const amrex::Array< amrex::Real, 4 > &  slopes,
const amrex::Array< bool, 4 > &  open,
const amrex::Array< std::string, 4 > &  bc_names 
)

Warning text for the inflow and outflow faces of one level whose band slope (from FaceBandSlopes) exceeds open_face_slope_warn, or an empty string if there is none. The caller prints it only when no steep-terrain option is on at that level.

Parameters
[in]levlevel, for the text
[in]bandband width in cells, for the text
[in]slopesband slopes in the order xlo, xhi, ylo, yhi (-1 = no cells)
[in]openwhether each face is an inflow or outflow face
[in]bc_namesboundary type of each face, for the text

◆ OpenFaceSlopeWarning() [2/2]

std::string erf_terrain_file::OpenFaceSlopeWarning ( int  lev,
int  band,
const Array< Real, 4 > &  slopes,
const Array< bool, 4 > &  open,
const Array< std::string, 4 > &  bc_names 
)
514 {
515  static const char* face_names[4] = {"xlo", "xhi", "ylo", "yhi"};
516  std::ostringstream os;
517  for (int f = 0; f < 4; ++f) {
518  if (open[f] && slopes[f] > open_face_slope_warn) {
519  os << "WARNING: at level " << lev << " the terrain slope |grad h| reaches " << slopes[f]
520  << " within " << band << " cells of the " << face_names[f] << " face ("
521  << bc_names[f] << "), above " << open_face_slope_warn << "\n";
522  }
523  }
524  if (os.str().empty()) { return ""; }
525  os << " Flattening the terrain within " << band << " cells of inflow and outflow faces avoids"
526  << " this. With an eddy-diffusivity closure, erf.smag2d_slope_limiter or"
527  << " erf.smag2d_kh_cap (Smagorinsky2D), erf.implicit_terrain_metric (needs"
528  << " erf.vert_implicit_fac > 0) or erf.diffusive_dt_limit limit the terrain-metric"
529  << " diffusion on steep cells; none of them is on here\n";
530  return os.str();
531 }
constexpr amrex::Real open_face_slope_warn
Definition: ERF_TerrainFileChecks.H:179

Referenced by ERF::WarnSteepTerrainAtOpenFaces().

Here is the caller graph for this function:

◆ ReadHeightTable() [1/2]

const HeightTable& erf_terrain_file::ReadHeightTable ( const std::string &  fname,
bool  is_usgs,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  prob_lo,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  prob_hi,
bool  require_domain_coverage = true,
const amrex::Array< bool, 2 > &  periodic = {false, false} 
)

The height table in file fname, read, checked (TableProblem) and summarized (TableSummary) on the I/O rank the first time the file is asked for, then broadcast; later calls return the same table without reading the file again. Aborts, naming the file and the line, on a file that cannot be read as the layout says.

Parameters
[in]fnamefile name
[in]is_usgsUSGS layout
[in]prob_lo,prob_hidomain extent, for the coverage check
[in]require_domain_coveragefalse for local building patches; all other checks remain
[in]periodicwhether x and y are periodic; the table is then made periodic in that direction (MakeTablePeriodic) after it has been checked

◆ ReadHeightTable() [2/2]

const HeightTable& erf_terrain_file::ReadHeightTable ( const std::string &  fname,
bool  is_usgs,
const GpuArray< Real, AMREX_SPACEDIM > &  prob_lo,
const GpuArray< Real, AMREX_SPACEDIM > &  prob_hi,
bool  require_domain_coverage,
const Array< bool, 2 > &  periodic 
)
443 {
444  // Include the coverage policy so a cached building patch cannot bypass the terrain check
445  // if the same file is subsequently requested as terrain, and the periodicity, which can
446  // add a row of heights to the table.
447  static std::map<std::string, HeightTable> tables;
448  const std::string key = std::string(require_domain_coverage ? "covered:" : "partial:")
449  + (periodic[0] ? "px:" : "") + (periodic[1] ? "py:" : "")
450  + (is_usgs ? "USGS:" : "ERF:") + fname;
451  auto it = tables.find(key);
452  if (it == tables.end()) {
453  it = tables.emplace(key, read_and_broadcast(fname, is_usgs, prob_lo, prob_hi,
454  require_domain_coverage, periodic)).first;
455  }
456  return it->second;
457 }

Referenced by ProblemBase::read_custom_terrain().

Here is the caller graph for this function:

◆ TableProblem() [1/2]

std::string erf_terrain_file::TableProblem ( bool  is_usgs,
int  nx,
int  ny,
const amrex::Vector< amrex::Real > &  x,
const amrex::Vector< amrex::Real > &  y,
const amrex::Vector< amrex::Real > &  z,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  prob_lo,
const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &  prob_hi,
bool  require_domain_coverage = true 
)

The first problem found in a height table, or an empty string if there is none. Problems: fewer points than the layout needs (ERF format: one in each direction, USGS: two; one value in a direction is not checked further), list sizes that do not match nx and ny, a value that is not finite, x or y values that do not increase strictly (in the USGS format: the x values of each row, and the y values from row to row), and a table that does not cover the domain: each end of the x and y lists may stop at most one table spacing inside prob_lo or prob_hi (the layout of a file with one height per cell starting at prob_lo), with an allowance of 1e-3 of that spacing for rounded coordinates. Beyond the table the reader only extends the heights from its edge: linearly before the first point, and (ERF format) by holding the last value after the last point; USGS extends linearly at both ends. Setting require_domain_coverage to false skips only the coverage check, for building files that describe a local patch. Coordinate ordering and all format checks still apply.

Parameters
[in]is_usgsUSGS layout (x varies fastest, one x per point)
[in]nx,nytable size
[in]x,y,ztable coordinates and heights
[in]prob_lo,prob_hidomain extent
[in]require_domain_coveragewhether the table must cover the domain

◆ TableProblem() [2/2]

std::string erf_terrain_file::TableProblem ( bool  is_usgs,
int  nx,
int  ny,
const Vector< Real > &  x,
const Vector< Real > &  y,
const Vector< Real > &  z,
const GpuArray< Real, AMREX_SPACEDIM > &  prob_lo,
const GpuArray< Real, AMREX_SPACEDIM > &  prob_hi,
bool  require_domain_coverage 
)
80 {
81  std::ostringstream os;
82  const int nmin = is_usgs ? 2 : 1;
83  if (nx < nmin || ny < nmin) {
84  os << "nx = " << nx << " and ny = " << ny << " must both be at least " << nmin
85  << (is_usgs ? " in the USGS format" : "");
86  return os.str();
87  }
88  const Long npts = Long(nx) * Long(ny);
89  const Long nxv = is_usgs ? npts : Long(nx);
90  if (Long(x.size()) != nxv || Long(y.size()) != Long(ny) || Long(z.size()) != npts) {
91  os << "expected " << nxv << " x values, " << ny << " y values and " << npts
92  << " heights, found " << x.size() << ", " << y.size() << " and " << z.size();
93  return os.str();
94  }
95  // A file cannot hold nan or inf (the reader stops on them as "not a number"); this is a
96  // guard for tables built otherwise
97  auto finite = [] (const Vector<Real>& v, const char* name) -> std::string {
98  for (Long n = 0; n < Long(v.size()); ++n) {
99  if (!std::isfinite(v[n])) {
100  std::ostringstream o;
101  o << name << " value " << n << " is not finite (" << v[n] << ")";
102  return o.str();
103  }
104  }
105  return "";
106  };
107  for (const auto& s : {finite(x,"x"), finite(y,"y"), finite(z,"height")}) {
108  if (!s.empty()) { return s; }
109  }
110 
111  std::string s = list_problem("y", ny, [&] (int m) { return y[m]; }, prob_lo[1], prob_hi[1],
112  require_domain_coverage);
113  if (!s.empty()) { return s; }
114  if (is_usgs) {
115  for (int j = 0; j < ny; ++j) {
116  s = list_problem("x", nx, [&] (int m) { return x[j*nx + m]; }, prob_lo[0], prob_hi[0],
117  require_domain_coverage);
118  if (!s.empty()) {
119  return s + " (row " + std::to_string(j) + " of the x-fastest USGS layout)";
120  }
121  }
122  } else {
123  s = list_problem("x", nx, [&] (int m) { return x[m]; }, prob_lo[0], prob_hi[0],
124  require_domain_coverage);
125  if (!s.empty()) { return s; }
126  }
127  return "";
128 }
const int nx
Definition: ERF_InitCustomPertVels_CloudChamber.H:14
const int ny
Definition: ERF_InitCustomPertVels_CloudChamber.H:15
bool finite(amrex::Real value) noexcept
Definition: ERF_CloudChamber.H:362
Here is the call graph for this function:

◆ TableSummary() [1/2]

std::string erf_terrain_file::TableSummary ( const std::string &  fname,
bool  is_usgs,
int  nx,
int  ny,
const amrex::Vector< amrex::Real > &  x,
const amrex::Vector< amrex::Real > &  y,
const amrex::Vector< amrex::Real > &  z 
)

Text describing a valid height table: its size and extent, the order its heights are read in, where the lowest and highest heights sit, and the largest slopes |dh/dx| and |dh/dy| between neighboring table points with where they sit. Meant to be printed once per file, so that a transposed or mis-ordered file can be spotted at start-up.

Parameters
[in]fnamefile name, for the first line
[in]is_usgsUSGS layout
[in]nx,nytable size
[in]x,y,ztable coordinates and heights (must pass TableProblem)

◆ TableSummary() [2/2]

std::string erf_terrain_file::TableSummary ( const std::string &  fname,
bool  is_usgs,
int  nx,
int  ny,
const Vector< Real > &  x,
const Vector< Real > &  y,
const Vector< Real > &  z 
)
133 {
134  int imin = 0, jmin = 0, imax = 0, jmax = 0;
135  Real zmin = z_at(is_usgs, nx, ny, z, 0, 0), zmax = zmin;
136  Real sx = Real(-1.), sy = Real(-1.);
137  Real sx_x = 0, sx_y = 0, sy_x = 0, sy_y = 0;
138  for (int j = 0; j < ny; ++j) {
139  for (int i = 0; i < nx; ++i) {
140  const Real h = z_at(is_usgs, nx, ny, z, i, j);
141  if (h < zmin) { zmin = h; imin = i; jmin = j; }
142  if (h > zmax) { zmax = h; imax = i; jmax = j; }
143  if (i+1 < nx) {
144  const Real x0 = x_at(is_usgs, nx, x, i, j), x1 = x_at(is_usgs, nx, x, i+1, j);
145  const Real s = std::abs(z_at(is_usgs, nx, ny, z, i+1, j) - h) / (x1 - x0);
146  if (s > sx) { sx = s; sx_x = Real(0.5)*(x0 + x1); sx_y = y[j]; }
147  }
148  if (j+1 < ny) {
149  const Real s = std::abs(z_at(is_usgs, nx, ny, z, i, j+1) - h) / (y[j+1] - y[j]);
150  if (s > sy) { sy = s; sy_x = x_at(is_usgs, nx, x, i, j); sy_y = Real(0.5)*(y[j] + y[j+1]); }
151  }
152  }
153  }
154 
155  std::ostringstream os;
156  os << "Height file " << fname << ": " << nx << " x " << ny << " heights over x "
157  << x_at(is_usgs, nx, x, 0, 0) << " .. " << x_at(is_usgs, nx, x, nx-1, 0)
158  << ", y " << y[0] << " .. " << y[ny-1] << "\n";
159  if (is_usgs) {
160  os << " read in USGS order: x varies fastest, height n is at (x[n], y[n / nx])\n";
161  } else {
162  os << " read in ERF order: y varies fastest, height n is at (x[n / ny], y[n % ny])\n";
163  }
164  os << " lowest " << zmin << " m at (x, y) = (" << x_at(is_usgs, nx, x, imin, jmin)
165  << ", " << y[jmin] << ")\n";
166  os << " highest " << zmax << " m at (x, y) = (" << x_at(is_usgs, nx, x, imax, jmax)
167  << ", " << y[jmax] << ")\n";
168  if (sx < Real(0.)) {
169  os << " one x value: constant in x";
170  } else {
171  os << " largest |dh/dx| " << sx << " at (" << sx_x << ", " << sx_y << ")";
172  }
173  if (sy < Real(0.)) {
174  os << ", one y value: constant in y\n";
175  } else {
176  os << ", largest |dh/dy| " << sy << " at (" << sy_x << ", " << sy_y << ")\n";
177  }
178  return os.str();
179 }

Variable Documentation

◆ open_face_slope_warn

constexpr amrex::Real erf_terrain_file::open_face_slope_warn = amrex::Real(0.3)
constexpr

Terrain slope |grad h| above which a band next to an inflow or outflow face is reported.

Referenced by OpenFaceSlopeWarning(), and ERF::WarnSteepTerrainAtOpenFaces().