ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
TerrainIF Class Reference

AMReX EB implicit-function sign convention: >0 is body, 0 is boundary, <0 is fluid. More...

#include <ERF_EBIFTerrain.H>

Inheritance diagram for TerrainIF:
Collaboration diagram for TerrainIF:

Public Member Functions

 TerrainIF (amrex::FArrayBox const &a_z_terrain, amrex::Geometry const &a_geom, amrex::Gpu::DeviceVector< amrex::Real > &a_dz_stretched, bool a_periodic_wrap=false)
 Construct a terrain implicit function from height and geometry data. More...
 
AMREX_GPU_HOST_DEVICE amrex::Real operator() (AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z)) const noexcept
 Evaluate the signed implicit-function value at physical coordinates. More...
 
AMREX_GPU_HOST_DEVICE amrex::Real operator() (const amrex::RealArray &p) const noexcept
 Evaluate the signed implicit-function value at a point array. More...
 

Protected Attributes

amrex::Array4< amrex::Real const > terr_arr
 Terrain height array sampled on the horizontal mesh. More...
 
amrex::Real const * dz_s
 Device pointer to stretched vertical cell sizes. More...
 
amrex::Real dx
 Uniform computational grid spacing in each direction. More...
 
amrex::Real dy
 Uniform computational grid spacing in y. More...
 
amrex::Real dz
 Uniform computational grid spacing in z. More...
 
amrex::Real prob_lo_x
 Low problem bounds used for interpolation. More...
 
amrex::Real prob_lo_y
 Low problem bound in y. More...
 
amrex::Real prob_lo_z
 Low problem bound in z. More...
 
amrex::Real prob_hi_x
 High problem bounds used for interpolation. More...
 
amrex::Real prob_hi_y
 High problem bound in y. More...
 
int i_hi
 Highest terrain-array index in the x and y directions. More...
 
int j_hi
 Highest terrain-array index in y. More...
 
int k_hi
 Number of vertical cells (one past the highest valid dz_s index). More...
 
bool per_x
 Whether x and y are evaluated at their periodic image inside the domain. More...
 
bool per_y
 

Detailed Description

AMReX EB implicit-function sign convention: >0 is body, 0 is boundary, <0 is fluid.

Terrain implicit function backed by gridded terrain heights.

The operator interpolates terrain height in x-y, maps the query z coordinate through stretched vertical spacing, and returns the AMReX EB signed value.

Constructor & Destructor Documentation

◆ TerrainIF()

TerrainIF::TerrainIF ( amrex::FArrayBox const &  a_z_terrain,
amrex::Geometry const &  a_geom,
amrex::Gpu::DeviceVector< amrex::Real > &  a_dz_stretched,
bool  a_periodic_wrap = false 
)
inline

Construct a terrain implicit function from height and geometry data.

Parameters
a_z_terrainTerrain elevation values on the horizontal mesh.
a_geomGeometry used for grid spacing and problem bounds.
a_dz_stretchedDevice vector of stretched vertical cell sizes.
a_periodic_wrapIn a periodic direction of a_geom, evaluate at the periodic image inside the domain, so that the surface is the same across the periodic faces.
38  : terr_arr(a_z_terrain.const_array()),
39  dz_s(a_dz_stretched.data()),
40  dx(a_geom.CellSize(0)),
41  dy(a_geom.CellSize(1)),
42  dz(a_geom.CellSize(2)),
43  prob_lo_x(a_geom.ProbLo(0)),
44  prob_lo_y(a_geom.ProbLo(1)),
45  prob_lo_z(a_geom.ProbLo(2)),
46  prob_hi_x(a_geom.ProbHi(0)),
47  prob_hi_y(a_geom.ProbHi(1)),
48  i_hi(static_cast<int>(std::round((a_geom.ProbHi(0)-a_geom.ProbLo(0))/a_geom.CellSize(0)))),
49  j_hi(static_cast<int>(std::round((a_geom.ProbHi(1)-a_geom.ProbLo(1))/a_geom.CellSize(1)))),
50  k_hi(static_cast<int>(std::round((a_geom.ProbHi(2)-a_geom.ProbLo(2))/a_geom.CellSize(2)))),
51  per_x(a_periodic_wrap && a_geom.isPeriodic(0)),
52  per_y(a_periodic_wrap && a_geom.isPeriodic(1))
53  {}
bool per_x
Whether x and y are evaluated at their periodic image inside the domain.
Definition: ERF_EBIFTerrain.H:184
amrex::Real prob_lo_x
Low problem bounds used for interpolation.
Definition: ERF_EBIFTerrain.H:176
amrex::Array4< amrex::Real const > terr_arr
Terrain height array sampled on the horizontal mesh.
Definition: ERF_EBIFTerrain.H:170
amrex::Real prob_hi_x
High problem bounds used for interpolation.
Definition: ERF_EBIFTerrain.H:178
int k_hi
Number of vertical cells (one past the highest valid dz_s index).
Definition: ERF_EBIFTerrain.H:182
amrex::Real prob_lo_y
Low problem bound in y.
Definition: ERF_EBIFTerrain.H:176
amrex::Real const * dz_s
Device pointer to stretched vertical cell sizes.
Definition: ERF_EBIFTerrain.H:172
amrex::Real dx
Uniform computational grid spacing in each direction.
Definition: ERF_EBIFTerrain.H:174
amrex::Real prob_lo_z
Low problem bound in z.
Definition: ERF_EBIFTerrain.H:176
int j_hi
Highest terrain-array index in y.
Definition: ERF_EBIFTerrain.H:180
int i_hi
Highest terrain-array index in the x and y directions.
Definition: ERF_EBIFTerrain.H:180
amrex::Real dy
Uniform computational grid spacing in y.
Definition: ERF_EBIFTerrain.H:174
bool per_y
Definition: ERF_EBIFTerrain.H:184
amrex::Real dz
Uniform computational grid spacing in z.
Definition: ERF_EBIFTerrain.H:174
amrex::Real prob_hi_y
High problem bound in y.
Definition: ERF_EBIFTerrain.H:178

