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 {
13 };
14 
16 {
17  None,
19 };
20 
21 inline const char*
23 {
24  switch (mode) {
25  case ShocTransportMode::StateUpdate: return "state_update";
26  }
27  return "unknown";
28 }
29 
30 inline const char*
32 {
33  switch (mode) {
34  case ShocMomentumTransport::None: return "none";
35  case ShocMomentumTransport::StateUpdate: return "state_update";
36  }
37  return "unknown";
38 }
39 
40 inline bool
42 {
43  return (mode == ShocMomentumTransport::StateUpdate);
44 }
45 
46 inline bool
48 {
49  return (mode == ShocMomentumTransport::None);
50 }
51 
52 inline std::string
53 shoc_to_lower (std::string value)
54 {
55  std::transform(value.begin(), value.end(), value.begin(),
56  [] (unsigned char c) { return static_cast<char>(std::tolower(c)); });
57  return value;
58 }
59 
60 inline bool
62  ShocTransportMode& mode,
63  std::string& error_message)
64 {
65  value = shoc_to_lower(value);
66  if (value == "state_update") {
68  return true;
69  }
70  if (value == "host_diffusion") {
71  error_message =
72  "erf.shoc.transport_mode = host_diffusion has been removed for native SHOC. Use erf.shoc.transport_mode = state_update.";
73  return false;
74  }
75  if (value == "tendencies") {
76  error_message =
77  "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.";
78  return false;
79  }
80 
81  error_message = "erf.shoc.transport_mode must be 'state_update'";
82  return false;
83 }
84 
85 inline bool
88  std::string& error_message)
89 {
90  value = shoc_to_lower(value);
91  if (value == "none") {
93  return true;
94  }
95  if (value == "state_update") {
97  return true;
98  }
99  if (value == "host_diffusion") {
100  error_message =
101  "erf.shoc.momentum_transport = host_diffusion has been removed for native SHOC. Use 'state_update' to retain SHOC momentum transport, or 'none' to disable SHOC momentum transport.";
102  return false;
103  }
104 
105  error_message = "erf.shoc.momentum_transport must be 'none' or 'state_update'";
106  return false;
107 }
108 
109 /**
110  * @brief Read the native SHOC transport modes from the erf.shoc input namespace.
111  *
112  * This is the single parse point shared by SolverChoice and the SHOC runtime
113  * options, so the dycore and the SHOC driver can never disagree about which
114  * component owns transport. Values that are absent from the inputs leave the
115  * incoming modes untouched.
116  */
117 inline void
119  ShocMomentumTransport& momentum_transport)
120 {
121  amrex::ParmParse pp("erf.shoc");
122 
123  std::string transport_mode_string;
124  if (pp.query("transport_mode", transport_mode_string)) {
125  std::string error_message;
126  if (!parse_shoc_transport_mode_string(transport_mode_string,
127  transport_mode,
128  error_message)) {
129  amrex::Abort(error_message.c_str());
130  }
131  }
132 
133  std::string momentum_transport_string;
134  if (pp.query("momentum_transport", momentum_transport_string)) {
135  std::string error_message;
136  if (!parse_shoc_momentum_transport_string(momentum_transport_string,
137  momentum_transport,
138  error_message)) {
139  amrex::Abort(error_message.c_str());
140  }
141  }
142 }
143 #endif
ParmParse pp("prob")
bool parse_shoc_momentum_transport_string(std::string value, ShocMomentumTransport &mode, std::string &error_message)
Definition: ERF_ShocTransportStruct.H:86
bool parse_shoc_transport_mode_string(std::string value, ShocTransportMode &mode, std::string &error_message)
Definition: ERF_ShocTransportStruct.H:61
const char * shoc_transport_mode_name(ShocTransportMode mode)
Definition: ERF_ShocTransportStruct.H:22
ShocMomentumTransport
Definition: ERF_ShocTransportStruct.H:16
bool shoc_disables_momentum_transport(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:47
bool shoc_uses_momentum_state_update(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:41
std::string shoc_to_lower(std::string value)
Definition: ERF_ShocTransportStruct.H:53
const char * shoc_momentum_transport_name(ShocMomentumTransport mode)
Definition: ERF_ShocTransportStruct.H:31
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:118
ShocTransportMode
Definition: ERF_ShocTransportStruct.H:11