ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ActuatorGeometry.H
Go to the documentation of this file.
1 #ifndef ERF_ACTUATOR_GEOMETRY_H
2 #define ERF_ACTUATOR_GEOMETRY_H
3 
4 /** Face heights and face volumes of the staggered grid, shared by the actuator sampler and spreader. */
5 
6 #include <AMReX_Array4.H>
7 #include <AMReX_GpuQualifiers.H>
8 #include <AMReX_REAL.H>
9 
10 namespace erf_actuator {
11 
12 /**
13  * Return the height (m) of the center of face (i,j,k) of the staggered grid dir (0: x face,
14  * 1: y face, 2: z face): the mean of the four mesh nodes of that face on a stretched or
15  * terrain-following mesh (znd, has_znd true), or the nominal height on a uniform-dz mesh:
16  * zlo + k dz for a z face (z face k is the bottom face of cell k), zlo + (k + 1/2) dz otherwise.
17  * Shared by the velocity sampling and the force spreading so that both see the same face positions.
18  */
19 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
20 amrex::Real face_height (int dir, int i, int j, int k,
21  amrex::Array4<amrex::Real const> const& znd, bool has_znd,
22  amrex::Real zlo, amrex::Real dz)
23 {
24  using amrex::Real;
25  if (!has_znd) {
26  return (dir == 2) ? zlo + k * dz : zlo + (k + Real(0.5)) * dz;
27  }
28  if (dir == 0) {
29  return Real(0.25) * (znd(i,j,k) + znd(i,j+1,k) + znd(i,j,k+1) + znd(i,j+1,k+1));
30  }
31  if (dir == 1) {
32  return Real(0.25) * (znd(i,j,k) + znd(i+1,j,k) + znd(i,j,k+1) + znd(i+1,j,k+1));
33  }
34  return Real(0.25) * (znd(i,j,k) + znd(i+1,j,k) + znd(i,j+1,k) + znd(i+1,j+1,k));
35 }
36 
37 /**
38  * Return the volume (m^3) attached to face (i,j,k) of the staggered grid dir: half of each
39  * neighboring cell, with the cell volumes dx dy dz detJ on a stretched or terrain-following mesh
40  * (detJ = 1 otherwise). Reads detj at i-1 (x), j-1 (y) or k-1 (z): detJ needs one ghost cell at a
41  * box's low faces.
42  */
43 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
44 amrex::Real face_volume (int dir, int i, int j, int k,
45  amrex::Array4<amrex::Real const> const& detj, bool has_detj,
46  amrex::Real dxdydz)
47 {
48  using amrex::Real;
49  if (!has_detj) { return dxdydz; }
50  if (dir == 0) { return Real(0.5) * (detj(i-1,j,k) + detj(i,j,k)) * dxdydz; }
51  if (dir == 1) { return Real(0.5) * (detj(i,j-1,k) + detj(i,j,k)) * dxdydz; }
52  return Real(0.5) * (detj(i,j,k-1) + detj(i,j,k)) * dxdydz;
53 }
54 
55 } // namespace erf_actuator
56 
57 #endif
Real dxdydz
Definition: ERF_ActuatorSpreading.cpp:133
bool has_znd
Definition: ERF_ActuatorSpreading.cpp:134
bool has_detj
Definition: ERF_ActuatorSpreading.cpp:134
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
Definition: ERF_ActuatorDeviceBuffers.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real face_volume(int dir, int i, int j, int k, amrex::Array4< amrex::Real const > const &detj, bool has_detj, amrex::Real dxdydz)
Definition: ERF_ActuatorGeometry.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real face_height(int dir, int i, int j, int k, amrex::Array4< amrex::Real const > const &znd, bool has_znd, amrex::Real zlo, amrex::Real dz)
Definition: ERF_ActuatorGeometry.H:20