ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MicrophysicsUtils.H File Reference
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <AMReX_REAL.H>
#include <AMReX_Array.H>
#include <ERF_Constants.H>
#include "ERF_EOS.H"
Include dependency graph for ERF_MicrophysicsUtils.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MicrophysicsThermoState
 

Functions

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
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_gammafff (amrex::Real x)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esati (amrex::Real t)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_cc (amrex::Real t)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_flatau_poly (amrex::Real dtt)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_flatau_poly (amrex::Real dtt)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_use_positive_esatw_poly (amrex::Real t)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw (amrex::Real t, bool use_empirical=false)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesati (amrex::Real t)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_cc (amrex::Real t)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw (amrex::Real t)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_qsat_from_esat (amrex::Real esat, amrex::Real p)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtqsat_from_esat (amrex::Real esat, amrex::Real dtesat, amrex::Real p)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsati (amrex::Real t, amrex::Real p, amrex::Real &qsati)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw (amrex::Real t, amrex::Real p, amrex::Real &qsatw)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsati (amrex::Real t, amrex::Real p, amrex::Real &dtqsati)
 
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsatw (amrex::Real t, amrex::Real p, amrex::Real &dtqsatw)
 

Function Documentation

◆ diagnose_microphysics_thermo_state()

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

Diagnose the state used by one Eulerian microphysics cell.

In anelastic mode, the conserved state supplies theta while the hydrostatic reference pressure supplied by BaseState supplies the thermodynamic pressure. In compressible mode, retain ERF's existing local-EOS diagnosis.

