ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SAMUtils.H
Go to the documentation of this file.
1 #ifndef ERF_SAM_UTILS_H_
2 #define ERF_SAM_UTILS_H_
3 
4 #include <cmath>
5 #include <limits>
6 #include <sstream>
7 
8 #include <AMReX.H>
9 #include <AMReX_Array4.H>
10 #include <AMReX_GpuQualifiers.H>
11 
12 #include "ERF_Constants.H"
14 #include "ERF_DataStruct.H"
15 #include "ERF_EOS.H"
16 #include "ERF_IndexDefines.H"
17 #include "ERF_MicrophysicsUtils.H"
18 
20  amrex::Real omn{one};
21  amrex::Real omp{one};
22  amrex::Real omg{zero};
23 };
24 
26  amrex::Real omn{one};
27  amrex::Real delta_qv{zero};
28  amrex::Real delta_qc{zero};
29  amrex::Real delta_qi{zero};
30  amrex::Real qv{zero};
31  amrex::Real qcl{zero};
32  amrex::Real qci{zero};
33  amrex::Real qn{zero};
34  amrex::Real qt{zero};
35  amrex::Real tabs{zero};
36 };
37 
39  amrex::Real dqca{zero};
40  amrex::Real dprc{zero};
41  amrex::Real dpsc{zero};
42  amrex::Real dpgc{zero};
43  amrex::Real dqia{zero};
44  amrex::Real dpsi{zero};
45  amrex::Real dpgi{zero};
46  amrex::Real dqc{zero};
47  amrex::Real dqi{zero};
48  amrex::Real dqpr{zero};
49  amrex::Real dqps{zero};
50  amrex::Real dqpg{zero};
51  amrex::Real dqp{zero};
52 };
53 
55  amrex::Real rho{zero};
56  amrex::Real theta{zero};
57  amrex::Real tabs{zero};
58  amrex::Real pres_mbar{zero};
59  amrex::Real qv{zero};
60  amrex::Real qcl{zero};
61  amrex::Real qci{zero};
62  amrex::Real qn{zero};
63  amrex::Real qt{zero};
64  amrex::Real qpr{zero};
65  amrex::Real qps{zero};
66  amrex::Real qpg{zero};
67  amrex::Real qp{zero};
68 };
69 
71 
74  bool enable_precip{true};
75  amrex::Real dtn{zero};
76  amrex::Real rdOcp{zero};
77  amrex::Real fac_cond{zero};
78  amrex::Real fac_fus{zero};
79  amrex::Real fac_sub{zero};
80  amrex::Real eps{zero};
81  amrex::Real powr1{zero};
82  amrex::Real pows1{zero};
83  amrex::Real powg1{zero};
84  amrex::Real powr2{zero};
85  amrex::Real pows2{zero};
86  amrex::Real powg2{zero};
87 };
88 
95  amrex::Real qsat{zero};
96  amrex::Real omn{one};
97  amrex::Real omp{one};
98  amrex::Real omg{zero};
99 };
100 
102  amrex::Real accrrc{zero};
103  amrex::Real accrsi{zero};
104  amrex::Real accrsc{zero};
105  amrex::Real coefice{zero};
106  amrex::Real evaps1{zero};
107  amrex::Real evaps2{zero};
108  amrex::Real accrgi{zero};
109  amrex::Real accrgc{zero};
110  amrex::Real evapg1{zero};
111  amrex::Real evapg2{zero};
112  amrex::Real evapr1{zero};
113  amrex::Real evapr2{zero};
114 };
115 
117  amrex::Real rho_avg{zero};
118  amrex::Real tabs_avg{zero};
119  amrex::Real qp_avg{zero};
120  amrex::Real omp{one};
121  amrex::Real omg{zero};
122  amrex::Real qrr{zero};
123  amrex::Real qss{zero};
124  amrex::Real qgg{zero};
125 };
126 
128  amrex::Real rho_avg{zero};
129  amrex::Real tabs_avg{zero};
130  amrex::Real qpr_avg{zero};
131  amrex::Real qps_avg{zero};
132  amrex::Real qpg_avg{zero};
133 };
134 
135 struct SAMFaceState {
136  amrex::Real rho_avg{zero};
137  amrex::Real tabs_avg{zero};
138  amrex::Real qci_avg{zero};
139  amrex::Real qp_avg{zero};
140 };
141 
143  amrex::Real rain{zero};
144  amrex::Real snow{zero};
145  amrex::Real graupel{zero};
146 };
147 
149  amrex::Real rain{zero};
150  amrex::Real snow{zero};
151  amrex::Real graupel{zero};
152 };
153 
154 // SAM local source updates are treated as constant-pressure microphysics
155 // updates. Copy-in reconstructs tabs and pres_mbar from the conserved state;
156 // source helpers hold pres_mbar fixed while latent heating/cooling changes
157 // tabs; theta is then refreshed from T and the held pressure. Pressure is
158 // stored in mbar on this path, EOS/theta helpers expect Pa, and the saturation
159 // helpers below consume mbar where SAM currently calls them that way.
160 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
161 amrex::Real sam_mbar_to_pa (const amrex::Real& pres_mbar) noexcept
162 {
163  // SAM stores pressure in mbar. EOS and theta helpers expect Pa.
164  return amrex::Real(100.0) * pres_mbar;
165 }
166 
167 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
168 amrex::Real sam_pa_to_mbar (const amrex::Real& pres_pa) noexcept
169 {
170  return amrex::Real(0.01) * pres_pa;
171 }
172 
173 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
174 amrex::Real sam_theta_from_stored_mbar_converted_to_pa (const amrex::Real& tabs,
175  const amrex::Real& pres_mbar,
176  const amrex::Real rdOcp) noexcept
177 {
178  // Do not replace this with getThgivenRandT(rho,T,qv): that would enforce a
179  // fixed-density EOS projection rather than the SAM source-step
180  // thermodynamic contract.
181  return getThgivenTandP(tabs, sam_mbar_to_pa(pres_mbar), rdOcp);
182 }
183 
184 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
186  const amrex::Real& rho,
187  const amrex::Real& rho_theta,
188  const amrex::Real& rho_qv,
189  const amrex::Real& rho_qcl,
190  const amrex::Real& rho_qci,
191  const amrex::Real& rho_qpr,
192  const amrex::Real& rho_qps,
193  const amrex::Real& rho_qpg,
194  const MicrophysicsThermoState& thermo) noexcept
195 {
196  // The pressure and temperature are supplied by ERF's shared thermodynamic
197  // contract. SAM converts pressure to its established mbar storage here.
198  SAMPrimitiveCell result{};
199  result.rho = rho;
200  result.theta = rho_theta / rho;
201  result.qv = amrex::max(amrex::Real(0.0), rho_qv / rho);
202  result.qcl = amrex::max(amrex::Real(0.0), rho_qcl / rho);
203  result.qci = amrex::max(amrex::Real(0.0), rho_qci / rho);
204  result.qn = result.qcl + result.qci;
205  result.qt = result.qv + result.qn;
206  result.qpr = amrex::max(amrex::Real(0.0), rho_qpr / rho);
207  result.qps = amrex::max(amrex::Real(0.0), rho_qps / rho);
208  result.qpg = amrex::max(amrex::Real(0.0), rho_qpg / rho);
209  result.qp = result.qpr + result.qps + result.qpg;
210  result.tabs = thermo.temperature;
211  result.pres_mbar = sam_pa_to_mbar(thermo.pressure_pa);
212  return result;
213 }
214 
215 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
217  const amrex::Real& rho,
218  const amrex::Real& rho_theta,
219  const amrex::Real& rho_qv,
220  const amrex::Real& rho_qcl,
221  const amrex::Real& rho_qci,
222  const amrex::Real& rho_qpr,
223  const amrex::Real& rho_qps,
224  const amrex::Real& rho_qpg,
225  const amrex::Real rdOcp,
226  const bool use_anelastic_reference_pressure,
227  const amrex::Real p0) noexcept
228 {
229  const amrex::Real qv = amrex::max(amrex::Real(0.0), rho_qv / rho);
231  rho, rho_theta, qv, rdOcp,
232  use_anelastic_reference_pressure, p0);
234  rho, rho_theta, rho_qv, rho_qcl, rho_qci, rho_qpr, rho_qps, rho_qpg,
235  thermo);
236 }
237 
238 // Array-level copy-in used by production and by the wiring test. This keeps
239 // state-component selection and SAM's primitive working arrays together.
240 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
242  const amrex::Array4<const amrex::Real>& states,
243  const amrex::Array4<const amrex::Real>& base,
244  const amrex::Array4<amrex::Real>& rho,
245  const amrex::Array4<amrex::Real>& theta,
246  const amrex::Array4<amrex::Real>& qv,
247  const amrex::Array4<amrex::Real>& qc,
248  const amrex::Array4<amrex::Real>& qi,
249  const amrex::Array4<amrex::Real>& qn,
250  const amrex::Array4<amrex::Real>& qt,
251  const amrex::Array4<amrex::Real>& qpr,
252  const amrex::Array4<amrex::Real>& qps,
253  const amrex::Array4<amrex::Real>& qpg,
254  const amrex::Array4<amrex::Real>& qp,
255  const amrex::Array4<amrex::Real>& tabs,
256  const amrex::Array4<amrex::Real>& pres,
257  const amrex::Real rdOcp,
258  const bool use_anelastic_reference_pressure,
259  const int i, const int j, const int k) noexcept
260 {
261  const amrex::Real rho_value = states(i,j,k,Rho_comp);
262  const amrex::Real p0 = use_anelastic_reference_pressure
263  ? base(i,j,k,BaseState::p0_comp) : amrex::Real(0.0);
265  rho_value, states(i,j,k,RhoTheta_comp),
266  states(i,j,k,RhoQ1_comp), states(i,j,k,RhoQ2_comp),
267  states(i,j,k,RhoQ3_comp), states(i,j,k,RhoQ4_comp),
268  states(i,j,k,RhoQ5_comp), states(i,j,k,RhoQ6_comp), rdOcp,
269  use_anelastic_reference_pressure, p0);
270  rho(i,j,k) = primitive.rho;
271  theta(i,j,k) = primitive.theta;
272  qv(i,j,k) = primitive.qv;
273  qc(i,j,k) = primitive.qcl;
274  qi(i,j,k) = primitive.qci;
275  qn(i,j,k) = primitive.qn;
276  qt(i,j,k) = primitive.qt;
277  qpr(i,j,k) = primitive.qpr;
278  qps(i,j,k) = primitive.qps;
279  qpg(i,j,k) = primitive.qpg;
280  qp(i,j,k) = primitive.qp;
281  tabs(i,j,k) = primitive.tabs;
282  pres(i,j,k) = primitive.pres_mbar;
283  return primitive;
284 }
285 
286 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
288  const amrex::Real& rho_theta,
289  const amrex::Real& rho_qv,
290  const amrex::Real& rho_qcl,
291  const amrex::Real& rho_qci,
292  const amrex::Real& rho_qpr,
293  const amrex::Real& rho_qps,
294  const amrex::Real& rho_qpg) noexcept
295 {
296  // Keep the established compressible copy-in formula as its own entry
297  // point so the compressible path retains its original evaluation order.
298  SAMPrimitiveCell result{};
299  result.rho = rho;
300  result.theta = rho_theta / rho;
301  result.qv = amrex::max(amrex::Real(0.0), rho_qv / rho);
302  result.qcl = amrex::max(amrex::Real(0.0), rho_qcl / rho);
303  result.qci = amrex::max(amrex::Real(0.0), rho_qci / rho);
304  result.qn = result.qcl + result.qci;
305  result.qt = result.qv + result.qn;
306  result.qpr = amrex::max(amrex::Real(0.0), rho_qpr / rho);
307  result.qps = amrex::max(amrex::Real(0.0), rho_qps / rho);
308  result.qpg = amrex::max(amrex::Real(0.0), rho_qpg / rho);
309  result.qp = result.qpr + result.qps + result.qpg;
310  result.tabs = getTgivenRandRTh(rho, rho_theta, result.qv);
311  result.pres_mbar = sam_pa_to_mbar(getPgivenRTh(rho_theta, result.qv));
312  return result;
313 }
314 
315 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
317  const amrex::Array4<amrex::Real>& states_arr,
318  const int& i,
319  const int& j,
320  const int& k) noexcept
321 {
322  // Copy-out writes rho*theta and clipped moisture species back to the
323  // conserved state. Pressure is not stored here; it is diagnosed again on
324  // the next copy-in.
325  states_arr(i,j,k,RhoTheta_comp) = primitive.rho * primitive.theta;
326  states_arr(i,j,k,RhoQ1_comp) = primitive.rho * amrex::max(amrex::Real(0.0), primitive.qv);
327  states_arr(i,j,k,RhoQ2_comp) = primitive.rho * amrex::max(amrex::Real(0.0), primitive.qcl);
328  states_arr(i,j,k,RhoQ3_comp) = primitive.rho * amrex::max(amrex::Real(0.0), primitive.qci);
329  states_arr(i,j,k,RhoQ4_comp) = primitive.rho * amrex::max(amrex::Real(0.0), primitive.qpr);
330  states_arr(i,j,k,RhoQ5_comp) = primitive.rho * amrex::max(amrex::Real(0.0), primitive.qps);
331  states_arr(i,j,k,RhoQ6_comp) = primitive.rho * amrex::max(amrex::Real(0.0), primitive.qpg);
332 }
333 
334 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
335 bool sam_is_no_ice (const MoistureType& moisture_type) noexcept
336 {
337  return moisture_type == MoistureType::SAM_NoIce ||
338  moisture_type == MoistureType::SAM_NoPrecip_NoIce;
339 }
340 
341 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
342 bool sam_is_no_precip (const MoistureType& moisture_type) noexcept
343 {
344  return moisture_type == MoistureType::SAM_NoPrecip_NoIce;
345 }
346 
347 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
348 amrex::Real sam_cloud_liquid_fraction (const int& SAM_moisture_type,
349  const amrex::Real& tabs,
350  const amrex::Real an,
351  const amrex::Real bn) noexcept
352 {
353  // Empirical cloud phase-fraction closure for omega_n. No-ice mode forces
354  // liquid fraction to one; the warm branch is all liquid, the cold branch
355  // is all ice, and the mixed branch varies linearly with temperature.
356  if (SAM_moisture_type == 2) {
357  return one;
358  }
359  if (tabs >= tbgmax) {
360  return one;
361  }
362  if (tabs <= tbgmin) {
363  return zero;
364  }
365  return an * tabs - bn;
366 }
367 
368 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
369 amrex::Real sam_precip_rain_fraction (const int& SAM_moisture_type,
370  const amrex::Real& tabs) noexcept
371 {
372  // Empirical precipitating rain fraction omega_p. No-ice mode forces rain
373  // fraction to one, and the result is clipped to [0, 1].
374  if (SAM_moisture_type == 2) {
375  return one;
376  }
377  return amrex::max(amrex::Real(0.0), amrex::min(amrex::Real(1.0), (tabs - tprmin) * a_pr));
378 }
379 
380 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
381 amrex::Real sam_graupel_fraction (const int& SAM_moisture_type,
382  const amrex::Real& tabs) noexcept
383 {
384  // Empirical graupel fraction omega_g. No-ice mode forces graupel fraction
385  // to zero, and the result is clipped to [0, 1].
386  if (SAM_moisture_type == 2) {
387  return zero;
388  }
389  return amrex::max(amrex::Real(0.0), amrex::min(amrex::Real(1.0), (tabs - tgrmin) * a_gr));
390 }
391 
392 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
393 SAMCloudPhaseChange sam_partition_cloud_phase (const int& SAM_moisture_type,
394  const amrex::Real& tabs,
395  const amrex::Real& qn,
396  const amrex::Real& qcl,
397  const amrex::Real& qci,
398  const amrex::Real fac_cond,
399  const amrex::Real fac_fus,
400  const amrex::Real an,
401  const amrex::Real bn) noexcept
402 {
403  // Repartition cloud condensate between liquid and ice using omega_n while
404  // preserving total cloud condensate qn. The temperature increment accounts
405  // for fusion heating/cooling under the held-pressure source-step
406  // convention; no-ice mode collapses condensate into liquid.
407  SAMCloudPhaseChange result{};
408  result.qcl = qcl;
409  result.qci = qci;
410  result.tabs = tabs;
411  result.omn = sam_cloud_liquid_fraction(SAM_moisture_type, tabs, an, bn);
412 
413  if (SAM_moisture_type == 1) {
414  if (tabs >= tbgmax) {
415  result.omn = one;
416  result.delta_qi = qci;
417  result.qci = zero;
418  result.qcl += result.delta_qi;
419  result.tabs -= fac_fus * result.delta_qi;
420  } else if (tabs <= tbgmin) {
421  result.omn = zero;
422  result.delta_qc = qcl;
423  result.qcl = zero;
424  result.qci += result.delta_qc;
425  result.tabs += fac_fus * result.delta_qc;
426  } else {
427  result.delta_qc = qcl - qn * result.omn;
428  result.delta_qi = qci - qn * (one - result.omn);
429  result.qcl = qn * result.omn;
430  result.qci = qn * (one - result.omn);
431  result.tabs += fac_fus * result.delta_qc;
432  result.omn = sam_cloud_liquid_fraction(SAM_moisture_type, result.tabs, an, bn);
433  }
434  } else {
435  result.omn = one;
436  result.delta_qc = qcl - qn;
437  result.qcl = qn;
438  result.qci = zero;
439  result.tabs += fac_cond * result.delta_qc;
440  }
441 
442  result.qn = result.qcl + result.qci;
443  return result;
444 }
445 
446 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
447 amrex::Real sam_mixed_qsat (const amrex::Real& omn,
448  const amrex::Real& qsatw,
449  const amrex::Real& qsati) noexcept
450 {
451  // Mixed liquid/ice saturation relation used by the SAM cloud adjustment.
452  return omn * qsatw + (one - omn) * qsati;
453 }
454 
455 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
456 amrex::Real sam_mixed_dqsat_dT (const amrex::Real& omn,
457  const amrex::Real& domn,
458  const amrex::Real& qsatw,
459  const amrex::Real& qsati,
460  const amrex::Real& dqsatw,
461  const amrex::Real& dqsati) noexcept
462 {
463  // Temperature derivative of mixed saturation, including the mixed-branch
464  // temperature derivative of the liquid/ice phase fraction.
465  return omn * dqsatw + (one - omn) * dqsati + domn * qsatw - domn * qsati;
466 }
467 
468 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
469 amrex::Real sam_mixed_dqif_dT (const amrex::Real& omn,
470  const amrex::Real& domn,
471  const amrex::Real& qn,
472  const amrex::Real& dqsatm) noexcept
473 {
474  // Temperature derivative of the final ice fraction
475  return -domn * qn - (one - omn) * dqsatm;
476 }
477 
478 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
479 amrex::Real sam_newton_residual (const amrex::Real& tabs_new,
480  const amrex::Real& tabs_old,
481  const amrex::Real fcond,
482  const amrex::Real& qv,
483  const amrex::Real& qsatm,
484  const amrex::Real ffus,
485  const amrex::Real& qi,
486  const amrex::Real& qif) noexcept
487 {
488  // Residual for the local constant-pressure saturation adjustment solve.
489  return -tabs_new + tabs_old + fcond * (qv - qsatm) - ffus * (qi - qif);
490 }
491 
492 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
493 amrex::Real sam_newton_residual_derivative (const amrex::Real fcond,
494  const amrex::Real ffus,
495  const amrex::Real& dqsatm,
496  const amrex::Real& dqif) noexcept
497 {
498  // Derivative for the local constant-pressure saturation adjustment solve.
499  return -one - fcond * dqsatm + ffus * dqif;
500 }
501 
502 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
504  const amrex::Real& qcc,
505  const amrex::Real& qii,
506  const amrex::Real& coefice_k) noexcept
507 {
508  SAMPrecipSources result{};
509  // Thresholded cloud-liquid and cloud-ice autoconversion increments over
510  // the microphysics time step dtn. The strict qcw0/qci0 thresholds are
511  // intentional: equality leaves the source inactive.
512  const amrex::Real auto_r = (qcc > qcw0) ? alphaelq : zero;
513  const amrex::Real autos = (qii > qci0) ? betaelq * coefice_k : zero;
514  result.dqca = dtn * auto_r * (qcc - qcw0);
515  result.dqia = dtn * autos * (qii - qci0);
516  return result;
517 }
518 
519 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
520 SAMPrecipSources sam_accretion_rates (const amrex::Real& dtn,
521  const amrex::Real& qcc,
522  const amrex::Real& qii,
523  const amrex::Real& qpr,
524  const amrex::Real& qps,
525  const amrex::Real& qpg,
526  const amrex::Real& powr1,
527  const amrex::Real& pows1,
528  const amrex::Real& powg1,
529  const amrex::Real& omp,
530  const amrex::Real& omg,
531  const amrex::Real& accrrc_k,
532  const amrex::Real& accrsc_k,
533  const amrex::Real& accrsi_k,
534  const amrex::Real& accrgc_k,
535  const amrex::Real& accrgi_k) noexcept
536 {
537  SAMPrecipSources result{};
538  amrex::Real accrcr = zero;
539  amrex::Real accrcs = zero;
540  amrex::Real accris = zero;
541  amrex::Real accrcg = zero;
542  amrex::Real accrig = zero;
543 
544  // Accretion increments over dtn. Liquid-origin sinks feed rain, snow, and
545  // graupel; ice-origin sinks feed snow and graupel. These strict empirical
546  // selector thresholds are implementation rules, not fundamental laws:
547  // rain requires omp > 0.001, snow requires omp < 0.999 and omg < 0.999,
548  // and graupel requires omp < 0.999 and omg > 0.001. Equality is inactive.
549  if (omp > amrex::Real(0.001)) {
550  accrcr = accrrc_k;
551  }
552  if (omp < amrex::Real(0.999) && omg < amrex::Real(0.999)) {
553  accrcs = accrsc_k;
554  accris = accrsi_k;
555  }
556  if (omp < amrex::Real(0.999) && omg > amrex::Real(0.001)) {
557  accrcg = accrgc_k;
558  accrig = accrgi_k;
559  }
560 
561  result.dprc = dtn * accrcr * qcc * std::pow(qpr, powr1);
562  result.dpsc = dtn * accrcs * qcc * std::pow(qps, pows1);
563  result.dpgc = dtn * accrcg * qcc * std::pow(qpg, powg1);
564  result.dpsi = dtn * accris * qii * std::pow(qps, pows1);
565  result.dpgi = dtn * accrig * qii * std::pow(qpg, powg1);
566  return result;
567 }
568 
569 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
571  const amrex::Real& qci,
572  const amrex::Real& eps,
573  SAMPrecipSources result) noexcept
574 {
575  // Proportional donor limiter. If requested liquid or ice sinks exceed
576  // available qcl/qci, all competing sinks from the same donor phase share
577  // one scale factor. This preserves source ratios while preventing negative
578  // qcl or qci. The eps denominator intentionally leaves only an epsilon-
579  // scale undershoot.
580  result.dqc = result.dqca + result.dprc + result.dpsc + result.dpgc;
581  result.dqi = result.dqia + result.dpsi + result.dpgi;
582 
583  const amrex::Real scalec = amrex::min(qcl, result.dqc) / (result.dqc + eps);
584  const amrex::Real scalei = amrex::min(qci, result.dqi) / (result.dqi + eps);
585 
586  result.dqca *= scalec;
587  result.dprc *= scalec;
588  result.dpsc *= scalec;
589  result.dpgc *= scalec;
590  result.dqia *= scalei;
591  result.dpsi *= scalei;
592  result.dpgi *= scalei;
593  result.dqc = result.dqca + result.dprc + result.dpsc + result.dpgc;
594  result.dqi = result.dqia + result.dpsi + result.dpgi;
595 
596  return result;
597 }
598 
599 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
601  const amrex::Real& omp,
602  const amrex::Real& omg) noexcept
603 {
604  // Partitions limited autoconversion sources into rain/snow/graupel using
605  // the precipitating phase fractions and adds direct accretion
606  // contributions. dqpr + dqps + dqpg equals the limited cloud sink total.
607  result.dqpr = (result.dqca + result.dqia) * omp + result.dprc;
608  result.dqps = (result.dqca + result.dqia) * (one - omp) * (one - omg) + result.dpsc + result.dpsi;
609  result.dqpg = (result.dqca + result.dqia) * (one - omp) * omg + result.dpgc + result.dpgi;
610  return result;
611 }
612 
613 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
615  const amrex::Real& qps,
616  const amrex::Real& qpg,
617  const amrex::Real& powr2,
618  const amrex::Real& pows2,
619  const amrex::Real& powg2,
620  const amrex::Real& evapr1_k,
621  const amrex::Real& evapr2_k,
622  const amrex::Real& evaps1_k,
623  const amrex::Real& evaps2_k,
624  const amrex::Real& evapg1_k,
625  const amrex::Real& evapg2_k) noexcept
626 {
627  // Positive-domain evaporation/sublimation rate form for precipitating
628  // species: C1*sqrt(q_m) + C2*q_m^p. The derivative is singular at q_m = 0,
629  // so derivative checks only make sense away from zero.
630  SAMPrecipSources result{};
631  result.dqpr = evapr1_k * std::sqrt(qpr) + evapr2_k * std::pow(qpr, powr2);
632  result.dqps = evaps1_k * std::sqrt(qps) + evaps2_k * std::pow(qps, pows2);
633  result.dqpg = evapg1_k * std::sqrt(qpg) + evapg2_k * std::pow(qpg, powg2);
634  return result;
635 }
636 
637 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
639  const amrex::Real& qps,
640  const amrex::Real& qpg,
641  SAMPrecipSources result) noexcept
642 {
643  // Limits rain evaporation and snow/graupel sublimation by available
644  // qpr/qps/qpg so the source update cannot make precipitating species
645  // negative.
646  result.dqpr = amrex::min(qpr, result.dqpr);
647  result.dqps = amrex::min(qps, result.dqps);
648  result.dqpg = amrex::min(qpg, result.dqpg);
649  result.dqp = result.dqpr + result.dqps + result.dqpg;
650  return result;
651 }
652 
653 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
655  const SAMCoefficientRow& coeffs,
656  const SAMPrecipConfig& config,
657  SAMPrecipCellDiagnostics* diagnostics = nullptr) noexcept
658 {
659  // Local SAM precipitation source update. This is a cell-local,
660  // held-pressure microphysics update; sedimentation and surface
661  // accumulation are handled in PrecipFall. Before sedimentation, the source
662  // terms exchange water among qv/qcl/qci/qpr/qps/qpg, conserve total water,
663  // and conserve the constant-pressure latent proxy
664  // tabs + fac_cond*qv - fac_fus*(qci + qps + qpg)
665  // up to limiter and roundoff effects.
666  if (diagnostics != nullptr) {
667  *diagnostics = {};
668  }
669 
670  state.qn = state.qcl + state.qci;
671  state.qt = state.qv + state.qn;
672  state.qp = state.qpr + state.qps + state.qpg;
673 
674  if (!config.enable_precip || state.qn + state.qp <= zero) {
675  return state;
676  }
677 
678  amrex::Real omn;
679  amrex::Real omp;
680  amrex::Real omg;
681  if (config.sam_moisture_type == 2) {
682  omn = one;
683  omp = one;
684  omg = zero;
685  } else {
686  omn = sam_cloud_liquid_fraction(config.sam_moisture_type,
687  state.tabs, a_bg, tbgmin * a_bg);
688  omp = sam_precip_rain_fraction(config.sam_moisture_type,
689  state.tabs);
690  omg = sam_graupel_fraction(config.sam_moisture_type,
691  state.tabs);
692  }
693 
694  if (diagnostics != nullptr) {
695  diagnostics->omn = omn;
696  diagnostics->omp = omp;
697  diagnostics->omg = omg;
698  }
699 
700  if (state.qn > zero) {
701  SAMPrecipSources source_terms =
702  sam_autoconversion_rates(config.dtn, state.qcl, state.qci, coeffs.coefice);
703  const SAMPrecipSources accretion_terms =
704  sam_accretion_rates(config.dtn, state.qcl, state.qci, state.qpr, state.qps, state.qpg,
705  config.powr1, config.pows1, config.powg1,
706  omp, omg,
707  coeffs.accrrc, coeffs.accrsc, coeffs.accrsi,
708  coeffs.accrgc, coeffs.accrgi);
709  if (diagnostics != nullptr) {
710  diagnostics->autoconversion = source_terms;
711  diagnostics->accretion = accretion_terms;
712  }
713 
714  source_terms.dprc = accretion_terms.dprc;
715  source_terms.dpsc = accretion_terms.dpsc;
716  source_terms.dpgc = accretion_terms.dpgc;
717  source_terms.dpsi = accretion_terms.dpsi;
718  source_terms.dpgi = accretion_terms.dpgi;
719  source_terms = sam_rescale_cloud_sinks(state.qcl, state.qci,
720  config.eps, source_terms);
721  if (diagnostics != nullptr) {
722  diagnostics->limited_sources = source_terms;
723  }
724 
725  source_terms = sam_partition_autoconverted_precip(source_terms, omp, omg);
726  if (diagnostics != nullptr) {
727  diagnostics->partitioned_sources = source_terms;
728  }
729 
730  const amrex::Real dqca = source_terms.dqca;
731  const amrex::Real dqia = source_terms.dqia;
732 
733  state.qcl -= source_terms.dqc;
734  state.qci -= source_terms.dqi;
735  state.qpr += source_terms.dqpr;
736  state.qps += source_terms.dqps;
737  state.qpg += source_terms.dqpg;
738 
739  state.qn = state.qcl + state.qci;
740  state.qt = state.qv + state.qn;
741  state.qp = state.qpr + state.qps + state.qpg;
742 
743  // Cloud-liquid accretion onto snow and graupel increases frozen mass
744  // and must contribute the same fusion-heating term to the local latent
745  // proxy as the autoconverted frozen branch.
746  state.tabs += config.fac_fus * (dqca * (one - omp) - dqia * omp
747  + source_terms.dpsc + source_terms.dpgc);
749  state.pres_mbar,
750  config.rdOcp);
751  }
752 
753  amrex::Real qsatw;
754  amrex::Real qsati;
755  erf_qsatw(state.tabs, state.pres_mbar, qsatw);
756  erf_qsati(state.tabs, state.pres_mbar, qsati);
757  const amrex::Real qsat = sam_mixed_qsat(omn, qsatw, qsati);
758  if (diagnostics != nullptr) {
759  diagnostics->qsat = qsat;
760  }
761 
762  if (state.qp > zero && state.qv < qsat) {
763  SAMPrecipSources evaporation_terms =
764  sam_precip_evaporation_rates(state.qpr, state.qps, state.qpg,
765  config.powr2, config.pows2, config.powg2,
766  coeffs.evapr1, coeffs.evapr2,
767  coeffs.evaps1, coeffs.evaps2,
768  coeffs.evapg1, coeffs.evapg2);
769 
770  const amrex::Real supersat_factor = config.dtn * (one - state.qv / qsat);
771  evaporation_terms.dqpr *= supersat_factor;
772  evaporation_terms.dqps *= supersat_factor;
773  evaporation_terms.dqpg *= supersat_factor;
774  evaporation_terms = sam_apply_precip_evaporation_limiter(state.qpr,
775  state.qps,
776  state.qpg,
777  evaporation_terms);
778  if (diagnostics != nullptr) {
779  diagnostics->evaporation = evaporation_terms;
780  }
781 
782  state.qv += evaporation_terms.dqp;
783  state.qpr -= evaporation_terms.dqpr;
784  state.qps -= evaporation_terms.dqps;
785  state.qpg -= evaporation_terms.dqpg;
786 
787  state.qt = state.qv + state.qn;
788  state.qp = state.qpr + state.qps + state.qpg;
789 
790  // Rain evaporation cools with Lv/cp; snow and graupel sublimation cool
791  // with Ls/cp, preserving the same local latent proxy.
792  state.tabs -= config.fac_cond * evaporation_terms.dqpr
793  + config.fac_sub * (evaporation_terms.dqps + evaporation_terms.dqpg);
795  state.pres_mbar,
796  config.rdOcp);
797  }
798 
799  return state;
800 }
801 
802 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
803 // Closure coefficients for the SAM source parameterizations at one vertical
804 // level. The formula ordering is kept close to the SAM baseline to avoid
805 // unintended numerical drift.
807  const amrex::Real& tabs,
808  const amrex::Real& gamr1,
809  const amrex::Real& gamr2,
810  const amrex::Real& gams1,
811  const amrex::Real& gams2,
812  const amrex::Real& gamg1,
813  const amrex::Real& gamg2) noexcept
814 {
815  // Preserve the SAM baseline formula ordering in these closure rows.
816  SAMCoefficientRow row{};
817  amrex::Real prefactor;
818  amrex::Real pratio = std::sqrt(amrex::Real(1.29) / rho);
819  amrex::Real estw = amrex::Real(100.0) * erf_esatw(tabs);
820  amrex::Real esti = amrex::Real(100.0) * erf_esati(tabs);
821 
822  amrex::Real coef1 = fourth * PI * nzeros * a_snow * gams1 * pratio
823  / std::pow((PI * rhos * nzeros / rho), ((three + b_snow) / amrex::Real(4.0)));
824  amrex::Real coef2 = std::exp(amrex::Real(0.025) * (tabs - amrex::Real(273.15)));
825  row.accrsi = coef1 * coef2 * esicoef;
826  row.accrsc = coef1 * esccoef;
827  row.coefice = coef2;
828 
829  coef1 = (lsub / (tabs * R_v) - one) * lsub / (therco * tabs);
830  coef2 = R_v * tabs / (diffelq * esti);
831  prefactor = two * PI * nzeros / (rho * (coef1 + coef2));
832  prefactor *= (two / PI);
833  row.evaps1 = prefactor * amrex::Real(0.65) * std::sqrt(rho / (PI * rhos * nzeros));
834  row.evaps2 = prefactor * amrex::Real(0.44) * std::sqrt(a_snow * rho / muelq) * gams2
835  * std::sqrt(pratio) * std::pow(rho / (PI * rhos * nzeros), ((amrex::Real(5.0) + b_snow) / amrex::Real(8.0)));
836 
837  coef1 = fourth * PI * nzerog * a_grau * gamg1 * pratio
838  / std::pow((PI * rhog * nzerog / rho), ((three + b_grau) / amrex::Real(4.0)));
839  coef2 = std::exp(amrex::Real(0.025) * (tabs - amrex::Real(273.15)));
840  row.accrgi = coef1 * coef2 * egicoef;
841  row.accrgc = coef1 * egccoef;
842 
843  coef1 = (lsub / (tabs * R_v) - one) * lsub / (therco * tabs);
844  coef2 = R_v * tabs / (diffelq * esti);
845  prefactor = two * PI * nzerog / (rho * (coef1 + coef2));
846  row.evapg1 = prefactor * amrex::Real(0.78) * std::sqrt(rho / (PI * rhog * nzerog));
847  row.evapg2 = prefactor * amrex::Real(0.31) * std::sqrt(a_grau * rho / muelq) * gamg2
848  * std::sqrt(pratio) * std::pow(rho / (PI * rhog * nzerog), ((amrex::Real(5.0) + b_grau) / amrex::Real(8.0)));
849 
850  row.accrrc = fourth * PI * nzeror * a_rain * gamr1 * pratio
851  / std::pow((PI * rhor * nzeror / rho), ((three + b_rain) / amrex::Real(4.0))) * erccoef;
852 
853  coef1 = (lcond / (tabs * R_v) - one) * lcond / (therco * tabs);
854  coef2 = R_v * tabs / (diffelq * estw);
855  prefactor = two * PI * nzeror / (rho * (coef1 + coef2));
856  row.evapr1 = prefactor * amrex::Real(0.78) * std::sqrt(rho / (PI * rhor * nzeror));
857  row.evapr2 = prefactor * amrex::Real(0.31) * std::sqrt(a_rain * rho / muelq) * gamr2
858  * std::sqrt(pratio) * std::pow(rho / (PI * rhor * nzeror), ((amrex::Real(5.0) + b_rain) / amrex::Real(8.0)));
859  return row;
860 }
861 
862 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
863 amrex::Real sam_cloud_ice_terminal_velocity (const amrex::Real& qci_avg) noexcept
864 {
865  // MUST MATCH: SAM cloud-ice terminal-velocity coefficient and exponent.
866  return amrex::min(amrex::Real(0.4),
867  amrex::Real(8.66) * std::pow((amrex::max(amrex::Real(0.0), qci_avg) + amrex::Real(1.e-10)), amrex::Real(0.24)));
868 }
869 
870 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
872  const int& k_lo,
873  const int& k_hi,
874  const amrex::Real& rho_km1,
875  const amrex::Real& rho_k,
876  const amrex::Real tabs_km1,
877  const amrex::Real tabs_k,
878  const amrex::Real& /*qci_km1*/,
879  const amrex::Real& qci_k,
880  const amrex::Real /*qp_km1*/,
881  const amrex::Real qp_k) noexcept
882 {
883  SAMFaceState result{};
884  if (k == k_lo) {
885  result.rho_avg = rho_k;
886  result.tabs_avg = tabs_k;
887  result.qci_avg = qci_k;
888  result.qp_avg = qp_k;
889  } else if (k == k_hi + 1) {
890  // Nothing falls in through the model top: no ice or precipitation lies
891  // above the domain.
892  result.rho_avg = rho_km1;
893  result.tabs_avg = tabs_km1;
894  result.qci_avg = zero;
895  result.qp_avg = zero;
896  } else {
897  // Sedimentation only moves mass down, out of cell k: keep rho and T
898  // centered on the face but take the transported mixing ratios from that
899  // donor cell, so the flux does not depend on the receiving cell below
900  // (a dry donor sends nothing).
901  result.rho_avg = myhalf * (rho_km1 + rho_k);
902  result.tabs_avg = myhalf * (tabs_km1 + tabs_k);
903  result.qci_avg = qci_k;
904  result.qp_avg = qp_k;
905  }
906  return result;
907 }
908 
909 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
910 int sam_precip_face_donor_k (const int& face_k,
911  const int& k_lo,
912  const int& k_hi) noexcept
913 {
914  if (face_k <= k_lo) {
915  return k_lo;
916  }
917  if (face_k >= k_hi + 1) {
918  return k_hi;
919  }
920  return face_k;
921 }
922 
923 // The largest fall Courant number a sedimentation substep may take; SAM::CFL_MAX is this value.
924 static constexpr amrex::Real sam_sedimentation_cfl_max = myhalf;
925 
926 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
927 int sam_precip_face_receiver_k (const int& face_k,
928  const int& k_lo,
929  const int& k_hi) noexcept
930 {
931  // The cell a face drains into, the one below it. The surface face drains out of the
932  // domain and the top face carries nothing, so both return their donor cell instead.
933  if (face_k <= k_lo || face_k >= k_hi + 1) {
934  return sam_precip_face_donor_k(face_k, k_lo, k_hi);
935  }
936  return face_k - 1;
937 }
938 
939 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
940 amrex::Real sam_fall_sizing_detJ (const amrex::Real& detJ_donor,
941  const amrex::Real& detJ_receiver) noexcept
942 {
943  // The cell height (in units of the reference dz) a face's fall Courant number is taken
944  // over when sizing the substeps: the smaller of the cell the face drains and the cell it
945  // drains into. The substep count is fixed at the start of the step, from cells that
946  // already hold precipitation; the cells below the front are dry then and do not count,
947  // but they become donors in later substeps. Looking one cell below covers the first
948  // cell the front enters. If within one step the front crosses several cells thinner
949  // than the ones above, the Courant number there can still exceed CFL_MAX; the donor cap
950  // (sam_limit_precip_component_flux) is the backstop and keeps the mixing ratios
951  // non-negative.
952  return amrex::min(detJ_donor, detJ_receiver);
953 }
954 
955 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
956 int sam_sedimentation_substep_count (const amrex::Real& max_courant) noexcept
957 {
958  // max_courant is the largest fall Courant number over the faces for the full step,
959  // v*dt over the cell height of sam_fall_sizing_detJ (#5168): enough substeps that no
960  // species falls more than CFL_MAX of that cell per substep, and always at least one.
961  // The caller checks that max_courant is finite and the count sane
962  // (sam_check_sedimentation_substeps).
963  return amrex::max(1, static_cast<int>(std::ceil(max_courant / sam_sedimentation_cfl_max)));
964 }
965 
966 // A host-side check of the global maximum fall Courant number before it becomes a substep
967 // count: a NaN, an infinity or an absurd count would be undefined behavior in the cast to int,
968 // or would hang the substep loop, and points to a state that is not usable.
969 inline void
970 sam_check_sedimentation_substeps (const char* routine, const amrex::Real max_courant)
971 {
972  // Far above anything a healthy state gives: under the compressible time step (dt of a
973  // few seconds) the count stays at about 20 or less
974  constexpr amrex::Real max_substeps = amrex::Real(1000.0);
975  if (!std::isfinite(max_courant) || (max_courant / sam_sedimentation_cfl_max > max_substeps)) {
976  std::ostringstream message;
977  message.precision(17);
978  message << routine << ": cannot form the sedimentation substep count: the largest fall"
979  << " Courant number is " << max_courant << " (CFL_MAX = " << sam_sedimentation_cfl_max
980  << ", at most " << max_substeps << " substeps allowed)."
981  << " The fall speeds or the cell heights are not usable.";
982  amrex::Abort(message.str());
983  }
984 }
985 
986 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
987 amrex::Real sam_fall_courant (const amrex::Real& fall_speed,
988  const amrex::Real& dt,
989  const amrex::Real& dz,
990  const amrex::Real& detJ) noexcept
991 {
992  // The fall Courant number at a face: the distance fallen in dt over the physical height
993  // dz*detJ of a cell. The substep sizing passes sam_fall_sizing_detJ, the smaller of the
994  // cell the face drains and the cell it drains into.
995  return fall_speed * dt / (dz * detJ);
996 }
997 
998 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1000  const amrex::Real& vrain,
1001  const amrex::Real& vsnow,
1002  const amrex::Real& vgrau,
1003  const amrex::Real& rho_0) noexcept
1004 {
1005  // The largest fall speed of rain, snow and graupel at a face: each density-corrected
1006  // flux of sam_precip_component_fluxes_from_face_state divided by its rho_avg*q, so
1007  // v*(rho_avg*q)^c*sqrt(rho_0/rho_avg). A component with no mass does not fall.
1008  const amrex::Real density_correction = std::sqrt(rho_0 / face_state.rho_avg);
1009  amrex::Real vmax = zero;
1010  if (face_state.qpr_avg > zero) {
1011  vmax = amrex::max(vmax, vrain * std::pow(face_state.rho_avg * face_state.qpr_avg, crain));
1012  }
1013  if (face_state.qps_avg > zero) {
1014  vmax = amrex::max(vmax, vsnow * std::pow(face_state.rho_avg * face_state.qps_avg, csnow));
1015  }
1016  if (face_state.qpg_avg > zero) {
1017  vmax = amrex::max(vmax, vgrau * std::pow(face_state.rho_avg * face_state.qpg_avg, cgrau));
1018  }
1019  return vmax * density_correction;
1020 }
1021 
1022 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1023 SAMPrecipFaceState sam_precip_face_state (const int& SAM_moisture_type,
1024  const amrex::Array4<const amrex::Real>& rho_array,
1025  const amrex::Array4<const amrex::Real>& tabs_array,
1026  const amrex::Array4<const amrex::Real>& qp_array,
1027  const int& i,
1028  const int& j,
1029  const int& k,
1030  const int& k_lo,
1031  const int& k_hi) noexcept
1032 {
1033  // MUST MATCH: SAM PrecipFall bottom/interior/top face rules.
1034  SAMPrecipFaceState result{};
1035  if (k == k_lo) {
1036  result.rho_avg = rho_array(i,j,k);
1037  result.tabs_avg = tabs_array(i,j,k);
1038  result.qp_avg = qp_array(i,j,k);
1039  } else if (k == k_hi + 1) {
1040  // Nothing falls in through the model top.
1041  result.rho_avg = rho_array(i,j,k-1);
1042  result.tabs_avg = tabs_array(i,j,k-1);
1043  result.qp_avg = zero;
1044  } else {
1045  // Centered rho and T, donor (upwind) qp from the cell above the face.
1046  result.rho_avg = myhalf * (rho_array(i,j,k-1) + rho_array(i,j,k));
1047  result.tabs_avg = myhalf * (tabs_array(i,j,k-1) + tabs_array(i,j,k));
1048  result.qp_avg = qp_array(i,j,k);
1049  }
1050  result.omp = sam_precip_rain_fraction(SAM_moisture_type, result.tabs_avg);
1051  result.omg = sam_graupel_fraction(SAM_moisture_type, result.tabs_avg);
1052  result.qrr = result.omp * result.qp_avg;
1053  result.qss = (one - result.omp) * (one - result.omg) * result.qp_avg;
1054  result.qgg = (one - result.omp) * result.omg * result.qp_avg;
1055  return result;
1056 }
1057 
1058 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1059 // Component PrecipFall face state. Uses the same bottom/interior/top face
1060 // selection rules, but reads qpr/qps/qpg directly so each precipitating
1061 // species can be sedimented and limited conservatively.
1062 SAMPrecipComponentFaceState sam_precip_component_face_state (const amrex::Array4<const amrex::Real>& rho_array,
1063  const amrex::Array4<const amrex::Real>& tabs_array,
1064  const amrex::Array4<const amrex::Real>& qpr_array,
1065  const amrex::Array4<const amrex::Real>& qps_array,
1066  const amrex::Array4<const amrex::Real>& qpg_array,
1067  const int& i,
1068  const int& j,
1069  const int& k,
1070  const int& k_lo,
1071  const int& k_hi) noexcept
1072 {
1073  // MUST MATCH: SAM PrecipFall bottom/interior/top face rules.
1074  SAMPrecipComponentFaceState result{};
1075  if (k == k_lo) {
1076  result.rho_avg = rho_array(i,j,k);
1077  result.tabs_avg = tabs_array(i,j,k);
1078  result.qpr_avg = qpr_array(i,j,k);
1079  result.qps_avg = qps_array(i,j,k);
1080  result.qpg_avg = qpg_array(i,j,k);
1081  } else if (k == k_hi + 1) {
1082  // Nothing falls in through the model top.
1083  result.rho_avg = rho_array(i,j,k-1);
1084  result.tabs_avg = tabs_array(i,j,k-1);
1085  result.qpr_avg = zero;
1086  result.qps_avg = zero;
1087  result.qpg_avg = zero;
1088  } else {
1089  // Centered rho and T, donor (upwind) qpr/qps/qpg from the cell above the face.
1090  result.rho_avg = myhalf * (rho_array(i,j,k-1) + rho_array(i,j,k));
1091  result.tabs_avg = myhalf * (tabs_array(i,j,k-1) + tabs_array(i,j,k));
1092  result.qpr_avg = qpr_array(i,j,k);
1093  result.qps_avg = qps_array(i,j,k);
1094  result.qpg_avg = qpg_array(i,j,k);
1095  }
1096  return result;
1097 }
1098 
1099 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1100 // Legacy total-qp precip flux helper. It partitions a total qp into rain/
1101 // snow/graupel by temperature phase fractions and applies the qp_threshold
1102 // branch. The conservative production PrecipFall path uses the component
1103 // helper below.
1105  const amrex::Real& vrain,
1106  const amrex::Real& vsnow,
1107  const amrex::Real& vgrau) noexcept
1108 {
1109  if (face_state.qp_avg <= qp_threshold) {
1110  return zero;
1111  }
1112  return face_state.omp * vrain * std::pow(face_state.rho_avg * face_state.qrr, one + crain)
1113  + (one - face_state.omp)
1114  * ((one - face_state.omg) * vsnow * std::pow(face_state.rho_avg * face_state.qss, one + csnow)
1115  + face_state.omg * vgrau * std::pow(face_state.rho_avg * face_state.qgg, one + cgrau));
1116 }
1117 
1118 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1119 // Legacy total-qp companion returning the partitioned rain/snow/graupel face
1120 // fluxes. The conservative production PrecipFall path uses the component
1121 // helper below instead of repartitioning total qp.
1123  const amrex::Real& vrain,
1124  const amrex::Real& vsnow,
1125  const amrex::Real& vgrau) noexcept
1126 {
1127  SAMPrecipFluxComponents result{};
1128  if (face_state.qp_avg <= qp_threshold) {
1129  return result;
1130  }
1131 
1132  result.rain = face_state.omp * vrain * std::pow(face_state.rho_avg * face_state.qrr, one + crain);
1133  result.snow = (one - face_state.omp) * (one - face_state.omg)
1134  * vsnow * std::pow(face_state.rho_avg * face_state.qss, one + csnow);
1135  result.graupel = (one - face_state.omp) * face_state.omg
1136  * vgrau * std::pow(face_state.rho_avg * face_state.qgg, one + cgrau);
1137  return result;
1138 }
1139 
1140 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1141 // Component PrecipFall fluxes. Unlike the legacy total-qp helper, these
1142 // fluxes are zero only when the corresponding component mass is nonpositive;
1143 // tiny positive qpr/qps/qpg produce tiny positive fluxes and are donor-limited
1144 // later.
1146  const amrex::Real& vrain,
1147  const amrex::Real& vsnow,
1148  const amrex::Real& vgrau) noexcept
1149 {
1150  SAMPrecipFluxComponents result{};
1151  if (face_state.qpr_avg > zero) {
1152  result.rain = vrain * std::pow(face_state.rho_avg * face_state.qpr_avg, one + crain);
1153  }
1154  if (face_state.qps_avg > zero) {
1155  result.snow = vsnow * std::pow(face_state.rho_avg * face_state.qps_avg, one + csnow);
1156  }
1157  if (face_state.qpg_avg > zero) {
1158  result.graupel = vgrau * std::pow(face_state.rho_avg * face_state.qpg_avg, one + cgrau);
1159  }
1160  return result;
1161 }
1162 
1163 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1164 amrex::Real sam_precip_flux_density_corrected (const amrex::Real& precip_flux,
1165  const amrex::Real& rho_0,
1166  const amrex::Real& rho_avg) noexcept
1167 {
1168  return precip_flux * std::sqrt(rho_0 / rho_avg);
1169 }
1170 
1171 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1173  const amrex::Real& rho_0,
1174  const amrex::Real& rho_avg) noexcept
1175 {
1176  const amrex::Real density_correction = std::sqrt(rho_0 / rho_avg);
1177  return {
1178  precip_fluxes.rain * density_correction,
1179  precip_fluxes.snow * density_correction,
1180  precip_fluxes.graupel * density_correction};
1181 }
1182 
1183 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1184 // Donor-cap limiter for conservative component sedimentation. The limited flux
1185 // cannot export more component mass over one substep than the donor cell
1186 // contains, including detJ for terrain-following cell mass.
1187 amrex::Real sam_limit_precip_component_flux (const amrex::Real& raw_flux,
1188  const amrex::Real& rho_donor,
1189  const amrex::Real& q_donor,
1190  const amrex::Real& detJ_donor,
1191  const amrex::Real& coef) noexcept
1192 {
1193  const amrex::Real available_flux =
1194  rho_donor * amrex::max(amrex::Real(0.0), q_donor) * detJ_donor / coef;
1195  return amrex::min(raw_flux, available_flux);
1196 }
1197 
1198 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1199 // Converts face-flux divergence into a mixing-ratio tendency. With the same
1200 // limited face fluxes used for accumulation, column component budgets
1201 // telescope.
1202 amrex::Real sam_sedimentation_tendency (const amrex::Real& fz_hi,
1203  const amrex::Real& fz_lo,
1204  const amrex::Real& rho,
1205  const amrex::Real& dJinv,
1206  const amrex::Real& coef) noexcept
1207 {
1208  return dJinv * (one / rho) * (fz_hi - fz_lo) * coef;
1209 }
1210 
1211 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1212 // Converts the already-limited bottom component fluxes to accumulated surface
1213 // depths. These are the same fluxes used in the in-column sedimentation
1214 // update.
1216  const SAMPrecipFluxComponents& component_fluxes,
1217  const amrex::Real& dtn) noexcept
1218 {
1219  SAMSurfaceAccumulation result{};
1220  result.rain = component_fluxes.rain * dtn / rhor * amrex::Real(1000.0);
1221  result.snow = component_fluxes.snow * dtn / rhos * amrex::Real(1000.0);
1222  result.graupel = component_fluxes.graupel * dtn / rhog * amrex::Real(1000.0);
1223  return result;
1224 }
1225 
1226 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
1228  const amrex::Real& rho_0,
1229  const amrex::Real& vrain,
1230  const amrex::Real& vsnow,
1231  const amrex::Real& vgrau,
1232  const amrex::Real& dtn) noexcept
1233 {
1234  const SAMPrecipFluxComponents face_fluxes =
1235  sam_precip_flux_components_from_face_state(face_state, vrain, vsnow, vgrau);
1236 
1238  sam_precip_flux_components_density_corrected(face_fluxes, rho_0, face_state.rho_avg),
1239  dtn);
1240 }
1241 
1242 #endif
constexpr amrex::Real R_v
Definition: ERF_Constants.H:50
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 getThgivenTandP(const amrex::Real T, const amrex::Real P, const amrex::Real rdOcp)
Definition: ERF_EOS.H:18
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:61
#define RhoQ4_comp
Definition: ERF_IndexDefines.H:81
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoQ2_comp
Definition: ERF_IndexDefines.H:79
#define RhoQ3_comp
Definition: ERF_IndexDefines.H:80
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
#define RhoQ6_comp
Definition: ERF_IndexDefines.H:83
#define RhoQ5_comp
Definition: ERF_IndexDefines.H:82
Real rho_0
Definition: ERF_InitCustomPert_ABL.H:18
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:128
const auto config
Definition: ERF_InitCustomPert_CloudChamber.H:38
std::string message
Definition: ERF_InputPreflight.cpp:25
std::vector< Diagnostic > diagnostics
Definition: ERF_InputPreflight.cpp:31
Physical constants and tuning parameters used only by the moisture and cloud-physics code.
constexpr amrex::Real csnow
Definition: ERF_MicrophysicsConstants.H:70
constexpr amrex::Real rhog
Definition: ERF_MicrophysicsConstants.H:41
constexpr amrex::Real a_bg
Definition: ERF_MicrophysicsConstants.H:55
constexpr amrex::Real muelq
Definition: ERF_MicrophysicsConstants.H:104
constexpr amrex::Real a_gr
Definition: ERF_MicrophysicsConstants.H:57
constexpr amrex::Real qci0
Definition: ERF_MicrophysicsConstants.H:77
constexpr amrex::Real nzerog
Definition: ERF_MicrophysicsConstants.H:95
constexpr amrex::Real cgrau
Definition: ERF_MicrophysicsConstants.H:71
constexpr amrex::Real tbgmax
Definition: ERF_MicrophysicsConstants.H:49
constexpr amrex::Real betaelq
Definition: ERF_MicrophysicsConstants.H:79
constexpr amrex::Real a_grau
Definition: ERF_MicrophysicsConstants.H:66
constexpr amrex::Real lsub
Definition: ERF_MicrophysicsConstants.H:111
constexpr amrex::Real alphaelq
Definition: ERF_MicrophysicsConstants.H:78
constexpr amrex::Real esicoef
Definition: ERF_MicrophysicsConstants.H:86
constexpr amrex::Real diffelq
Definition: ERF_MicrophysicsConstants.H:102
constexpr amrex::Real therco
Definition: ERF_MicrophysicsConstants.H:103
constexpr amrex::Real b_grau
Definition: ERF_MicrophysicsConstants.H:67
constexpr amrex::Real egccoef
Definition: ERF_MicrophysicsConstants.H:87
constexpr amrex::Real egicoef
Definition: ERF_MicrophysicsConstants.H:88
constexpr amrex::Real b_rain
Definition: ERF_MicrophysicsConstants.H:63
constexpr amrex::Real lcond
Definition: ERF_MicrophysicsConstants.H:109
constexpr amrex::Real qcw0
Definition: ERF_MicrophysicsConstants.H:76
constexpr amrex::Real tprmin
Definition: ERF_MicrophysicsConstants.H:50
constexpr amrex::Real qp_threshold
Definition: ERF_MicrophysicsConstants.H:96
constexpr amrex::Real nzeror
Definition: ERF_MicrophysicsConstants.H:93
constexpr amrex::Real tbgmin
Definition: ERF_MicrophysicsConstants.H:48
constexpr amrex::Real rhos
Definition: ERF_MicrophysicsConstants.H:40
constexpr amrex::Real esccoef
Definition: ERF_MicrophysicsConstants.H:85
constexpr amrex::Real rhor
Definition: ERF_MicrophysicsConstants.H:39
constexpr amrex::Real a_rain
Definition: ERF_MicrophysicsConstants.H:62
constexpr amrex::Real nzeros
Definition: ERF_MicrophysicsConstants.H:94
constexpr amrex::Real a_snow
Definition: ERF_MicrophysicsConstants.H:64
constexpr amrex::Real crain
Definition: ERF_MicrophysicsConstants.H:69
constexpr amrex::Real b_snow
Definition: ERF_MicrophysicsConstants.H:65
constexpr amrex::Real erccoef
Definition: ERF_MicrophysicsConstants.H:84
constexpr amrex::Real tgrmin
Definition: ERF_MicrophysicsConstants.H:52
constexpr amrex::Real a_pr
Definition: ERF_MicrophysicsConstants.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esati(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:68
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE MicrophysicsThermoState diagnose_microphysics_thermo_state(const amrex::Real rho, const amrex::Real rho_theta, const amrex::Real qv, const amrex::Real rdOcp, const bool use_anelastic_reference_pressure, const amrex::Real p0) noexcept
Definition: ERF_MicrophysicsUtils.H:36
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:265
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsati(amrex::Real t, amrex::Real p, amrex::Real &qsati)
Definition: ERF_MicrophysicsUtils.H:255
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t, bool use_empirical=false)
Definition: ERF_MicrophysicsUtils.H:160
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:42
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
constexpr amrex::Real PI
Definition: ERF_NumericalConstants.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipSources sam_accretion_rates(const amrex::Real &dtn, const amrex::Real &qcc, const amrex::Real &qii, const amrex::Real &qpr, const amrex::Real &qps, const amrex::Real &qpg, const amrex::Real &powr1, const amrex::Real &pows1, const amrex::Real &powg1, const amrex::Real &omp, const amrex::Real &omg, const amrex::Real &accrrc_k, const amrex::Real &accrsc_k, const amrex::Real &accrsi_k, const amrex::Real &accrgc_k, const amrex::Real &accrgi_k) noexcept
Definition: ERF_SAMUtils.H:520
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipFaceState sam_precip_face_state(const int &SAM_moisture_type, const amrex::Array4< const amrex::Real > &rho_array, const amrex::Array4< const amrex::Real > &tabs_array, const amrex::Array4< const amrex::Real > &qp_array, const int &i, const int &j, const int &k, const int &k_lo, const int &k_hi) noexcept
Definition: ERF_SAMUtils.H:1023
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMCloudPhaseChange sam_partition_cloud_phase(const int &SAM_moisture_type, const amrex::Real &tabs, const amrex::Real &qn, const amrex::Real &qcl, const amrex::Real &qci, const amrex::Real fac_cond, const amrex::Real fac_fus, const amrex::Real an, const amrex::Real bn) noexcept
Definition: ERF_SAMUtils.H:393
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_graupel_fraction(const int &SAM_moisture_type, const amrex::Real &tabs) noexcept
Definition: ERF_SAMUtils.H:381
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipFluxComponents sam_precip_flux_components_from_face_state(const SAMPrecipFaceState &face_state, const amrex::Real &vrain, const amrex::Real &vsnow, const amrex::Real &vgrau) noexcept
Definition: ERF_SAMUtils.H:1122
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrimitiveCell sam_copy_state_to_micro_cell(const amrex::Array4< const amrex::Real > &states, const amrex::Array4< const amrex::Real > &base, const amrex::Array4< amrex::Real > &rho, const amrex::Array4< amrex::Real > &theta, const amrex::Array4< amrex::Real > &qv, const amrex::Array4< amrex::Real > &qc, const amrex::Array4< amrex::Real > &qi, const amrex::Array4< amrex::Real > &qn, const amrex::Array4< amrex::Real > &qt, const amrex::Array4< amrex::Real > &qpr, const amrex::Array4< amrex::Real > &qps, const amrex::Array4< amrex::Real > &qpg, const amrex::Array4< amrex::Real > &qp, const amrex::Array4< amrex::Real > &tabs, const amrex::Array4< amrex::Real > &pres, const amrex::Real rdOcp, const bool use_anelastic_reference_pressure, const int i, const int j, const int k) noexcept
Definition: ERF_SAMUtils.H:241
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_mbar_to_pa(const amrex::Real &pres_mbar) noexcept
Definition: ERF_SAMUtils.H:161
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_fall_courant(const amrex::Real &fall_speed, const amrex::Real &dt, const amrex::Real &dz, const amrex::Real &detJ) noexcept
Definition: ERF_SAMUtils.H:987
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipFluxComponents sam_precip_component_fluxes_from_face_state(const SAMPrecipComponentFaceState &face_state, const amrex::Real &vrain, const amrex::Real &vsnow, const amrex::Real &vgrau) noexcept
Definition: ERF_SAMUtils.H:1145
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_precip_rain_fraction(const int &SAM_moisture_type, const amrex::Real &tabs) noexcept
Definition: ERF_SAMUtils.H:369
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_newton_residual(const amrex::Real &tabs_new, const amrex::Real &tabs_old, const amrex::Real fcond, const amrex::Real &qv, const amrex::Real &qsatm, const amrex::Real ffus, const amrex::Real &qi, const amrex::Real &qif) noexcept
Definition: ERF_SAMUtils.H:479
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMSurfaceAccumulation sam_surface_accumulation_from_component_fluxes(const SAMPrecipFluxComponents &component_fluxes, const amrex::Real &dtn) noexcept
Definition: ERF_SAMUtils.H:1215
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_mixed_dqif_dT(const amrex::Real &omn, const amrex::Real &domn, const amrex::Real &qn, const amrex::Real &dqsatm) noexcept
Definition: ERF_SAMUtils.H:469
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_fall_sizing_detJ(const amrex::Real &detJ_donor, const amrex::Real &detJ_receiver) noexcept
Definition: ERF_SAMUtils.H:940
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_pa_to_mbar(const amrex::Real &pres_pa) noexcept
Definition: ERF_SAMUtils.H:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipSources sam_autoconversion_rates(const amrex::Real &dtn, const amrex::Real &qcc, const amrex::Real &qii, const amrex::Real &coefice_k) noexcept
Definition: ERF_SAMUtils.H:503
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipSources sam_rescale_cloud_sinks(const amrex::Real &qcl, const amrex::Real &qci, const amrex::Real &eps, SAMPrecipSources result) noexcept
Definition: ERF_SAMUtils.H:570
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMCellState sam_precip_cell_update(SAMCellState state, const SAMCoefficientRow &coeffs, const SAMPrecipConfig &config, SAMPrecipCellDiagnostics *diagnostics=nullptr) noexcept
Definition: ERF_SAMUtils.H:654
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_precip_flux_density_corrected(const amrex::Real &precip_flux, const amrex::Real &rho_0, const amrex::Real &rho_avg) noexcept
Definition: ERF_SAMUtils.H:1164
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrimitiveCell sam_cons_to_primitive_with_base_state(const amrex::Real &rho, const amrex::Real &rho_theta, const amrex::Real &rho_qv, const amrex::Real &rho_qcl, const amrex::Real &rho_qci, const amrex::Real &rho_qpr, const amrex::Real &rho_qps, const amrex::Real &rho_qpg, const amrex::Real rdOcp, const bool use_anelastic_reference_pressure, const amrex::Real p0) noexcept
Definition: ERF_SAMUtils.H:216
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sam_is_no_ice(const MoistureType &moisture_type) noexcept
Definition: ERF_SAMUtils.H:335
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool sam_is_no_precip(const MoistureType &moisture_type) noexcept
Definition: ERF_SAMUtils.H:342
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int sam_sedimentation_substep_count(const amrex::Real &max_courant) noexcept
Definition: ERF_SAMUtils.H:956
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_precip_component_max_fall_speed(const SAMPrecipComponentFaceState &face_state, const amrex::Real &vrain, const amrex::Real &vsnow, const amrex::Real &vgrau, const amrex::Real &rho_0) noexcept
Definition: ERF_SAMUtils.H:999
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void sam_primitive_to_cons(const SAMPrimitiveCell &primitive, const amrex::Array4< amrex::Real > &states_arr, const int &i, const int &j, const int &k) noexcept
Definition: ERF_SAMUtils.H:316
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMCoefficientRow sam_compute_coefficient_row(const amrex::Real &rho, const amrex::Real &tabs, const amrex::Real &gamr1, const amrex::Real &gamr2, const amrex::Real &gams1, const amrex::Real &gams2, const amrex::Real &gamg1, const amrex::Real &gamg2) noexcept
Definition: ERF_SAMUtils.H:806
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_limit_precip_component_flux(const amrex::Real &raw_flux, const amrex::Real &rho_donor, const amrex::Real &q_donor, const amrex::Real &detJ_donor, const amrex::Real &coef) noexcept
Definition: ERF_SAMUtils.H:1187
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrimitiveCell sam_cons_to_primitive_with_thermo(const amrex::Real &rho, const amrex::Real &rho_theta, const amrex::Real &rho_qv, const amrex::Real &rho_qcl, const amrex::Real &rho_qci, const amrex::Real &rho_qpr, const amrex::Real &rho_qps, const amrex::Real &rho_qpg, const MicrophysicsThermoState &thermo) noexcept
Definition: ERF_SAMUtils.H:185
static constexpr amrex::Real sam_sedimentation_cfl_max
Definition: ERF_SAMUtils.H:924
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_sedimentation_tendency(const amrex::Real &fz_hi, const amrex::Real &fz_lo, const amrex::Real &rho, const amrex::Real &dJinv, const amrex::Real &coef) noexcept
Definition: ERF_SAMUtils.H:1202
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_cloud_ice_terminal_velocity(const amrex::Real &qci_avg) noexcept
Definition: ERF_SAMUtils.H:863
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMFaceState sam_face_average_state(const int &k, const int &k_lo, const int &k_hi, const amrex::Real &rho_km1, const amrex::Real &rho_k, const amrex::Real tabs_km1, const amrex::Real tabs_k, const amrex::Real &, const amrex::Real &qci_k, const amrex::Real, const amrex::Real qp_k) noexcept
Definition: ERF_SAMUtils.H:871
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMSurfaceAccumulation sam_surface_accumulation(const SAMPrecipFaceState &face_state, const amrex::Real &rho_0, const amrex::Real &vrain, const amrex::Real &vsnow, const amrex::Real &vgrau, const amrex::Real &dtn) noexcept
Definition: ERF_SAMUtils.H:1227
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipSources sam_apply_precip_evaporation_limiter(const amrex::Real &qpr, const amrex::Real &qps, const amrex::Real &qpg, SAMPrecipSources result) noexcept
Definition: ERF_SAMUtils.H:638
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_precip_flux_from_face_state(const SAMPrecipFaceState &face_state, const amrex::Real &vrain, const amrex::Real &vsnow, const amrex::Real &vgrau) noexcept
Definition: ERF_SAMUtils.H:1104
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipComponentFaceState sam_precip_component_face_state(const amrex::Array4< const amrex::Real > &rho_array, const amrex::Array4< const amrex::Real > &tabs_array, const amrex::Array4< const amrex::Real > &qpr_array, const amrex::Array4< const amrex::Real > &qps_array, const amrex::Array4< const amrex::Real > &qpg_array, const int &i, const int &j, const int &k, const int &k_lo, const int &k_hi) noexcept
Definition: ERF_SAMUtils.H:1062
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_theta_from_stored_mbar_converted_to_pa(const amrex::Real &tabs, const amrex::Real &pres_mbar, const amrex::Real rdOcp) noexcept
Definition: ERF_SAMUtils.H:174
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipSources sam_partition_autoconverted_precip(SAMPrecipSources result, const amrex::Real &omp, const amrex::Real &omg) noexcept
Definition: ERF_SAMUtils.H:600
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_newton_residual_derivative(const amrex::Real fcond, const amrex::Real ffus, const amrex::Real &dqsatm, const amrex::Real &dqif) noexcept
Definition: ERF_SAMUtils.H:493
void sam_check_sedimentation_substeps(const char *routine, const amrex::Real max_courant)
Definition: ERF_SAMUtils.H:970
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrimitiveCell sam_cons_to_primitive(const amrex::Real &rho, const amrex::Real &rho_theta, const amrex::Real &rho_qv, const amrex::Real &rho_qcl, const amrex::Real &rho_qci, const amrex::Real &rho_qpr, const amrex::Real &rho_qps, const amrex::Real &rho_qpg) noexcept
Definition: ERF_SAMUtils.H:287
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int sam_precip_face_receiver_k(const int &face_k, const int &k_lo, const int &k_hi) noexcept
Definition: ERF_SAMUtils.H:927
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int sam_precip_face_donor_k(const int &face_k, const int &k_lo, const int &k_hi) noexcept
Definition: ERF_SAMUtils.H:910
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_cloud_liquid_fraction(const int &SAM_moisture_type, const amrex::Real &tabs, const amrex::Real an, const amrex::Real bn) noexcept
Definition: ERF_SAMUtils.H:348
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipFluxComponents sam_precip_flux_components_density_corrected(const SAMPrecipFluxComponents &precip_fluxes, const amrex::Real &rho_0, const amrex::Real &rho_avg) noexcept
Definition: ERF_SAMUtils.H:1172
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_mixed_qsat(const amrex::Real &omn, const amrex::Real &qsatw, const amrex::Real &qsati) noexcept
Definition: ERF_SAMUtils.H:447
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE SAMPrecipSources sam_precip_evaporation_rates(const amrex::Real &qpr, const amrex::Real &qps, const amrex::Real &qpg, const amrex::Real &powr2, const amrex::Real &pows2, const amrex::Real &powg2, const amrex::Real &evapr1_k, const amrex::Real &evapr2_k, const amrex::Real &evaps1_k, const amrex::Real &evaps2_k, const amrex::Real &evapg1_k, const amrex::Real &evapg2_k) noexcept
Definition: ERF_SAMUtils.H:614
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sam_mixed_dqsat_dT(const amrex::Real &omn, const amrex::Real &domn, const amrex::Real &qsatw, const amrex::Real &qsati, const amrex::Real &dqsatw, const amrex::Real &dqsati) noexcept
Definition: ERF_SAMUtils.H:456
@ p0_comp
Definition: ERF_IndexDefines.H:110
@ qp
Definition: ERF_Kessler.H:34
@ qcl
Definition: ERF_Kessler.H:32
@ tabs
Definition: ERF_Kessler.H:27
@ pres
Definition: ERF_Kessler.H:28
@ rho
Definition: ERF_Kessler.H:25
@ theta
Definition: ERF_Kessler.H:26
@ qt
Definition: ERF_Kessler.H:30
@ qv
Definition: ERF_Kessler.H:31
@ qpg
Definition: ERF_Morrison.H:44
@ qps
Definition: ERF_Morrison.H:43
@ qn
Definition: ERF_Morrison.H:36
@ qpr
Definition: ERF_Morrison.H:42
@ qci
Definition: ERF_Morrison.H:39
@ qi
Definition: ERF_Morrison.H:111
@ qc
Definition: ERF_Morrison.H:110
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
@ qsatw
Definition: ERF_WSM6.H:363
@ qsati
Definition: ERF_WSM6.H:363
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real eps()
Definition: ERF_ShocMoments.cpp:19
real(c_double), parameter p0
Definition: ERF_module_model_constants.F90:40
Definition: ERF_MicrophysicsUtils.H:22
Definition: ERF_SAMUtils.H:25
amrex::Real delta_qi
Definition: ERF_SAMUtils.H:29
amrex::Real qcl
Definition: ERF_SAMUtils.H:31
amrex::Real qn
Definition: ERF_SAMUtils.H:33
amrex::Real tabs
Definition: ERF_SAMUtils.H:35
amrex::Real qt
Definition: ERF_SAMUtils.H:34
amrex::Real qv
Definition: ERF_SAMUtils.H:30
amrex::Real delta_qv
Definition: ERF_SAMUtils.H:27
amrex::Real delta_qc
Definition: ERF_SAMUtils.H:28
amrex::Real omn
Definition: ERF_SAMUtils.H:26
amrex::Real qci
Definition: ERF_SAMUtils.H:32
Definition: ERF_SAMUtils.H:101
amrex::Real coefice
Definition: ERF_SAMUtils.H:105
amrex::Real evaps2
Definition: ERF_SAMUtils.H:107
amrex::Real accrsi
Definition: ERF_SAMUtils.H:103
amrex::Real accrgc
Definition: ERF_SAMUtils.H:109
amrex::Real accrgi
Definition: ERF_SAMUtils.H:108
amrex::Real accrsc
Definition: ERF_SAMUtils.H:104
amrex::Real evapg1
Definition: ERF_SAMUtils.H:110
amrex::Real evapr1
Definition: ERF_SAMUtils.H:112
amrex::Real evapg2
Definition: ERF_SAMUtils.H:111
amrex::Real accrrc
Definition: ERF_SAMUtils.H:102
amrex::Real evapr2
Definition: ERF_SAMUtils.H:113
amrex::Real evaps1
Definition: ERF_SAMUtils.H:106
Definition: ERF_SAMUtils.H:135
amrex::Real qp_avg
Definition: ERF_SAMUtils.H:139
amrex::Real qci_avg
Definition: ERF_SAMUtils.H:138
amrex::Real tabs_avg
Definition: ERF_SAMUtils.H:137
amrex::Real rho_avg
Definition: ERF_SAMUtils.H:136
Definition: ERF_SAMUtils.H:19
amrex::Real omg
Definition: ERF_SAMUtils.H:22
amrex::Real omp
Definition: ERF_SAMUtils.H:21
amrex::Real omn
Definition: ERF_SAMUtils.H:20
Definition: ERF_SAMUtils.H:89
SAMPrecipSources limited_sources
Definition: ERF_SAMUtils.H:92
amrex::Real omg
Definition: ERF_SAMUtils.H:98
amrex::Real omp
Definition: ERF_SAMUtils.H:97
SAMPrecipSources partitioned_sources
Definition: ERF_SAMUtils.H:93
amrex::Real qsat
Definition: ERF_SAMUtils.H:95
SAMPrecipSources evaporation
Definition: ERF_SAMUtils.H:94
amrex::Real omn
Definition: ERF_SAMUtils.H:96
SAMPrecipSources autoconversion
Definition: ERF_SAMUtils.H:90
SAMPrecipSources accretion
Definition: ERF_SAMUtils.H:91
Definition: ERF_SAMUtils.H:127
amrex::Real qpr_avg
Definition: ERF_SAMUtils.H:130
amrex::Real qpg_avg
Definition: ERF_SAMUtils.H:132
amrex::Real qps_avg
Definition: ERF_SAMUtils.H:131
amrex::Real tabs_avg
Definition: ERF_SAMUtils.H:129
amrex::Real rho_avg
Definition: ERF_SAMUtils.H:128
Definition: ERF_SAMUtils.H:72
bool enable_precip
Definition: ERF_SAMUtils.H:74
amrex::Real fac_cond
Definition: ERF_SAMUtils.H:77
amrex::Real rdOcp
Definition: ERF_SAMUtils.H:76
amrex::Real dtn
Definition: ERF_SAMUtils.H:75
amrex::Real eps
Definition: ERF_SAMUtils.H:80
amrex::Real powr2
Definition: ERF_SAMUtils.H:84
amrex::Real fac_sub
Definition: ERF_SAMUtils.H:79
amrex::Real pows2
Definition: ERF_SAMUtils.H:85
amrex::Real pows1
Definition: ERF_SAMUtils.H:82
amrex::Real fac_fus
Definition: ERF_SAMUtils.H:78
amrex::Real powg2
Definition: ERF_SAMUtils.H:86
amrex::Real powg1
Definition: ERF_SAMUtils.H:83
int sam_moisture_type
Definition: ERF_SAMUtils.H:73
amrex::Real powr1
Definition: ERF_SAMUtils.H:81
Definition: ERF_SAMUtils.H:116
amrex::Real omg
Definition: ERF_SAMUtils.H:121
amrex::Real qss
Definition: ERF_SAMUtils.H:123
amrex::Real qrr
Definition: ERF_SAMUtils.H:122
amrex::Real qp_avg
Definition: ERF_SAMUtils.H:119
amrex::Real rho_avg
Definition: ERF_SAMUtils.H:117
amrex::Real qgg
Definition: ERF_SAMUtils.H:124
amrex::Real tabs_avg
Definition: ERF_SAMUtils.H:118
amrex::Real omp
Definition: ERF_SAMUtils.H:120
Definition: ERF_SAMUtils.H:148
amrex::Real snow
Definition: ERF_SAMUtils.H:150
amrex::Real rain
Definition: ERF_SAMUtils.H:149
amrex::Real graupel
Definition: ERF_SAMUtils.H:151
Definition: ERF_SAMUtils.H:38
amrex::Real dqpg
Definition: ERF_SAMUtils.H:50
amrex::Real dpgc
Definition: ERF_SAMUtils.H:42
amrex::Real dqca
Definition: ERF_SAMUtils.H:39
amrex::Real dqps
Definition: ERF_SAMUtils.H:49
amrex::Real dqp
Definition: ERF_SAMUtils.H:51
amrex::Real dqc
Definition: ERF_SAMUtils.H:46
amrex::Real dpsc
Definition: ERF_SAMUtils.H:41
amrex::Real dpgi
Definition: ERF_SAMUtils.H:45
amrex::Real dprc
Definition: ERF_SAMUtils.H:40
amrex::Real dqia
Definition: ERF_SAMUtils.H:43
amrex::Real dqpr
Definition: ERF_SAMUtils.H:48
amrex::Real dpsi
Definition: ERF_SAMUtils.H:44
amrex::Real dqi
Definition: ERF_SAMUtils.H:47
Definition: ERF_SAMUtils.H:54
amrex::Real theta
Definition: ERF_SAMUtils.H:56
amrex::Real qpr
Definition: ERF_SAMUtils.H:64
amrex::Real qn
Definition: ERF_SAMUtils.H:62
amrex::Real qps
Definition: ERF_SAMUtils.H:65
amrex::Real qci
Definition: ERF_SAMUtils.H:61
amrex::Real qv
Definition: ERF_SAMUtils.H:59
amrex::Real tabs
Definition: ERF_SAMUtils.H:57
amrex::Real qpg
Definition: ERF_SAMUtils.H:66
amrex::Real qt
Definition: ERF_SAMUtils.H:63
amrex::Real qcl
Definition: ERF_SAMUtils.H:60
amrex::Real rho
Definition: ERF_SAMUtils.H:55
amrex::Real pres_mbar
Definition: ERF_SAMUtils.H:58
amrex::Real qp
Definition: ERF_SAMUtils.H:67
Definition: ERF_SAMUtils.H:142
amrex::Real rain
Definition: ERF_SAMUtils.H:143
amrex::Real snow
Definition: ERF_SAMUtils.H:144
amrex::Real graupel
Definition: ERF_SAMUtils.H:145