Compute vertical diffusivity using the Medium-Range Forecast (MRF) boundary layer scheme.
210 int klo = geom.Domain().smallEnd(2);
211 int khi = geom.Domain().bigEnd(2);
216 MultiFab pblh_mf(eddyViscosity.boxArray(), eddyViscosity.DistributionMap(), 1, 0);
230 const auto widen_sfc = [&] (
const MultiFab* mf) -> std::unique_ptr<MultiFab> {
231 if (mf ==
nullptr || std::min(mf->nGrowVect()[0], mf->nGrowVect()[1]) >= ng_pblh) {
235 [&] (MultiFab& wide) { SurfLayer->fill_planar_boundary(level, wide); });
237 const std::unique_ptr<MultiFab> u_star_wide = widen_sfc(SurfLayer->get_u_star(level));
238 const std::unique_ptr<MultiFab> t_star_wide = widen_sfc(SurfLayer->get_t_star(level));
239 const std::unique_ptr<MultiFab> q_star_wide = widen_sfc(SurfLayer->get_q_star(level));
240 const std::unique_ptr<MultiFab> olen_wide = widen_sfc(SurfLayer->get_olen(level));
241 const MultiFab* u_star_src = (u_star_wide) ? u_star_wide.get() : SurfLayer->get_u_star(level);
242 const MultiFab* t_star_src = (t_star_wide) ? t_star_wide.get() : SurfLayer->get_t_star(level);
243 const MultiFab* q_star_src = (q_star_wide) ? q_star_wide.get() : SurfLayer->get_q_star(level);
244 const MultiFab* olen_src = (olen_wide) ? olen_wide.get() : SurfLayer->get_olen(level);
247 int ng_avail = std::min({cons_in.nGrowVect()[0], cons_in.nGrowVect()[1],
248 xvel.nGrowVect()[0],
xvel.nGrowVect()[1],
249 yvel.nGrowVect()[0],
yvel.nGrowVect()[1],
250 u_star_src->nGrowVect()[0], u_star_src->nGrowVect()[1],
251 olen_src->nGrowVect()[0], olen_src->nGrowVect()[1],
252 (terrain_blank) ? terrain_blank->nGrowVect()[0] : 1000,
253 (terrain_blank) ? terrain_blank->nGrowVect()[1] : 1000});
256 auto limit_by = [&ng_avail] (
const auto* mf) {
257 if (mf) { ng_avail = std::min({ng_avail, mf->nGrowVect()[0], mf->nGrowVect()[1]}); }
259 limit_by(t_star_src);
260 limit_by(q_star_src);
261 limit_by(SurfLayer->get_mac_avg(level, 3));
262 limit_by(SurfLayer->get_mac_avg(level, 4));
263 limit_by(SurfLayer->get_lmask(level));
264 limit_by((use_terrain_fitted_coords) ? z_phys_nd.get() :
nullptr);
265 if (ng_pblh > ng_avail) {
267 +
" needs " + std::to_string(ng_pblh) +
" halo columns, but the fields the "
268 "PBLH passes read carry only " + std::to_string(ng_avail)
269 +
"; reduce erf.pblh_smoothing_passes to at most " + std::to_string(ng_avail));
274 #pragma omp parallel if (Gpu::notInLaunchRegion())
277 for (MFIter mfi(eddyViscosity,
TileNoZ()); mfi.isValid(); ++mfi) {
280 const Box& gbx = mfi.growntilebox(IntVect(1,1,0));
282 gbx.bigEnd(2) ==
khi );
285 const GeometryData gdata = geom.data();
286 const Box xybx = PerpendicularBox<ZDir>(gbx, IntVect{0, 0, 0});
296 ? amrex::grow(mfi.tilebox(), IntVect(ng_pblh,ng_pblh,0)) : gbx;
297 const Box xybx_work = PerpendicularBox<ZDir>(gbx_work, IntVect{0, 0, 0});
298 const Box xybx_tile = PerpendicularBox<ZDir>(mfi.tilebox(), IntVect{0, 0, 0});
305 FArrayBox pbl_height_predictor(xybx_work, 1, The_Async_Arena());
306 FArrayBox pbl_height_corrector(xybx_work, 1, The_Async_Arena());
307 IArrayBox pbl_index(xybx_work, 1, The_Async_Arena());
308 IArrayBox pbl_index_zero_ri(xybx_work, 1, The_Async_Arena());
309 FArrayBox hgamt_fab(xybx_work, 1, The_Async_Arena());
310 FArrayBox hgamq_fab(xybx_work, 1, The_Async_Arena());
311 FArrayBox wstar_fab(xybx_work, 1, The_Async_Arena());
312 FArrayBox vpert_fab(xybx_work, 1, The_Async_Arena());
313 FArrayBox pblh_floor_fab(xybx_work, 1, The_Async_Arena());
314 const auto& pblh_pred_arr = pbl_height_predictor.array();
315 const auto& pblh_corr_arr = pbl_height_corrector.array();
316 const auto& pblh_floor_arr = pblh_floor_fab.array();
317 const auto& pbli_arr = pbl_index.array();
318 const auto& pbli_zero_arr = pbl_index_zero_ri.array();
319 const auto& hgamt_arr = hgamt_fab.array();
320 const auto& hgamq_arr = hgamq_fab.array();
321 const auto& wstar_arr = wstar_fab.array();
322 const auto& vpert_arr = vpert_fab.array();
325 const auto& cell_data = cons_in.const_array(mfi);
326 const auto& uvel =
xvel.const_array(mfi);
327 const auto& vvel =
yvel.const_array(mfi);
330 const auto& u_star_arr = u_star_src->const_array(mfi);
331 const auto& t_star_arr = t_star_src->const_array(mfi);
332 const auto& l_obuk_arr = olen_src->const_array(mfi);
333 const auto& t10av_arr = SurfLayer->get_mac_avg(level, 3)->const_array(mfi);
334 const auto& q10av_arr = SurfLayer->get_mac_avg(level, 4)->const_array(mfi);
335 const auto& lmask_arr = (SurfLayer->get_lmask(level)) ?
336 SurfLayer->get_lmask(level)->const_array(mfi) :
339 const Array4<Real const> z_nd_arr = use_terrain_fitted_coords ? z_phys_nd->array(mfi)
340 : Array4<Real const>{};
351 const amrex::MultiFab* q_star_mf = q_star_src;
352 Array4<Real const> q_star_arr = (q_star_mf !=
nullptr) ? q_star_mf->const_array(mfi)
353 : Array4<Real const>{};
366 const bool l_ib = turbChoice.
pbl_ib_aware && (terrain_blank !=
nullptr);
368 "erf.pbl_ib_aware is not supported with terrain-fitted coordinates");
369 const Array4<Real const> blank_arr = l_ib ? terrain_blank->const_array(mfi) : Array4<Real const>{};
370 IArrayBox ksurf_fab(xybx_work, 1, The_Async_Arena());
371 FArrayBox zib_fab(xybx_work, 1, The_Async_Arena());
372 FArrayBox us_eff_fab(xybx_work, 1, The_Async_Arena()), ts_eff_fab(xybx_work, 1, The_Async_Arena());
373 FArrayBox qs_eff_fab(xybx_work, 1, The_Async_Arena()), ol_eff_fab(xybx_work, 1, The_Async_Arena());
374 FArrayBox t10_eff_fab(xybx_work, 1, The_Async_Arena()), q10_eff_fab(xybx_work, 1, The_Async_Arena());
375 const auto& ksurf_arr = ksurf_fab.array();
376 const auto& zib_arr = zib_fab.array();
377 const auto& us_eff_arr = us_eff_fab.array();
const auto& ts_eff_arr = ts_eff_fab.array();
378 const auto& qs_eff_arr = qs_eff_fab.array();
const auto& ol_eff_arr = ol_eff_fab.array();
379 const auto& t10_eff_arr = t10_eff_fab.array();
const auto& q10_eff_arr = q10_eff_fab.array();
381 const Real dz_ib = geom.CellSize(2);
383 const Array4<Real const>& uv_ib =
xvel.const_array(mfi);
384 const Array4<Real const>& vv_ib =
yvel.const_array(mfi);
385 const bool have_qstar = (q_star_mf !=
nullptr);
386 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
390 for (
int kk =
klo; kk <=
khi; ++kk) {
if (blank_arr(i, j, kk) >=
Real(0.5)) {
ks = kk + 1; } }
393 ksurf_arr(i, j, 0) =
ks;
394 zib_arr(i, j, 0) = (
ks -
klo) * dz_ib;
397 const Real u_top =
myhalf * (uv_ib(i, j,
ks) + uv_ib(i + 1, j,
ks));
398 const Real v_top =
myhalf * (vv_ib(i, j,
ks) + vv_ib(i, j + 1,
ks));
399 const Real ws_top = std::sqrt(u_top * u_top + v_top * v_top);
400 us_eff_arr(i, j, 0) = amrex::max(
KAPPA * ws_top / std::log(
myhalf * dz_ib / z0_ib),
Real(1.0e-3));
401 ts_eff_arr(i, j, 0) =
Real(0);
402 qs_eff_arr(i, j, 0) =
Real(0);
408 us_eff_arr(i, j, 0) = u_star_arr(i, j, 0);
409 ts_eff_arr(i, j, 0) = t_star_arr(i, j, 0);
410 qs_eff_arr(i, j, 0) = have_qstar ? q_star_arr(i, j, 0) :
Real(0);
411 ol_eff_arr(i, j, 0) = l_obuk_arr(i, j, 0);
412 t10_eff_arr(i, j, 0) = t10av_arr(i, j, 0);
418 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
420 const int ksrf = ksurf_arr(i, j, 0);
421 const Real zib = zib_arr(i, j, 0);
422 amrex::ignore_unused(zib);
423 const Real t_layer = t10_eff_arr(i, j, 0);
425 const Real t_layer_v = t_layer * (
one +
epsv * moisture_fraction);
431 zval = (use_terrain_fitted_coords)
433 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
434 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
435 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
436 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
437 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
438 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
439 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
446 : amrex::max(ws2_raw,
Real(1.0));
447 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
450 Real zval0 = zval, Rib0 = Rib;
451 bool above_critical =
false;
452 while (!above_critical && ((kpbl + 1) <=
khi)) {
457 zval = (use_terrain_fitted_coords)
459 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
460 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
461 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
462 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
463 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
464 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
465 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
470 : amrex::max(ws2_raw,
Real(1.0));
471 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
472 above_critical = (Rib >= Ribcr);
475 const Real pblh_emp = (use_terrain_fitted_coords)
477 :
myhalf * gdata.CellSize(2);
478 const Real z_max = (use_terrain_fitted_coords)
480 : ((
khi +
myhalf) * gdata.CellSize(2) - zib);
481 const Real pblh_max =
Real(0.9) * z_max;
482 const Real pblh_min = amrex::max(pblh_emp,
Real(10.0));
484 if (above_critical) {
486 const Real rib_diff = Rib - Rib0;
491 }
else if (std::abs(rib_diff) >
Real(1.0e-10)) {
492 pblh_interp = zval0 + (zval - zval0) / rib_diff * (Ribcr - Rib0);
497 pblh_pred_arr(i, j, 0) = amrex::max(amrex::min(pblh_interp, pblh_max), pblh_min);
498 pbli_arr(i, j, 0) = kpbl;
503 pblh_pred_arr(i, j, 0) = amrex::max(amrex::min(zval, pblh_max), pblh_min);
504 pbli_arr(i, j, 0) = kpbl;
513 constexpr
Real GAMCRQ =
Real(2.e-3);
524 ParallelFor(xybx_work, [=,zero_d=
zero] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
526 const int ksrf = ksurf_arr(i, j, 0);
527 const Real zib = zib_arr(i, j, 0);
528 amrex::ignore_unused(zib);
529 const Real t_layer = t10_eff_arr(i, j, 0);
530 Real obuk_val = ol_eff_arr(i, j, 0);
536 const Real HOL = sf * pblh_pred_arr(i, j, 0) / obuk_val;
537 const Real HOL_bounded = amrex::max(amrex::min(HOL,
Real(100.0)),
Real(-100.0));
541 const Real HOL_abs = std::abs(HOL_bounded);
542 const Real one_quarter =
Real(0.25);
543 const Real phiM = (obuk_val > 0)
544 ? (1 + 5 * HOL_bounded)
545 : std::pow(1 + 16 * HOL_abs, -one_quarter);
546 const Real phiM_safe = amrex::max(phiM,
Real(0.01));
557 const Real theta_v0 = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
558 const Real wthv0 = amrex::max(-us_eff_arr(i,j,0) * ts_eff_arr(i,j,0),
Real(0.0));
559 const Real zi = amrex::max(pblh_pred_arr(i, j, 0),
Real(10.0));
562 Real wstar_shear = us_eff_arr(i, j, 0) / phiM_safe;
566 Real wstar = std::cbrt(wstar_shear*wstar_shear*wstar_shear +
567 wstar_conv*wstar_conv*wstar_conv);
569 wstar = amrex::max(wstar,
Real(0.01));
570 wstar = amrex::min(wstar,
Real(5.0));
572 bool SFCFLG = (obuk_val <= zero_d);
573 const Real HGAMT = (SFCFLG && enable_mrf_countergradient)
574 ? amrex::min(-const_b * us_eff_arr(i, j, 0) * ts_eff_arr(i, j, 0) / wstar, GAMCRT)
578 if (SFCFLG &&
use_moisture && enable_mrf_countergradient) {
579 const Real q_star = qs_eff_arr(i, j, 0);
580 const Real HGAMQ_calc = -const_b * us_eff_arr(i, j, 0) * q_star / wstar;
581 HGAMQ = amrex::max(amrex::min(HGAMQ_calc, GAMCRQ),
Real(0));
584 bool is_land = (lmask_arr(i,j,0) == 1);
585 if (!is_land) HGAMQ = zero_d;
588 if (moisture_indices.
qv >= 0) {
589 Real qv_klo = cell_data(i, j, ksrf, moisture_indices.
qv) / cell_data(i, j, ksrf,
Rho_comp);
593 Real qsat_klo = zero_d;
595 Real rh_klo = (qsat_klo >
Real(1.0e-10)) ? (qv_klo / qsat_klo) :
Real(0);
596 if (rh_klo >
Real(0.95)) {
597 Real rh_scaling = amrex::max(zero_d, (
Real(1) - rh_klo) /
Real(0.05));
606 if (pbli_arr(i, j, 0) <= ksrf + 1 || !enable_mrf_countergradient) {
607 vpert_arr(i, j, 0) = zero_d;
609 const Real VPERT_raw = HGAMT +
epsv * t_layer * HGAMQ;
610 const Real VPERT_capped = enable_mrf_unbounded_vpert
612 : amrex::min(VPERT_raw, GAMCRT);
613 vpert_arr(i, j, 0) = amrex::max(VPERT_capped, zero_d);
626 AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
628 const int ksrf = ksurf_arr(i, j, 0);
629 const Real zib = zib_arr(i, j, 0);
630 amrex::ignore_unused(zib);
631 const Real t_layer = t10_eff_arr(i, j, 0);
634 const Real t_layer_v = t_layer * (
one +
epsv * moisture_fraction)
635 + vpert_arr(i, j, 0);
637 Real obuk_val = ol_eff_arr(i, j, 0);
645 zval = (use_terrain_fitted_coords)
647 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
648 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
649 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
650 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
651 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
652 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
653 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
657 : amrex::max(ws2_raw, one_d);
658 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
660 Real zval0 = zval, Rib0 = Rib;
662 bool above_critical =
false;
663 while (!above_critical && ((kpbl + 1) <=
khi)) {
668 zval = (use_terrain_fitted_coords)
670 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
671 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
672 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
673 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
674 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
675 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
676 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
680 : amrex::max(ws2_raw, one_d);
681 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
682 above_critical = (Rib >= Ribcr);
685 const Real pblh_emp = (use_terrain_fitted_coords)
687 :
myhalf * gdata.CellSize(2);
688 const Real z_max = (use_terrain_fitted_coords)
690 : ((
khi +
myhalf) * gdata.CellSize(2) - zib);
691 const Real pblh_max =
Real(0.9) * z_max;
692 const Real pblh_min = amrex::max(pblh_emp,
Real(10.0));
694 if (above_critical) {
696 const Real rib_diff = Rib - Rib0;
701 }
else if (std::abs(rib_diff) >
Real(1.0e-10)) {
702 pblh_interp = zval0 + (zval - zval0) / rib_diff * (Ribcr - Rib0);
707 pblh_corr_arr(i, j, 0) = amrex::max(amrex::min(pblh_interp, pblh_max), pblh_min);
708 pbli_arr(i, j, 0) = kpbl;
713 pblh_corr_arr(i, j, 0) = amrex::max(amrex::min(zval, pblh_max), pblh_min);
714 pbli_arr(i, j, 0) = kpbl;
716 pblh_floor_arr(i, j, 0) = pblh_min;
732 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept {
733 pblh_corr_arr(i, j, 0) += zib_arr(i, j, 0);
738 geom.Domain(), geom.periodicity());
739 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept {
740 pblh_corr_arr(i, j, 0) = amrex::max(pblh_corr_arr(i, j, 0) - zib_arr(i, j, 0), pblh_floor_arr(i, j, 0));
750 auto pblh_out = pblh_mf.array(mfi);
751 const Box& tbx = mfi.tilebox();
756 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
757 pblh_out(i, j, k) = pblh_corr_arr(i, j, 0) + zib_arr(i, j, 0);
767 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
769 const int ksrf = ksurf_arr(i, j, 0);
770 const Real zib = zib_arr(i, j, 0);
771 amrex::ignore_unused(zib);
773 Real obuk_val = ol_eff_arr(i, j, 0);
779 const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
780 const Real HOL_bounded = amrex::max(amrex::min(HOL,
Real(100.0)),
Real(-100.0));
784 const Real HOL_abs = std::abs(HOL_bounded);
785 const Real one_quarter =
Real(0.25);
790 const Real phiM = (obuk_val > 0)
791 ? (enable_qnse_d >
Real(0.5)
792 ? (1 + qnse_am_d * HOL_bounded) / (1 + qnse_bm_d * HOL_bounded)
793 : (1 + 5 * HOL_bounded))
794 : std::pow(1 + 16 * HOL_abs, -one_quarter);
795 const Real phiM_safe = amrex::max(phiM,
Real(0.01));
800 const Real theta_v0 = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
801 const Real wthv0 = amrex::max(-us_eff_arr(i,j,0) * ts_eff_arr(i,j,0),
Real(0.0));
805 const Real zi = amrex::max(pblh_corr_arr(i, j, 0),
Real(10.0));
808 Real wstar_shear = us_eff_arr(i, j, 0) / phiM_safe;
812 Real wstar = std::cbrt(wstar_shear*wstar_shear*wstar_shear +
813 wstar_conv*wstar_conv*wstar_conv);
815 wstar = amrex::max(wstar,
Real(0.01));
816 wstar = amrex::min(wstar,
Real(5.0));
817 wstar_arr(i, j, 0) = wstar;
818 bool SFCFLG = (obuk_val <=
Real(0));
828 const Real HGAMT = (SFCFLG && enable_mrf_countergradient)
829 ? amrex::max(amrex::min(-const_b * us_eff_arr(i, j, 0)
830 * ts_eff_arr(i, j, 0) / wstar, GAMCRT),
Real(0))
834 if (SFCFLG &&
use_moisture && enable_mrf_countergradient) {
835 const Real q_star = qs_eff_arr(i, j, 0);
836 const Real HGAMQ_calc = -const_b * us_eff_arr(i, j, 0) * q_star / wstar;
837 HGAMQ = amrex::max(amrex::min(HGAMQ_calc, GAMCRQ),
Real(0));
840 bool is_land = (lmask_arr(i,j,0) == 1);
841 if (!is_land) HGAMQ =
Real(0);
844 if (moisture_indices.
qv >= 0) {
845 Real qv_klo = cell_data(i, j, ksrf, moisture_indices.
qv) / cell_data(i, j, ksrf,
Rho_comp);
851 Real rh_klo = (qsat_klo >
Real(1.0e-10)) ? (qv_klo / qsat_klo) :
Real(0);
852 if (rh_klo >
Real(0.95)) {
859 if (pbli_arr(i, j, 0) <= ksrf + 1) {
860 hgamt_arr(i, j, 0) =
Real(0);
861 hgamq_arr(i, j, 0) =
Real(0);
863 const Real pblh = pblh_corr_arr(i, j, 0);
864 if (pblh >
Real(1.0e-10)) {
865 hgamt_arr(i, j, 0) = (enable_mrf_countergradient) ? HGAMT / pblh :
Real(0);
866 hgamq_arr(i, j, 0) = (enable_mrf_countergradient &&
use_moisture) ? HGAMQ / pblh :
Real(0);
868 hgamt_arr(i, j, 0) =
Real(0);
869 hgamq_arr(i, j, 0) =
Real(0);
879 constexpr
Real Ribcr_zero =
Real(0);
881 AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
883 const int ksrf = ksurf_arr(i, j, 0);
884 const Real zib = zib_arr(i, j, 0);
885 amrex::ignore_unused(zib);
886 const Real t_layer = t10_eff_arr(i, j, 0);
888 const Real t_layer_v = t_layer * (
one +
epsv * moisture_fraction);
889 const Real t_layer_v_enhanced = t_layer_v + vpert_arr(i, j, 0);
891 int kpbl_zero = ksrf;
892 Real zval_zero, Rib_zero;
894 zval_zero = (use_terrain_fitted_coords)
896 : ((kpbl_zero +
myhalf) * gdata.CellSize(2) - zib);
897 const Real theta_v =
GetThetav(i, j, kpbl_zero, cell_data, moisture_indices);
898 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
899 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) *
900 (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) +
901 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) *
902 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) );
906 : amrex::max(ws2_raw, one_d);
907 Rib_zero =
CONST_GRAV * zval_zero * (theta_v - t_layer_v_enhanced) / (ws2 * theta_v_klo);
910 bool above_critical_zero =
false;
911 while (!above_critical_zero && ((kpbl_zero + 1) <=
khi)) {
913 zval_zero = (use_terrain_fitted_coords)
915 : ((kpbl_zero +
myhalf) * gdata.CellSize(2) - zib);
916 const Real theta_v =
GetThetav(i, j, kpbl_zero, cell_data, moisture_indices);
917 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
918 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) *
919 (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) +
920 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) *
921 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) );
925 : amrex::max(ws2_raw, one_d);
926 Rib_zero =
CONST_GRAV * zval_zero * (theta_v - t_layer_v_enhanced) / (ws2 * theta_v_klo);
927 above_critical_zero = (Rib_zero >= Ribcr_zero);
930 if (above_critical_zero) {
931 pbli_zero_arr(i, j, 0) = kpbl_zero;
935 pbli_zero_arr(i, j, 0) = kpbl_zero;
941 const Array4<Real>& K_turb = eddyViscosity.array(mfi);
950 const auto&
dxInv = geom.InvCellSizeArray();
951 const Real dz_inv = geom.InvCellSize(2);
952 const int izmin = geom.Domain().smallEnd(2);
953 const int izmax = geom.Domain().bigEnd(2);
963 ParallelFor(gbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
965 const int ksrf = ksurf_arr(i, j, 0);
966 const Real zib = zib_arr(i, j, 0);
967 amrex::ignore_unused(zib);
968 Real obuk_val = ol_eff_arr(i, j, 0);
973 const Real zval = (use_terrain_fitted_coords)
975 : ((k +
myhalf) * gdata.CellSize(2) - zib);
982 if (
rho <=
Real(0) || k < ksrf) {
991 const Real met_h_zeta = (use_terrain_fitted_coords)
993 const Real dz_terrain = met_h_zeta / dz_inv;
995 constexpr
Real qc_threshold =
Real(1.0e-4);
999 if (moisture_indices.
qc >= 0) {
1000 qc_mix = cell_data(i, j, k, moisture_indices.
qc) /
rho;
1002 if (moisture_indices.
qi >= 0) {
1003 qi_mix = cell_data(i, j, k, moisture_indices.
qi) /
rho;
1006 const Real total_qcloud = qc_mix + qi_mix;
1011 if (k < pbli_extent) {
1012 const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
1013 const Real HOL_bounded = amrex::max(amrex::min(HOL,
Real(100.0)),
Real(-100.0));
1017 const Real HOL_abs = std::abs(HOL_bounded);
1019 const Real one_quarter =
Real(0.25);
1026 const Real phiM = (obuk_val > 0)
1027 ? (enable_qnse_d >
Real(0.5)
1028 ? (1 + qnse_am_d * HOL_bounded) / (1 + qnse_bm_d * HOL_bounded)
1029 : (1 + 5 * HOL_bounded))
1030 : std::pow(1 + 16 * HOL_abs, -one_quarter);
1031 const Real phit = (obuk_val > 0)
1032 ? (enable_qnse_d >
Real(0.5)
1033 ? (1 + qnse_ah_d * HOL_bounded) / (1 + qnse_bh_d * HOL_bounded)
1034 : (1 + 5 * HOL_bounded))
1035 : std::pow(1 + 16 * HOL_abs, -
Real(0.5));
1037 Real phit_cloud = phit;
1038 Real phiM_cloud = phiM;
1039 if (has_cloud && obuk_val >
Real(0)) {
1040 Real reduction_factor =
Real(1) -
Real(0.15) * amrex::min(total_qcloud / qc_threshold,
Real(1));
1042 if (enable_qnse_d >
Real(0.5)) {
1043 phiM_cloud = ((1 + qnse_am_d * HOL_bounded * reduction_factor) / (1 + qnse_bm_d * HOL_bounded));
1044 phit_cloud = ((1 + qnse_ah_d * HOL_bounded * reduction_factor) / (1 + qnse_bh_d * HOL_bounded));
1046 phiM_cloud =
Real(1) +
Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1047 phit_cloud =
Real(1) +
Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1049 }
else if (has_cloud && obuk_val <=
Real(0)) {
1050 Real cloud_boost =
Real(1.0) +
Real(0.05) * amrex::min(total_qcloud / qc_threshold,
Real(1));
1051 phiM_cloud = std::pow(
Real(1) +
Real(16.0) * HOL_abs / cloud_boost, -one_quarter);
1052 phit_cloud = std::pow(
Real(1) +
Real(16.0) * HOL_abs / cloud_boost, -
Real(0.5));
1055 const Real phiM_eff = phiM_cloud;
1056 const Real phit_eff = phit_cloud;
1058 Real Prt_base = phit_eff / phiM_eff;
1059 const Real Prt = amrex::min(amrex::max(Prt_base + const_b *
KAPPA * sf, prmin), prmax);
1064 const Real wstar = wstar_arr(i, j, 0);
1077 const Real zl1 = (use_terrain_fitted_coords)
1079 : ((ksrf +
myhalf) * gdata.CellSize(2) - zib);
1080 const Real pblh = pblh_corr_arr(i, j, 0);
1085 const Real pblh_rel = amrex::max(pblh - zl1,
Real(1.0e-4));
1086 const Real zfac = amrex::max(
Real(1) - (zval - zl1) / pblh_rel,
Real(1.0e-8));
1091 }
else if (k >= pbli_extent) {
1096 const Real lscale = (
KAPPA * zval * lambda) / (
KAPPA * zval + lambda);
1097 Real dthetadz, dudz, dvdz;
1098 ComputeVerticalDerivativesPBL(i, j, k, uvel, vvel, cell_data, izmin, izmax, pbl_derivative_dz_inv(i,j,k),
1099 c_ext_dir_on_zlo, c_ext_dir_on_zhi, u_ext_dir_on_zlo,
1100 u_ext_dir_on_zhi, v_ext_dir_on_zlo, v_ext_dir_on_zhi, dthetadz,
1101 dudz, dvdz, moisture_indices, pbl_strat);
1103 const Real dudz_safe = (k < izmax) ? dudz :
Real(0);
1104 const Real dvdz_safe = (k < izmax) ? dvdz :
Real(0);
1105 const Real wind_shear = dudz_safe * dudz_safe + dvdz_safe * dvdz_safe;
1106 const Real wind_shear_safe = std::max(wind_shear,
Real(1.0e-8));
1107 const Real theta_v = amrex::max(
GetThetav(i, j, k, cell_data, moisture_indices),
Real(1.0));
1108 const Real dtheta_v_dz = dthetadz;
1110 Real grad_Ri =
CONST_GRAV / theta_v * dtheta_v_dz / wind_shear_safe;
1111 grad_Ri = std::max(std::min(grad_Ri,
Real(100.0)), -
Real(100.0));
1113 const Real grad_Ri_safe = amrex::max(grad_Ri, -
Real(100.0));
1121 const Real sqrt_neg_Ri = std::sqrt(std::abs(grad_Ri_safe));
1123 const Real fm = (grad_Ri_safe > 0)
1125 : 1 - 8 * grad_Ri_safe / (1 +
Real(1.746) * sqrt_neg_Ri);
1126 const Real ft = (grad_Ri_safe > 0)
1128 : 1 - 8 * grad_Ri_safe / (1 +
Real(1.286) * sqrt_neg_Ri);
1129 const Real rl2wsp =
rho * lscale * lscale * std::sqrt(wind_shear);
1139 const Real Pr_mom = (grad_Ri_safe > 0) ? Pr :
Real(1);
1155 if (l_blend_length > 0.0) {
1161 l_dx, l_blend_length, l_blend_cs, l_blend_cmax,
1166 l_dx, l_blend_length, l_blend_cs, l_blend_cmax,
1173 Real rhoKmin, rhoKmax;
1176 constexpr
Real Kmax =
Real(1000.0);
1177 rhoKmin = ckz * dz_terrain *
rho;
1178 rhoKmax =
rho * Kmax;
1182 rhoKmin =
rho * Kmin;
1183 rhoKmax =
rho * Kmax;
1191 std::min(K_turb(i, j, k,
EddyDiff::Q_v), rhoKmax), rhoKmin);
1209 if (k < pbli_extent) {
1219 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int ) noexcept
1237 SurfLayer->set_pblh(level, pblh_mf);
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
constexpr amrex::Real immersed_neutral_obukhov_length
Definition: ERF_Constants.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getTgivenRandRTh(const amrex::Real rho, const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real getPgivenRTh(const amrex::Real rhotheta, const amrex::Real qv=amrex::Real(0))
Definition: ERF_EOS.H:81
#define Rho_comp
Definition: ERF_IndexDefines.H:53
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:54
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:71
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
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void erf_qsatw(amrex::Real t, amrex::Real p, amrex::Real &qsatw)
Definition: ERF_MicrophysicsUtils.H:264
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 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
std::unique_ptr< amrex::MultiFab > WidenForPBLH(const amrex::MultiFab &src, const int ng, const std::function< void(amrex::MultiFab &)> &fill)
Definition: ERF_PBLModels.H:805
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void ComputeVerticalDerivativesPBL(int i, int j, int k, const amrex::Array4< const amrex::Real > &uvel, const amrex::Array4< const amrex::Real > &vvel, const amrex::Array4< const amrex::Real > &cell_data, const int izmin, const int izmax, const PBLDerivativeDzInv &dz_inv, const bool c_ext_dir_on_zlo, const bool c_ext_dir_on_zhi, const bool u_ext_dir_on_zlo, const bool u_ext_dir_on_zhi, const bool v_ext_dir_on_zlo, const bool v_ext_dir_on_zhi, amrex::Real &dthetadz, amrex::Real &dudz, amrex::Real &dvdz, const MoistureComponentIndices &moisture_indices, const StratType strat=StratType::thetav)
Definition: ERF_PBLModels.H:309
void ApplyPBLHSmoothing(amrex::FArrayBox &pblh_fab, const amrex::Box &xybx_valid, const amrex::Real weight, const int passes, const amrex::Box &domain, const amrex::Periodicity &periodicity)
Apply spatial smoothing to PBLH field using 5-point stencil.
Definition: ERF_PBLModels.H:722
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real pbl_kh_blend_and_cap(amrex::Real K_h, amrex::Real dx, amrex::Real L_blend, amrex::Real C_s, amrex::Real c_max, amrex::Real SmnSmn, bool use_smag) noexcept
Apply scale-aware blending and ceiling to a single K_h value.
Definition: ERF_PBLScaleAwareBlending.H:133
amrex::Real Real
Definition: ERF_ShocInterface.H:19
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_Zrel_AtCellCenter(const int &i, const int &j, const int &k, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:762
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtCellCenter(const int &i, const int &j, const int &k, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:201
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ yvel_bc
Definition: ERF_IndexDefines.H:127
@ cons_bc
Definition: ERF_IndexDefines.H:110
@ xvel_bc
Definition: ERF_IndexDefines.H:126
@ ext_dir
Definition: ERF_IndexDefines.H:340
@ Theta_v
Definition: ERF_IndexDefines.H:290
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:294
@ Q_v
Definition: ERF_IndexDefines.H:293
@ Mom_v
Definition: ERF_IndexDefines.H:289
@ HGAMQ_v
Definition: ERF_IndexDefines.H:301
@ HGAMT_v
Definition: ERF_IndexDefines.H:300
@ ks
Definition: ERF_SLM.H:74
@ rho
Definition: ERF_Kessler.H:25
@ xvel
Definition: ERF_IndexDefines.H:255
@ yvel
Definition: ERF_IndexDefines.H:256
@ zi
Definition: ERF_AdvanceWDM6.cpp:277
int qi
cloud ice
Definition: ERF_DataStruct.H:264
int qv
water vapor
Definition: ERF_DataStruct.H:262
int qc
cloud liquid water
Definition: ERF_DataStruct.H:263
Functor for inverse vertical spacings for terrain-following grids using cell-center heights.
Definition: ERF_PBLModels.H:668
bool enable_mrf_unbounded_vpert
Whether MRF leaves VPERT unlimited by GAMCRT.
Definition: ERF_TurbStruct.H:1050
amrex::Real pbl_blend_length
Boutle blending length L [m]. 0 = off.
Definition: ERF_TurbStruct.H:1041
bool pbl_mrf_use_zero_ri_extent
Whether MRF uses the Ri=0 K-profile extent.
Definition: ERF_TurbStruct.H:1051
amrex::Real qnse_ah
Definition: ERF_TurbStruct.H:1061
StratType pbl_strat_type
Definition: ERF_TurbStruct.H:868
bool enable_vh96_shear_correction
Whether Vogelezang & Holtslag (1996) shear-correction term is enabled.
Definition: ERF_TurbStruct.H:1028
bool enable_mrf_cloud_adjustment
Whether MRF cloud-aware stability adjustments are enabled.
Definition: ERF_TurbStruct.H:1048
amrex::Real pbl_mrf_const_b
MRF constant used to compute PBL height.
Definition: ERF_TurbStruct.H:1036
amrex::Real pblh_smoothing_weight
Center-cell weight in PBLH smoothing stencil (must be in [0,1]).
Definition: ERF_TurbStruct.H:1032
amrex::Real pbl_blend_cs
Smagorinsky coeff for K_h ceiling.
Definition: ERF_TurbStruct.H:1042
amrex::Real qnse_bm
Definition: ERF_TurbStruct.H:1060
amrex::Real pbl_blend_c_max
Power-law ceiling coeff [m^(2/3)/s].
Definition: ERF_TurbStruct.H:1043
amrex::Real qnse_bh
Definition: ERF_TurbStruct.H:1062
bool enable_qnse_stable_functions
Definition: ERF_TurbStruct.H:1057
bool enable_mrf_countergradient
Whether MRF countergradient corrections are enabled.
Definition: ERF_TurbStruct.H:1045
bool enable_pblh_smoothing
Whether spatial smoothing of diagnosed PBLH is enabled.
Definition: ERF_TurbStruct.H:1030
int pblh_smoothing_passes
Number of PBLH smoothing iterations to apply.
Definition: ERF_TurbStruct.H:1031
amrex::Real pbl_ib_z0
Definition: ERF_TurbStruct.H:1047
bool pbl_ib_aware
Definition: ERF_TurbStruct.H:1046
bool pbl_mrf_highres_bounds
Whether MRF applies high-resolution grid-dependent diffusivity bounds.
Definition: ERF_TurbStruct.H:1049
amrex::Real vh96_shear_const_b
Vogelezang & Holtslag (1996) shear-correction constant b.
Definition: ERF_TurbStruct.H:1029
amrex::Real pbl_mrf_Ribcr
Critical bulk Richardson number for the MRF PBL scheme.
Definition: ERF_TurbStruct.H:1035
amrex::Real qnse_am
Definition: ERF_TurbStruct.H:1059
amrex::Real pbl_mrf_sf
MRF surface flux value used to compute PBL height.
Definition: ERF_TurbStruct.H:1037