Member Function Documentation

◆ operator()() [1/2]

AMREX_GPU_HOST_DEVICE amrex::Real TerrainIF::operator() ( AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z)  ) const
inlinenoexcept

Evaluate the signed implicit-function value at physical coordinates.

The coordinates are passed through AMREX_D_DECL for spatial-dimension portability.

Returns
Positive inside terrain, zero at the terrain surface, negative in fluid.
66  {
67  int i1{};
68  int j1{};
69  int i2{};
70  int j2{};
71 
72  amrex::Real x1{};
73  amrex::Real x2{};
74  amrex::Real y1{};
75  amrex::Real y2{};
76  amrex::Real w1{};
77  amrex::Real w2{};
78  amrex::Real terr_z{amrex::Real(0.0)};
79 
80  // A point beyond a periodic face sees the surface at its periodic image; a point
81  // inside the domain is left exactly as it is
82  auto wrap = [] (amrex::Real a, amrex::Real lo, amrex::Real hi) {
83  if (a >= lo && a < hi) { return a; }
84  const amrex::Real len = hi - lo;
85  amrex::Real r = std::fmod(a - lo, len);
86  if (r < amrex::Real(0.0)) { r += len; }
87  if (r >= len) { r = amrex::Real(0.0); }
88  return lo + r;
89  };
90  if (per_x) { x = wrap(x, prob_lo_x, prob_hi_x); }
91  if (per_y) { y = wrap(y, prob_lo_y, prob_hi_y); }
92 
93  // z_stretched
94  const int k1 = amrex::Clamp(static_cast<int>(std::floor((z-prob_lo_z) / dz)), 0, k_hi - 1);
95  const amrex::Real z1 = prob_lo_z + k1*dz;
96  const amrex::Real remainder_z = (z - z1)/dz;
97  amrex::Real z_stretched = prob_lo_z;
98  for (int kk = 0; kk < k1; ++kk) {
99  z_stretched += dz_s[kk];
100  }
101  z_stretched += remainder_z * dz_s[k1];
102 
103  // Interpolation (nine subregions of x-y plane)
104  if (x <= prob_lo_x && y <= prob_lo_y) {
105  terr_z = terr_arr(0 ,0 ,0);
106  } else if (x >= prob_hi_x && y <= prob_lo_y) {
107  terr_z = terr_arr(i_hi,0 ,0);
108  } else if (x >= prob_hi_x && y >= prob_hi_y) {
109  terr_z = terr_arr(i_hi,j_hi,0);
110  } else if (x <= prob_lo_x && y >= prob_hi_y) {
111  terr_z = terr_arr(0 ,j_hi,0);
112  } else if (x > prob_lo_x && x < prob_hi_x && (y <= prob_lo_y || y >= prob_hi_y) ) {
113  i1 = static_cast<int>(std::floor((x-prob_lo_x) / dx));
114  i2 = i1+1;
115  x1 = prob_lo_x + i1*dx;
116  x2 = x1 + dx;
117  w1 = (x2-x)/dx;
118  w2 = (x-x1)/dx;
119  if (y <= prob_lo_y){
120  terr_z = w1*terr_arr(i1,0 ,0) + w2*terr_arr(i2,0 ,0);
121  } else if (y >= prob_hi_y) {
122  terr_z = w1*terr_arr(i1,j_hi,0) + w2*terr_arr(i2,j_hi,0);
123  }
124  } else if (y > prob_lo_y && y < prob_hi_y && (x <= prob_lo_x || x >= prob_hi_x) ) {
125  j1 = static_cast<int>(std::floor((y-prob_lo_y) / dy));
126  j2 = j1+1;
127  y1 = prob_lo_y + j1*dy;
128  y2 = y1 + dy;
129  w1 = (y2-y)/dy;
130  w2 = (y-y1)/dy;
131  if (x <= prob_lo_x){
132  terr_z = w1*terr_arr(0 ,j1,0) + w2*terr_arr(0 ,j2,0);
133  } else if (x >= prob_hi_x) {
134  terr_z = w1*terr_arr(i_hi,j1,0) + w2*terr_arr(i_hi,j2,0);
135  }
136  } else {
137  // Do bilinear interpolation of the terrain surface
138  i1 = static_cast<int>(std::floor((x-prob_lo_x) / dx));
139  i2 = i1+1;
140  j1 = static_cast<int>(std::floor((y-prob_lo_y) / dy));
141  j2 = j1+1;
142  x1 = prob_lo_x + i1*dx;
143  x2 = x1 + dx;
144  y1 = prob_lo_y + j1*dy;
145  y2 = y1 + dy;
146 
147  const amrex::Real denom = dx*dy;
148  const amrex::Real w11 = (x2-x)*(y2-y)/denom;
149  const amrex::Real w12 = (x2-x)*(y-y1)/denom;
150  const amrex::Real w21 = (x-x1)*(y2-y)/denom;
151  const amrex::Real w22 = (x-x1)*(y-y1)/denom;
152  terr_z = w11*terr_arr(i1,j1,0) + w12*terr_arr(i1,j2,0) + w21*terr_arr(i2,j1,0) + w22*terr_arr(i2,j2,0);
153  }
154  return -(z_stretched - terr_z);
155  }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int wrap(int i, int lo, int n)
Definition: ERF_TopographicShadingKernels.H:36
real(c_double), private k1
Definition: ERF_module_mp_morr_two_moment.F90:213

