ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MicrophysicsUtils.H
Go to the documentation of this file.
1 /*
2  * utility tools for microphysics
3  *
4  */
5 #ifndef ERF_Microphysics_Utils_H
6 #define ERF_Microphysics_Utils_H
7 
8 #include <cmath>
9 #include <vector>
10 #include <AMReX_REAL.H>
11 #include <AMReX_Array.H>
12 #include <ERF_Constants.H>
13 
14 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
16  return std::exp(lgamma(x));
17 }
18 
19 // Saturation vapor pressure of ice [mbar]
20 //
21 // From Flatau et al. (1992):
22 // https://doi.org/10.1175/1520-0450(1992)031<1507:PFTSVP>2.0.CO;2
23 // Coefficients come from Table 4 and the data is valid over a
24 // temperature range of [-90 0] C. Return 0 if above this temp range.
25 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
27  amrex::Real const a0 = 6.11147274;
28  amrex::Real const a1 = 0.503160820;
29  amrex::Real const a2 = 0.188439774e-1;
30  amrex::Real const a3 = 0.420895665e-3;
31  amrex::Real const a4 = 0.615021634e-5;
32  amrex::Real const a5 = 0.602588177e-7;
33  amrex::Real const a6 = 0.385852041e-9;
34  amrex::Real const a7 = 0.146898966e-11;
35  amrex::Real const a8 = 0.252751365e-14;
36 
37  amrex::Real dtt = t-273.16;
38  AMREX_ALWAYS_ASSERT(dtt>-90);
39 
40  amrex::Real esati;
41  if (dtt > 0.0) {
42  esati = 0.0;
43  } else {
44  esati = a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
45  }
46  return esati;
47 }
48 
49 // From Clausius-Clapeyron
50 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
52  constexpr amrex::Real svp1 = 0.6112;
53  constexpr amrex::Real svp2 = 17.67;
54  constexpr amrex::Real svp3 = 29.65;
55  constexpr amrex::Real svpt0 = 273.15;
56  // NOTE: units of
57  amrex::Real esatw = 10.0 * svp1 * std::exp(svp2 * (t - svpt0) / (t - svp3));
58  return esatw;
59 }
60 
61 // Saturation vapor pressure of water vapor [mbar]
62 //
63 // From Flatau et al. (1992):
64 // https://doi.org/10.1175/1520-0450(1992)031<1507:PFTSVP>2.0.CO;2
65 // Coefficients come from Table 4 and the data is valid over a
66 // temperature range of [-85 70] C. Assert we are in this temp range.
67 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
69  amrex::Real const a0 = 6.11239921;
70  amrex::Real const a1 = 0.443987641;
71  amrex::Real const a2 = 0.142986287e-1;
72  amrex::Real const a3 = 0.264847430e-3;
73  amrex::Real const a4 = 0.302950461e-5;
74  amrex::Real const a5 = 0.206739458e-7;
75  amrex::Real const a6 = 0.640689451e-10;
76  amrex::Real const a7 = -0.952447341e-13;
77  amrex::Real const a8 = -0.976195544e-15;
78 
79  amrex::Real dtt = t-273.16;
80  amrex::Real esatw;
81  if (dtt>-85 && dtt<70.0) {
82  esatw = a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
83  } else {
84  esatw = erf_esatw_cc(t);
85  }
86  return esatw;
87 }
88 
89 // From Flatau et al. (1992):
90 // https://doi.org/10.1175/1520-0450(1992)031<1507:PFTSVP>2.0.CO;2
91 // Coefficients come from Table 4 and the data is valid over a
92 // temperature range of [-90 0] C. Return 0 if above this temp range.
93 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
95  amrex::Real const a0 = 0.503223089;
96  amrex::Real const a1 = 0.377174432e-1;
97  amrex::Real const a2 = 0.126710138e-2;
98  amrex::Real const a3 = 0.249065913e-4;
99  amrex::Real const a4 = 0.312668753e-6;
100  amrex::Real const a5 = 0.255653718e-8;
101  amrex::Real const a6 = 0.132073448e-10;
102  amrex::Real const a7 = 0.390204672e-13;
103  amrex::Real const a8 = 0.497275778e-16;
104 
105  amrex::Real dtt = t-273.16;
106  AMREX_ALWAYS_ASSERT(dtt>-85);
107  amrex::Real dtesati;
108  if (dtt > 0.0) {
109  dtesati = 0.0;
110  } else {
111  dtesati = a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
112  }
113  return dtesati;
114 }
115 
116 // From Clausius-Clapeyron
117 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
119  constexpr amrex::Real svp1 = 0.6112;
120  constexpr amrex::Real svp2 = 17.67;
121  constexpr amrex::Real svp3 = 29.65;
122  constexpr amrex::Real svpt0 = 273.15;
123  amrex::Real dtesatw = 10.0 * svp1 * svp2 * std::exp(svp2 * (t - svpt0) / (t - svp3))
124  * (svpt0 - svp3) / ((t - svp3) * (t - svp3));
125  return dtesatw;
126 }
127 
128 // From Flatau et al. (1992):
129 // https://doi.org/10.1175/1520-0450(1992)031<1507:PFTSVP>2.0.CO;2
130 // Coefficients come from Table 4 and the data is valid over a
131 // temperature range of [-85 70] C. Assert we are in this temp range.
132 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
134  amrex::Real const a0 = 0.443956472;
135  amrex::Real const a1 = 0.285976452e-1;
136  amrex::Real const a2 = 0.794747212e-3;
137  amrex::Real const a3 = 0.121167162e-4;
138  amrex::Real const a4 = 0.103167413e-6;
139  amrex::Real const a5 = 0.385208005e-9;
140  amrex::Real const a6 = -0.604119582e-12;
141  amrex::Real const a7 = -0.792933209e-14;
142  amrex::Real const a8 = -0.599634321e-17;
143 
144  amrex::Real dtt = t-273.16; // Goff-Gratch
145  amrex::Real dtesatw;
146  if (dtt>-85.0 && dtt<70.) {
147  dtesatw = a0 + dtt*(a1+dtt*(a2+dtt*(a3+dtt*(a4+dtt*(a5+dtt*(a6+dtt*(a7+a8*dtt)))))));
148  } else {
149  dtesatw = erf_dtesatw_cc(t);
150  }
151  return dtesatw;
152 }
153 
154 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
156  amrex::Real esati;
157  esati = erf_esati(t);
158  qsati = Rd_on_Rv*esati/std::max(esati,p-esati);
159 }
160 
161 /* saturated water vapor mixing ratio
162  * t: temperature [K]
163  * p: pressure [mbar]
164  */
165 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
167  amrex::Real esatw;
168  esatw = erf_esatw(t);
169  qsatw = Rd_on_Rv*esatw/std::max(esatw,p-esatw);
170 }
171 
172 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
174  amrex::Real esati = erf_esati(t);
175  amrex::Real dtesati = erf_dtesati(t);
176  amrex::Real denom = p - esati;
177  dtqsati = Rd_on_Rv * dtesati * p / (denom * denom);
178 }
179 
180 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
182  amrex::Real esatw = erf_esatw(t);
183  amrex::Real dtesatw = erf_dtesatw(t);
184  amrex::Real denom = p - esatw;
185  dtqsatw = Rd_on_Rv * dtesatw * p / (denom * denom);
186 }
187 
188 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
190  amrex::Real vonk = 0.4;
191  amrex::Real eps = 1.0e-10;
192  amrex::Real am = 4.8;
193  amrex::Real bm = 19.3;
194  amrex::Real c1 = 3.14159/2.0 - 3.0*log(2.0);
195  amrex::Real rlmo = -bflx*vonk/(ustar*ustar*ustar+eps);
196  amrex::Real zeta = std::min(1.0,z*rlmo);
197  amrex::Real x;
198  amrex::Real psi1;
199  if(zeta >= 0.0) {
200  psi1 = -am*zeta;
201  }
202  else {
203  x = std::sqrt(sqrt(1.0-bm*zeta));
204  psi1 = 2.0*std::log(1.0+x) + std::log(1.0+x*x) -2.0*std::atan(x) + c1;
205  }
206  amrex::Real lnz = std::max(0.0, vonk*wnd/(ustar+eps) +psi1);
207  z0 = z*std::exp(-lnz);
208 }
209 
210 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
212  amrex::Real vrain,
213  amrex::Real vsnow,
214  amrex::Real vgrau,
217 {
218  amrex::Real term_vel = 0.0;
219  if(qploc > qp_threshold) {
220  amrex::Real omp = std::max(0.0,std::min(1.0,(tabs-tprmin)*a_pr));
221  amrex::Real omg = std::max(0.0,std::min(1.0,(tabs-tgrmin)*a_gr));
222  amrex::Real qrr = omp*qploc;
223  amrex::Real qss = (1.0-omp)*(1.0-omg)*qploc;
224  amrex::Real qgg = (1.0-omp)*(omg)*qploc;
225  term_vel = omp*vrain*std::pow(rho*qrr,crain)
226  + (1.0-omp)*( (1.0-omg)*vsnow*std::pow(rho*qss,csnow)
227  + omg *vgrau*std::pow(rho*qgg,cgrau) );
228  }
229  return term_vel;
230 }
231 
232 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
234  return std::max(0.0,y);
235 }
236 
237 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
239  return -std::min(0.0,y);
240 }
241 #endif
constexpr amrex::Real csnow
Definition: ERF_Constants.H:82
constexpr amrex::Real a_gr
Definition: ERF_Constants.H:79
constexpr amrex::Real Rd_on_Rv
Definition: ERF_Constants.H:87
constexpr amrex::Real cgrau
Definition: ERF_Constants.H:83
constexpr amrex::Real tprmin
Definition: ERF_Constants.H:33
constexpr amrex::Real qp_threshold
Definition: ERF_Constants.H:60
constexpr amrex::Real crain
Definition: ERF_Constants.H:81
constexpr amrex::Real tgrmin
Definition: ERF_Constants.H:35
constexpr amrex::Real a_pr
Definition: ERF_Constants.H:78
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:68
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:133
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsatw(amrex::Real t, amrex::Real p, amrex::Real &dtqsatw)
Definition: ERF_MicrophysicsUtils.H:181
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesati(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esati(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pn(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:238
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void z0_est(amrex::Real z, amrex::Real bflx, amrex::Real wnd, amrex::Real ustar, amrex::Real &z0)
Definition: ERF_MicrophysicsUtils.H:189
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_dtesatw_cc(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:118
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_dtqsati(amrex::Real t, amrex::Real p, amrex::Real &dtqsati)
Definition: ERF_MicrophysicsUtils.H:173
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real term_vel_qp(amrex::Real qploc, amrex::Real vrain, amrex::Real vsnow, amrex::Real vgrau, amrex::Real rho, amrex::Real tabs)
Definition: ERF_MicrophysicsUtils.H:211
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:166
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_gammafff(amrex::Real x)
Definition: ERF_MicrophysicsUtils.H:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsati(amrex::Real t, amrex::Real p, amrex::Real &qsati)
Definition: ERF_MicrophysicsUtils.H:155
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pp(amrex::Real y)
Definition: ERF_MicrophysicsUtils.H:233
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real erf_esatw_cc(amrex::Real t)
Definition: ERF_MicrophysicsUtils.H:51
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ tabs
Definition: ERF_Kessler.H:24
@ rho
Definition: ERF_Kessler.H:22
real(c_double), parameter svp1
Definition: ERF_module_model_constants.F90:78
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 svp3
Definition: ERF_module_model_constants.F90:80
real(c_double), parameter svp2
Definition: ERF_module_model_constants.F90:79
real(c_double), parameter a4
Definition: ERF_module_model_constants.F90:97
real(c_double), parameter svpt0
Definition: ERF_module_model_constants.F90:81
real(c_double), private c1
Definition: ERF_module_mp_morr_two_moment.F90:211