42 {
43  if (use_anelastic_reference_pressure) {
44  const amrex::Real theta = rho_theta / rho;
45  return {p0, getTgivenPandTh(p0, theta, rdOcp)};
46  }
47 
48  return {getPgivenRTh(rho_theta, qv),
49  getTgivenRandRTh(rho, rho_theta, qv)};
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 getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenPandTh(const amrex::Real P, const amrex::Real th, const amrex::Real rdOcp)
Definition: ERF_EOS.H:32
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:72
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ theta
Definition: ERF_SLM.H:19
@ rho
Definition: ERF_Kessler.H:25
@ qv
Definition: ERF_Kessler.H:31
real(c_double), parameter p0
Definition: ERF_module_model_constants.F90:40

Referenced by kessler_copy_state_to_micro_cell(), morrison_copy_state_to_micro_cell(), sam_cons_to_primitive_with_base_state(), wdm6_copy_state_to_micro_cell(), and wsm6_copy_state_to_micro_cell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_dtesati()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesati ( amrex::Real  t)
179  {
180  amrex::Real const a0 = amrex::Real(0.503223089);
181  amrex::Real const a1 = amrex::Real(0.377174432e-1);
182  amrex::Real const a2 = amrex::Real(0.126710138e-2);
183  amrex::Real const a3 = amrex::Real(0.249065913e-4);
184  amrex::Real const a4 = amrex::Real(0.312668753e-6);
185  amrex::Real const a5 = amrex::Real(0.255653718e-8);
186  amrex::Real const a6 = amrex::Real(0.132073448e-10);
187  amrex::Real const a7 = amrex::Real(0.390204672e-13);
188  amrex::Real const a8 = amrex::Real(0.497275778e-16);
189 
190  amrex::Real dtt = t-amrex::Real(273.16);
192  AMREX_ALWAYS_ASSERT(dtt >= -amrex::Real(85.0) - tol);
193  amrex::Real dtesati;
194  if (dtt > amrex::Real(0)) {
195  dtesati = amrex::Real(0);
196  } else {
197  dtesati = a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
198  }
199  return dtesati;
200 }
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
@ t
Definition: ERF_WSM6.H:272
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
real(c_double), parameter a2
Definition: ERF_module_model_constants.F90:95
real(c_double), parameter a3
Definition: ERF_module_model_constants.F90:96
real(c_double), parameter a4
Definition: ERF_module_model_constants.F90:97

Referenced by erf_dtqsati().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_dtesatw()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw ( amrex::Real  t)
222  {
224  return erf_dtesatw_flatau_poly(t - amrex::Real(273.16));
225  }
226 
227  return erf_dtesatw_cc(t);
228 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_use_positive_esatw_poly(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:140
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_flatau_poly(amrex::Real dtt)
Definition: ERF_MicrophysicsUtils.H:124
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_cc(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:206

Referenced by erf_dtqsatw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_dtesatw_cc()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_cc ( amrex::Real  t)
206  {
207  constexpr amrex::Real svp1 = amrex::Real(0.6112);
208  constexpr amrex::Real svp2 = amrex::Real(17.67);
209  constexpr amrex::Real svp3 = amrex::Real(29.65);
210  constexpr amrex::Real svpt0 = amrex::Real(273.15);
211  amrex::Real dtesatw = amrex::Real(10.0) * svp1 * svp2 * std::exp(svp2 * (t - svpt0) / (t - svp3))
212  * (svpt0 - svp3) / ((t - svp3) * (t - svp3));
213  return dtesatw;
214 }
real(c_double), parameter svp1
Definition: ERF_module_model_constants.F90:78
real(c_double), parameter svp3
Definition: ERF_module_model_constants.F90:80
real(c_double), parameter svp2
Definition: ERF_module_model_constants.F90:79
real(c_double), parameter svpt0
Definition: ERF_module_model_constants.F90:81

Referenced by erf_dtesatw().

Here is the caller graph for this function:

◆ erf_dtesatw_flatau_poly()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_flatau_poly ( amrex::Real  dtt)
125 {
126  amrex::Real const a0 = amrex::Real(0.443956472);
127  amrex::Real const a1 = amrex::Real(0.285976452e-1);
128  amrex::Real const a2 = amrex::Real(0.794747212e-3);
129  amrex::Real const a3 = amrex::Real(0.121167162e-4);
130  amrex::Real const a4 = amrex::Real(0.103167413e-6);
131  amrex::Real const a5 = amrex::Real(0.385208005e-9);
132  amrex::Real const a6 = -amrex::Real(0.604119582e-12);
133  amrex::Real const a7 = -amrex::Real(0.792933209e-14);
134  amrex::Real const a8 = -amrex::Real(0.599634321e-17);
135 
136  return a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
137 }

Referenced by erf_dtesatw().

Here is the caller graph for this function:

◆ erf_dtqsat_from_esat()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtqsat_from_esat ( amrex::Real  esat,
amrex::Real  dtesat,
amrex::Real  p 
)
242 {
243  if ((p - esat) >= esat) {
244  amrex::Real const denom = p - esat;
245  return RdoRv * dtesat * p / (denom * denom);
246  }
247 
248  return amrex::Real(0);
249 }
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:44
@ p
Definition: ERF_WSM6.H:280

Referenced by erf_dtqsati(), and erf_dtqsatw().

Here is the caller graph for this function:

◆ erf_dtqsati()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsati ( amrex::Real  t,
amrex::Real  p,
amrex::Real dtqsati 
)
271  {
272  amrex::Real esati = erf_esati(t);
273  amrex::Real dtesati = erf_dtesati(t);
274  dtqsati = erf_dtqsat_from_esat(esati, dtesati, p);
275 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesati(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:179
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esati(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:67
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtqsat_from_esat(amrex::Real esat, amrex::Real dtesat, amrex::Real p)
Definition: ERF_MicrophysicsUtils.H:241

Referenced by SAM::NewtonIterSat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_dtqsatw()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsatw ( amrex::Real  t,
amrex::Real  p,
amrex::Real dtqsatw 
)
280  {
281  amrex::Real esatw = erf_esatw(t);
282  amrex::Real dtesatw = erf_dtesatw(t);
283  dtqsatw = erf_dtqsat_from_esat(esatw, dtesatw, p);
284 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:222
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t, bool use_empirical=false)
Definition: ERF_MicrophysicsUtils.H:159

Referenced by Kessler::AdvanceKessler(), SAM::NewtonIterSat(), and SatAdj::NewtonSolveSatTemperature().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_esati()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esati ( amrex::Real  t)
67  {
68  amrex::Real const a0 = amrex::Real(6.11147274);
69  amrex::Real const a1 = amrex::Real(0.503160820);
70  amrex::Real const a2 = amrex::Real(0.188439774e-1);
71  amrex::Real const a3 = amrex::Real(0.420895665e-3);
72  amrex::Real const a4 = amrex::Real(0.615021634e-5);
73  amrex::Real const a5 = amrex::Real(0.602588177e-7);
74  amrex::Real const a6 = amrex::Real(0.385852041e-9);
75  amrex::Real const a7 = amrex::Real(0.146898966e-11);
76  amrex::Real const a8 = amrex::Real(0.252751365e-14);
77 
78  amrex::Real dtt = t-amrex::Real(273.16);
80  AMREX_ALWAYS_ASSERT(dtt >= -amrex::Real(90.0) - tol);
81 
82  amrex::Real esati;
83  if (dtt > amrex::Real(0)) {
84  esati = amrex::Real(0);
85  } else {
86  esati = a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
87  }
88  return esati;
89 }

Referenced by saturation_funcs::compute_saturation_pressure_ice(), erf_dtqsati(), erf_qsati(), and sam_compute_coefficient_row().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_esatw()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw ( amrex::Real  t,
bool  use_empirical = false 
)
160 {
161  if (use_empirical) {
162  return amrex::Real(0.01) *
163  std::exp(amrex::Real(34.494) - amrex::Real(4924.99)/(t - amrex::Real(273.15) + amrex::Real(237.1))) /
164  std::pow(t - amrex::Real(273.15) + amrex::Real(105.0), amrex::Real(1.57));
165  }
166 
168  return erf_esatw_flatau_poly(t - amrex::Real(273.16));
169  }
170 
171  return erf_esatw_cc(t);
172 }
bool use_empirical
Definition: ERF_InitCustomPert_MultiSpeciesBubble.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_flatau_poly(amrex::Real dtt)
Definition: ERF_MicrophysicsUtils.H:108
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_cc(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:98

Referenced by HSEutils::compute_saturation_pressure(), saturation_funcs::compute_saturation_pressure_H2O(), erf_dtqsatw(), erf_qsatw(), ERF::FillPlot3DVars(), sam_compute_coefficient_row(), and erf_cloud_chamber::vapor_mixing_ratio_from_relative_humidity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_esatw_cc()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_cc ( amrex::Real  t)
98  {
99  constexpr amrex::Real svp1 = amrex::Real(0.6112);
100  constexpr amrex::Real svp2 = amrex::Real(17.67);
101  constexpr amrex::Real svp3 = amrex::Real(29.65);
102  constexpr amrex::Real svpt0 = amrex::Real(273.15);
103  amrex::Real esatw = amrex::Real(10.0) * svp1 * std::exp(svp2 * (t - svpt0) / (t - svp3));
104  return esatw;
105 }

Referenced by erf_esatw(), and ERF::FillPlot3DVars().

Here is the caller graph for this function:

◆ erf_esatw_flatau_poly()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_flatau_poly ( amrex::Real  dtt)
109 {
110  amrex::Real const a0 = amrex::Real(6.11239921);
111  amrex::Real const a1 = amrex::Real(0.443987641);
112  amrex::Real const a2 = amrex::Real(0.142986287e-1);
113  amrex::Real const a3 = amrex::Real(0.264847430e-3);
114  amrex::Real const a4 = amrex::Real(0.302950461e-5);
115  amrex::Real const a5 = amrex::Real(0.206739458e-7);
116  amrex::Real const a6 = amrex::Real(0.640689451e-10);
117  amrex::Real const a7 = -amrex::Real(0.952447341e-13);
118  amrex::Real const a8 = -amrex::Real(0.976195544e-15);
119 
120  return a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
121 }

Referenced by erf_esatw(), and erf_use_positive_esatw_poly().

Here is the caller graph for this function:

◆ erf_gammafff()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_gammafff ( amrex::Real  x)
55  {
57  return std::exp(std::lgamma(x));
58 }

Referenced by SAM::Compute_Coefficients(), and SAM::PrecipFall().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_qsat_from_esat()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_qsat_from_esat ( amrex::Real  esat,
amrex::Real  p 
)
234 {
235  return RdoRv * esat / std::max(esat, p - esat);
236 }

Referenced by erf_qsati(), and erf_qsatw().

Here is the caller graph for this function:

◆ erf_qsati()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsati ( amrex::Real  t,
amrex::Real  p,
amrex::Real qsati 
)
254  {
256 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_qsat_from_esat(amrex::Real esat, amrex::Real p)
Definition: ERF_MicrophysicsUtils.H:233
@ qsati
Definition: ERF_WSM6.H:340

Referenced by SAM::Cloud(), saturation_funcs::compute_saturation_vapfrac_ice(), ComputeMoistStratification(), SAM::NewtonIterSat(), and sam_precip_cell_update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erf_qsatw()

◆ erf_use_positive_esatw_poly()

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool erf_use_positive_esatw_poly ( amrex::Real  t)
141 {
142  amrex::Real const dtt = t - amrex::Real(273.16);
143  amrex::Real const poly_min_dtt = -amrex::Real(70.0);
144  return dtt > poly_min_dtt && dtt < amrex::Real(70.0) &&
146 }

Referenced by erf_dtesatw(), and erf_esatw().

Here is the call graph for this function:
Here is the caller graph for this function: