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)
 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...
 

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 
)
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.
35  : terr_arr(a_z_terrain.const_array()),
36  dz_s(a_dz_stretched.data()),
37  dx(a_geom.CellSize(0)),
38  dy(a_geom.CellSize(1)),
39  dz(a_geom.CellSize(2)),
40  prob_lo_x(a_geom.ProbLo(0)),
41  prob_lo_y(a_geom.ProbLo(1)),
42  prob_lo_z(a_geom.ProbLo(2)),
43  prob_hi_x(a_geom.ProbHi(0)),
44  prob_hi_y(a_geom.ProbHi(1)),
45  i_hi(static_cast<int>(std::round((a_geom.ProbHi(0)-a_geom.ProbLo(0))/a_geom.CellSize(0)))),
46  j_hi(static_cast<int>(std::round((a_geom.ProbHi(1)-a_geom.ProbLo(1))/a_geom.CellSize(1)))),
47  k_hi(static_cast<int>(std::round((a_geom.ProbHi(2)-a_geom.ProbLo(2))/a_geom.CellSize(2))))
48  {}
amrex::Real prob_lo_x
Low problem bounds used for interpolation.
Definition: ERF_EBIFTerrain.H:158
amrex::Array4< amrex::Real const > terr_arr
Terrain height array sampled on the horizontal mesh.
Definition: ERF_EBIFTerrain.H:152
amrex::Real prob_hi_x
High problem bounds used for interpolation.
Definition: ERF_EBIFTerrain.H:160
int k_hi
Number of vertical cells (one past the highest valid dz_s index).
Definition: ERF_EBIFTerrain.H:164
amrex::Real prob_lo_y
Low problem bound in y.
Definition: ERF_EBIFTerrain.H:158
amrex::Real const * dz_s
Device pointer to stretched vertical cell sizes.
Definition: ERF_EBIFTerrain.H:154
amrex::Real dx
Uniform computational grid spacing in each direction.
Definition: ERF_EBIFTerrain.H:156
amrex::Real prob_lo_z
Low problem bound in z.
Definition: ERF_EBIFTerrain.H:158
int j_hi
Highest terrain-array index in y.
Definition: ERF_EBIFTerrain.H:162
int i_hi
Highest terrain-array index in the x and y directions.
Definition: ERF_EBIFTerrain.H:162
amrex::Real dy
Uniform computational grid spacing in y.
Definition: ERF_EBIFTerrain.H:156
amrex::Real dz
Uniform computational grid spacing in z.
Definition: ERF_EBIFTerrain.H:156
amrex::Real prob_hi_y
High problem bound in y.
Definition: ERF_EBIFTerrain.H:160

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.
61  {
62  int i1{};
63  int j1{};
64  int i2{};
65  int j2{};
66 
67  amrex::Real x1{};
68  amrex::Real x2{};
69  amrex::Real y1{};
70  amrex::Real y2{};
71  amrex::Real w1{};
72  amrex::Real w2{};
73  amrex::Real terr_z{amrex::Real(0.0)};
74 
75  // z_stretched
76  const int k1 = amrex::Clamp(static_cast<int>(std::floor((z-prob_lo_z) / dz)), 0, k_hi - 1);
77  const amrex::Real z1 = prob_lo_z + k1*dz;
78  const amrex::Real remainder_z = (z - z1)/dz;
79  amrex::Real z_stretched = prob_lo_z;
80  for (int kk = 0; kk < k1; ++kk) {
81  z_stretched += dz_s[kk];
82  }
83  z_stretched += remainder_z * dz_s[k1];
84 
85  // Interpolation (nine subregions of x-y plane)
86  if (x <= prob_lo_x && y <= prob_lo_y) {
87  terr_z = terr_arr(0 ,0 ,0);
88  } else if (x >= prob_hi_x && y <= prob_lo_y) {
89  terr_z = terr_arr(i_hi,0 ,0);
90  } else if (x >= prob_hi_x && y >= prob_hi_y) {
91  terr_z = terr_arr(i_hi,j_hi,0);
92  } else if (x <= prob_lo_x && y >= prob_hi_y) {
93  terr_z = terr_arr(0 ,j_hi,0);
94  } else if (x > prob_lo_x && x < prob_hi_x && (y <= prob_lo_y || y >= prob_hi_y) ) {
95  i1 = static_cast<int>(std::floor((x-prob_lo_x) / dx));
96  i2 = i1+1;
97  x1 = prob_lo_x + i1*dx;
98  x2 = x1 + dx;
99  w1 = (x2-x)/dx;
100  w2 = (x-x1)/dx;
101  if (y <= prob_lo_y){
102  terr_z = w1*terr_arr(i1,0 ,0) + w2*terr_arr(i2,0 ,0);
103  } else if (y >= prob_hi_y) {
104  terr_z = w1*terr_arr(i1,j_hi,0) + w2*terr_arr(i2,j_hi,0);
105  }
106  } else if (y > prob_lo_y && y < prob_hi_y && (x <= prob_lo_x || x >= prob_hi_x) ) {
107  j1 = static_cast<int>(std::floor((y-prob_lo_y) / dy));
108  j2 = j1+1;
109  y1 = prob_lo_y + j1*dy;
110  y2 = y1 + dy;
111  w1 = (y2-y)/dy;
112  w2 = (y-y1)/dy;
113  if (x <= prob_lo_x){
114  terr_z = w1*terr_arr(0 ,j1,0) + w2*terr_arr(0 ,j2,0);
115  } else if (x >= prob_hi_x) {
116  terr_z = w1*terr_arr(i_hi,j1,0) + w2*terr_arr(i_hi,j2,0);
117  }
118  } else {
119  // Do bilinear interpolation of the terrain surface
120  i1 = static_cast<int>(std::floor((x-prob_lo_x) / dx));
121  i2 = i1+1;
122  j1 = static_cast<int>(std::floor((y-prob_lo_y) / dy));
123  j2 = j1+1;
124  x1 = prob_lo_x + i1*dx;
125  x2 = x1 + dx;
126  y1 = prob_lo_y + j1*dy;
127  y2 = y1 + dy;
128 
129  const amrex::Real denom = dx*dy;
130  const amrex::Real w11 = (x2-x)*(y2-y)/denom;
131  const amrex::Real w12 = (x2-x)*(y-y1)/denom;
132  const amrex::Real w21 = (x-x1)*(y2-y)/denom;
133  const amrex::Real w22 = (x-x1)*(y-y1)/denom;
134  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);
135  }
136  return -(z_stretched - terr_z);
137  }
amrex::Real Real
Definition: ERF_ShocInterface.H:19
real(c_double), private k1
Definition: ERF_module_mp_morr_two_moment.F90:213

Referenced by operator()().

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.
146  {
147  return this->operator() (AMREX_D_DECL(p[0], p[1], p[2]));
148  }
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:59
@ p
Definition: ERF_WSM6.H:191
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()().

◆ 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: