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 AMREX_GPU_DEVICE AMREX_FORCE_INLINE
92  const amrex::Array4<const amrex::Real>& cons_arr,
93  const amrex::Array4<const amrex::Real>& z_phys_cc_arr,
94  const amrex::Array4<const amrex::Real>& z_phys_nd_arr,
95  bool have_z_phys_cc,
96  int i, int j, int k,
97  const MoistureComponentIndices& moisture_indices) noexcept
98 {
99  const amrex::Real rho = cons_arr(i, j, k, Rho_comp);
100  const bool has_moisture = (moisture_indices.qv >= 0);
101  // Microphysical fields are sampled as mixing ratios. The conserved state
102  // stores rho*q, so field evaluation divides by rho before interpolation.
103  const amrex::Real qv_for_eos = has_moisture
104  ? cons_arr(i, j, k, moisture_indices.qv) / rho
105  : amrex::Real(0.0);
106 
107  switch (field_id) {
108  case SampledFieldID::Rho:
109  return rho;
111  return cons_arr(i, j, k, RhoTheta_comp) / rho;
113  return getTgivenRandRTh(rho, cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
115  return getPgivenRTh(cons_arr(i, j, k, RhoTheta_comp), qv_for_eos);
117  if (have_z_phys_cc) {
118  return z_phys_cc_arr(i, j, k);
119  }
120  return Compute_Z_AtCellCenter(i, j, k, z_phys_nd_arr);
122  return Compute_Zrel_AtCellCenter(i, j, k, z_phys_nd_arr);
123  case SampledFieldID::Qv:
124  return has_moisture ? cons_arr(i, j, k, moisture_indices.qv) / rho : amrex::Real(0.0);
125  case SampledFieldID::Qc:
126  return (moisture_indices.qc >= 0) ? cons_arr(i, j, k, moisture_indices.qc) / rho : amrex::Real(0.0);
127  case SampledFieldID::Qi:
128  return (moisture_indices.qi >= 0) ? cons_arr(i, j, k, moisture_indices.qi) / rho : amrex::Real(0.0);
129  case SampledFieldID::Qr:
130  return (moisture_indices.qr >= 0) ? cons_arr(i, j, k, moisture_indices.qr) / rho : amrex::Real(0.0);
131  case SampledFieldID::Qs:
132  return (moisture_indices.qs >= 0) ? cons_arr(i, j, k, moisture_indices.qs) / rho : amrex::Real(0.0);
133  case SampledFieldID::Qg:
134  return (moisture_indices.qg >= 0) ? cons_arr(i, j, k, moisture_indices.qg) / rho : amrex::Real(0.0);
137  case SampledFieldID::W:
140  return amrex::Real(0.0);
141  }
142 
143  return amrex::Real(0.0);
144 }
145 
146 inline const char*
148 {
149  switch (field_id) {
150  case SampledFieldID::Rho: return "rho";
151  case SampledFieldID::Theta: return "theta";
152  case SampledFieldID::Temp: return "temp";
153  case SampledFieldID::Pressure: return "pressure";
154  case SampledFieldID::HeightMSL: return "height_msl";
155  case SampledFieldID::HeightAGL: return "height_agl";
156  case SampledFieldID::Qv: return "qv";
157  case SampledFieldID::Qc: return "qc";
158  case SampledFieldID::Qi: return "qi";
159  case SampledFieldID::Qr: return "qr";
160  case SampledFieldID::Qs: return "qs";
161  case SampledFieldID::Qg: return "qg";
162  case SampledFieldID::UEast: return "u_east";
163  case SampledFieldID::VNorth: return "v_north";
164  case SampledFieldID::W: return "w";
165  case SampledFieldID::WindSpeed: return "wind_speed";
166  case SampledFieldID::WindDir: return "wind_dir";
167  }
168 
169  return "unknown";
170 }
171 
172 } // namespace plotfile2d
173 
174 #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: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: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:10
const char * sampled_field_name(SampledFieldID field_id) noexcept
Definition: ERF_Plotfile2DSampledField.H:147
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_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:91
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
Component indices for moisture species in the conserved state.
Definition: ERF_DataStruct.H:166
Definition: ERF_DataStruct.H:241
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