ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Plotfile2DSampledField.H
Go to the documentation of this file.
1 #ifndef ERF_PLOTFILE2DSAMPLED_FIELD_H_
2 #define ERF_PLOTFILE2DSAMPLED_FIELD_H_
3 
4 #include <string>
5 
6 #include <AMReX_GpuQualifiers.H>
7 #include <AMReX_Vector.H>
8 
9 #include "ERF_DataStruct.H"
10 #include "ERF_EOS.H"
11 #include "ERF_TerrainMetrics.H"
12 
13 // Field registry for sampled-level 2D diagnostics. Each field defines its
14 // public name, units, availability, and cell-centered value. Derived fields can
15 // be added here without changing the sampled-level parser.
16 
17 namespace plotfile2d
18 {
19 
20 enum class SampledFieldID
21 {
22  Rho,
23  Theta,
24  Temp,
25  Pressure,
26  HeightMSL,
27  HeightAGL,
28  Qv,
29  Qc,
30  Qi,
31  Qr,
32  Qs,
33  Qg,
34  UEast,
35  VNorth,
36  W,
37  WindSpeed,
38  WindDir
39 };
40 
42 {
44  const char* name;
45  const char* long_name;
46  const char* units;
47 };
48 
50 {
51  amrex::Vector<SampledFieldDescriptor> accepted;
52  amrex::Vector<std::string> unavailable;
53 };
54 
55 const amrex::Vector<SampledFieldDescriptor>& sampled_field_catalog ();
56 
57 const SampledFieldDescriptor* find_sampled_field (const std::string& name);
58 
59 amrex::Vector<std::string> available_sampled_field_names (const SolverChoice& solver_choice);
60 
61 SampledFieldSelection select_requested_sampled_fields (const amrex::Vector<std::string>& requested,
62  const SolverChoice& solver_choice);
63 
64 std::string sampled_field_id_to_string (SampledFieldID field_id);
65 
66 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
67 bool sampled_field_is_wind (SampledFieldID field_id) noexcept
68 {
69  switch (field_id) {
72  case SampledFieldID::W:
75  return true;
76  default:
77  return false;
78  }
79 }
80 
81 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
83 {
84  return !sampled_field_is_wind(field_id);
85 }
86 
87 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
89  const amrex::Array4<const amrex::Real>& cons_arr,
90  const amrex::Array4<const amrex::Real>& z_phys_cc_arr,
91  const amrex::Array4<const amrex::Real>& z_phys_nd_arr,
92  bool have_z_phys_cc,
93  int i, int j, int k,
94  const MoistureComponentIndices& moisture_indices) noexcept
95 {
96  const amrex::Real rho = cons_arr(i, j, k, Rho_comp);
97  const bool has_moisture = (moisture_indices.qv >= 0);
98  // Microphysical fields are sampled as mixing ratios. The conserved state
99  // stores rho*q, so field evaluation divides by rho before interpolation.
100  const amrex::Real qv_for_eos = has_moisture
101  ? cons_arr(i, j, k, moisture_indices.qv) / rho
102  : amrex::Real(0.0);
103 
104  switch (field_id) {
105  case SampledFieldID::Rho:
106  return rho;
108  return cons_arr(i, j, k, RhoTheta_comp) / rho;
110  return getTgivenRandRTh(rho, cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
112  return getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
114  if (have_z_phys_cc) {
115  return z_phys_cc_arr(i, j, k);
116  }
117  return Compute_Z_AtCellCenter(i, j, k, z_phys_nd_arr);
119  return Compute_Zrel_AtCellCenter(i, j, k, z_phys_nd_arr);
120  case SampledFieldID::Qv:
121  return has_moisture ? cons_arr(i, j, k, moisture_indices.qv) / rho : amrex::Real(0.0);
122  case SampledFieldID::Qc:
123  return (moisture_indices.qc >= 0) ? cons_arr(i, j, k, moisture_indices.qc) / rho : amrex::Real(0.0);
124  case SampledFieldID::Qi:
125  return (moisture_indices.qi >= 0) ? cons_arr(i, j, k, moisture_indices.qi) / rho : amrex::Real(0.0);
126  case SampledFieldID::Qr:
127  return (moisture_indices.qr >= 0) ? cons_arr(i, j, k, moisture_indices.qr) / rho : amrex::Real(0.0);
128  case SampledFieldID::Qs:
129  return (moisture_indices.qs >= 0) ? cons_arr(i, j, k, moisture_indices.qs) / rho : amrex::Real(0.0);
130  case SampledFieldID::Qg:
131  return (moisture_indices.qg >= 0) ? cons_arr(i, j, k, moisture_indices.qg) / rho : amrex::Real(0.0);
134  case SampledFieldID::W:
137  return amrex::Real(0.0);
138  }
139 
140  return amrex::Real(0.0);
141 }
142 
143 inline const char*
145 {
146  switch (field_id) {
147  case SampledFieldID::Rho: return "rho";
148  case SampledFieldID::Theta: return "theta";
149  case SampledFieldID::Temp: return "temp";
150  case SampledFieldID::Pressure: return "pressure";
151  case SampledFieldID::HeightMSL: return "height_msl";
152  case SampledFieldID::HeightAGL: return "height_agl";
153  case SampledFieldID::Qv: return "qv";
154  case SampledFieldID::Qc: return "qc";
155  case SampledFieldID::Qi: return "qi";
156  case SampledFieldID::Qr: return "qr";
157  case SampledFieldID::Qs: return "qs";
158  case SampledFieldID::Qg: return "qg";
159  case SampledFieldID::UEast: return "u_east";
160  case SampledFieldID::VNorth: return "v_north";
161  case SampledFieldID::W: return "w";
162  case SampledFieldID::WindSpeed: return "wind_speed";
163  case SampledFieldID::WindDir: return "wind_dir";
164  }
165 
166  return "unknown";
167 }
168 
169 } // namespace plotfile2d
170 
171 #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:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
rho
Definition: ERF_InitCustomPert_Bubble.H:107
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:97
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:389
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:361
Definition: ERF_Plotfile2DCatalog.cpp:7
const char * sampled_field_name(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:144
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sampled_field_is_wind(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:67
SampledFieldSelection select_requested_sampled_fields(const amrex::Vector< std::string > &requested, const SolverChoice &solver_choice)
Definition: ERF_Plotfile2DSampledField.cpp:106
const SampledFieldDescriptor * find_sampled_field(const std::string &name)
Definition: ERF_Plotfile2DSampledField.cpp:79
std::string sampled_field_id_to_string(SampledFieldID field_id)
Definition: ERF_Plotfile2DSampledField.cpp:134
const amrex::Vector< SampledFieldDescriptor > & sampled_field_catalog()
Definition: ERF_Plotfile2DSampledField.cpp:73
amrex::Vector< std::string > available_sampled_field_names(const SolverChoice &solver_choice)
Definition: ERF_Plotfile2DSampledField.cpp:91
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, bool have_z_phys_cc, int i, int j, int k, const MoistureComponentIndices &moisture_indices) noexcept
Definition: ERF_Plotfile2DSampledField.H:88
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sampled_field_is_scalar_state(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:82
SampledFieldID
Definition: ERF_Plotfile2DSampledField.H:21
Definition: ERF_DataStruct.H:106
Definition: ERF_DataStruct.H:141
Definition: ERF_Plotfile2DSampledField.H:42
SampledFieldID id
Definition: ERF_Plotfile2DSampledField.H:43
const char * name
Definition: ERF_Plotfile2DSampledField.H:44
const char * units
Definition: ERF_Plotfile2DSampledField.H:46
const char * long_name
Definition: ERF_Plotfile2DSampledField.H:45
Definition: ERF_Plotfile2DSampledField.H:50
amrex::Vector< std::string > unavailable
Definition: ERF_Plotfile2DSampledField.H:52
amrex::Vector< SampledFieldDescriptor > accepted
Definition: ERF_Plotfile2DSampledField.H:51