ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MOSTUtils.H
Go to the documentation of this file.
1 #ifndef ERF_MOSTUtils_H
2 #define ERF_MOSTUtils_H
3 
4 #include <AMReX_Algorithm.H>
5 #include <AMReX_BLassert.H>
6 #include <AMReX_Math.H>
7 #include <AMReX_ParmParse.H>
8 #include <AMReX_Print.H>
9 #include <string>
10 #include "ERF_Constants.H"
11 
12 /**
13  * Structure of plain old data relevant to MOST BCs
14  */
15 struct most_data
16 {
17 public:
18  amrex::Real z0_const{amrex::Real(0.1)}; ///< Roughness height -- default constant value(m)
19  amrex::Real kappa{KAPPA}; ///< von Karman constant
20  amrex::Real gravity{CONST_GRAV}; ///< Acceleration due to gravity (m/s^2)
21  amrex::Real surf_temp_flux{zero}; ///< Heat flux TODO: decide whether this is <θ'w'> or <θv'w'> under moist conditions
22  amrex::Real surf_moist_flux{zero}; ///< Moisture flux
23 
24  amrex::Real Cnk_a{amrex::Real(0.0185)}; ///< Standard Charnock constant https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137.1)
25  amrex::Real Cnk_b1{one/amrex::Real(30.0)}; ///< Modified Charnock Eq (4) https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137.1)
26  amrex::Real Cnk_b2{amrex::Real(1260.0)}; ///< Modified Charnock Eq (4) https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137.1)
27  amrex::Real Cnk_d{amrex::Real(30.0)}; ///< Modified Charnock Eq (4) https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137.1)
28  amrex::Real Cnk_b = Cnk_b1 * std::log(Cnk_b2 / Cnk_d); ///< Modified Charnock derived quantity
29  bool visc{true}; ///< Use viscous Charnock formulation
30 
31  amrex::Real Cd{amrex::Real(0.001)};
32  amrex::Real Ch{amrex::Real(0.001)};
33  amrex::Real Cq{amrex::Real(0.001)};
34 
35  const amrex::Real Bjr_beta = amrex::Real(1.2); // Empirical parameter from Beljaars 1995 QJRMS
36 };
37 
38 
39 /**
40  * Lower bound of the log-law bracket ln(zref/z0) - psi of the MOST flux kernels: C/2 held
41  * between 1/2 and 1.
42  *
43  * The bound is 1 for zref >= e^2 z0 and C/2 down to zref = e z0, so it does not exceed the
44  * neutral bracket C wherever zref >= e^(1/2) z0. The lower limit of 1/2 keeps the bracket,
45  * and so u*, positive and finite when z0 approaches or exceeds zref (C <= 0).
46  *
47  * The bound is set by the under-relaxed u* iteration, not by the physics. At an unstable
48  * fixed point the relaxed map has slope (1 - alpha) - alpha s / bracket, with
49  * s = 3 (z/L) dpsi_m/d(z/L) = 3 (1 - phi_m) between 1.3 (z/L = -0.5) and 2.4 (z/L = -50) for
50  * Businger-Dyer.
51  * With alpha = 0.5 the iteration converges only for bracket > s/3 (0.4 to 0.8), so a bound of
52  * 1 keeps the switch between the bounded and free branches inside the convergent range, while
53  * 0.1 C (0.3 at C = 3) does not and the iteration oscillates between two values. If alpha
54  * changes, the bound needs revisiting; see PR #4866.
55  *
56  * @param[in] C ln(zref/z0)
57  */
58 AMREX_GPU_HOST_DEVICE
59 AMREX_FORCE_INLINE
60 amrex::Real
61 most_bracket_floor (amrex::Real C)
62 {
63  return amrex::max(amrex::min(amrex::Real(0.5) * C, amrex::Real(1.0)), amrex::Real(0.5));
64 }
65 
66 
67 /**
68  * Bound on |z/L| of the MOST kernels (see most_rib_zeta_bracketed, most_clamp_zeta and
69  * similarity_funs::calc_zeta_fold).
70  */
71 inline constexpr amrex::Real most_zeta_lim = amrex::Real(100.0);
72 
73 /**
74  * Structure of similarity functions for Moeng formulation.
75  *
76  * The unstable side is Businger-Dyer. The stable side is Businger-Dyer (the default,
77  * phi = 1 + beta zeta, psi = -beta zeta) or, after set_stable_functions, the QNSE form
78  * phi = (1 + a zeta)/(1 + b zeta), psi = -((a - b)/b) ln(1 + b zeta) of Sukoriansky, Galperin
79  * and Perov (2005), with its own coefficients for momentum and heat (most.stable_functions,
80  * read by read_most_similarity_funs). The Jimenez (2012) pair (calc_psi_m2, calc_psi_h2) is
81  * not affected by the choice.
82  */
84 {
85  //
86  // Similarity functions from Jimenez (2012)
87  //
88  /**
89  * Compute the Jimenez momentum stability correction.
90  *
91  * @param[in] zeta stability coordinate z/L
92  */
93  AMREX_GPU_HOST_DEVICE
94  AMREX_FORCE_INLINE
95  amrex::Real
96  calc_psi_m2 (amrex::Real zeta) const
97  {
98  if (zeta > 0) {
99  amrex::Real x = std::pow(one + std::pow(zeta, amrex::Real(2.5)), one/amrex::Real(2.5));
100  return ( -amrex::Real(6.1)*std::log(zeta + x) );
101  } else {
102  amrex::Real x = std::pow(one - amrex::Real(16.0)*zeta, fourth);
103  amrex::Real psi_k_m = two * std::log(myhalf * (one + x)) + std::log(myhalf * (one + x * x)) -
104  two * std::atan(x) + PIoTwo;
105  amrex::Real y = std::pow(one - amrex::Real(10.0)*zeta, one/three);
106  amrex::Real psi_c_m = (three/two)*std::log((y*y + y + one)/three)
107  - std::sqrt(three)*std::atan((two*y + one)/std::sqrt(three))
108  + PI/std::sqrt(three);
109  return ( (psi_k_m + zeta*zeta*psi_c_m) / (one + zeta*zeta) );
110  }
111  }
112 
113  /**
114  * Compute the Jimenez heat stability correction.
115  *
116  * @param[in] zeta stability coordinate z/L
117  */
118  AMREX_GPU_HOST_DEVICE
119  AMREX_FORCE_INLINE
120  amrex::Real
121  calc_psi_h2 (amrex::Real zeta) const
122  {
123  if (zeta > 0) {
124  amrex::Real x = std::pow(one + std::pow(zeta, amrex::Real(1.1)), one/amrex::Real(1.1));
125  return ( -amrex::Real(5.3)*std::log(zeta + x) );
126  } else {
127  amrex::Real x = std::sqrt(one - amrex::Real(16.0)*zeta);
128  amrex::Real psi_k_h = two * std::log(myhalf * (one + x));
129  amrex::Real y = std::pow(one - amrex::Real(34.0)*zeta, one/three);
130  amrex::Real psi_c_h = (three/two)*std::log((y*y + y + one)/three)
131  - std::sqrt(three)*std::atan((two*y + one)/std::sqrt(three))
132  + PI/std::sqrt(three);
133  return ( (psi_k_h + zeta*zeta*psi_c_h) / (one + zeta*zeta) );
134  }
135  }
136 
137 
138  //
139  // Similarity functions from Businger & Dyer (1966); stable side Businger-Dyer or QNSE
140  //
141  /**
142  * Compute the momentum stability correction (Businger-Dyer, or QNSE on the stable side).
143  *
144  * @param[in] zeta stability coordinate z/L
145  */
146  AMREX_GPU_HOST_DEVICE
147  AMREX_FORCE_INLINE
148  amrex::Real
149  calc_psi_m (amrex::Real zeta) const
150  {
151  if (zeta > 0) {
152  return m_qnse ? qnse_psi(zeta, m_qnse_am, m_qnse_bm) : -beta_m * zeta;
153  } else {
154  amrex::Real x = std::sqrt(std::sqrt(one - gamma_m * zeta));
155  return two * std::log(myhalf * (one + x)) + std::log(myhalf * (one + x * x)) -
156  two * std::atan(x) + PIoTwo;
157  }
158  }
159 
160  /**
161  * Compute the heat stability correction (Businger-Dyer, or QNSE on the stable side).
162  *
163  * @param[in] zeta stability coordinate z/L
164  */
165  AMREX_GPU_HOST_DEVICE
166  AMREX_FORCE_INLINE
167  amrex::Real
168  calc_psi_h (amrex::Real zeta) const
169  {
170  if (zeta > 0) {
171  return m_qnse ? qnse_psi(zeta, m_qnse_ah, m_qnse_bh) : -beta_h * zeta;
172  } else {
173  amrex::Real x = std::sqrt(one - gamma_h * zeta);
174  return two * std::log(myhalf * (one + x));
175  }
176  }
177 
178  //
179  // Gradient (phi) functions
180  //
181  /**
182  * Compute the momentum gradient function (Businger-Dyer, or QNSE on the stable side).
183  *
184  * This is the exact companion of calc_psi_m: the two are tied by
185  * psi_m(zeta) = int_0^zeta (1 - phi_m(x))/x dx, so differentiating the MOST
186  * wind profile u(z) = (u_star/kappa)[ln(z/z0) - psi_m(z/L)] gives
187  * du/dz = u_* phi_m(zeta) / (kappa z).
188  *
189  * NOTE: the surface_temp* flux calculators use the Jimenez psi pair
190  * (calc_psi_m2/calc_psi_h2) rather than this one; their companions are
191  * not implemented yet, so a prescribed-surface-temperature run gets the
192  * Businger-Dyer gradient here.
193  *
194  * @param[in] zeta stability coordinate z/L
195  */
196  AMREX_GPU_HOST_DEVICE
197  AMREX_FORCE_INLINE
198  amrex::Real
199  calc_phi_m (amrex::Real zeta) const
200  {
201  if (zeta > 0) {
202  return m_qnse ? qnse_phi(zeta, m_qnse_am, m_qnse_bm) : one + beta_m * zeta;
203  } else {
204  return one / std::sqrt(std::sqrt(one - gamma_m * zeta));
205  }
206  }
207 
208  /**
209  * Compute the heat gradient function (Businger-Dyer, or QNSE on the stable side), the
210  * exact companion of calc_psi_h: dtheta/dz = theta_* phi_h(zeta) / (kappa z).
211  *
212  * See the note in calc_phi_m about the Jimenez pair.
213  *
214  * @param[in] zeta stability coordinate z/L
215  */
216  AMREX_GPU_HOST_DEVICE
217  AMREX_FORCE_INLINE
218  amrex::Real
219  calc_phi_h (amrex::Real zeta) const
220  {
221  if (zeta > 0) {
222  return m_qnse ? qnse_phi(zeta, m_qnse_ah, m_qnse_bh) : one + beta_h * zeta;
223  } else {
224  return one / std::sqrt(one - gamma_h * zeta);
225  }
226  }
227 
228  /**
229  * Stable z/L at which the prescribed-flux problem folds.
230  *
231  * With L fixed by u* and the flux, the wind a given u* supports is
232  * u* max(C - psi_m, b) / kappa, with b = most_bracket_floor(C). Below the smallest such
233  * wind the prescribed stable flux has no solution with z/L below most_zeta_lim (Basu et
234  * al., BLM 2008; with QNSE the supported wind rises again past its first minimum to a
235  * local maximum at the second zero of f below, at z/L of order 1e3 to 1e4, and only then
236  * tends to zero with u*; the kernels never reach that range). The physical
237  * (large u*) branch has z/L below this value, so bounding z/L by it leaves every point that
238  * has a solution unchanged. The result is positive for every C.
239  *
240  * Businger-Dyer (psi_m = -beta_m z/L): for C > 0 the minimum is at z/L = C / (2 beta_m);
241  * for small or negative C (z0 near or above zref) the floor binds first and the minimum is
242  * at the kink z/L = (b - C) / beta_m.
243  *
244  * QNSE (psi_m = -c ln(1 + b_m z/L), c = (a_m - b_m)/b_m): with u* proportional to
245  * (z/L)^(-1/3), the supported wind falls with z/L while
246  * f(z/L) = C + c ln(1 + b_m z/L) - 3 c b_m (z/L) / (1 + b_m z/L) is positive, and f falls
247  * from C at z/L = 0 to its minimum at z/L = 2 / b_m and rises without bound after it. The
248  * fold is the first zero of f beyond the kink where the floor stops binding
249  * (C - psi_m = b), found by Newton's method on the bracket [kink, 2 / b_m] where f is
250  * convex and decreasing (f' = c b_m (b_m z/L - 2) / (1 + b_m z/L)^2 < 0, f'' > 0 for
251  * b_m z/L < 5): after the first step the iterates approach the root from the left, a step
252  * that would leave the bracket is replaced by its midpoint, and the iteration stops at a
253  * relative change of 1e-10 (a handful of steps against the 60 passes of a bisection to
254  * the same precision; the roughness kernels call this once per u* iteration). It is the
255  * kink itself when f is already negative there, and most_zeta_lim when f has no zero
256  * (C > c (2 - ln 3), 10.4 with the default coefficients): the wind then falls
257  * monotonically with z/L up to the bound, where the kernels hold z/L and reduce the flux
258  * as at a fold. Every return value is at most most_zeta_lim.
259  *
260  * @param[in] C ln(zref/z0)
261  */
262  AMREX_GPU_HOST_DEVICE
263  AMREX_FORCE_INLINE
264  amrex::Real
265  calc_zeta_fold (amrex::Real C) const
266  {
267  if (!m_qnse) {
268  return amrex::max(C / (two * beta_m), (most_bracket_floor(C) - C) / beta_m);
269  }
270  // A non-finite C (bad zref or z0) is returned as it is, as most_rib_zeta_bracketed does,
271  // so that it shows up in the kernel's results instead of a bisection artifact
272  if (!amrex::Math::isfinite(C)) { return C; }
273  const amrex::Real b = m_qnse_bm;
274  const amrex::Real c = (m_qnse_am - m_qnse_bm) / m_qnse_bm;
275  if (c <= zero) { return most_zeta_lim; } // a_m <= b_m is refused by the reader; psi_m = 0 would have no fold
276  const amrex::Real bf = most_bracket_floor(C);
277  amrex::Real lo = (C < bf) ? (std::exp((bf - C) / c) - one) / b : zero;
278  auto f = [&] (amrex::Real z) {
279  const amrex::Real s = one + b * z;
280  return C + c * std::log(s) - three * c * b * z / s;
281  };
282  auto df = [&] (amrex::Real z) {
283  const amrex::Real s = one + b * z;
284  return c * b * (b * z - two) / (s * s);
285  };
286  const amrex::Real zlim = most_zeta_lim; // by value: a namespace constant must not bind to min's reference in device code
287  if (f(lo) <= zero) { return amrex::min(lo, zlim); }
288  amrex::Real hi = two / b;
289  if (lo >= hi || f(hi) >= zero) { return zlim; }
290  // Safeguarded Newton on [lo, hi]: f(lo) > 0 > f(hi), f convex and decreasing, so from
291  // the second step on the iterates rise monotonically to the root; a step outside the
292  // bracket (the first one can be, from the midpoint) falls back to the midpoint
293  amrex::Real z = myhalf * (lo + hi);
294  constexpr amrex::Real rtol = amrex::Real(1.0e-10);
295  for (int n = 0; n < 30; ++n) {
296  const amrex::Real fz = f(z);
297  if (fz > zero) { lo = z; } else if (fz < zero) { hi = z; } else { break; }
298  const amrex::Real d = df(z);
299  amrex::Real zn = (d < zero) ? z - fz / d : myhalf * (lo + hi);
300  if (!(zn > lo && zn < hi)) { zn = myhalf * (lo + hi); }
301  const bool done = std::abs(zn - z) <= rtol * zn;
302  z = zn;
303  if (done) { break; }
304  }
305  return amrex::min(z, zlim);
306  }
307 
308  /**
309  * Select the QNSE stable-side functions phi = (1 + a zeta)/(1 + b zeta) for momentum
310  * (a_m, b_m) and heat (a_h, b_h), or return to Businger-Dyer (use_qnse false, the
311  * coefficients then unused). read_most_similarity_funs checks the inputs: b_m, b_h > 0
312  * and a_m > b_m, a_h > b_h.
313  *
314  * @param[in] use_qnse whether the stable side is QNSE
315  * @param[in] am a_m
316  * @param[in] bm b_m
317  * @param[in] ah a_h
318  * @param[in] bh b_h
319  */
320  AMREX_GPU_HOST_DEVICE
321  void
322  set_stable_functions (bool use_qnse, amrex::Real am, amrex::Real bm,
323  amrex::Real ah, amrex::Real bh)
324  {
325  m_qnse = use_qnse;
326  m_qnse_am = am;
327  m_qnse_bm = bm;
328  m_qnse_ah = ah;
329  m_qnse_bh = bh;
330  }
331 
332  /** Whether the stable side is QNSE. */
333  AMREX_GPU_HOST_DEVICE
334  bool uses_qnse () const { return m_qnse; }
335 
336 private:
337  /** QNSE integrated function, psi = -((a - b)/b) ln(1 + b zeta), zeta > 0. */
338  AMREX_GPU_HOST_DEVICE
339  AMREX_FORCE_INLINE
340  static amrex::Real
341  qnse_psi (amrex::Real zeta, amrex::Real a, amrex::Real b)
342  {
343  return -((a - b) / b) * std::log(one + b * zeta);
344  }
345 
346  /** QNSE gradient function, phi = (1 + a zeta)/(1 + b zeta), zeta > 0. */
347  AMREX_GPU_HOST_DEVICE
348  AMREX_FORCE_INLINE
349  static amrex::Real
350  qnse_phi (amrex::Real zeta, amrex::Real a, amrex::Real b)
351  {
352  return (one + a * zeta) / (one + b * zeta);
353  }
354 
355  amrex::Real beta_m{amrex::Real(5.0)}; ///< Constants from Dyer, BLM, 1974
356  amrex::Real beta_h{amrex::Real(5.0)}; ///< https://doi.org/amrex::Real(10.1007)/BF00240838
357  amrex::Real gamma_m{amrex::Real(16.0)};
358  amrex::Real gamma_h{amrex::Real(16.0)};
359  bool m_qnse{false}; ///< stable side QNSE instead of Businger-Dyer
360  amrex::Real m_qnse_am{amrex::Real(2.5)}; ///< QNSE a_m (Sukoriansky et al. 2005)
361  amrex::Real m_qnse_bm{amrex::Real(0.2)}; ///< QNSE b_m
362  amrex::Real m_qnse_ah{amrex::Real(2.5)}; ///< QNSE a_h
363  amrex::Real m_qnse_bh{amrex::Real(0.2)}; ///< QNSE b_h
364 };
365 
366 /**
367  * Stable-side similarity functions of a surface layer from its inputs:
368  * <prefix>.most.stable_functions = businger_dyer (the default) | qnse, and with qnse the
369  * coefficients <prefix>.most.qnse_am, qnse_bm, qnse_ah, qnse_bh (2.5, 0.2, 2.5, 0.2 by
370  * default, the values of the PBL schemes' erf.qnse_*). The run stops when a coefficient is
371  * given without qnse, is not finite, b_m or b_h is not positive, or a_m <= b_m or a_h <= b_h
372  * (phi would not exceed 1 on the stable side: no stability correction, or one of the wrong sign).
373  *
374  * @param[in] pp parameter parser of the reader (prefix erf, or erf.<face> for a side-face
375  * surface layer; the immersed wall laws read the unqualified erf.most.* keys)
376  * @param[in] who the reader, for the start-up line
377  */
378 inline similarity_funs
379 read_most_similarity_funs (amrex::ParmParse& pp, const std::string& who = "Surface layer")
380 {
381  similarity_funs sfuns;
382  const std::string prefix = pp.getPrefix() + ".most.";
383  std::string name = "businger_dyer";
384  pp.queryAdd("most.stable_functions", name);
385  const char* keys[4] = {"qnse_am", "qnse_bm", "qnse_ah", "qnse_bh"};
386  amrex::Real coef[4] = {amrex::Real(2.5), amrex::Real(0.2), amrex::Real(2.5), amrex::Real(0.2)};
387  bool given = false;
388  for (int n = 0; n < 4; ++n) {
389  const std::string key = std::string("most.") + keys[n];
390  given = pp.query(key.c_str(), coef[n]) || given;
391  }
392  if (name == "qnse") {
393  for (int n = 0; n < 4; ++n) {
394  if (!amrex::Math::isfinite(coef[n])) {
395  amrex::Abort(prefix + keys[n] + " must be finite");
396  }
397  }
398  for (int n = 1; n < 4; n += 2) {
399  if (!(coef[n] > zero)) {
400  amrex::Abort(prefix + keys[n] + " must be positive (phi = (1 + a zeta)/(1 + b zeta))");
401  }
402  if (coef[n-1] <= coef[n]) {
403  amrex::Abort(prefix + keys[n-1] + " must exceed " + prefix + keys[n] +
404  " (phi > 1 on the stable side)");
405  }
406  }
407  sfuns.set_stable_functions(true, coef[0], coef[1], coef[2], coef[3]);
408  amrex::Print() << who << " stable-side similarity functions: qnse (a_m " << coef[0]
409  << ", b_m " << coef[1] << ", a_h " << coef[2] << ", b_h " << coef[3] << ")\n";
410  } else if (name == "businger_dyer") {
411  if (given) {
412  amrex::Abort(prefix + "qnse_am, qnse_bm, qnse_ah and qnse_bh belong to " + prefix +
413  "stable_functions = qnse");
414  }
415  } else {
416  amrex::Abort(prefix + "stable_functions must be businger_dyer or qnse, not " + name);
417  }
418  return sfuns;
419 }
420 
421 
422 /**
423  * Log-law bracket ln(zref/z0) - psi of the MOST flux kernels, held at or above
424  * most_bracket_floor(C).
425  *
426  * In strongly unstable air psi exceeds C = ln(zref/z0) and the bracket changes sign, which
427  * turns u* negative and puts the diagnosed surface temperature on the wrong side of the air
428  * for a prescribed flux. With the floor the bracket is at least 1/2, so u* stays positive and
429  * finite for every C.
430  *
431  * @param[in] C ln(zref/z0)
432  * @param[in] psi stability correction (momentum or heat)
433  */
434 AMREX_GPU_HOST_DEVICE
435 AMREX_FORCE_INLINE
436 amrex::Real
437 most_bracket (amrex::Real C, amrex::Real psi)
438 {
439  return amrex::max(C - psi, most_bracket_floor(C));
440 }
441 
442 /**
443  * Residual zeta - Rib (C - psi_m)^2 / (C - psi_h) of the prescribed-temperature kernels'
444  * z/L equation, with the Jimenez functions and the brackets of most_bracket.
445  *
446  * @param[in] sfuns similarity functions
447  * @param[in] C ln(zref/z0)
448  * @param[in] Rib bulk Richardson number
449  * @param[in] zeta z/L
450  */
451 AMREX_GPU_HOST_DEVICE
452 AMREX_FORCE_INLINE
453 amrex::Real
454 most_rib_resid (const similarity_funs& sfuns, amrex::Real C, amrex::Real Rib, amrex::Real zeta)
455 {
456  const amrex::Real CmPsim = most_bracket(C, sfuns.calc_psi_m2(zeta));
457  const amrex::Real CmPsih = most_bracket(C, sfuns.calc_psi_h2(zeta));
458  return zeta - Rib * CmPsim * CmPsim / CmPsih;
459 }
460 
461 /**
462  * Whether a root of most_rib_resid lies within delta of zeta.
463  *
464  * The relaxed fixed-point iteration stops on a small step, which a near-touch of the
465  * residual also gives where no root is near; the residual must change sign across
466  * [zeta - delta, zeta + delta] for zeta to be taken as a solution.
467  *
468  * @param[in] sfuns similarity functions
469  * @param[in] C ln(zref/z0)
470  * @param[in] Rib bulk Richardson number
471  * @param[in] zeta z/L the relaxed iteration stopped at
472  * @param[in] delta half-width of the interval checked
473  */
474 AMREX_GPU_HOST_DEVICE
475 AMREX_FORCE_INLINE
476 bool
477 most_rib_zeta_is_root (const similarity_funs& sfuns, amrex::Real C, amrex::Real Rib,
478  amrex::Real zeta, amrex::Real delta)
479 {
480  const amrex::Real rlo = most_rib_resid(sfuns, C, Rib, zeta - delta);
481  const amrex::Real rhi = most_rib_resid(sfuns, C, Rib, zeta + delta);
482  return (rlo > zero) != (rhi > zero) || rlo == zero || rhi == zero;
483 }
484 
485 /**
486  * Solve zeta = Rib (C - psi_m)^2 / (C - psi_h) of the prescribed-temperature kernels by
487  * bracketing and bisection, with the Jimenez functions and the brackets of most_bracket.
488  *
489  * The relaxed fixed-point iteration stalls where zeta - Rib F(zeta) nearly touches zero
490  * without crossing it, which the Jimenez stable functions produce when z0 is comparable to or
491  * above zref (C below about 1): each pass then moves zeta by about the tolerance. From zeta0
492  * this steps, with doubling steps, in the direction the iteration moves until the residual
493  * changes sign, and bisects that interval, so it returns the root the iteration was heading
494  * to, or the next one past a near-touch. The first step is limited so that two nearby roots
495  * are not stepped over together. The search stays within +-most_zeta_lim, and returns that
496  * bound when no root lies inside it, as the prescribed-flux kernels bound zeta.
497  *
498  * @param[in] sfuns similarity functions
499  * @param[in] C ln(zref/z0)
500  * @param[in] Rib bulk Richardson number
501  * @param[in] zeta0 z/L to start from
502  * @param[in] tol width of the final interval
503  */
504 AMREX_GPU_HOST_DEVICE
505 AMREX_FORCE_INLINE
506 amrex::Real
507 most_rib_zeta_bracketed (const similarity_funs& sfuns, amrex::Real C, amrex::Real Rib,
508  amrex::Real zeta0, amrex::Real tol)
509 {
510  auto resid = [&] (amrex::Real zeta) { return most_rib_resid(sfuns, C, Rib, zeta); };
511 
512  amrex::Real a = zeta0;
513  amrex::Real ra = resid(a);
514  if (ra == zero) { return a; }
515 
516  // A non-finite residual (a NaN or infinite C, Rib or zeta0) cannot be bracketed: with it the
517  // step below is NaN and the search never reaches zlim. Return it, so the bad input shows up
518  // in the caller's results rather than as a hang.
519  if (!amrex::Math::isfinite(ra)) { return ra; }
520 
521  // Step against the residual, within +-most_zeta_lim, until it changes sign
522  const amrex::Real dir = (ra > zero) ? amrex::Real(-1.0) : amrex::Real(1.0);
523  const amrex::Real zlim = dir * most_zeta_lim;
524  auto step = [&] (amrex::Real z, amrex::Real dz) {
525  return (dir > zero) ? amrex::min(z + dz, zlim) : amrex::max(z - dz, zlim);
526  };
527  amrex::Real h = amrex::max(amrex::min(std::abs(ra),
528  amrex::Real(0.1) * amrex::max(amrex::Real(one), std::abs(a))),
529  tol);
530  amrex::Real b = step(a, h);
531  amrex::Real rb = resid(b);
532  // With finite values the doubling step reaches zlim in well under 200 steps (from tol to
533  // 2 most_zeta_lim); the cap only guarantees that this loop ends
534  int nstep = 0;
535  while ((rb > zero) == (ra > zero) && b != zlim && nstep < 200) {
536  a = b;
537  ra = rb;
538  h *= two;
539  b = step(a, h);
540  rb = resid(b);
541  ++nstep;
542  }
543  // No root within the bound: hold zeta there
544  if ((rb > zero) == (ra > zero)) { return zlim; }
545 
546  // Bisect [a, b]
547  int n = 0;
548  while (std::abs(b - a) > tol && n < 60) {
549  const amrex::Real m = myhalf * (a + b);
550  const amrex::Real rm = resid(m);
551  if ((rm > zero) == (ra > zero)) {
552  a = m;
553  ra = rm;
554  } else {
555  b = m;
556  }
557  ++n;
558  }
559  return myhalf * (a + b);
560 }
561 
562 /**
563  * z/L of the prescribed-flux kernels, bounded below by -most_zeta_lim and above by the fold (see
564  * similarity_funs::calc_zeta_fold), where the prescribed stable flux stops having a solution.
565  *
566  * @param[in] zeta z/L from the current u* and flux
567  * @param[in] zeta_fold z/L at the fold
568  * @param[out] at_fold whether the fold bound was applied
569  */
570 AMREX_GPU_HOST_DEVICE
571 AMREX_FORCE_INLINE
572 amrex::Real
573 most_clamp_zeta (amrex::Real zeta, amrex::Real zeta_fold, bool& at_fold)
574 {
575  at_fold = (zeta >= zeta_fold);
576  return amrex::max(amrex::min(zeta, zeta_fold), -most_zeta_lim);
577 }
578 
579 /**
580  * Factors applied to the prescribed sensible and moisture fluxes at the stable fold.
581  */
583 {
584  amrex::Real temp{amrex::Real(1.0)}; ///< factor on surf_temp_flux
585  amrex::Real moist{amrex::Real(1.0)}; ///< factor on surf_moist_flux
586 };
587 
588 /**
589  * Part of a prescribed stable flux the wind can carry at the fold.
590  *
591  * The virtual heat flux is tflux_s + tflux_q, with tflux_s = surf_temp_flux (1 + epsv qv) and
592  * tflux_q = qflux epsv theta. When z/L is held at the fold (see
593  * similarity_funs::calc_zeta_fold), the wind is below the minimum the prescribed flux needs and
594  * carries only -u*^3 thv zeta_fold / (kappa g zref). Only the prescribed components that are
595  * downward drive the fold, so only they are reduced, by a common factor, until the net virtual
596  * flux equals that value. An upward component, or a moisture flux diagnosed from q_surf, is
597  * left unchanged; if no prescribed component is downward, nothing is reduced. The factor is
598  * not taken below 0, so when a diagnosed condensation flux alone is stronger than the fold
599  * value, the downward prescribed components are removed and the net flux remains stronger
600  * than the fold value. Returns 1 for both factors away from the fold.
601  *
602  * @param[in] at_fold whether z/L was held at the fold
603  * @param[in] zeta_fold z/L at the fold
604  * @param[in] ustar friction velocity
605  * @param[in] thv virtual potential temperature at zref
606  * @param[in] tflux_s sensible part of the virtual heat flux
607  * @param[in] tflux_q moisture part of the virtual heat flux
608  * @param[in] spec_qflux whether the moisture flux is prescribed
609  * @param[in] kappa von Karman constant
610  * @param[in] gravity gravitational acceleration
611  * @param[in] zref reference height
612  */
613 AMREX_GPU_HOST_DEVICE
614 AMREX_FORCE_INLINE
616 most_fold_flux_scale (bool at_fold, amrex::Real zeta_fold, amrex::Real ustar,
617  amrex::Real thv, amrex::Real tflux_s, amrex::Real tflux_q,
618  bool spec_qflux, amrex::Real kappa, amrex::Real gravity,
619  amrex::Real zref)
620 {
621  most_flux_scale scale;
622  const amrex::Real tflux = tflux_s + tflux_q;
623  if (!at_fold || tflux >= zero) { return scale; }
624  const amrex::Real tflux_fold = -ustar * ustar * ustar * thv * zeta_fold / (kappa * gravity * zref);
625  if (tflux_fold <= tflux) { return scale; }
626  const bool down_s = (tflux_s < zero);
627  const bool down_q = (spec_qflux && tflux_q < zero);
628  const amrex::Real down = (down_s ? tflux_s : zero) + (down_q ? tflux_q : zero);
629  if (down >= zero) { return scale; }
630  const amrex::Real r = amrex::max((down + tflux_fold - tflux) / down, amrex::Real(0.0));
631  if (down_s) { scale.temp = r; }
632  if (down_q) { scale.moist = r; }
633  return scale;
634 }
635 
636 /**
637  * Minimum friction velocity [m/s] of the prescribed-flux kernels' outputs (see most_flux_outputs).
638  */
639 inline constexpr amrex::Real most_min_ustar = amrex::Real(0.001);
640 
641 /**
642  * Surface state of a prescribed-flux kernel once its u* iteration has converged.
643  *
644  * Sets t_surf, t_star and q_star (and q_surf when the moisture flux is prescribed). At the
645  * fold the prescribed fluxes are reduced by most_fold_flux_scale and the Obukhov length is set
646  * to the fold value. u* is floored at most_min_ustar here, so every kernel applies the same floor.
647  *
648  * @param[in] mdata MOST data (prescribed fluxes, kappa, gravity)
649  * @param[in] spec_qflux whether the moisture flux is prescribed
650  * @param[in] at_fold whether z/L was held at the fold on the last pass
651  * @param[in] zeta_fold z/L at the fold
652  * @param[in] C ln(zref/z0)
653  * @param[in] psi_h heat stability correction of the last pass
654  * @param[in] ustar friction velocity (floored at most_min_ustar)
655  * @param[in] zref reference height
656  * @param[in] tm potential temperature at zref
657  * @param[in] tvm virtual potential temperature at zref
658  * @param[in] qvm water vapor at zref
659  * @param[in] qflux moisture flux of the last pass
660  * @param[inout] olen Obukhov length
661  * @param[out] t_surf surface potential temperature
662  * @param[out] t_star temperature scale
663  * @param[inout] q_surf surface water vapor (read when the moisture flux is diagnosed)
664  * @param[out] q_star moisture scale
665  */
666 AMREX_GPU_HOST_DEVICE
667 AMREX_FORCE_INLINE
668 void
669 most_flux_outputs (const most_data& mdata, bool spec_qflux, bool at_fold,
670  amrex::Real zeta_fold, amrex::Real C, amrex::Real psi_h,
671  amrex::Real ustar, amrex::Real zref, amrex::Real tm,
672  amrex::Real tvm, amrex::Real qvm, amrex::Real qflux,
673  amrex::Real& olen, amrex::Real& t_surf, amrex::Real& t_star,
674  amrex::Real& q_surf, amrex::Real& q_star)
675 {
676  ustar = amrex::max(ustar, amrex::Real(most_min_ustar));
677  const most_flux_scale scale = most_fold_flux_scale(at_fold, zeta_fold, ustar, tvm,
678  mdata.surf_temp_flux * (one + epsv * qvm),
679  qflux * epsv * tm, spec_qflux,
680  mdata.kappa, mdata.gravity, zref);
681  if (at_fold) { olen = zref / zeta_fold; }
682  const amrex::Real CmPsih = most_bracket(C, psi_h);
683  const amrex::Real hflux = scale.temp * mdata.surf_temp_flux;
684  t_surf = hflux * CmPsih / (ustar * mdata.kappa) + tm;
685  t_star = -hflux / ustar;
686  if (spec_qflux) {
687  const amrex::Real mflux = scale.moist * mdata.surf_moist_flux;
688  q_surf = mflux * CmPsih / (ustar * mdata.kappa) + qvm;
689  q_star = -mflux / ustar;
690  } else {
691  q_star = mdata.kappa * (qvm - q_surf) / CmPsih;
692  }
693 }
694 
695 /**
696  * Aitken delta-squared acceleration of the relaxed u* iteration in the prescribed-flux kernels.
697  *
698  * Near the stable fold the slope of the fixed-point map approaches 1 and the plain iteration
699  * needs hundreds of passes. From pass `start` on, every third iterate is replaced by the
700  * Aitken extrapolation of the last three (kept only within a factor of 2 of them), so points
701  * that converge before `start` are unchanged. The map is not stationary when w* or a
702  * u*-dependent z0 also changes from pass to pass, so the kernels do not stop on an
703  * extrapolated pass: the plain pass after it, with zeta and psi from the same u*, decides
704  * convergence.
705  */
707 {
708  /**
709  * Return the iterate to continue from.
710  *
711  * @param[in] u_new iterate after pass `iter`
712  * @param[in] iter number of passes done
713  */
714  AMREX_GPU_HOST_DEVICE
715  AMREX_FORCE_INLINE
716  amrex::Real
717  update (amrex::Real u_new, int iter)
718  {
719  extrapolated = false;
720  if (iter < start) { return u_new; }
721  u0 = u1;
722  u1 = u2;
723  u2 = u_new;
724  if (++n < 3) { return u_new; }
725  const amrex::Real d = u2 - two * u1 + u0;
726  const amrex::Real ua = (d != zero) ? u2 - (u2 - u1) * (u2 - u1) / d : u_new;
727  const amrex::Real lo = myhalf * amrex::min(u0, amrex::min(u1, u2));
728  const amrex::Real hi = two * amrex::max(u0, amrex::max(u1, u2));
729  if (d == zero || !(ua > lo && ua < hi)) {
730  n = 0;
731  return u_new;
732  }
733  // The extrapolated value starts the next triple
734  u2 = ua;
735  n = 1;
736  extrapolated = true;
737  return ua;
738  }
739 
740  int start{25};
741  bool extrapolated{false}; ///< whether the last update returned an extrapolated value
742  int n{0};
743  amrex::Real u0{zero};
744  amrex::Real u1{zero};
745  amrex::Real u2{zero};
746 };
747 
748 
749 /**
750  * Empirical kinematic viscosity [m2/s] formula from Andreas (1989) CRREL Rep.
751  * 89-11, valid between -173 and 277 deg C.
752  *
753  * @param[in] T_degK air temperature in Kelvin
754  */
755 AMREX_GPU_DEVICE
756 AMREX_FORCE_INLINE
757 amrex::Real
758 air_viscosity (amrex::Real T_degK)
759 {
760  amrex::Real TC = T_degK - amrex::Real(273.15);
761  return amrex::Real(1.326e-5)*(one + amrex::Real(6.542e-3)*TC + amrex::Real(8.301e-6)*TC*TC - amrex::Real(4.84e-9)*TC*TC*TC);
762 }
763 
764 /**
765  * Charnock roughness with optional aerodynamically-smooth contribution
766  *
767  * Smooth-flow limit follows z0 = 0.11 nu / u* (Smith 1988; ECMWF; WRF)
768  *
769  * @param[in] ustar friction velocity
770  * @param[in] cnk_a charnock constant
771  * @param[in] nu intrinsic fluid viscosity
772  * @param[in] visc flag to apply smooth flow limit
773  */
774 AMREX_GPU_DEVICE
775 AMREX_FORCE_INLINE
776 amrex::Real
778  amrex::Real Cnk_a,
779  amrex::Real nu,
780  bool visc)
781 {
782  amrex::Real z0 = (Cnk_a / CONST_GRAV) * ustar * ustar;
783  if (visc) {
784  z0 += amrex::Real(0.11) * nu / std::max(ustar, amrex::Real(0.01));
785  }
786  // From Davis et al 2008 MWR
787  return std::min(std::max(z0, amrex::Real(1.27e-7)), amrex::Real(2.85e-3));
788 }
789 
790 /**
791  * Modified Charnock roughness
792  *
793  * Smooth-flow limit is intrinsic.
794  *
795  * @param[in] ustar friction velocity
796  * @param[in] cnk_b modified charnock constant
797  */
798 AMREX_GPU_DEVICE
799 AMREX_FORCE_INLINE
800 amrex::Real
802  amrex::Real Cnk_b)
803 {
804  amrex::Real z0 = std::exp( (amrex::Real(2.7)*ustar - amrex::Real(1.8)/Cnk_b) / (ustar + amrex::Real(0.17)/Cnk_b) );
805  return std::min(std::max(z0, amrex::Real(1.27e-7)), amrex::Real(1.0e-2));
806 }
807 
808 /**
809  * COARE3.0, following WRF phys/module_sf_mynn.F
810  *
811  * Smooth-flow limit follows z0 = 0.11 nu / u* (Smith 1988; ECMWF; WRF)
812  *
813  * @param[in] zref reference height for the wind speed
814  * @param[in] umm horizontal wind speed magnitude at zref
815  * @param[in] ustar friction velocity
816  * @param[in] nu intrinsic fluid viscosity
817  * @param[in] visc flag to apply smooth flow limit
818  */
819 AMREX_GPU_DEVICE
820 AMREX_FORCE_INLINE
821 amrex::Real
822 COARE3_roughness (amrex::Real zref,
823  amrex::Real umm,
824  amrex::Real ustar,
825  amrex::Real nu,
826  bool visc)
827 {
828  amrex::Real ws10m = umm*std::log(amrex::Real(10.)/amrex::Real(1e-4)) / std::log(zref/amrex::Real(1e-4));
829  amrex::Real Czc = amrex::Real(0.011) + amrex::Real(0.007)*std::min(std::max((ws10m-amrex::Real(10.))/amrex::Real(8.), amrex::Real(0.0)), amrex::Real(1.0));
830  amrex::Real z0 = (Czc / CONST_GRAV) * ustar * ustar;
831  if (visc) {
832  z0 += amrex::Real(0.11) * nu / std::max(ustar, amrex::Real(0.01));
833  }
834  // From Davis et al 2008 MWR
835  return std::min(std::max(z0, amrex::Real(1.27e-7)), amrex::Real(2.85e-3));
836 }
837 
838 /**
839  * Updated Donelan 2004 as found in AHW
840  *
841  * Matches implementations in WRF phys/physics_mmm/sf_sfclayrev.F90 and
842  * phys/module_sf_mynn.F
843  *
844  * Smooth flow limit is intrinsic in zn2.
845  *
846  * @param[in] ustar friction velocity
847  * @param[in] nu intrinsic fluid viscosity
848  * @param[in] visc flag to apply smooth flow limit
849  */
850 AMREX_GPU_DEVICE
851 AMREX_FORCE_INLINE
852 amrex::Real
854  amrex::Real nu,
855  bool visc)
856 {
857  constexpr amrex::Real ozo{amrex::Real(1.59e-5)};
858  amrex::Real zw = std::min(std::pow(ustar/amrex::Real(1.06), amrex::Real(0.3)),amrex::Real(1.0));
859  amrex::Real zn1 = amrex::Real(0.011)*ustar*ustar/CONST_GRAV + ozo;
860  amrex::Real zn2 = amrex::Real(10.)*std::exp(-amrex::Real(9.5)*std::pow(ustar, -amrex::Real(.3333)));
861  if (visc) {
862  zn2 += amrex::Real(0.11) * nu / std::max(ustar, amrex::Real(0.01));
863  }
864  amrex::Real z0 = (amrex::Real(1.0)-zw) * zn1 + zw * zn2;
865  // From Davis et al 2008 MWR
866  return std::min(std::max(z0, amrex::Real(1.27e-7)), amrex::Real(2.85e-3));
867 }
868 
869 
870 /**
871  * Wave coupled roughness
872  *
873  * Smooth-flow limit follows z0 = 0.11 nu / u* (Smith 1988; ECMWF; WRF)
874  *
875  * @param[in] Hwave wave height
876  * @param[in] Lwave wave length
877  * @param[in] eps avoid divide by zero
878  * @param[in] ustar friction velocity
879  * @param[in] nu intrinsic fluid viscosity
880  * @param[in] visc flag to apply smooth flow limit
881  */
882 AMREX_GPU_DEVICE
883 AMREX_FORCE_INLINE
884 amrex::Real
885 WaveCoupled_roughness (amrex::Real Hwave,
886  amrex::Real Lwave,
887  amrex::Real eps,
888  amrex::Real ustar,
889  amrex::Real nu,
890  bool visc)
891 {
892 
893  amrex::Real z0 = amrex::Real(1200.0) * Hwave * std::pow( Hwave/(Lwave+eps), amrex::Real(4.5) );
894  if (visc) {
895  z0 += amrex::Real(0.11) * nu / std::max(ustar, amrex::Real(0.01));
896  }
897  return std::min(std::max(z0, amrex::Real(1.27e-7)), amrex::Real(1.0e-2));
898 }
899 
900 
901 /// Lower bound of the roughness recovered by Compute_roughness; shared with
902 /// the guard in Compute_roughness so the two cannot drift apart.
903 constexpr amrex::Real inverted_roughness_lo = amrex::Real(1.0e-7);
904 
905 /**
906  * Bounds on the roughness recovered by Compute_roughness. The inversion is
907  * unbounded above: in weak wind under strong stability (u* from an LSM or bulk
908  * flux large relative to kappa*U, psi_m << 0) it returns z0 >> zref. The
909  * upper bound is above every tabulated land-cover roughness in NoahmpTable.TBL
910  * (Z0MVT <= 1.10 m) and below the 2 m diagnostic height; z0 is also kept below
911  * half of zref so that ln(zref/z0) stays positive.
912  */
913 AMREX_GPU_HOST_DEVICE
914 AMREX_FORCE_INLINE
915 amrex::Real
916 bound_inverted_roughness (amrex::Real z0, amrex::Real zref) noexcept
917 {
918  const amrex::Real z0_lo = inverted_roughness_lo;
919  const amrex::Real z0_hi = amrex::min(amrex::Real(1.5), amrex::Real(0.5) * zref);
920  return amrex::min(amrex::max(z0, z0_lo), z0_hi);
921 }
922 
923 /**
924  * Invert log-law to get roughness
925  *
926  * @param[in] zref reference height for the wind speed
927  * @param[in] Olen Obukhov length
928  * @param[in] umm horizontal wind speed magnitude at zref
929  * @param[in] ustar friction velocity
930  */
931 AMREX_GPU_DEVICE
932 AMREX_FORCE_INLINE
933 amrex::Real
934 Compute_roughness (amrex::Real zref,
935  amrex::Real Olen,
936  amrex::Real umm,
937  amrex::Real ustar)
938 {
939  similarity_funs sfuns;
940  amrex::Real zeta = zref / Olen;
941  amrex::Real psi_m = sfuns.calc_psi_m2(zeta);
942  // z0 = zref / exp(arg) is below the lower bound once arg > log(zref / z0_lo),
943  // so the bound is returned without evaluating exp(arg), which overflows when
944  // u* sits at its floor of machine epsilon (zero stress: bulk_coeff with
945  // Cd = 0, or an LSM that returns none). At or below the threshold exp(arg)
946  // is finite and the inversion runs as before, so no other input changes.
947  const amrex::Real arg = KAPPA*umm/ustar + psi_m;
948  if (arg > std::log(zref / inverted_roughness_lo)) {
950  }
951  amrex::Real z0 = zref / std::exp(arg);
952  return bound_inverted_roughness(z0, zref);
953 }
954 #endif
constexpr amrex::Real epsv
Definition: ERF_Constants.H:56
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
ParmParse pp("prob")
constexpr amrex::Real most_min_ustar
Definition: ERF_MOSTUtils.H:639
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real WaveCoupled_roughness(amrex::Real Hwave, amrex::Real Lwave, amrex::Real eps, amrex::Real ustar, amrex::Real nu, bool visc)
Definition: ERF_MOSTUtils.H:885
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_rib_zeta_bracketed(const similarity_funs &sfuns, amrex::Real C, amrex::Real Rib, amrex::Real zeta0, amrex::Real tol)
Definition: ERF_MOSTUtils.H:507
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_bracket_floor(amrex::Real C)
Definition: ERF_MOSTUtils.H:61
constexpr amrex::Real inverted_roughness_lo
Definition: ERF_MOSTUtils.H:903
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE most_flux_scale most_fold_flux_scale(bool at_fold, amrex::Real zeta_fold, amrex::Real ustar, amrex::Real thv, amrex::Real tflux_s, amrex::Real tflux_q, bool spec_qflux, amrex::Real kappa, amrex::Real gravity, amrex::Real zref)
Definition: ERF_MOSTUtils.H:616
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_bracket(amrex::Real C, amrex::Real psi)
Definition: ERF_MOSTUtils.H:437
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real bound_inverted_roughness(amrex::Real z0, amrex::Real zref) noexcept
Definition: ERF_MOSTUtils.H:916
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real COARE3_roughness(amrex::Real zref, amrex::Real umm, amrex::Real ustar, amrex::Real nu, bool visc)
Definition: ERF_MOSTUtils.H:822
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_roughness(amrex::Real zref, amrex::Real Olen, amrex::Real umm, amrex::Real ustar)
Definition: ERF_MOSTUtils.H:934
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Mod_Charnock_roughness(amrex::Real ustar, amrex::Real Cnk_b)
Definition: ERF_MOSTUtils.H:801
constexpr amrex::Real most_zeta_lim
Definition: ERF_MOSTUtils.H:71
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_rib_resid(const similarity_funs &sfuns, amrex::Real C, amrex::Real Rib, amrex::Real zeta)
Definition: ERF_MOSTUtils.H:454
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void most_flux_outputs(const most_data &mdata, bool spec_qflux, bool at_fold, amrex::Real zeta_fold, amrex::Real C, amrex::Real psi_h, amrex::Real ustar, amrex::Real zref, amrex::Real tm, amrex::Real tvm, amrex::Real qvm, amrex::Real qflux, amrex::Real &olen, amrex::Real &t_surf, amrex::Real &t_star, amrex::Real &q_surf, amrex::Real &q_star)
Definition: ERF_MOSTUtils.H:669
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real air_viscosity(amrex::Real T_degK)
Definition: ERF_MOSTUtils.H:758
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool most_rib_zeta_is_root(const similarity_funs &sfuns, amrex::Real C, amrex::Real Rib, amrex::Real zeta, amrex::Real delta)
Definition: ERF_MOSTUtils.H:477
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real most_clamp_zeta(amrex::Real zeta, amrex::Real zeta_fold, bool &at_fold)
Definition: ERF_MOSTUtils.H:573
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Donelan_roughness(amrex::Real ustar, amrex::Real nu, bool visc)
Definition: ERF_MOSTUtils.H:853
similarity_funs read_most_similarity_funs(amrex::ParmParse &pp, const std::string &who="Surface layer")
Definition: ERF_MOSTUtils.H:379
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Charnock_roughness(amrex::Real ustar, amrex::Real Cnk_a, amrex::Real nu, bool visc)
Definition: ERF_MOSTUtils.H:777
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
constexpr amrex::Real PIoTwo
Definition: ERF_NumericalConstants.H:47
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:139
@ olen
Definition: ERF_SLM.H:106
@ ustar
Definition: ERF_SLM.H:30
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
@ rhi
Definition: ERF_WSM6.H:362
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real eps()
Definition: ERF_ShocMoments.cpp:19
Definition: ERF_MOSTUtils.H:707
amrex::Real u2
Definition: ERF_MOSTUtils.H:745
int start
Definition: ERF_MOSTUtils.H:740
bool extrapolated
whether the last update returned an extrapolated value
Definition: ERF_MOSTUtils.H:741
int n
Definition: ERF_MOSTUtils.H:742
amrex::Real u0
Definition: ERF_MOSTUtils.H:743
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real update(amrex::Real u_new, int iter)
Definition: ERF_MOSTUtils.H:717
amrex::Real u1
Definition: ERF_MOSTUtils.H:744
Definition: ERF_MOSTUtils.H:16
amrex::Real surf_moist_flux
Moisture flux.
Definition: ERF_MOSTUtils.H:22
amrex::Real Cnk_b2
Modified Charnock Eq (4) https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137....
Definition: ERF_MOSTUtils.H:26
amrex::Real Cnk_b
Modified Charnock derived quantity.
Definition: ERF_MOSTUtils.H:28
amrex::Real Ch
Definition: ERF_MOSTUtils.H:32
amrex::Real Cnk_d
Modified Charnock Eq (4) https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137....
Definition: ERF_MOSTUtils.H:27
amrex::Real kappa
von Karman constant
Definition: ERF_MOSTUtils.H:19
amrex::Real gravity
Acceleration due to gravity (m/s^2)
Definition: ERF_MOSTUtils.H:20
amrex::Real Cnk_a
Standard Charnock constant https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137....
Definition: ERF_MOSTUtils.H:24
amrex::Real Cd
Definition: ERF_MOSTUtils.H:31
amrex::Real Cq
Definition: ERF_MOSTUtils.H:33
const amrex::Real Bjr_beta
Definition: ERF_MOSTUtils.H:35
amrex::Real Cnk_b1
Modified Charnock Eq (4) https://doi.org/amrex::Real(10.1175)/JAMC-D-17-amrex::Real(0137....
Definition: ERF_MOSTUtils.H:25
amrex::Real z0_const
Roughness height – default constant value(m)
Definition: ERF_MOSTUtils.H:18
bool visc
Use viscous Charnock formulation.
Definition: ERF_MOSTUtils.H:29
amrex::Real surf_temp_flux
Heat flux TODO: decide whether this is <θ'w'> or <θv'w'> under moist conditions.
Definition: ERF_MOSTUtils.H:21
Definition: ERF_MOSTUtils.H:583
amrex::Real temp
factor on surf_temp_flux
Definition: ERF_MOSTUtils.H:584
amrex::Real moist
factor on surf_moist_flux
Definition: ERF_MOSTUtils.H:585
Definition: ERF_MOSTUtils.H:84
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_phi_h(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:219
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_m(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:149
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real qnse_psi(amrex::Real zeta, amrex::Real a, amrex::Real b)
Definition: ERF_MOSTUtils.H:341
amrex::Real beta_m
Constants from Dyer, BLM, 1974.
Definition: ERF_MOSTUtils.H:355
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_h2(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:121
amrex::Real beta_h
https://doi.org/amrex::Real(10.1007)/BF00240838
Definition: ERF_MOSTUtils.H:356
amrex::Real m_qnse_bm
QNSE b_m.
Definition: ERF_MOSTUtils.H:361
amrex::Real m_qnse_bh
QNSE b_h.
Definition: ERF_MOSTUtils.H:363
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real qnse_phi(amrex::Real zeta, amrex::Real a, amrex::Real b)
Definition: ERF_MOSTUtils.H:350
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_zeta_fold(amrex::Real C) const
Definition: ERF_MOSTUtils.H:265
amrex::Real gamma_h
Definition: ERF_MOSTUtils.H:358
amrex::Real m_qnse_am
QNSE a_m (Sukoriansky et al. 2005)
Definition: ERF_MOSTUtils.H:360
AMREX_GPU_HOST_DEVICE void set_stable_functions(bool use_qnse, amrex::Real am, amrex::Real bm, amrex::Real ah, amrex::Real bh)
Definition: ERF_MOSTUtils.H:322
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_h(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:168
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_phi_m(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:199
AMREX_GPU_HOST_DEVICE bool uses_qnse() const
Definition: ERF_MOSTUtils.H:334
amrex::Real gamma_m
Definition: ERF_MOSTUtils.H:357
amrex::Real m_qnse_ah
QNSE a_h.
Definition: ERF_MOSTUtils.H:362
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real calc_psi_m2(amrex::Real zeta) const
Definition: ERF_MOSTUtils.H:96
bool m_qnse
stable side QNSE instead of Businger-Dyer
Definition: ERF_MOSTUtils.H:359