1 #ifndef ERF_PBL_HEIGHT_H_
2 #define ERF_PBL_HEIGHT_H_
4 #include <AMReX_MultiFabUtil.H>
27 const amrex::MultiFab* z_phys_cc,
28 amrex::MultiFab* pblh,
29 const amrex::MultiFab&
cons,
30 const amrex::iMultiFab* lmask,
37 auto const& cons_arrs =
cons.const_arrays();
38 auto thetav_min = amrex::ReduceToPlane<amrex::ReduceOpMin,amrex::Real>(dir, bxlow,
cons,
39 [=] AMREX_GPU_DEVICE (
int box_no,
int i,
int j,
int k) -> amrex::Real
41 return GetThetav(i,j,k,cons_arrs[box_no],moisture_indices);
46 auto const& ba = pblh->boxArray();
47 auto const& dm = pblh->DistributionMap();
48 auto const&
ng = pblh->nGrowVect();
50 amrex::MultiFab min_thetav(ba,dm,1,
ng);
53 amrex::MultiFab max_tke(ba,dm,1,
ng);
56 amrex::MultiFab pblh_tke(ba,dm,1,
ng);
57 pblh_tke.setVal(
zero);
66 "MYNNPBLH::compute_pblh: the state must carry a ghost cell in z; the scan reads "
67 "one cell above the top of every box");
69 "MYNNPBLH::compute_pblh: z_phys_cc must carry a ghost cell in z; the scan reads "
70 "one cell above the top of every box");
73 for (amrex::MFIter mfi(
cons,
TileNoZ()); mfi.isValid(); ++mfi)
75 const amrex::Box& domain = geom.Domain();
88 const amrex::Box& vbx = mfi.validbox();
90 "MYNNPBLH::compute_pblh: every box must start at the bottom of the domain");
91 amrex::Box gtbx = mfi.growntilebox(
ng);
92 gtbx.setSmall(2,vbx.smallEnd(2));
93 gtbx.setBig(2,vbx.bigEnd(2));
100 amrex::Box gtbx2d = gtbx; gtbx2d.setRange(2,0);
101 const int klo = gtbx.smallEnd(2);
102 const int khi = gtbx.bigEnd(2);
104 auto min_thv_arr = min_thetav.array(mfi);
105 auto max_tke_arr = max_tke.array(mfi);
106 auto pblh_arr = pblh->array(mfi);
107 auto pblh_tke_arr = pblh_tke.array(mfi);
109 const auto cons_arr =
cons.const_array(mfi);
110 const auto lmask_arr = (lmask) ? lmask->const_array(mfi) : amrex::Array4<int> {};
117 const auto zphys_arr = z_phys_cc->const_array(mfi);
120 int imin = lbound(zphys_arr).x;
121 int jmin = lbound(zphys_arr).y;
122 int imax = ubound(zphys_arr).x;
123 int jmax = ubound(zphys_arr).y;
130 ParallelFor(gtbx2d, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
132 int ii = amrex::max(amrex::min(i,imax),imin);
133 int jj = amrex::max(amrex::min(j,jmax),jmin);
134 const amrex::Real z_sfc =
myhalf * (zphys_arr(ii,jj,
klo) + zphys_arr(ii,jj,
klo-1));
136 amrex::Real min_thv = min_thv_arr(i,j,0);
137 amrex::Real maxtke = max_tke_arr(i,j,0);
138 for (
int k(
klo); k <=
khi; ++k) {
140 amrex::Real thv =
GetThetav(i, j, k, cons_arr, moisture_indices);
141 min_thv = amrex::min(min_thv, thv);
145 min_thv_arr(i,j,0) = min_thv;
146 max_tke_arr(i,j,0) = maxtke;
150 ParallelFor(gtbx2d, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
152 int ii = amrex::max(amrex::min(i,imax),imin);
153 int jj = amrex::max(amrex::min(j,jmax),jmin);
154 const amrex::Real z_sfc =
myhalf * (zphys_arr(ii,jj,
klo) + zphys_arr(ii,jj,
klo-1));
156 const amrex::Real min_thv = min_thv_arr(i,j,0);
157 const int is_land = (lmask_arr) ? lmask_arr(i,j,0) : 1;
159 amrex::Real
zi = pblh_arr(i,j,0);
160 amrex::Real zi_tke = pblh_tke_arr(i,j,0);
162 const amrex::Real TKEeps =
tke_threshold(max_tke_arr(i,j,0));
164 for (
int k(
klo); k <=
khi; ++k)
171 amrex::Real thv =
GetThetav(i, j, k , cons_arr, moisture_indices);
172 amrex::Real thv1 =
GetThetav(i, j, k+1, cons_arr, moisture_indices);
178 zi = zphys_arr(ii,jj,k) - z_sfc
179 + (zphys_arr(ii,jj,k+1)-zphys_arr(ii,jj,k))/(thv1-thv)
186 zi = zphys_arr(ii,jj,k) - z_sfc
187 + (zphys_arr(ii,jj,k+1)-zphys_arr(ii,jj,k))/(thv1-thv)
199 if ((tke1 <= TKEeps) && (tke > TKEeps))
202 zi_tke = zphys_arr(ii,jj,k) - z_sfc
203 + (zphys_arr(ii,jj,k+1)-zphys_arr(ii,jj,k))/(tke1-tke)
208 if ((
zi != 0) && (zi_tke != 0)) {
break; }
211 pblh_arr(i,j,0) =
zi;
212 pblh_tke_arr(i,j,0) = zi_tke;
220 const amrex::Real dz_no_terrain = geom.CellSize(2);
228 const int khi_low = amrex::min(amrex::max(kmax,
klo),
khi);
230 ParallelFor(gtbx2d, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
232 amrex::Real min_thv = min_thv_arr(i,j,0);
233 amrex::Real maxtke = max_tke_arr(i,j,0);
234 for (
int k(
klo); k <= khi_low; ++k) {
235 amrex::Real thv =
GetThetav(i, j, k, cons_arr, moisture_indices);
236 min_thv = amrex::min(min_thv, thv);
239 min_thv_arr(i,j,0) = min_thv;
240 max_tke_arr(i,j,0) = maxtke;
244 ParallelFor(gtbx2d, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
246 const amrex::Real min_thv = min_thv_arr(i,j,0);
247 const int is_land = (lmask_arr) ? lmask_arr(i,j,0) : 1;
249 amrex::Real
zi = pblh_arr(i,j,0);
250 amrex::Real zi_tke = pblh_tke_arr(i,j,0);
252 const amrex::Real TKEeps =
tke_threshold(max_tke_arr(i,j,0));
254 for (
int k(
klo); k <=
khi; ++k)
261 amrex::Real thv =
GetThetav(i, j, k , cons_arr, moisture_indices);
262 amrex::Real thv1 =
GetThetav(i, j, k+1, cons_arr, moisture_indices);
269 + dz_no_terrain/(thv1-thv)
277 + dz_no_terrain/(thv1-thv)
289 if ((tke1 <= TKEeps) && (tke > TKEeps))
292 zi_tke = (k+
myhalf)*dz_no_terrain
293 + dz_no_terrain/(tke1-tke) * (TKEeps - tke);
297 if ((
zi != 0) && (zi_tke != 0)) {
break; }
300 pblh_arr(i,j,0) =
zi;
301 pblh_tke_arr(i,j,0) = zi_tke;
309 for (amrex::MFIter mfi(*pblh); mfi.isValid(); ++mfi)
311 const auto cons_arr =
cons.const_array(mfi);
312 auto pblh_tke_arr = pblh_tke.array(mfi);
313 auto pblh_arr = pblh->array(mfi);
315 amrex::Box gtbx = mfi.growntilebox();
316 ParallelFor(gtbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
327 amrex::Real
zi = pblh_arr(i,j,0);
328 pblh_tke_arr(i,j,0) = amrex::max(
329 amrex::min(pblh_tke_arr(i,j,0),
zi+amrex::Real(350.)),
330 amrex::max(
zi-amrex::Real(350.), amrex::Real(10.)));
338 if (qke_sfc > amrex::Real(0.05)) {
340 pblh_arr(i,j,0) = (
one-wt)*pblh_tke_arr(i,j,0) + wt*pblh_arr(i,j,0);
352 AMREX_GPU_HOST_DEVICE
356 return amrex::max(amrex::Real(0.05) * maxtke, amrex::Real(0.02));
374 static constexpr amrex::Real
sbl_lim = amrex::Real(200.0);
375 static constexpr amrex::Real
sbl_damp = amrex::Real(400.0);
constexpr amrex::Real bogus_large_value
Definition: ERF_Constants.H:19
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
const int klo
Definition: ERF_InitCustomPert_KE.H:9
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetav(const int &i, const int &j, const int &k, const amrex::Array4< amrex::Real const > &cell_data, const MoistureComponentIndices &moisture_indices)
Definition: ERF_MoistUtils.H:93
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ ng
Definition: ERF_Morrison.H:51
@ cons
Definition: ERF_IndexDefines.H:231
@ zi
Definition: ERF_AdvanceWDM6.cpp:277
Diagnostic utility for the planetary boundary layer height.
Definition: ERF_PBLHeight.H:12
static constexpr amrex::Real sbl_lim
Upper limit of the stable boundary layer height [m].
Definition: ERF_PBLHeight.H:374
AMREX_GPU_HOST AMREX_FORCE_INLINE void compute_pblh(const amrex::Geometry &geom, const amrex::MultiFab *z_phys_cc, amrex::MultiFab *pblh, const amrex::MultiFab &cons, const amrex::iMultiFab *lmask, const MoistureComponentIndices &moisture_indices) const
Definition: ERF_PBLHeight.H:26
static constexpr amrex::Real sbl_damp
Transition length for blending [m].
Definition: ERF_PBLHeight.H:375
static constexpr amrex::Real theta_incr_water
Theta increase determining the capping inversion height over water [K].
Definition: ERF_PBLHeight.H:373
static constexpr amrex::Real thetamin_height
Height below which minimum theta-v and maximum TKE are determined [m].
Definition: ERF_PBLHeight.H:371
static constexpr amrex::Real theta_incr_land
Theta increase determining the capping inversion height over land [K].
Definition: ERF_PBLHeight.H:372
AMREX_GPU_HOST_DEVICE static AMREX_FORCE_INLINE amrex::Real tke_threshold(const amrex::Real maxtke) noexcept
Definition: ERF_PBLHeight.H:354
The moisture data carried by the active microphysics scheme.
Definition: ERF_DataStruct.H:279