5 #ifndef ERF_TERRAIN_IF_H_
6 #define ERF_TERRAIN_IF_H_
8 #include <AMReX_Array.H>
9 #include <AMReX_EB2_IF_Base.H>
35 TerrainIF (amrex::FArrayBox
const& a_z_terrain, amrex::Geometry
const& a_geom,
36 amrex::Gpu::DeviceVector<amrex::Real>& a_dz_stretched,
37 bool a_periodic_wrap =
false)
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)),
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))
63 AMREX_GPU_HOST_DEVICE
inline
64 amrex::Real
operator() (AMREX_D_DECL(amrex::Real
x, amrex::Real
y, amrex::Real
z))
78 amrex::Real terr_z{amrex::Real(0.0)};
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); }
94 const int k1 = amrex::Clamp(
static_cast<int>(std::floor((
z-
prob_lo_z) /
dz)), 0,
k_hi - 1);
96 const amrex::Real remainder_z = (
z - z1)/
dz;
98 for (
int kk = 0; kk <
k1; ++kk) {
99 z_stretched +=
dz_s[kk];
101 z_stretched += remainder_z *
dz_s[
k1];
110 }
else if (x <= prob_lo_x && y >=
prob_hi_y) {
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;
154 return -(z_stretched - terr_z);
162 AMREX_GPU_HOST_DEVICE
163 inline amrex::Real
operator() (
const amrex::RealArray&
p)
const noexcept
AMReX EB implicit-function sign convention: >0 is body, 0 is boundary, <0 is fluid.
Definition: ERF_EBIFTerrain.H:24
bool per_x
Whether x and y are evaluated at their periodic image inside the domain.
Definition: ERF_EBIFTerrain.H:184
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.
Definition: ERF_EBIFTerrain.H:35
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_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
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
@ p
Definition: ERF_WSM6.H:303
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