ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_PBLRibCrossing.H
Go to the documentation of this file.
1 #ifndef ERF_PBL_RIB_CROSSING_H_
2 #define ERF_PBL_RIB_CROSSING_H_
3 
4 #include <AMReX_REAL.H>
5 #include <AMReX_GpuQualifiers.H>
6 #include <AMReX_Algorithm.H>
7 
8 /**
9  * Result of a bulk Richardson number scan up one column.
10  */
11 struct RibCrossing {
12  int kpbl; //!< level where Rib first reaches Ribcr; khi when it never does
13  amrex::Real pblh; //!< PBL height, kept in [pblh_min, pblh_max]
14  bool crossed; //!< Rib reached Ribcr at or below khi
15 };
16 
17 /**
18  * Lower bound of the YSU and MRF PBL heights: the top face of the column's
19  * first fluid cell, and at least 10 m.
20  *
21  * The top face of the first cell is WRF's zq(i,2) (bl_ysu.F90; ZQ(I,KL) in
22  * module_bl_mrf.F), the height below which WRF sets its PBL index to the
23  * first level. It lies half a cell above zl1, the first level of the K
24  * profile, so the profile's depth pblh - zl1 stays positive. In YSU, with
25  * pblh at the floor the profile is zero at that face, and the first cell
26  * keeps the background diffusivity. The same expression is used on every
27  * mesh type. With erf.pbl_ib_aware the two schemes pass zl1 in their own
28  * frame: YSU from the domain bottom, MRF from the top of the immersed column.
29  *
30  * @param[in] zl1 height of the center of the column's first fluid cell
31  * @param[in] dz1 thickness of that cell
32  */
33 AMREX_GPU_HOST_DEVICE
34 AMREX_FORCE_INLINE
35 amrex::Real
36 pblh_floor (amrex::Real zl1, amrex::Real dz1) noexcept
37 {
38  return amrex::max(zl1 + amrex::Real(0.5) * dz1, amrex::Real(10.0));
39 }
40 
41 /**
42  * Find the PBL height where the bulk Richardson number first reaches Ribcr,
43  * scanning one column from its surface cell ksrf up to the top cell khi
44  * (YSU, Hong et al. 2006; WRF bl_ysu.F90, the "brint" interpolation).
45  *
46  * - The scan looks for the first level k in (ksrf, khi] with Rib >= Ribcr.
47  * The surface value Rib(ksrf) only seeds the lower end of the first
48  * interval, as WRF's br does: a surface cell above Ribcr does not stop the
49  * scan by itself.
50  * - If Rib(ksrf) and Rib(ksrf+1) are both at or above Ribcr, the height is
51  * z(ksrf) and kpbl = ksrf (WRF: brint = 0); with the bounds below this is
52  * pblh_min.
53  * - Otherwise the height is interpolated linearly in Rib between k-1, the last
54  * level below Ribcr, and k. The two levels bracket Ribcr, so the Rib
55  * difference is positive.
56  * - No crossing up to khi: the height is the top of the scan, z(khi), and
57  * kpbl = khi (WRF: brint = 1). The pblh_max cap then applies.
58  *
59  * Every height is then kept in [pblh_min, pblh_max] in that order, so
60  * pblh_min wins when a shallow column has pblh_max < pblh_min.
61  *
62  * @param[in] ksrf first fluid cell of the column
63  * @param[in] khi top cell of the scan
64  * @param[in] Ribcr critical bulk Richardson number
65  * @param[in] rib_at callable, rib_at(k) gives the bulk Richardson number at level k
66  * @param[in] z_at callable, z_at(k) gives the height of level k
67  * @param[in] pblh_min lower bound on the height
68  * @param[in] pblh_max upper bound on the height
69  */
70 template <typename RibAt, typename ZAt>
71 AMREX_GPU_HOST_DEVICE
72 AMREX_FORCE_INLINE
74 find_rib_crossing (int ksrf, int khi, amrex::Real Ribcr,
75  RibAt const& rib_at, ZAt const& z_at,
76  amrex::Real pblh_min, amrex::Real pblh_max) noexcept
77 {
78  amrex::Real rib_lo = rib_at(ksrf);
79  amrex::Real z_lo = z_at(ksrf);
80  for (int k = ksrf + 1; k <= khi; ++k) {
81  const amrex::Real rib_k = rib_at(k);
82  const amrex::Real z_k = z_at(k);
83  if (rib_k >= Ribcr) {
84  if (rib_lo >= Ribcr) {
85  // only possible for k = ksrf + 1: both surface levels at or above Ribcr
86  return RibCrossing{ksrf, amrex::max(amrex::min(z_lo, pblh_max), pblh_min), true};
87  }
88  const amrex::Real pblh = z_lo + (z_k - z_lo) / (rib_k - rib_lo) * (Ribcr - rib_lo);
89  return RibCrossing{k, amrex::max(amrex::min(pblh, pblh_max), pblh_min), true};
90  }
91  rib_lo = rib_k;
92  z_lo = z_k;
93  }
94  return RibCrossing{khi, amrex::max(amrex::min(z_lo, pblh_max), pblh_min), false};
95 }
96 
97 #endif
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE RibCrossing find_rib_crossing(int ksrf, int khi, amrex::Real Ribcr, RibAt const &rib_at, ZAt const &z_at, amrex::Real pblh_min, amrex::Real pblh_max) noexcept
Definition: ERF_PBLRibCrossing.H:74
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pblh_floor(amrex::Real zl1, amrex::Real dz1) noexcept
Definition: ERF_PBLRibCrossing.H:36
Definition: ERF_PBLRibCrossing.H:11
amrex::Real pblh
PBL height, kept in [pblh_min, pblh_max].
Definition: ERF_PBLRibCrossing.H:13
int kpbl
level where Rib first reaches Ribcr; khi when it never does
Definition: ERF_PBLRibCrossing.H:12
bool crossed
Rib reached Ribcr at or below khi.
Definition: ERF_PBLRibCrossing.H:14