ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ShocTransportStruct.H
Go to the documentation of this file.
1 #ifndef ERF_SHOC_TRANSPORT_STRUCT_H_
2 #define ERF_SHOC_TRANSPORT_STRUCT_H_
3 
4 #include <AMReX_ParmParse.H>
5 
6 #include <algorithm>
7 #include <cctype>
8 #include <string>
9 
11 {
14 };
15 
17 {
18  None,
21 };
22 
23 inline const char*
25 {
26  switch (mode) {
27  case ShocTransportMode::StateUpdate: return "state_update";
28  case ShocTransportMode::HostDiffusion: return "host_diffusion";
29  }
30  return "unknown";
31 }
32 
33 inline const char*
35 {
36  switch (mode) {
37  case ShocMomentumTransport::None: return "none";
38  case ShocMomentumTransport::StateUpdate: return "state_update";
39  case ShocMomentumTransport::HostDiffusion: return "host_diffusion";
40  }
41  return "unknown";
42 }
43 
44 inline bool
46 {
47  return (mode == ShocTransportMode::StateUpdate);
48 }
49 
50 inline bool
52 {
53  return (mode == ShocTransportMode::HostDiffusion);
54 }
55 
56 inline bool
58 {
59  return (mode == ShocMomentumTransport::StateUpdate);
60 }
61 
62 inline bool
64 {
65  return (mode == ShocMomentumTransport::HostDiffusion);
66 }
67 
68 inline bool
70 {
71  return (mode == ShocMomentumTransport::None);
72 }
73 
74 inline std::string
75 shoc_to_lower (std::string value)
76 {
77  std::transform(value.begin(), value.end(), value.begin(),
78  [] (unsigned char c) { return static_cast<char>(std::tolower(c)); });
79  return value;
80 }
81 
82 inline bool
84  ShocTransportMode& mode,
85  std::string& error_message)
86 {
87  value = shoc_to_lower(value);
88  if (value == "state_update") {
90  return true;
91  }
92  if (value == "host_diffusion") {
94  return true;
95  }
96  if (value == "tendencies") {
97  error_message =
98  "erf.shoc.transport_mode = tendencies has been removed for native SHOC. Use erf.shoc.transport_mode = state_update. Native SHOC now applies its coupled column increment before the dycore to avoid splitting theta and momentum from moisture.";
99  return false;
100  }
101 
102  error_message = "erf.shoc.transport_mode must be 'state_update' or 'host_diffusion'";
103  return false;
104 }
105 
106 inline bool
108  ShocMomentumTransport& mode,
109  std::string& error_message)
110 {
111  value = shoc_to_lower(value);
112  if (value == "none") {
114  return true;
115  }
116  if (value == "state_update") {
118  return true;
119  }
120  if (value == "host_diffusion") {
122  return true;
123  }
124 
125  error_message = "erf.shoc.momentum_transport must be 'none', 'state_update', or 'host_diffusion'";
126  return false;
127 }
128 
129 /**
130  * @brief Read the native SHOC transport modes from the erf.shoc input namespace.
131  *
132  * This is the single parse point shared by SolverChoice and the SHOC runtime
133  * options, so the dycore and the SHOC driver can never disagree about which
134  * component owns transport. Values that are absent from the inputs leave the
135  * incoming modes untouched.
136  */
137 inline void
139  ShocMomentumTransport& momentum_transport)
140 {
141  amrex::ParmParse pp("erf.shoc");
142 
143  std::string transport_mode_string;
144  if (pp.query("transport_mode", transport_mode_string)) {
145  std::string error_message;
146  if (!parse_shoc_transport_mode_string(transport_mode_string,
147  transport_mode,
148  error_message)) {
149  amrex::Abort(error_message.c_str());
150  }
151  }
152 
153  std::string momentum_transport_string;
154  if (pp.query("momentum_transport", momentum_transport_string)) {
155  std::string error_message;
156  if (!parse_shoc_momentum_transport_string(momentum_transport_string,
157  momentum_transport,
158  error_message)) {
159  amrex::Abort(error_message.c_str());
160  }
161  }
162 }
163 #endif
ParmParse pp("prob")
bool parse_shoc_momentum_transport_string(std::string value, ShocMomentumTransport &mode, std::string &error_message)
Definition: ERF_ShocTransportStruct.H:107
bool parse_shoc_transport_mode_string(std::string value, ShocTransportMode &mode, std::string &error_message)
Definition: ERF_ShocTransportStruct.H:83
const char * shoc_transport_mode_name(ShocTransportMode mode)
Definition: ERF_ShocTransportStruct.H:24
ShocMomentumTransport
Definition: ERF_ShocTransportStruct.H:17
bool shoc_disables_momentum_transport(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:69
bool shoc_uses_momentum_state_update(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:57
bool shoc_uses_host_diffusion(ShocTransportMode mode)
Definition: ERF_ShocTransportStruct.H:51
std::string shoc_to_lower(std::string value)
Definition: ERF_ShocTransportStruct.H:75
const char * shoc_momentum_transport_name(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:34
void read_shoc_transport_modes(ShocTransportMode &transport_mode, ShocMomentumTransport &momentum_transport)
Read the native SHOC transport modes from the erf.shoc input namespace.
Definition: ERF_ShocTransportStruct.H:138
bool shoc_uses_state_update(ShocTransportMode mode)
Definition: ERF_ShocTransportStruct.H:45
bool shoc_uses_momentum_host_diffusion(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:63
ShocTransportMode
Definition: ERF_ShocTransportStruct.H:11