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 run is anelastic -- see the comment
92 // at SampledFieldID::Pressure below. When use_hse_pressure is false the array is
93 // not read, so the caller may pass any valid array.
94 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
96  const amrex::Array4<const amrex::Real>& cons_arr,
97  const amrex::Array4<const amrex::Real>& z_phys_cc_arr,
98  const amrex::Array4<const amrex::Real>& z_phys_nd_arr,
99  const amrex::Array4<const amrex::Real>& p_hse_arr,
100  bool have_z_phys_cc,
101  bool use_hse_pressure,
102  int i, int j, int k,
103  const MoistureComponentIndices& moisture_indices) noexcept
104 {
105  const amrex::Real rho = cons_arr(i, j, k, Rho_comp);
106  const bool has_moisture = (moisture_indices.qv >= 0);
107  // Microphysical fields are sampled as mixing ratios. The conserved state
108  // stores rho*q, so field evaluation divides by rho before interpolation.
109  const amrex::Real qv_for_eos = has_moisture
110  ? cons_arr(i, j, k, moisture_indices.qv) / rho
111  : amrex::Real(0.0);
112 
113  switch (field_id) {
114  case SampledFieldID::Rho:
115  return rho;
117  return cons_arr(i, j, k, RhoTheta_comp) / rho;
119  return getTgivenRandRTh(rho, cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
121  // In an anelastic run the compressible EOS does not give the pressure of the
122  // system -- rho is the (frozen) base state density, so getPgivenRTh would
123  // respond to theta perturbations. We use the base state pressure instead,
124  // just as the 3-D plotfile path does.
125  return use_hse_pressure ? p_hse_arr(i, j, k)
126  : getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
128  if (have_z_phys_cc) {
129  return z_phys_cc_arr(i, j, k);
130  }
131  return Compute_Z_AtCellCenter(i, j, k, z_phys_nd_arr);
133  return Compute_Zrel_AtCellCenter(i, j, k, z_phys_nd_arr);
134  case SampledFieldID::Qv:
135  return has_moisture ? cons_arr(i, j, k, moisture_indices.qv) / rho : amrex::Real(0.0);
136  case SampledFieldID::Qc:
137  return (moisture_indices.qc >= 0) ? cons_arr(i, j, k, moisture_indices.qc) / rho : amrex::Real(0.0);
138  case SampledFieldID::Qi:
139  return (moisture_indices.qi >= 0) ? cons_arr(i, j, k, moisture_indices.qi) / rho : amrex::Real(0.0);
140  case SampledFieldID::Qr:
141  return (moisture_indices.qr >= 0) ? cons_arr(i, j, k, moisture_indices.qr) / rho : amrex::Real(0.0);
142  case SampledFieldID::Qs:
143  return (moisture_indices.qs >= 0) ? cons_arr(i, j, k, moisture_indices.qs) / rho : amrex::Real(0.0);
144  case SampledFieldID::Qg:
145  return (moisture_indices.qg >= 0) ? cons_arr(i, j, k, moisture_indices.qg) / rho : amrex::Real(0.0);
148  case SampledFieldID::W:
151  return amrex::Real(0.0);
152  }
153 
154  return amrex::Real(0.0);
155 }
156 
157 inline const char*
159 {
160  switch (field_id) {
161  case SampledFieldID::Rho: return "rho";
162  case SampledFieldID::Theta: return "theta";
163  case SampledFieldID::Temp: return "temp";
164  case SampledFieldID::Pressure: return "pressure";
165  case SampledFieldID::HeightMSL: return "height_msl";
166  case SampledFieldID::HeightAGL: return "height_agl";
167  case SampledFieldID::Qv: return "qv";
168  case SampledFieldID::Qc: return "qc";
169  case SampledFieldID::Qi: return "qi";
170  case SampledFieldID::Qr: return "qr";
171  case SampledFieldID::Qs: return "qs";
172  case SampledFieldID::Qg: return "qg";
173  case SampledFieldID::UEast: return "u_east";
174  case SampledFieldID::VNorth: return "v_north";
175  case SampledFieldID::W: return "w";
176  case SampledFieldID::WindSpeed: return "wind_speed";
177  case SampledFieldID::WindDir: return "wind_dir";
178  }
179 
180  return "unknown";
181 }
182 
183 } // namespace plotfile2d
184 
185 #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:39
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:101
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_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_nd)
Definition: ERF_TerrainMetrics.H:740
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:694
@ rho
Definition: ERF_Kessler.H:24
Definition: ERF_Plotfile2DCatalog.cpp:10
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 > &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:95
const char * sampled_field_name(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:158
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::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:195
Definition: ERF_DataStruct.H:634
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