ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_IndexDefines.H
Go to the documentation of this file.
1 #ifndef ERF_INDEX_DEFINES_H_
2 #define ERF_INDEX_DEFINES_H_
3 
4 #include <AMReX_REAL.H>
5 #include <AMReX_Arena.H>
6 #include <AMReX_Extension.H>
7 #include <AMReX_GpuQualifiers.H>
8 
9 /**
10  * Definition of indexing parameters
11 */
12 
13 // This defines the ACTUAL number of non-moisture vars =
14 // rho, rhotheta, rhoKE
15 #define NDRY 3
16 
17 // Smoke: a passive tracer the fire coupling emits from the fire's heat [kg/m^3],
18 // present in builds with the fire coupling (ERF_USE_FIRE)
19 #ifdef ERF_USE_FIRE
20 #define NSCALARS_SMOKE 1
21 #else
22 #define NSCALARS_SMOKE 0
23 #endif
24 
25 // This defines the ACTUAL number of non-moisture scalar vars
26 #define NSCALARS (1 + NSCALARS_SMOKE)
27 
28 // This defines the MAXIMUM number of moisture vars (six q's plus five n's)
29 #define NMOIST_max 11
30 
31 // This is the number of components if using moisture
32 // We use this to allocate the 1d arrays of boundary condition types,
33 // but not to allocate actual solution data
34 // Full moist state with no additional non-moist species
35 #define NVAR_MOIST_max (NDRY + NSCALARS + NMOIST_max)
36 
37 #define NVAR_max ((NDRY + NSCALARS + NMOIST_max) + 2*5) // allow up to 5 non-moist species
38 
39 // This is the number of components if we assume there is only one passive scalar
40 // We can use this when we assume all passive scalars have the same bc's
41 // We also assume (the final "+1" that the base state components have the same bcs)
42 #define NBCVAR_max ((NDRY + 1 + NMOIST_max + 1) + 2*5) // allow up to 5 non-moist species
43 
44 // Number of primitive components: one per conserved component after Rho_comp,
45 // counting every passive scalar (the base scalar and, with the fire coupling, smoke)
46 // and the moist quantities.
47 // The trailing 2*5 mirrors NVAR_max: a microphysics model may append up to 5 non-moist
48 // species (two components each) after the water species, and the diffusion coefficient
49 // tables are indexed by primitive component over that full range as well.
50 #define NPRIMVAR_max ((NDRY + NSCALARS + NMOIST_max) + 2*5)
51 
52 // Cell-centered state variables
53 #define Rho_comp 0
54 #define RhoTheta_comp (Rho_comp+1)
55 #define RhoKE_comp (Rho_comp+2) // for Deardorff LES Model, k-equation RANS, or MYNN PBL Model
56 
57 #define RhoScalar_comp (RhoKE_comp+1)
58 
59 // Scalar slots (consecutive, starting at RhoScalar_comp = NDRY):
60 // [RhoScalar_comp] always present (base passive scalar)
61 // [RhoSmoke_comp] smoke, only with ERF_USE_FIRE
62 // [RhoQ1_comp ...] moisture variables
63 #ifdef ERF_USE_FIRE
64 #define RhoSmoke_comp (RhoScalar_comp+1)
65 #endif
66 #define RhoQ1_comp (RhoScalar_comp+NSCALARS)
67 #define RhoQ2_comp (RhoQ1_comp+1)
68 #define RhoQ3_comp (RhoQ1_comp+2)
69 #define RhoQ4_comp (RhoQ1_comp+3)
70 #define RhoQ5_comp (RhoQ1_comp+4)
71 #define RhoQ6_comp (RhoQ1_comp+5)
72 #define RhoQ7_comp (RhoQ1_comp+6)
73 #define RhoQ8_comp (RhoQ1_comp+7)
74 #define RhoQ9_comp (RhoQ1_comp+8)
75 #define RhoQ10_comp (RhoQ1_comp+9)
76 #define RhoQ11_comp (RhoQ1_comp+10)
77 
78 // Cell-centered primitive variables
79 #define PrimTheta_comp (RhoTheta_comp -1)
80 #define PrimKE_comp (RhoKE_comp -1)
81 #define PrimScalar_comp (RhoScalar_comp-1)
82 #define PrimQ1_comp (RhoQ1_comp-1)
83 #define PrimQ2_comp (RhoQ2_comp-1)
84 #define PrimQ3_comp (RhoQ3_comp-1)
85 #define PrimQ4_comp (RhoQ4_comp-1)
86 #define PrimQ5_comp (RhoQ5_comp-1)
87 #define PrimQ6_comp (RhoQ6_comp-1)
88 #define PrimQ7_comp (RhoQ7_comp-1)
89 #define PrimQ8_comp (RhoQ8_comp-1)
90 #define PrimQ9_comp (RhoQ9_comp-1)
91 #define PrimQ10_comp (RhoQ10_comp-1)
92 #define PrimQ11_comp (RhoQ11_comp-1)
93 
94 // Base state variables
95 namespace BaseState {
96  enum {
97  r0_comp = 0,
102  num_comps
103  };
104 }
105 
106 // NOTE: we still use this indexing even if no moisture
107 // NOTE: We assume a single boundary condition for all passive scalars
108 namespace BCVars {
109  enum {
110  cons_bc = 0,
129  NumTypes
130  };
131 }
132 
133 /**
134  * The boundary-condition slot (BCVars) of conserved component n: every passive
135  * scalar shares BCVars::RhoScalar_bc_comp, and each component above the scalars
136  * has its own slot, NSCALARS - 1 below its component index. Boundary planes are
137  * stored by these slots too (ReadBndryPlanes::plane_slot).
138  */
139 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
140 int cons_bc_comp (int n) noexcept
141 {
142  if (n >= RhoScalar_comp && n < RhoScalar_comp + NSCALARS) { return BCVars::RhoScalar_bc_comp; }
143  return (n >= RhoScalar_comp + NSCALARS) ? n - (NSCALARS - 1) : n;
144 }
145 
146 AMREX_FORCE_INLINE
147 bool cons_bc_run_contiguous (int prev, int next) noexcept
148 {
149  return next == prev + 1 && cons_bc_comp(next) == cons_bc_comp(prev) + 1;
150 }
151 
152 // Note that we don't use these, but we need this vector to be long enough
153 // not to segfault when we do the FillPatch operation.
154 namespace BaseBCVars {
155  enum {
161  };
162 }
163 
164 namespace RealBdyVars {
165  enum {
166  U = 0,
167  V = 1,
168  T = 2,
169  QV = 3,
170  R = 4,
171  QC = 5,
172  QI = 6,
173  NumTypes
174  };
175 }
176 
177 // Additional runtime boundary slots used when all precipitating
178 // hydrometeors are represented as separate ERF state components. Keep the
179 // compact QC/QI indices above unchanged for aggregate-boundary compatibility.
181  enum {
183  QS,
184  QG,
185  NumTypes
186  };
187 }
188 
189 namespace WRFBdyVars {
190  enum {
191  U = 0,
192  V = 1,
193  T = 2,
194  QV = 3, // water vapor
195  R = 4, // density
196  PH , // Perturbational geopotential
197  MU , // bdy perturbation dry air mass in column (we will get mub from the initial data)
198  PC , // p_s - p_top = dry hydrostatic pressure difference between the surface and the model top
199  QC , // cloud water
200  QI , // cloud ice
201  NumTypes
202  };
203 
204  constexpr int LegacyNumTypes = PC + 1;
205 }
206 
207 // Additional serialized/cache slots used when all precipitating hydrometeors
208 // are retained separately. The legacy and aggregate layouts remain unchanged.
210  enum {
212  QS,
213  QG,
214  NumTypes
215  };
216 }
217 
218 static_assert(WRFBdyVars::U == 0 && WRFBdyVars::V == 1 &&
219  WRFBdyVars::T == 2 && WRFBdyVars::QV == 3 &&
220  WRFBdyVars::R == 4 && WRFBdyVars::PH == 5 &&
221  WRFBdyVars::MU == 6 && WRFBdyVars::PC == 7,
222  "The serialized legacy WRF boundary layout must not change");
223 
224 namespace MetGridBdyVars {
225  enum {
226  U = 0,
227  V = 1,
228  T = 2,
229  QV = 3,
230  NumTypes
231  };
232 }
233 
234 namespace MetGridTmpSrcVars {
235  enum {
236  Theta = 0,
237  QV = 1,
238  NumTypes
239  };
240 }
241 
242 namespace MetGridTmpDstVars {
243  enum {
244  P = 0,
245  T = 1,
246  Theta = 2,
247  QV = 3,
248  NumTypes
249  };
250 }
251 
252 namespace Vars {
253  enum {
254  cons = 0,
258  NumTypes
259  };
260 }
261 
262 namespace GpVars {
263  enum {
264  gpx = 0,
267  };
268 }
269 
270 namespace IntVars {
271  enum {
272  cons = 0,
276  NumTypes
277  };
278 }
279 
280 // We separate out horizontal and vertical turbulent diffusivities
281 // These are the same for LES, but different for PBL models
282 namespace EddyDiff {
283  enum {
284  Mom_h = 0,
295  // Nonlocal (countergradient) terms. All four are stored *normalized by the
296  // PBL height*, i.e. as a gradient of the transported quantity, so that the
297  // implicit vertical diffusion solvers form the countergradient flux as
298  // F_cg = +rho*alpha*gamma
299  // with no further metric or grid-spacing factors.
300  HGAMT_v, // MRF/YSU countergradient for heat (HGAMT/h, units K/m), zero outside PBL
301  HGAMQ_v, // MRF/YSU countergradient for moisture (HGAMQ/h, units kg/kg/m), zero outside PBL
302  HGAMU_v, // YSU countergradient for x-momentum (HGAMU/h, units 1/s), zero outside PBL
303  HGAMV_v, // YSU countergradient for y-momentum (HGAMV/h, units 1/s), zero outside PBL
304  // k-eqn RANS diagnostics: smoothed turbulent Richardson number and the
305  // two stability functions (Axell & Liungman 2001, Eqs. 29-32)
309  // k-eqn RANS: nu_t over its realizability cap C_r k / S (erf.rans_realizability);
310  // above 1 the cap is active, 0 when the cap is off
312  NumDiffs
313  };
314 }
315 
316 enum struct ERF_BC {
317  symmetry,
318  inflow,
319  outflow,
321  ho_outflow,
322  open,
323  no_slip_wall,
324  slip_wall,
325  periodic,
327  undefined
328 };
329 
330 // NOTE: the first of these must match up with the BCType enum
331 // in amrex/Src/Base/AMReX_BC_TYPES.H. We had extras at
332 // the end to use locally
333 namespace ERFBCType {
335  bogus = -666,
337  int_dir = 0,
339  foextrap = 2,
340  ext_dir = 3,
341  hoextrap = 4,
345  neumann = 104,
346  neumann_int = 105,
347  open = 106,
348  ext_dir_upwind = 107
349 };
350 }
351 
352 enum struct AdvType : int {
353  Centered_2nd = 101,
354  Upwind_3rd = 102,
355  Upwind_3rd_SL = 103,
356  Centered_4th = 104,
357  Upwind_5th = 105,
358  Centered_6th = 106,
359  Weno_3 = 107,
360  Weno_3Z = 108,
361  Weno_5 = 109,
362  Weno_5Z = 110,
363  Weno_3MZQ = 111,
364  Weno_7 = 112,
365  Weno_7Z = 113,
366  Unknown = 114
367 };
368 #endif
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:57
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int cons_bc_comp(int n) noexcept
Definition: ERF_IndexDefines.H:140
#define NBCVAR_max
Definition: ERF_IndexDefines.H:42
#define NSCALARS
Definition: ERF_IndexDefines.H:26
AMREX_FORCE_INLINE bool cons_bc_run_contiguous(int prev, int next) noexcept
Definition: ERF_IndexDefines.H:147
AdvType
Definition: ERF_IndexDefines.H:352
@ Upwind_3rd_SL
@ Centered_4th
@ Centered_6th
@ Centered_2nd
ERF_BC
Definition: ERF_IndexDefines.H:316
@ ho_outflow
@ inflow_outflow
@ no_slip_wall
@ surface_layer
Definition: ERF_IndexDefines.H:108
@ RhoQ6_bc_comp
Definition: ERF_IndexDefines.H:120
@ RhoScalar_bc_comp
Definition: ERF_IndexDefines.H:114
@ zvel_bc
Definition: ERF_IndexDefines.H:128
@ RhoQ1_bc_comp
Definition: ERF_IndexDefines.H:115
@ NumTypes
Definition: ERF_IndexDefines.H:129
@ RhoQ4_bc_comp
Definition: ERF_IndexDefines.H:118
@ RhoKE_bc_comp
Definition: ERF_IndexDefines.H:113
@ RhoQ7_bc_comp
Definition: ERF_IndexDefines.H:121
@ RhoQ10_bc_comp
Definition: ERF_IndexDefines.H:124
@ RhoQ3_bc_comp
Definition: ERF_IndexDefines.H:117
@ RhoTheta_bc_comp
Definition: ERF_IndexDefines.H:112
@ RhoQ2_bc_comp
Definition: ERF_IndexDefines.H:116
@ Rho_bc_comp
Definition: ERF_IndexDefines.H:111
@ RhoQ11_bc_comp
Definition: ERF_IndexDefines.H:125
@ yvel_bc
Definition: ERF_IndexDefines.H:127
@ cons_bc
Definition: ERF_IndexDefines.H:110
@ xvel_bc
Definition: ERF_IndexDefines.H:126
@ RhoQ9_bc_comp
Definition: ERF_IndexDefines.H:123
@ RhoQ8_bc_comp
Definition: ERF_IndexDefines.H:122
@ RhoQ5_bc_comp
Definition: ERF_IndexDefines.H:119
Definition: ERF_IndexDefines.H:154
@ rho0_bc_comp
Definition: ERF_IndexDefines.H:156
@ th0_bc_comp
Definition: ERF_IndexDefines.H:159
@ qv0_bc_comp
Definition: ERF_IndexDefines.H:160
@ pi0_bc_comp
Definition: ERF_IndexDefines.H:158
@ p0_bc_comp
Definition: ERF_IndexDefines.H:157
Definition: ERF_IndexDefines.H:95
@ num_comps
Definition: ERF_IndexDefines.H:102
@ qv0_comp
Definition: ERF_IndexDefines.H:101
@ pi0_comp
Definition: ERF_IndexDefines.H:99
@ p0_comp
Definition: ERF_IndexDefines.H:98
@ th0_comp
Definition: ERF_IndexDefines.H:100
@ r0_comp
Definition: ERF_IndexDefines.H:97
Definition: ERF_IndexDefines.H:333
mathematicalBndryTypes
Definition: ERF_IndexDefines.H:334
@ neumann
Definition: ERF_IndexDefines.H:345
@ ext_dir_ingested
Definition: ERF_IndexDefines.H:344
@ open
Definition: ERF_IndexDefines.H:347
@ reflect_odd
Definition: ERF_IndexDefines.H:336
@ hoextrap
Definition: ERF_IndexDefines.H:341
@ foextrap
Definition: ERF_IndexDefines.H:339
@ ext_dir
Definition: ERF_IndexDefines.H:340
@ ext_dir_prim
Definition: ERF_IndexDefines.H:343
@ bogus
Definition: ERF_IndexDefines.H:335
@ surface_layer
Definition: ERF_IndexDefines.H:342
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:348
@ int_dir
Definition: ERF_IndexDefines.H:337
@ neumann_int
Definition: ERF_IndexDefines.H:346
@ reflect_even
Definition: ERF_IndexDefines.H:338
Definition: ERF_IndexDefines.H:282
@ Theta_v
Definition: ERF_IndexDefines.H:290
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:294
@ Scalar_v
Definition: ERF_IndexDefines.H:292
@ Mom_h
Definition: ERF_IndexDefines.H:284
@ HGAMU_v
Definition: ERF_IndexDefines.H:302
@ Q_v
Definition: ERF_IndexDefines.H:293
@ Q_h
Definition: ERF_IndexDefines.H:288
@ Mom_v
Definition: ERF_IndexDefines.H:289
@ RANS_Rt
Definition: ERF_IndexDefines.H:306
@ HGAMQ_v
Definition: ERF_IndexDefines.H:301
@ HGAMT_v
Definition: ERF_IndexDefines.H:300
@ RANS_cap_ratio
Definition: ERF_IndexDefines.H:311
@ Scalar_h
Definition: ERF_IndexDefines.H:287
@ KE_v
Definition: ERF_IndexDefines.H:291
@ NumDiffs
Definition: ERF_IndexDefines.H:312
@ RANS_cmu
Definition: ERF_IndexDefines.H:307
@ Theta_h
Definition: ERF_IndexDefines.H:285
@ HGAMV_v
Definition: ERF_IndexDefines.H:303
@ KE_h
Definition: ERF_IndexDefines.H:286
@ RANS_cmu_prime
Definition: ERF_IndexDefines.H:308
Definition: ERF_IndexDefines.H:262
@ gpz
Definition: ERF_IndexDefines.H:266
@ gpy
Definition: ERF_IndexDefines.H:265
@ gpx
Definition: ERF_IndexDefines.H:264
Definition: ERF_IndexDefines.H:270
@ NumTypes
Definition: ERF_IndexDefines.H:276
@ ymom
Definition: ERF_IndexDefines.H:274
@ cons
Definition: ERF_IndexDefines.H:272
@ zmom
Definition: ERF_IndexDefines.H:275
@ xmom
Definition: ERF_IndexDefines.H:273
Definition: ERF_IndexDefines.H:224
@ U
Definition: ERF_IndexDefines.H:226
@ NumTypes
Definition: ERF_IndexDefines.H:230
@ V
Definition: ERF_IndexDefines.H:227
@ QV
Definition: ERF_IndexDefines.H:229
@ T
Definition: ERF_IndexDefines.H:228
Definition: ERF_IndexDefines.H:242
@ P
Definition: ERF_IndexDefines.H:244
@ Theta
Definition: ERF_IndexDefines.H:246
@ QV
Definition: ERF_IndexDefines.H:247
@ T
Definition: ERF_IndexDefines.H:245
@ NumTypes
Definition: ERF_IndexDefines.H:248
Definition: ERF_IndexDefines.H:234
@ Theta
Definition: ERF_IndexDefines.H:236
@ QV
Definition: ERF_IndexDefines.H:237
@ NumTypes
Definition: ERF_IndexDefines.H:238
Definition: ERF_IndexDefines.H:180
@ QG
Definition: ERF_IndexDefines.H:184
@ NumTypes
Definition: ERF_IndexDefines.H:185
@ QR
Definition: ERF_IndexDefines.H:182
@ QS
Definition: ERF_IndexDefines.H:183
Definition: ERF_IndexDefines.H:164
@ R
Definition: ERF_IndexDefines.H:170
@ U
Definition: ERF_IndexDefines.H:166
@ NumTypes
Definition: ERF_IndexDefines.H:173
@ QV
Definition: ERF_IndexDefines.H:169
@ T
Definition: ERF_IndexDefines.H:168
@ QC
Definition: ERF_IndexDefines.H:171
@ QI
Definition: ERF_IndexDefines.H:172
@ V
Definition: ERF_IndexDefines.H:167
Definition: ERF_IndexDefines.H:252
@ xvel
Definition: ERF_IndexDefines.H:255
@ cons
Definition: ERF_IndexDefines.H:254
@ zvel
Definition: ERF_IndexDefines.H:257
@ NumTypes
Definition: ERF_IndexDefines.H:258
@ yvel
Definition: ERF_IndexDefines.H:256
Definition: ERF_IndexDefines.H:209
@ NumTypes
Definition: ERF_IndexDefines.H:214
@ QS
Definition: ERF_IndexDefines.H:212
@ QG
Definition: ERF_IndexDefines.H:213
@ QR
Definition: ERF_IndexDefines.H:211
Definition: ERF_IndexDefines.H:189
constexpr int LegacyNumTypes
Definition: ERF_IndexDefines.H:204
@ QI
Definition: ERF_IndexDefines.H:200
@ QC
Definition: ERF_IndexDefines.H:199
@ T
Definition: ERF_IndexDefines.H:193
@ R
Definition: ERF_IndexDefines.H:195
@ QV
Definition: ERF_IndexDefines.H:194
@ V
Definition: ERF_IndexDefines.H:192
@ PC
Definition: ERF_IndexDefines.H:198
@ NumTypes
Definition: ERF_IndexDefines.H:201
@ MU
Definition: ERF_IndexDefines.H:197
@ U
Definition: ERF_IndexDefines.H:191
@ PH
Definition: ERF_IndexDefines.H:196