ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ShocTypes.H
Go to the documentation of this file.
1 #ifndef ERF_SHOC_TYPES_H_
2 #define ERF_SHOC_TYPES_H_
3 
4 #include "ERF_DataStruct.H"
5 
6 #include <AMReX_FArrayBox.H>
7 #include <AMReX_Geometry.H>
8 #include <AMReX_GpuQualifiers.H>
9 #include <AMReX_ParmParse.H>
10 #include <AMReX_Vector.H>
11 
12 #include <algorithm>
13 #include <cctype>
14 #include <string>
15 
17 {
18  amrex::Real lambda_low = amrex::Real(0.001);
19  amrex::Real lambda_high = amrex::Real(0.04);
20  amrex::Real lambda_slope = amrex::Real(2.65);
21  amrex::Real lambda_thresh = amrex::Real(0.02);
22 
23  amrex::Real thl2tune = amrex::Real(1);
24  amrex::Real qw2tune = amrex::Real(1);
25  amrex::Real qwthl2tune = amrex::Real(1);
26  amrex::Real w2tune = amrex::Real(1);
27 
28  amrex::Real length_fac = amrex::Real(0.5);
29  amrex::Real c_diag_3rd_mom = amrex::Real(7.0);
30  amrex::Real coeff_kh = amrex::Real(0.1);
31  amrex::Real coeff_km = amrex::Real(0.1);
32  amrex::Real top_taper_depth = amrex::Real(0.0);
33  amrex::Real top_taper_min_factor = amrex::Real(0.0);
34 
35  bool shoc_1p5tke = false;
36  bool extra_shoc_diags = false;
38  bool debug_summary = false;
40  bool signed_tke_production = false;
43  bool debug_bad_column = false;
46  amrex::Real debug_bad_column_theta_tend_threshold = amrex::Real(10.0);
47  amrex::Real debug_bad_column_q_tend_threshold = amrex::Real(1.0e-2);
48  amrex::Real debug_bad_column_brunt_threshold = amrex::Real(1.0);
49  amrex::Real debug_bad_column_min_dz = amrex::Real(1.0);
50  amrex::Real debug_bad_column_scalar_moment_threshold = amrex::Real(1.0e4);
55 };
56 
58 {
59  int nx = 0;
60  int ny = 0;
61  int ncell = 0;
62  int nlev = 0;
63  int imin = 0;
64  int jmin = 0;
65  int kmin = 0;
66  int kmax = -1;
67 };
68 
70 {
72 
73  // Absolute physical cell-center and interface heights [m].
74  amrex::FArrayBox zt;
75  amrex::FArrayBox zi;
76  amrex::FArrayBox dz;
77  amrex::FArrayBox p_mid;
78  amrex::FArrayBox p_int;
79  amrex::FArrayBox rho;
80  amrex::FArrayBox theta;
81  amrex::FArrayBox exner;
82  amrex::FArrayBox theta_v;
83  amrex::FArrayBox thetal;
84  amrex::FArrayBox qv;
85  amrex::FArrayBox qc;
86  amrex::FArrayBox qi;
87  amrex::FArrayBox qw;
88  amrex::FArrayBox tabs;
89  amrex::FArrayBox tke;
90  amrex::FArrayBox u;
91  amrex::FArrayBox v;
92  amrex::FArrayBox w;
93  amrex::FArrayBox host_dse;
94 
95  // Map-factor product m_x m_y of each column (1 without map factors): the physical cell
96  // area is dx dy / (m_x m_y).
97  amrex::FArrayBox mf_area;
98 
99  // Native SHOC PBL height in meters above local ground (AGL).
100  amrex::FArrayBox pblh;
101  amrex::FArrayBox obklen;
102  amrex::FArrayBox ustar;
103  amrex::FArrayBox shoc_mix;
104  amrex::FArrayBox brunt;
105  amrex::FArrayBox isotropy;
106  amrex::FArrayBox tk;
107  amrex::FArrayBox tkh;
108  amrex::FArrayBox shear_prod;
109  amrex::FArrayBox buoy_prod;
110  amrex::FArrayBox diss_tke;
111  amrex::FArrayBox wthv_sec;
112  amrex::FArrayBox shoc_cldfrac;
113  amrex::FArrayBox shoc_ql;
114  amrex::FArrayBox shoc_ql2;
115  amrex::FArrayBox wqls_sec;
116  amrex::FArrayBox shoc_cond;
117  amrex::FArrayBox shoc_evap;
118 
119  amrex::FArrayBox thl_sec;
120  amrex::FArrayBox qw_sec;
121  amrex::FArrayBox qwthl_sec;
122  amrex::FArrayBox wthl_sec;
123  amrex::FArrayBox wqw_sec;
124  amrex::FArrayBox uw_sec;
125  amrex::FArrayBox vw_sec;
126  amrex::FArrayBox wtke_sec;
127  amrex::FArrayBox w3;
128  amrex::FArrayBox w_sec;
129 
130  amrex::FArrayBox thetal_base;
131  amrex::FArrayBox theta_base;
132  amrex::FArrayBox qv_base;
133  amrex::FArrayBox qc_base;
134  amrex::FArrayBox qi_base;
135  amrex::FArrayBox u_base;
136  amrex::FArrayBox v_base;
137  amrex::FArrayBox tke_base_state;
138 
139  amrex::FArrayBox theta_tend;
140  amrex::FArrayBox qv_tend;
141  amrex::FArrayBox qc_tend;
142  amrex::FArrayBox qi_tend;
143  amrex::FArrayBox u_tend;
144  amrex::FArrayBox v_tend;
145  amrex::FArrayBox tke_tend;
146  amrex::FArrayBox surf_sens_flux;
147  amrex::FArrayBox surf_lat_flux;
148  amrex::FArrayBox surf_tau_u;
149  amrex::FArrayBox surf_tau_v;
150 };
151 
152 inline void
154 {
155  amrex::ParmParse pp("erf.shoc");
156 
157  pp.query("lambda_low", opts.lambda_low);
158  pp.query("lambda_high", opts.lambda_high);
159  pp.query("lambda_slope", opts.lambda_slope);
160  pp.query("lambda_thresh", opts.lambda_thresh);
161  pp.query("thl2tune", opts.thl2tune);
162  pp.query("qw2tune", opts.qw2tune);
163  pp.query("qwthl2tune", opts.qwthl2tune);
164  pp.query("w2tune", opts.w2tune);
165  pp.query("length_fac", opts.length_fac);
166  pp.query("c_diag_3rd_mom", opts.c_diag_3rd_mom);
167  pp.query("coeff_kh", opts.coeff_kh);
168  pp.query("coeff_km", opts.coeff_km);
169  pp.query("top_taper_depth", opts.top_taper_depth);
170  pp.query("top_taper_min_factor", opts.top_taper_min_factor);
171  pp.query("shoc_1p5tke", opts.shoc_1p5tke);
172  pp.query("extra_shoc_diags", opts.extra_shoc_diags);
173  // apply_tms and check_flux_state were options of the EAMxx SHOC, which has been removed;
174  // native SHOC never used them, so a deck that still sets them stops here
175  for (const char* key : {"apply_tms", "check_flux_state"}) {
176  if (pp.contains(key)) {
177  amrex::Abort(std::string("erf.shoc.") + key + " is no longer accepted: it was an option "
178  "of the EAMxx SHOC, which has been removed, and native SHOC does not use it");
179  }
180  }
181  pp.query("column_conservation_check", opts.column_conservation_check);
182  pp.query("debug_summary", opts.debug_summary);
183  pp.query("allow_tendency_microphysics_overlap", opts.allow_tendency_microphysics_overlap);
184  pp.query("signed_tke_production", opts.signed_tke_production);
185  pp.query("debug_bad_column", opts.debug_bad_column);
186  pp.query("debug_bad_column_abort", opts.debug_bad_column_abort);
187  pp.query("debug_bad_column_max_reports", opts.debug_bad_column_max_reports);
188  pp.query("debug_bad_column_theta_tend_threshold", opts.debug_bad_column_theta_tend_threshold);
189  pp.query("debug_bad_column_q_tend_threshold", opts.debug_bad_column_q_tend_threshold);
190  pp.query("debug_bad_column_brunt_threshold", opts.debug_bad_column_brunt_threshold);
191  pp.query("debug_bad_column_min_dz", opts.debug_bad_column_min_dz);
192  pp.query("debug_bad_column_scalar_moment_threshold", opts.debug_bad_column_scalar_moment_threshold);
193  pp.query("debug_disable_pdf_cloud_increment", opts.debug_disable_pdf_cloud_increment);
194  pp.query("debug_disable_theta_state_update", opts.debug_disable_theta_state_update);
195  pp.query("debug_disable_moisture_state_update", opts.debug_disable_moisture_state_update);
196  pp.query("debug_disable_tke_state_update", opts.debug_disable_tke_state_update);
197 
198  // SolverChoice parses these too, since the dycore must know which component
199  // owns vertical diffusion before any SHOC driver exists. Both go through the
200  // same reader so the two views of the inputs cannot diverge.
202 }
203 
204 inline void
206 {
207  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(opts.lambda_low > 0.0, "erf.shoc.lambda_low must be positive");
209  "erf.shoc.lambda_high must be >= lambda_low");
210  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(opts.length_fac > 0.0, "erf.shoc.length_fac must be positive");
211  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(opts.coeff_kh >= 0.0, "erf.shoc.coeff_kh must be non-negative");
212  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(opts.coeff_km >= 0.0, "erf.shoc.coeff_km must be non-negative");
214  "erf.shoc.top_taper_depth must be non-negative");
216  opts.top_taper_min_factor <= 1.0,
217  "erf.shoc.top_taper_min_factor must be in [0, 1]");
219  "erf.shoc.debug_bad_column_max_reports must be positive");
221  "erf.shoc.debug_bad_column_theta_tend_threshold must be positive");
223  "erf.shoc.debug_bad_column_q_tend_threshold must be positive");
225  "erf.shoc.debug_bad_column_brunt_threshold must be positive");
227  "erf.shoc.debug_bad_column_min_dz must be positive");
229  "erf.shoc.debug_bad_column_scalar_moment_threshold must be positive");
230 }
231 
232 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
233 bool
234 shoc_valid_comp (int comp, int ncomp)
235 {
236  return comp >= 0 && comp < ncomp;
237 }
238 
239 template <typename T>
240 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
241 T
242 shoc_clamp (T value, T lo, T hi)
243 {
244  return amrex::max(lo, amrex::min(value, hi));
245 }
246 
247 #endif
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
ParmParse pp("prob")
ShocMomentumTransport
Definition: ERF_ShocTransportStruct.H:16
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
void validate_shoc_runtime_options(const ShocRuntimeOptions &opts)
Definition: ERF_ShocTypes.H:205
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool shoc_valid_comp(int comp, int ncomp)
Definition: ERF_ShocTypes.H:234
void read_shoc_runtime_options(ShocRuntimeOptions &opts)
Definition: ERF_ShocTypes.H:153
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T shoc_clamp(T value, T lo, T hi)
Definition: ERF_ShocTypes.H:242
@ T
Definition: ERF_IndexDefines.H:180
Definition: ERF_ShocTypes.H:70
amrex::FArrayBox theta_v
Definition: ERF_ShocTypes.H:82
amrex::FArrayBox theta
Definition: ERF_ShocTypes.H:80
amrex::FArrayBox qc_tend
Definition: ERF_ShocTypes.H:141
amrex::FArrayBox theta_base
Definition: ERF_ShocTypes.H:131
amrex::FArrayBox v_tend
Definition: ERF_ShocTypes.H:144
amrex::FArrayBox shoc_cond
Definition: ERF_ShocTypes.H:116
amrex::FArrayBox qi
Definition: ERF_ShocTypes.H:86
amrex::FArrayBox buoy_prod
Definition: ERF_ShocTypes.H:109
amrex::FArrayBox dz
Definition: ERF_ShocTypes.H:76
amrex::FArrayBox diss_tke
Definition: ERF_ShocTypes.H:110
amrex::FArrayBox w_sec
Definition: ERF_ShocTypes.H:128
amrex::FArrayBox tk
Definition: ERF_ShocTypes.H:106
amrex::FArrayBox w3
Definition: ERF_ShocTypes.H:127
amrex::FArrayBox vw_sec
Definition: ERF_ShocTypes.H:125
amrex::FArrayBox surf_lat_flux
Definition: ERF_ShocTypes.H:147
amrex::FArrayBox ustar
Definition: ERF_ShocTypes.H:102
amrex::FArrayBox shoc_evap
Definition: ERF_ShocTypes.H:117
amrex::FArrayBox shoc_mix
Definition: ERF_ShocTypes.H:103
amrex::FArrayBox v_base
Definition: ERF_ShocTypes.H:136
amrex::FArrayBox wthv_sec
Definition: ERF_ShocTypes.H:111
amrex::FArrayBox shear_prod
Definition: ERF_ShocTypes.H:108
amrex::FArrayBox rho
Definition: ERF_ShocTypes.H:79
amrex::FArrayBox tke_base_state
Definition: ERF_ShocTypes.H:137
amrex::FArrayBox wqw_sec
Definition: ERF_ShocTypes.H:123
amrex::FArrayBox qv_base
Definition: ERF_ShocTypes.H:132
amrex::FArrayBox shoc_ql
Definition: ERF_ShocTypes.H:113
amrex::FArrayBox uw_sec
Definition: ERF_ShocTypes.H:124
amrex::FArrayBox w
Definition: ERF_ShocTypes.H:92
amrex::FArrayBox host_dse
Definition: ERF_ShocTypes.H:93
amrex::FArrayBox pblh
Definition: ERF_ShocTypes.H:100
amrex::FArrayBox qc
Definition: ERF_ShocTypes.H:85
amrex::FArrayBox surf_tau_v
Definition: ERF_ShocTypes.H:149
amrex::FArrayBox isotropy
Definition: ERF_ShocTypes.H:105
amrex::FArrayBox tke
Definition: ERF_ShocTypes.H:89
amrex::FArrayBox p_int
Definition: ERF_ShocTypes.H:78
amrex::FArrayBox qw_sec
Definition: ERF_ShocTypes.H:120
amrex::FArrayBox qi_base
Definition: ERF_ShocTypes.H:134
amrex::FArrayBox tkh
Definition: ERF_ShocTypes.H:107
amrex::FArrayBox exner
Definition: ERF_ShocTypes.H:81
amrex::FArrayBox u_base
Definition: ERF_ShocTypes.H:135
amrex::FArrayBox tke_tend
Definition: ERF_ShocTypes.H:145
amrex::FArrayBox qi_tend
Definition: ERF_ShocTypes.H:142
amrex::FArrayBox qc_base
Definition: ERF_ShocTypes.H:133
amrex::FArrayBox u_tend
Definition: ERF_ShocTypes.H:143
ShocColumnLayout layout
Definition: ERF_ShocTypes.H:71
amrex::FArrayBox zi
Definition: ERF_ShocTypes.H:75
amrex::FArrayBox mf_area
Definition: ERF_ShocTypes.H:97
amrex::FArrayBox tabs
Definition: ERF_ShocTypes.H:88
amrex::FArrayBox surf_sens_flux
Definition: ERF_ShocTypes.H:146
amrex::FArrayBox qw
Definition: ERF_ShocTypes.H:87
amrex::FArrayBox v
Definition: ERF_ShocTypes.H:91
amrex::FArrayBox zt
Definition: ERF_ShocTypes.H:74
amrex::FArrayBox qv
Definition: ERF_ShocTypes.H:84
amrex::FArrayBox p_mid
Definition: ERF_ShocTypes.H:77
amrex::FArrayBox wtke_sec
Definition: ERF_ShocTypes.H:126
amrex::FArrayBox u
Definition: ERF_ShocTypes.H:90
amrex::FArrayBox theta_tend
Definition: ERF_ShocTypes.H:139
amrex::FArrayBox obklen
Definition: ERF_ShocTypes.H:101
amrex::FArrayBox wqls_sec
Definition: ERF_ShocTypes.H:115
amrex::FArrayBox surf_tau_u
Definition: ERF_ShocTypes.H:148
amrex::FArrayBox qv_tend
Definition: ERF_ShocTypes.H:140
amrex::FArrayBox wthl_sec
Definition: ERF_ShocTypes.H:122
amrex::FArrayBox thl_sec
Definition: ERF_ShocTypes.H:119
amrex::FArrayBox shoc_ql2
Definition: ERF_ShocTypes.H:114
amrex::FArrayBox thetal_base
Definition: ERF_ShocTypes.H:130
amrex::FArrayBox qwthl_sec
Definition: ERF_ShocTypes.H:121
amrex::FArrayBox brunt
Definition: ERF_ShocTypes.H:104
amrex::FArrayBox shoc_cldfrac
Definition: ERF_ShocTypes.H:112
amrex::FArrayBox thetal
Definition: ERF_ShocTypes.H:83
Definition: ERF_ShocTypes.H:58
int imin
Definition: ERF_ShocTypes.H:63
int nlev
Definition: ERF_ShocTypes.H:62
int kmax
Definition: ERF_ShocTypes.H:66
int ncell
Definition: ERF_ShocTypes.H:61
int jmin
Definition: ERF_ShocTypes.H:64
int ny
Definition: ERF_ShocTypes.H:60
int nx
Definition: ERF_ShocTypes.H:59
int kmin
Definition: ERF_ShocTypes.H:65
Definition: ERF_ShocTypes.H:17
int debug_bad_column_max_reports
Definition: ERF_ShocTypes.H:45
ShocTransportMode transport_mode
Definition: ERF_ShocTypes.H:41
bool debug_disable_moisture_state_update
Definition: ERF_ShocTypes.H:53
bool shoc_1p5tke
Definition: ERF_ShocTypes.H:35
amrex::Real debug_bad_column_q_tend_threshold
Definition: ERF_ShocTypes.H:47
amrex::Real coeff_kh
Definition: ERF_ShocTypes.H:30
amrex::Real top_taper_depth
Definition: ERF_ShocTypes.H:32
amrex::Real debug_bad_column_scalar_moment_threshold
Definition: ERF_ShocTypes.H:50
amrex::Real lambda_high
Definition: ERF_ShocTypes.H:19
amrex::Real w2tune
Definition: ERF_ShocTypes.H:26
amrex::Real debug_bad_column_min_dz
Definition: ERF_ShocTypes.H:49
amrex::Real qwthl2tune
Definition: ERF_ShocTypes.H:25
bool debug_disable_pdf_cloud_increment
Definition: ERF_ShocTypes.H:51
amrex::Real c_diag_3rd_mom
Definition: ERF_ShocTypes.H:29
ShocMomentumTransport momentum_transport
Definition: ERF_ShocTypes.H:42
bool column_conservation_check
Definition: ERF_ShocTypes.H:37
amrex::Real lambda_thresh
Definition: ERF_ShocTypes.H:21
bool extra_shoc_diags
Definition: ERF_ShocTypes.H:36
amrex::Real coeff_km
Definition: ERF_ShocTypes.H:31
bool debug_disable_theta_state_update
Definition: ERF_ShocTypes.H:52
amrex::Real debug_bad_column_theta_tend_threshold
Definition: ERF_ShocTypes.H:46
amrex::Real lambda_slope
Definition: ERF_ShocTypes.H:20
amrex::Real lambda_low
Definition: ERF_ShocTypes.H:18
bool debug_bad_column
Definition: ERF_ShocTypes.H:43
bool signed_tke_production
Definition: ERF_ShocTypes.H:40
amrex::Real debug_bad_column_brunt_threshold
Definition: ERF_ShocTypes.H:48
bool debug_disable_tke_state_update
Definition: ERF_ShocTypes.H:54
bool debug_bad_column_abort
Definition: ERF_ShocTypes.H:44
bool allow_tendency_microphysics_overlap
Definition: ERF_ShocTypes.H:39
amrex::Real length_fac
Definition: ERF_ShocTypes.H:28
amrex::Real top_taper_min_factor
Definition: ERF_ShocTypes.H:33
amrex::Real thl2tune
Definition: ERF_ShocTypes.H:23
amrex::Real qw2tune
Definition: ERF_ShocTypes.H:24
bool debug_summary
Definition: ERF_ShocTypes.H:38