ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SatMethods.H
Go to the documentation of this file.
1 // This class contains all methods for estimating
2 // the saturation vapor pressure of water.
3 //
4 // wv_saturation provides specific interfaces and utilities
5 // based on these formulae.
6 //
7 // Typical usage of this module:
8 //
9 // Init:
10 // call wv_sat_methods_init(r8, <constants>, errstring)
11 //
12 // Get scheme index from a name string:
13 // scheme_idx = wv_sat_get_scheme_idx(scheme_name)
14 // if (.not. wv_sat_valid_idx(scheme_idx)) <throw some error>
15 //
16 // Get pressures:
17 // es = wv_sat_svp_water(t, scheme_idx)
18 // es = wv_sat_svp_ice(t, scheme_idx)
19 //
20 // Use ice/water transition range:
21 // es = wv_sat_svp_trice(t, ttrice, scheme_idx)
22 //
23 // Note that elemental functions cannot be pointed to, nor passed
24 // as arguments. If you need to do either, it is recommended to
25 // wrap the function so that it can be given an explicit (non-
26 // elemental) interface.
27 #ifndef ERF_SAT_METHOD_H_
28 #define ERF_SAT_METHOD_H_
29 
30 #include <string>
31 #include <vector>
32 #include <memory>
33 #include <cmath>
34 
35 #include "ERF_Constants.H" // epsilo, omeps
36 #include "ERF_MicrophysicsConstants.H" // tmelt, h2otrip, tboil, ttrice
37 
38 /**
39  * @brief Methods for estimating the saturation vapor pressure of water.
40  */
41 class SatMethods {
42 public:
43  // Get saturation specific humidity given pressure and SVP.
44  // Specific humidity is limited to range 0-1
45  /**
46  * @brief Get saturation specific humidity given pressure and SVP.
47  * @param[in] es Saturation vapor pressure.
48  * @param[in] p Total pressure.
49  * @return Saturation specific humidity.
50  */
51  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
53  // If pressure is less than SVP, set qs to maximum of amrex::Real(1)
54  if ( (p - es) <= amrex::Real(0) )
55  return amrex::Real(1);
56  else
57  return epsilo*es / (p - omeps*es);
58  }
59 
60  /**
61  * @brief Calculate SVP over water and saturation specific humidity.
62  * @param[in] t Temperature.
63  * @param[in] p Total pressure.
64  * @param[out] es Saturation vapor pressure.
65  * @param[out] qs Saturation specific humidity.
66  * @param[in] idx Scheme index.
67  */
68  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
69  static void wv_sat_qsat_water (const amrex::Real& t, const amrex::Real& p,
70  amrex::Real &es, amrex::Real &qs, const int idx = 1) {
71  // Purpose:
72  // Calculate SVP over water at a given temperature, and then
73  // calculate and return saturation specific humidity.
74 
75  es = wv_sat_svp_water(t, idx);
76 
77  qs = wv_sat_svp_to_qsat(es, p);
78 
79  // Ensures returned es is consistent with limiters on qs.
80  es = std::min(es, p);
81  }
82 
83  /**
84  * @brief Calculate SVP over ice and saturation specific humidity.
85  * @param[in] t Temperature.
86  * @param[in] p Total pressure.
87  * @param[out] es Saturation vapor pressure.
88  * @param[out] qs Saturation specific humidity.
89  * @param[in] idx Scheme index.
90  */
91  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
92  static void wv_sat_qsat_ice (const amrex::Real& t, const amrex::Real& p,
93  amrex::Real &es, amrex::Real &qs, const int idx = 1) {
94  // Purpose:
95  // Calculate SVP over ice at a given temperature, and then
96  // calculate and return saturation specific humidity.
97 
98  es = wv_sat_svp_ice(t, idx);
99 
100  qs = wv_sat_svp_to_qsat(es, p);
101 
102  // Ensures returned es is consistent with limiters on qs.
103  es = std::min(es, p);
104  }
105 
106  /**
107  * @brief Calculate transition SVP and saturation specific humidity.
108  * @param[in] t Temperature.
109  * @param[in] p Total pressure.
110  * @param[out] es Saturation vapor pressure.
111  * @param[out] qs Saturation specific humidity.
112  * @param[in] idx Scheme index.
113  */
114  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
115  static void wv_sat_qsat_trans (const amrex::Real& t, const amrex::Real& p,
116  amrex::Real &es, amrex::Real &qs, const int idx = 1) {
117  // Purpose:
118  // Calculate SVP over ice at a given temperature, and then
119  // calculate and return saturation specific humidity.
120 
121  es = wv_sat_svp_trans(t, idx);
122 
123  qs = wv_sat_svp_to_qsat(es, p);
124 
125  // Ensures returned es is consistent with limiters on qs.
126  es = std::min(es, p);
127  }
128 
129  // SVP INTERFACE FUNCTIONS
130  /**
131  * @brief Dispatcher for saturation vapor pressure over water.
132  * @param[in] t Temperature.
133  * @param[in] idx Scheme index.
134  * @return Saturation vapor pressure over water.
135  */
136  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
137  static amrex::Real wv_sat_svp_water (const amrex::Real& t, const int idx = 1) {
138  amrex::Real es;
139  switch(idx)
140  {
141  case GoffGratch:
142  es = GoffGratch_svp_water(t); break;
143  case MurphyKoop:
144  es = MurphyKoop_svp_water(t); break;
145  case OldGoffGratch:
146  es = OldGoffGratch_svp_water(t); break;
147  case Bolton:
148  es = Bolton_svp_water(t); break;
149  }
150  return es;
151  }
152 
153  /**
154  * @brief Dispatcher for saturation vapor pressure over ice.
155  * @param[in] t Temperature.
156  * @param[in] idx Scheme index.
157  * @return Saturation vapor pressure over ice.
158  */
159  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
160  static amrex::Real wv_sat_svp_ice (const amrex::Real& t, const int idx = 1) {
161  amrex::Real es;
162  switch(idx)
163  {
164  case GoffGratch:
165  es = GoffGratch_svp_ice(t); break;
166  case MurphyKoop:
167  es = MurphyKoop_svp_ice(t); break;
168  case OldGoffGratch:
169  es = OldGoffGratch_svp_ice(t); break;
170  case Bolton:
171  es = Bolton_svp_water(t); break;
172  }
173  return es;
174  }
175 
176  /**
177  * @brief Calculate transition saturation vapor pressure.
178  * @param[in] t Temperature.
179  * @param[in] idx Scheme index.
180  * @return Transition saturation vapor pressure.
181  */
182  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
183  static amrex::Real wv_sat_svp_trans (const amrex::Real& t, const int idx = 1) {
184  amrex::Real esice; // Saturation vapor pressure over ice
185  amrex::Real weight; // Intermediate scratch variable for es transition
186  amrex::Real es;
187 
188  // Water
189  if (t >= (tmelt - ttrice))
190  es = wv_sat_svp_water(t,idx);
191  else
192  es = amrex::Real(0);
193 
194  // Ice
195  if (t < tmelt) {
196  esice = wv_sat_svp_ice(t,idx);
197  if ( (tmelt - t) > ttrice )
198  weight = amrex::Real(1);
199  else
200  weight = (tmelt - t)/ttrice;
201 
202  es = weight*esice + (amrex::Real(1) - weight)*es;
203  }
204  return es;
205  }
206 
207 
208  // Goff & Gratch (1946)
209  /**
210  * @brief Goff & Gratch (1946) saturation vapor pressure over water.
211  * @param[in] t Temperature.
212  * @return Saturation vapor pressure.
213  */
214  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
216  // uncertain below -70 C
217  return pow(amrex::Real(10.), (-amrex::Real(7.90298)*(tboil/t-amrex::Real(1))+
218  amrex::Real(5.02808)*std::log10(tboil/t)-
219  amrex::Real(1.3816e-7)*(pow(amrex::Real(10.), (amrex::Real(11.344)*(amrex::Real(1)-t/tboil)))-amrex::Real(1))+
220  amrex::Real(8.1328e-3)*(pow(amrex::Real(10.), (-amrex::Real(3.49149)*(tboil/t-amrex::Real(1))))-amrex::Real(1))+
221  std::log10(amrex::Real(1013.246))))*amrex::Real(100.);
222  }
223 
224  /**
225  * @brief Goff & Gratch (1946) saturation vapor pressure over ice.
226  * @param[in] t Temperature.
227  * @return Saturation vapor pressure.
228  */
229  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
231  // good down to -100 C
232  return pow(amrex::Real(10.), (-amrex::Real(9.09718)*(h2otrip/t-amrex::Real(1))-amrex::Real(3.56654)*
233  log10(h2otrip/t)+amrex::Real(0.876793)*(amrex::Real(1)-t/h2otrip)+
234  log10(amrex::Real(6.1071))))*amrex::Real(100.);
235  }
236 
237  // Murphy & Koop (2005)
238  /**
239  * @brief Murphy & Koop (2005) saturation vapor pressure over water.
240  * @param[in] t Temperature.
241  * @return Saturation vapor pressure.
242  */
243  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
245  // (good for 123 < T < 332 K)
246  return exp(amrex::Real(54.842763) - (amrex::Real(6763.22) / t) - (amrex::Real(4.210) * log(t)) +
247  (amrex::Real(0.000367) * t) + (tanh(amrex::Real(0.0415) * (t - amrex::Real(218.8))) *
248  (amrex::Real(53.878) - (amrex::Real(1331.22) / t) - (amrex::Real(9.44523) * log(t)) +
249  amrex::Real(0.014025) * t)));
250  }
251 
252  /**
253  * @brief Murphy & Koop (2005) saturation vapor pressure over ice.
254  * @param[in] t Temperature.
255  * @return Saturation vapor pressure.
256  */
257  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
259  // (good down to 110 K)
260  return exp(amrex::Real(9.550426) - (amrex::Real(5723.265) / t) + (amrex::Real(3.53068) * log(t))
261  - (amrex::Real(0.00728332) * t));
262  }
263 
264 
265  // Old CAM implementation, also labeled Goff & Gratch (1946)
266 
267  // The water formula differs only due to compiler-dependent order of
268  // operations, so differences are roundoff level, usually zero
269 
270  // The ice formula gives fairly close answers to the current
271  // implementation, but has been rearranged, and uses the
272  // 1 atm melting point of water as the triple point.
273  // Differences are thus small but above roundoff.
274 
275  // A curious fact: although using the melting point of water was
276  // probably a mistake, it mildly improves accuracy for ice svp,
277  // since it compensates for a systematic error in Goff & Gratch.
278  /**
279  * @brief Old CAM implementation of Goff & Gratch (1946) SVP over water.
280  * @param[in] t Temperature.
281  * @return Saturation vapor pressure.
282  */
283  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
285  auto ps = amrex::Real(1013.246);
286  auto e1 = amrex::Real(11.344)*(amrex::Real(1) - t/tboil);
287  auto e2 = -amrex::Real(3.49149)*(tboil/t - amrex::Real(1));
288  auto f1 = -amrex::Real(7.90298)*(tboil/t - amrex::Real(1));
289  auto f2 = amrex::Real(5.02808)*log10(tboil/t);
290  auto f3 = -amrex::Real(1.3816)*(pow(amrex::Real(10.0), e1) - amrex::Real(1))/amrex::Real(10000000.0);
291  auto f4 = amrex::Real(8.1328)*(pow(amrex::Real(10.0), e2) - amrex::Real(1))/amrex::Real(1000.0);
292  auto f5 = log10(ps);
293  auto f = f1 + f2 + f3 + f4 + f5;
294  return (pow(amrex::Real(10.0), f))*amrex::Real(100.0);
295  }
296 
297  /**
298  * @brief Old CAM implementation of Goff & Gratch (1946) SVP over ice.
299  * @param[in] t Temperature.
300  * @return Saturation vapor pressure.
301  */
302  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
304  auto term1 = amrex::Real(2.01889049)/(tmelt/t);
305  auto term2 = amrex::Real(3.56654)*log(tmelt/t);
306  auto term3 = amrex::Real(20.947031)*(tmelt/t);
307  return amrex::Real(575.185606e10)*exp(-(term1 + term2 + term3));
308  }
309 
310  // Bolton (1980)
311  // zm_conv deep convection scheme contained this SVP calculation.
312  // It appears to be from D. Bolton, 1980, Monthly Weather Review.
313  // Unlike the other schemes, no distinct ice formula is associated
314  // with it. (However, a Bolton ice formula exists in CLUBB.)
315 
316  // The original formula used degrees C, but this function
317  // takes Kelvin and internally converts.
318  /**
319  * @brief Bolton (1980) saturation vapor pressure over water.
320  * @param[in] t Temperature.
321  * @return Saturation vapor pressure.
322  */
323  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
325  constexpr auto c1 = amrex::Real(611.2);
326  constexpr auto c2 = amrex::Real(17.67);
327  constexpr auto c3 = amrex::Real(243.5);
328  return c1*exp( (c2*(t - tmelt))/((t - tmelt)+c3) );
329  }
330 
331  // private data
332 private:
333  // Indices representing individual schemes
334  enum Type {
335  Invalid = -1,
339  Bolton = 3
340  };
341 };
342 #endif
constexpr amrex::Real epsilo
Definition: ERF_Constants.H:48
constexpr amrex::Real omeps
Definition: ERF_Constants.H:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:396
Physical constants and tuning parameters used only by the moisture and cloud-physics code.
constexpr amrex::Real tboil
Definition: ERF_MicrophysicsConstants.H:124
constexpr amrex::Real tmelt
Definition: ERF_MicrophysicsConstants.H:122
constexpr amrex::Real ttrice
Definition: ERF_MicrophysicsConstants.H:125
constexpr amrex::Real h2otrip
Definition: ERF_MicrophysicsConstants.H:123
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Methods for estimating the saturation vapor pressure of water.
Definition: ERF_SatMethods.H:41
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE void wv_sat_qsat_trans(const amrex::Real &t, const amrex::Real &p, amrex::Real &es, amrex::Real &qs, const int idx=1)
Calculate transition SVP and saturation specific humidity.
Definition: ERF_SatMethods.H:115
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real Bolton_svp_water(const amrex::Real &t)
Bolton (1980) saturation vapor pressure over water.
Definition: ERF_SatMethods.H:324
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real OldGoffGratch_svp_ice(const amrex::Real &t)
Old CAM implementation of Goff & Gratch (1946) SVP over ice.
Definition: ERF_SatMethods.H:303
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real wv_sat_svp_water(const amrex::Real &t, const int idx=1)
Dispatcher for saturation vapor pressure over water.
Definition: ERF_SatMethods.H:137
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real wv_sat_svp_to_qsat(const amrex::Real &es, const amrex::Real &p)
Get saturation specific humidity given pressure and SVP.
Definition: ERF_SatMethods.H:52
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real GoffGratch_svp_water(const amrex::Real &t)
Goff & Gratch (1946) saturation vapor pressure over water.
Definition: ERF_SatMethods.H:215
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE void wv_sat_qsat_water(const amrex::Real &t, const amrex::Real &p, amrex::Real &es, amrex::Real &qs, const int idx=1)
Calculate SVP over water and saturation specific humidity.
Definition: ERF_SatMethods.H:69
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE void wv_sat_qsat_ice(const amrex::Real &t, const amrex::Real &p, amrex::Real &es, amrex::Real &qs, const int idx=1)
Calculate SVP over ice and saturation specific humidity.
Definition: ERF_SatMethods.H:92
Type
Definition: ERF_SatMethods.H:334
@ MurphyKoop
Definition: ERF_SatMethods.H:338
@ Invalid
Definition: ERF_SatMethods.H:335
@ Bolton
Definition: ERF_SatMethods.H:339
@ GoffGratch
Definition: ERF_SatMethods.H:337
@ OldGoffGratch
Definition: ERF_SatMethods.H:336
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real OldGoffGratch_svp_water(const amrex::Real &t)
Old CAM implementation of Goff & Gratch (1946) SVP over water.
Definition: ERF_SatMethods.H:284
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real MurphyKoop_svp_ice(const amrex::Real &t)
Murphy & Koop (2005) saturation vapor pressure over ice.
Definition: ERF_SatMethods.H:258
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real GoffGratch_svp_ice(const amrex::Real &t)
Goff & Gratch (1946) saturation vapor pressure over ice.
Definition: ERF_SatMethods.H:230
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real MurphyKoop_svp_water(const amrex::Real &t)
Murphy & Koop (2005) saturation vapor pressure over water.
Definition: ERF_SatMethods.H:244
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real wv_sat_svp_trans(const amrex::Real &t, const int idx=1)
Calculate transition saturation vapor pressure.
Definition: ERF_SatMethods.H:183
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real wv_sat_svp_ice(const amrex::Real &t, const int idx=1)
Dispatcher for saturation vapor pressure over ice.
Definition: ERF_SatMethods.H:160
@ qs
Definition: ERF_WDM6.H:30
@ t
Definition: ERF_WSM6.H:272
@ p
Definition: ERF_WSM6.H:280
real(c_double), parameter c2
Definition: ERF_module_model_constants.F90:35
real(c_double), private c1
Definition: ERF_module_mp_morr_two_moment.F90:212