Referenced by operator()().

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

◆ operator()() [2/2]

AMREX_GPU_HOST_DEVICE amrex::Real TerrainIF::operator() ( const amrex::RealArray &  p) const
inlinenoexcept

Evaluate the signed implicit-function value at a point array.

Parameters
pPhysical coordinate array.
Returns
Positive inside terrain, zero at the terrain surface, negative in fluid.
164  {
165  return this->operator() (AMREX_D_DECL(p[0], p[1], p[2]));
166  }
AMREX_GPU_HOST_DEVICE amrex::Real operator()(AMREX_D_DECL(amrex::Real x, amrex::Real y, amrex::Real z)) const noexcept
Evaluate the signed implicit-function value at physical coordinates.
Definition: ERF_EBIFTerrain.H:64
@ p
Definition: ERF_WSM6.H:303
Here is the call graph for this function:

Member Data Documentation

◆ dx

amrex::Real TerrainIF::dx
protected

Uniform computational grid spacing in each direction.

Referenced by operator()().

◆ dy

TerrainIF::dy
protected

Uniform computational grid spacing in y.

Referenced by operator()().

◆ dz

TerrainIF::dz
protected

Uniform computational grid spacing in z.

Referenced by operator()().

◆ dz_s

amrex::Real const* TerrainIF::dz_s
protected

Device pointer to stretched vertical cell sizes.

Referenced by operator()().

◆ i_hi

int TerrainIF::i_hi
protected

Highest terrain-array index in the x and y directions.

Referenced by operator()().

◆ j_hi

TerrainIF::j_hi
protected

Highest terrain-array index in y.

Referenced by operator()().

◆ k_hi

int TerrainIF::k_hi
protected

Number of vertical cells (one past the highest valid dz_s index).

Referenced by operator()().

◆ per_x

bool TerrainIF::per_x
protected

Whether x and y are evaluated at their periodic image inside the domain.

Referenced by operator()().

◆ per_y

bool TerrainIF::per_y
protected

Referenced by operator()().

◆ prob_hi_x

amrex::Real TerrainIF::prob_hi_x
protected

High problem bounds used for interpolation.

Referenced by operator()().

◆ prob_hi_y

TerrainIF::prob_hi_y
protected

High problem bound in y.

Referenced by operator()().

◆ prob_lo_x

amrex::Real TerrainIF::prob_lo_x
protected

Low problem bounds used for interpolation.

Referenced by operator()().

◆ prob_lo_y

TerrainIF::prob_lo_y
protected

Low problem bound in y.

Referenced by operator()().

◆ prob_lo_z

TerrainIF::prob_lo_z
protected

Low problem bound in z.

Referenced by operator()().

◆ terr_arr

amrex::Array4<amrex::Real const> TerrainIF::terr_arr
protected

Terrain height array sampled on the horizontal mesh.

Referenced by operator()().


The documentation for this class was generated from the following file: