ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_InflowProfile.H
Go to the documentation of this file.
1 #ifndef ERF_INFLOW_PROFILE_H_
2 #define ERF_INFLOW_PROFILE_H_
3 
4 /**
5  * Terrain-following inflow profiles for Inflow and InflowOutflow faces
6  * (xlo.inflow_profile = "log_law" or "file").
7  *
8  * A profile tabulates u, v and, when given, theta and tke against height above
9  * the local ground. Each boundary cell looks the profile up at its own height
10  * above the terrain beneath it, so the inflow follows the terrain along a
11  * sloping face, as WindNinja's inlets do. The terrain on the boundary is left
12  * as it is.
13  */
14 
15 #include <istream>
16 #include <string>
17 
18 #include <AMReX_Array4.H>
19 #include <AMReX_Gpu.H>
20 #include <AMReX_GpuContainers.H>
21 #include <AMReX_REAL.H>
22 #include <AMReX_Vector.H>
23 
25 {
26  bool active = false;
27  bool has_theta = false;
28  bool has_tke = false;
29  std::string source; ///< "log_law" or the profile file name
30 
31  /// Host tables against height above the ground (strictly increasing)
32  amrex::Vector<amrex::Real> z, u, v, theta, tke;
33 
34  /// Device copies used by the boundary fills
35  amrex::Gpu::DeviceVector<amrex::Real> z_d, u_d, v_d, theta_d, tke_d;
36 
37  void copy_to_device ();
38 };
39 
40 /** The neutral log law of inflow_log_law.* */
42 {
43  amrex::Real speed = amrex::Real(-1.0); ///< wind speed at `height` [m/s] (required)
44  amrex::Real height = amrex::Real(10.0); ///< reference height above the ground [m]
45  amrex::Real direction = amrex::Real(270.0); ///< direction the wind blows from [deg, meteorological]
46  amrex::Real z0 = amrex::Real(0.1); ///< roughness length [m]
47  amrex::Real max_speed = amrex::Real(-1.0); ///< cap on the speed; <= 0 means none
48  amrex::Real tke_zscale = amrex::Real(700.0); ///< tke tapers linearly to zero at u* tke_zscale
49  amrex::Real Cmu0 = amrex::Real(0.5562); ///< tke at the ground is u*^2 / Cmu0^2
50 };
51 
52 /** Parse a profile table; returns an empty string on success, otherwise the error. */
53 std::string parse_inflow_profile (std::istream& is, InflowProfile& prof);
54 
55 /** Read a profile file, aborting with the file name on any error. */
56 void read_inflow_profile_file (const std::string& fname, InflowProfile& prof);
57 
58 /** Tabulate the log law from the ground to ztop; returns an empty string on success. */
59 std::string make_log_law_inflow_profile (const InflowLogLaw& p, amrex::Real ztop, InflowProfile& prof);
60 
61 /** Linear interpolation in a strictly increasing table, held constant beyond both ends. */
62 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
63 amrex::Real
64 inflow_profile_value (const amrex::Real* z, const amrex::Real* f, const int n, const amrex::Real zq) noexcept
65 {
66  if (zq <= z[0]) { return f[0]; }
67  if (zq >= z[n-1]) { return f[n-1]; }
68  int lo = 0;
69  int hi = n - 1;
70  while (hi - lo > 1) {
71  const int mid = (lo + hi) / 2;
72  if (z[mid] <= zq) { lo = mid; } else { hi = mid; }
73  }
74  const amrex::Real w = (zq - z[lo]) / (z[hi] - z[lo]);
75  return f[lo] + w * (f[hi] - f[lo]);
76 }
77 
78 /**
79  * Mean height above the ground of the nodes [ilo,ihi] x [jlo,jhi] between
80  * levels k and k+1 of the terrain-fitted mesh: a cell center (two nodes in each
81  * lateral direction), an x-face (ilo == ihi) or a y-face (jlo == jhi). The
82  * ground is the same nodes on level klo. Indices are clamped to the array.
83  */
84 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
85 amrex::Real
86 height_above_ground (const amrex::Array4<const amrex::Real>& z_nd,
87  int ilo, int ihi, int jlo, int jhi, const int k, const int klo) noexcept
88 {
89  const auto lo = amrex::lbound(z_nd);
90  const auto hi = amrex::ubound(z_nd);
91  ilo = amrex::max(lo.x, amrex::min(ilo, hi.x));
92  ihi = amrex::max(lo.x, amrex::min(ihi, hi.x));
93  jlo = amrex::max(lo.y, amrex::min(jlo, hi.y));
94  jhi = amrex::max(lo.y, amrex::min(jhi, hi.y));
95  const int kc = amrex::max(lo.z, amrex::min(k, hi.z - 1));
96  const int kg = amrex::max(lo.z, amrex::min(klo, hi.z));
97  amrex::Real sum = amrex::Real(0.0);
98  int count = 0;
99  for (int j = jlo; j <= jhi; ++j) {
100  for (int i = ilo; i <= ihi; ++i) {
101  sum += amrex::Real(0.5) * (z_nd(i,j,kc) + z_nd(i,j,kc+1)) - z_nd(i,j,kg);
102  ++count;
103  }
104  }
105  return sum / static_cast<amrex::Real>(count);
106 }
107 
108 #endif
int count
Definition: ERF_ActuatorSpreading.cpp:264
void read_inflow_profile_file(const std::string &fname, InflowProfile &prof)
Definition: ERF_InflowProfile.cpp:171
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real inflow_profile_value(const amrex::Real *z, const amrex::Real *f, const int n, const amrex::Real zq) noexcept
Definition: ERF_InflowProfile.H:64
std::string parse_inflow_profile(std::istream &is, InflowProfile &prof)
Definition: ERF_InflowProfile.cpp:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real height_above_ground(const amrex::Array4< const amrex::Real > &z_nd, int ilo, int ihi, int jlo, int jhi, const int k, const int klo) noexcept
Definition: ERF_InflowProfile.H:86
std::string make_log_law_inflow_profile(const InflowLogLaw &p, amrex::Real ztop, InflowProfile &prof)
const Real ztop
Definition: ERF_InitCustomPertVels_ParticleTests.H:4
const int klo
Definition: ERF_InitCustomPert_KE.H:9
@ p
Definition: ERF_WSM6.H:303
Definition: ERF_InflowProfile.H:42
amrex::Real height
reference height above the ground [m]
Definition: ERF_InflowProfile.H:44
amrex::Real speed
wind speed at height [m/s] (required)
Definition: ERF_InflowProfile.H:43
amrex::Real Cmu0
tke at the ground is u*^2 / Cmu0^2
Definition: ERF_InflowProfile.H:49
amrex::Real z0
roughness length [m]
Definition: ERF_InflowProfile.H:46
amrex::Real direction
direction the wind blows from [deg, meteorological]
Definition: ERF_InflowProfile.H:45
amrex::Real max_speed
cap on the speed; <= 0 means none
Definition: ERF_InflowProfile.H:47
amrex::Real tke_zscale
tke tapers linearly to zero at u* tke_zscale
Definition: ERF_InflowProfile.H:48
Definition: ERF_InflowProfile.H:25
amrex::Vector< amrex::Real > tke
Definition: ERF_InflowProfile.H:32
bool has_tke
Definition: ERF_InflowProfile.H:28
void copy_to_device()
Definition: ERF_InflowProfile.cpp:18
amrex::Vector< amrex::Real > theta
Definition: ERF_InflowProfile.H:32
amrex::Gpu::DeviceVector< amrex::Real > z_d
Device copies used by the boundary fills.
Definition: ERF_InflowProfile.H:35
amrex::Gpu::DeviceVector< amrex::Real > theta_d
Definition: ERF_InflowProfile.H:35
amrex::Gpu::DeviceVector< amrex::Real > tke_d
Definition: ERF_InflowProfile.H:35
amrex::Vector< amrex::Real > v
Definition: ERF_InflowProfile.H:32
std::string source
"log_law" or the profile file name
Definition: ERF_InflowProfile.H:29
amrex::Gpu::DeviceVector< amrex::Real > u_d
Definition: ERF_InflowProfile.H:35
amrex::Gpu::DeviceVector< amrex::Real > v_d
Definition: ERF_InflowProfile.H:35
amrex::Vector< amrex::Real > z
Host tables against height above the ground (strictly increasing)
Definition: ERF_InflowProfile.H:32
bool has_theta
Definition: ERF_InflowProfile.H:27
bool active
Definition: ERF_InflowProfile.H:26
amrex::Vector< amrex::Real > u
Definition: ERF_InflowProfile.H:32