ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Plotfile2DSampledField.H
Go to the documentation of this file.
1 /**
2  * \file ERF_Plotfile2DSampledField.H
3  */
4 #ifndef ERF_PLOTFILE2DSAMPLED_FIELD_H_
5 #define ERF_PLOTFILE2DSAMPLED_FIELD_H_
6 
7 #include <string>
8 
9 #include <AMReX_GpuQualifiers.H>
10 #include <AMReX_Vector.H>
11 
12 #include "ERF_DataStruct.H"
13 #include "ERF_EOS.H"
14 #include "ERF_TerrainMetrics.H"
15 
16 // Field registry for sampled-level 2D diagnostics. Each field defines its
17 // public name, units, availability, and cell-centered value. Derived fields can
18 // be added here without changing the sampled-level parser.
19 
20 namespace plotfile2d
21 {
22 
23 enum class SampledFieldID
24 {
25  Rho,
26  Theta,
27  Temp,
28  Pressure,
29  HeightMSL,
30  HeightAGL,
31  Qv,
32  Qc,
33  Qi,
34  Qr,
35  Qs,
36  Qg,
37  UEast,
38  VNorth,
39  W,
40  WindSpeed,
41  WindDir
42 };
43 
45 {
47  const char* name;
48  const char* long_name;
49  const char* units;
50 };
51 
53 {
54  amrex::Vector<SampledFieldDescriptor> accepted;
55  amrex::Vector<std::string> unavailable;
56 };
57 
58 const amrex::Vector<SampledFieldDescriptor>& sampled_field_catalog ();
59 
60 const SampledFieldDescriptor* find_sampled_field (const std::string& name);
61 
62 amrex::Vector<std::string> available_sampled_field_names (const SolverChoice& solver_choice);
63 
64 SampledFieldSelection select_requested_sampled_fields (const amrex::Vector<std::string>& requested,
65  const SolverChoice& solver_choice);
66 
67 std::string sampled_field_id_to_string (SampledFieldID field_id);
68 
69 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
70 bool sampled_field_is_wind (SampledFieldID field_id) noexcept
71 {
72  switch (field_id) {
75  case SampledFieldID::W:
78  return true;
79  default:
80  return false;
81  }
82 }
83 
84 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
86 {
87  return !sampled_field_is_wind(field_id);
88 }
89 
90 // NOTE: p_hse_arr holds the base state pressure and is used for the pressure field only
91 // when use_hse_pressure is true, i.e. when the level is anelastic or
92 // pseudo-incompressible -- see the comment
93 // at SampledFieldID::Pressure below. When use_hse_pressure is false the array is
94 // not read, so the caller may pass any valid array.
95 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
96 amrex::Real sampled_field_value (SampledFieldID field_id,
97  const amrex::Array4<const amrex::Real>& cons_arr,
98  const amrex::Array4<const amrex::Real>& z_phys_cc_arr,
99  const amrex::Array4<const amrex::Real>& z_phys_nd_arr,
100  const amrex::Array4<const amrex::Real>& z_sfc_nd_arr,
101  const amrex::Array4<const amrex::Real>& p_hse_arr,
102  bool have_z_phys_cc,
103  bool use_hse_pressure,
104  int i, int j, int k,
105  const MoistureComponentIndices& moisture_indices) noexcept
106 {
107  const amrex::Real rho = cons_arr(i, j, k, Rho_comp);
108  const bool has_moisture = (moisture_indices.qv >= 0);
109  // Microphysical fields are sampled as mixing ratios. The conserved state
110  // stores rho*q, so field evaluation divides by rho before interpolation.
111  const amrex::Real qv_for_eos = has_moisture
112  ? cons_arr(i, j, k, moisture_indices.qv) / rho
113  : amrex::Real(0.0);
114 
115  switch (field_id) {
116  case SampledFieldID::Rho:
117  return rho;
119  return cons_arr(i, j, k, RhoTheta_comp) / rho;
121  return getTgivenRandRTh(rho, cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
123  // In an anelastic or pseudo-incompressible run the compressible EOS does not give
124  // the pressure of the system -- the pressure comes from the projection, and the
125  // thermodynamic pressure is the base state pressure (at an anelastic level rho is
126  // also the frozen base state density, so getPgivenRTh would respond to theta
127  // perturbations). We use the base state pressure instead, just as the 3-D
128  // plotfile path does.
129  return use_hse_pressure ? p_hse_arr(i, j, k)
130  : getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
132  if (have_z_phys_cc) {
133  return z_phys_cc_arr(i, j, k);
134  }
135  return Compute_Z_AtCellCenter(i, j, k, z_phys_nd_arr);
137  return Compute_Zrel_AtCellCenter(i, j, k, z_sfc_nd_arr, z_phys_nd_arr);
138  case SampledFieldID::Qv:
139  return has_moisture ? cons_arr(i, j, k, moisture_indices.qv) / rho : amrex::Real(0.0);
140  case SampledFieldID::Qc:
141  return (moisture_indices.qc >= 0) ? cons_arr(i, j, k, moisture_indices.qc) / rho : amrex::Real(0.0);
142  case SampledFieldID::Qi:
143  return (moisture_indices.qi >= 0) ? cons_arr(i, j, k, moisture_indices.qi) / rho : amrex::Real(0.0);
144  case SampledFieldID::Qr:
145  return (moisture_indices.qr >= 0) ? cons_arr(i, j, k, moisture_indices.qr) / rho : amrex::Real(0.0);
146  case SampledFieldID::Qs:
147  return (moisture_indices.qs >= 0) ? cons_arr(i, j, k, moisture_indices.qs) / rho : amrex::Real(0.0);
148  case SampledFieldID::Qg:
149  return (moisture_indices.qg >= 0) ? cons_arr(i, j, k, moisture_indices.qg) / rho : amrex::Real(0.0);
152  case SampledFieldID::W:
155  return amrex::Real(0.0);
156  }
157 
158  return amrex::Real(0.0);
159 }
160 
161 inline const char*
163 {
164  switch (field_id) {
165  case SampledFieldID::Rho: return "rho";
166  case SampledFieldID::Theta: return "theta";
167  case SampledFieldID::Temp: return "temp";
168  case SampledFieldID::Pressure: return "pressure";
169  case SampledFieldID::HeightMSL: return "height_msl";
170  case SampledFieldID::HeightAGL: return "height_agl";
171  case SampledFieldID::Qv: return "qv";
172  case SampledFieldID::Qc: return "qc";
173  case SampledFieldID::Qi: return "qi";
174  case SampledFieldID::Qr: return "qr";
175  case SampledFieldID::Qs: return "qs";
176  case SampledFieldID::Qg: return "qg";
177  case SampledFieldID::UEast: return "u_east";
178  case SampledFieldID::VNorth: return "v_north";
179  case SampledFieldID::W: return "w";
180  case SampledFieldID::WindSpeed: return "wind_speed";
181  case SampledFieldID::WindDir: return "wind_dir";
182  }
183 
184  return "unknown";
185 }
186 
187 } // namespace plotfile2d
188 
189 #endif
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Z_AtCellCenter(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:717
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Zrel_AtCellCenter(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_sfc_nd, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:764
@ rho
Definition: ERF_Kessler.H:25
Definition: ERF.H:125
const char * sampled_field_name(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:162
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sampled_field_is_wind(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:70
SampledFieldSelection select_requested_sampled_fields(const amrex::Vector< std::string > &requested, const SolverChoice &solver_choice)
Definition: ERF_Plotfile2DSampledField.cpp:109
const SampledFieldDescriptor * find_sampled_field(const std::string &name)
Definition: ERF_Plotfile2DSampledField.cpp:82
std::string sampled_field_id_to_string(SampledFieldID field_id)
Definition: ERF_Plotfile2DSampledField.cpp:137
const amrex::Vector< SampledFieldDescriptor > & sampled_field_catalog()
Definition: ERF_Plotfile2DSampledField.cpp:76
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real sampled_field_value(SampledFieldID field_id, const amrex::Array4< const amrex::Real > &cons_arr, const amrex::Array4< const amrex::Real > &z_phys_cc_arr, const amrex::Array4< const amrex::Real > &z_phys_nd_arr, const amrex::Array4< const amrex::Real > &z_sfc_nd_arr, const amrex::Array4< const amrex::Real > &p_hse_arr, bool have_z_phys_cc, bool use_hse_pressure, int i, int j, int k, const MoistureComponentIndices &moisture_indices) noexcept
Definition: ERF_Plotfile2DSampledField.H:96
amrex::Vector< std::string > available_sampled_field_names(const SolverChoice &solver_choice)
Definition: ERF_Plotfile2DSampledField.cpp:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sampled_field_is_scalar_state(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:85
SampledFieldID
Definition: ERF_Plotfile2DSampledField.H:24
The moisture data carried by the active microphysics scheme.
Definition: ERF_DataStruct.H:279
Definition: ERF_DataStruct.H:743
Definition: ERF_Plotfile2DSampledField.H:45
SampledFieldID id
Definition: ERF_Plotfile2DSampledField.H:46
const char * name
Definition: ERF_Plotfile2DSampledField.H:47
const char * units
Definition: ERF_Plotfile2DSampledField.H:49
const char * long_name
Definition: ERF_Plotfile2DSampledField.H:48
Definition: ERF_Plotfile2DSampledField.H:53
amrex::Vector< std::string > unavailable
Definition: ERF_Plotfile2DSampledField.H:55
amrex::Vector< SampledFieldDescriptor > accepted
Definition: ERF_Plotfile2DSampledField.H:54