Compute vertical diffusivity using the Medium-Range Forecast (MRF) boundary layer scheme.
211 int klo = geom.Domain().smallEnd(2);
212 int khi = geom.Domain().bigEnd(2);
217 MultiFab pblh_mf(eddyViscosity.boxArray(), eddyViscosity.DistributionMap(), 1, 0);
228 const int ng_avail = std::min({cons_in.nGrowVect()[0], cons_in.nGrowVect()[1],
229 xvel.nGrowVect()[0],
xvel.nGrowVect()[1],
230 yvel.nGrowVect()[0],
yvel.nGrowVect()[1],
231 SurfLayer->get_u_star(level)->nGrowVect()[0],
232 SurfLayer->get_u_star(level)->nGrowVect()[1],
233 SurfLayer->get_olen(level)->nGrowVect()[0],
234 SurfLayer->get_olen(level)->nGrowVect()[1],
235 (terrain_blank) ? terrain_blank->nGrowVect()[0] : 1000,
236 (terrain_blank) ? terrain_blank->nGrowVect()[1] : 1000});
237 if (ng_pblh > ng_avail) {
239 +
" needs " + std::to_string(ng_pblh) +
" halo columns, but the state and "
240 "surface-layer arrays carry only " + std::to_string(ng_avail)
241 +
"; reduce erf.pblh_smoothing_passes to at most " + std::to_string(ng_avail));
246 #pragma omp parallel if (Gpu::notInLaunchRegion())
249 for (MFIter mfi(eddyViscosity,
TileNoZ()); mfi.isValid(); ++mfi) {
252 const Box& gbx = mfi.growntilebox(IntVect(1,1,0));
254 gbx.bigEnd(2) ==
khi );
257 const GeometryData gdata = geom.data();
258 const Box xybx = PerpendicularBox<ZDir>(gbx, IntVect{0, 0, 0});
268 ? amrex::grow(mfi.tilebox(), IntVect(ng_pblh,ng_pblh,0)) : gbx;
269 const Box xybx_work = PerpendicularBox<ZDir>(gbx_work, IntVect{0, 0, 0});
270 const Box xybx_tile = PerpendicularBox<ZDir>(mfi.tilebox(), IntVect{0, 0, 0});
277 FArrayBox pbl_height_predictor(xybx_work, 1, The_Async_Arena());
278 FArrayBox pbl_height_corrector(xybx_work, 1, The_Async_Arena());
279 IArrayBox pbl_index(xybx_work, 1, The_Async_Arena());
280 IArrayBox pbl_index_zero_ri(xybx_work, 1, The_Async_Arena());
281 FArrayBox hgamt_fab(xybx_work, 1, The_Async_Arena());
282 FArrayBox hgamq_fab(xybx_work, 1, The_Async_Arena());
283 FArrayBox wstar_fab(xybx_work, 1, The_Async_Arena());
284 FArrayBox vpert_fab(xybx_work, 1, The_Async_Arena());
285 FArrayBox pblh_floor_fab(xybx_work, 1, The_Async_Arena());
286 const auto& pblh_pred_arr = pbl_height_predictor.array();
287 const auto& pblh_corr_arr = pbl_height_corrector.array();
288 const auto& pblh_floor_arr = pblh_floor_fab.array();
289 const auto& pbli_arr = pbl_index.array();
290 const auto& pbli_zero_arr = pbl_index_zero_ri.array();
291 const auto& hgamt_arr = hgamt_fab.array();
292 const auto& hgamq_arr = hgamq_fab.array();
293 const auto& wstar_arr = wstar_fab.array();
294 const auto& vpert_arr = vpert_fab.array();
297 const auto& cell_data = cons_in.const_array(mfi);
298 const auto& uvel =
xvel.const_array(mfi);
299 const auto& vvel =
yvel.const_array(mfi);
302 const auto& u_star_arr = SurfLayer->get_u_star(level)->const_array(mfi);
303 const auto& t_star_arr = SurfLayer->get_t_star(level)->const_array(mfi);
304 const auto& l_obuk_arr = SurfLayer->get_olen(level)->const_array(mfi);
305 const auto& t10av_arr = SurfLayer->get_mac_avg(level, 3)->const_array(mfi);
306 const auto& q10av_arr = SurfLayer->get_mac_avg(level, 4)->const_array(mfi);
307 const auto& lmask_arr = (SurfLayer->get_lmask(level)) ?
308 SurfLayer->get_lmask(level)->const_array(mfi) :
311 const Array4<Real const> z_nd_arr = use_terrain_fitted_coords ? z_phys_nd->array(mfi)
312 : Array4<Real const>{};
323 amrex::MultiFab* q_star_mf = SurfLayer->get_q_star(level);
324 Array4<Real const> q_star_arr = (q_star_mf !=
nullptr) ? q_star_mf->const_array(mfi)
325 : Array4<Real const>{};
338 const bool l_ib = turbChoice.
pbl_ib_aware && (terrain_blank !=
nullptr);
340 "erf.pbl_ib_aware is not supported with terrain-fitted coordinates");
341 const Array4<Real const> blank_arr = l_ib ? terrain_blank->const_array(mfi) : Array4<Real const>{};
342 IArrayBox ksurf_fab(xybx_work, 1, The_Async_Arena());
343 FArrayBox zib_fab(xybx_work, 1, The_Async_Arena());
344 FArrayBox us_eff_fab(xybx_work, 1, The_Async_Arena()), ts_eff_fab(xybx_work, 1, The_Async_Arena());
345 FArrayBox qs_eff_fab(xybx_work, 1, The_Async_Arena()), ol_eff_fab(xybx_work, 1, The_Async_Arena());
346 FArrayBox t10_eff_fab(xybx_work, 1, The_Async_Arena()), q10_eff_fab(xybx_work, 1, The_Async_Arena());
347 const auto& ksurf_arr = ksurf_fab.array();
348 const auto& zib_arr = zib_fab.array();
349 const auto& us_eff_arr = us_eff_fab.array();
const auto& ts_eff_arr = ts_eff_fab.array();
350 const auto& qs_eff_arr = qs_eff_fab.array();
const auto& ol_eff_arr = ol_eff_fab.array();
351 const auto& t10_eff_arr = t10_eff_fab.array();
const auto& q10_eff_arr = q10_eff_fab.array();
353 const Real dz_ib = geom.CellSize(2);
355 const Array4<Real const>& uv_ib =
xvel.const_array(mfi);
356 const Array4<Real const>& vv_ib =
yvel.const_array(mfi);
357 const bool have_qstar = (q_star_mf !=
nullptr);
358 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
362 for (
int kk =
klo; kk <=
khi; ++kk) {
if (blank_arr(i, j, kk) >=
Real(0.5)) { ks = kk + 1; } }
363 if (ks >
khi) { ks =
khi; }
365 ksurf_arr(i, j, 0) = ks;
366 zib_arr(i, j, 0) = (ks -
klo) * dz_ib;
369 const Real u_top =
myhalf * (uv_ib(i, j, ks) + uv_ib(i + 1, j, ks));
370 const Real v_top =
myhalf * (vv_ib(i, j, ks) + vv_ib(i, j + 1, ks));
371 const Real ws_top = std::sqrt(u_top * u_top + v_top * v_top);
372 us_eff_arr(i, j, 0) = amrex::max(
KAPPA * ws_top / std::log(
myhalf * dz_ib / z0_ib),
Real(1.0e-3));
373 ts_eff_arr(i, j, 0) =
Real(0);
374 qs_eff_arr(i, j, 0) =
Real(0);
375 ol_eff_arr(i, j, 0) =
Real(1.0e10);
378 ? cell_data(i, j, ks, moisture_indices.
qv) / cell_data(i, j, ks,
Rho_comp) :
Real(0);
380 us_eff_arr(i, j, 0) = u_star_arr(i, j, 0);
381 ts_eff_arr(i, j, 0) = t_star_arr(i, j, 0);
382 qs_eff_arr(i, j, 0) = have_qstar ? q_star_arr(i, j, 0) :
Real(0);
383 ol_eff_arr(i, j, 0) = l_obuk_arr(i, j, 0);
384 t10_eff_arr(i, j, 0) = t10av_arr(i, j, 0);
390 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
392 const int ksrf = ksurf_arr(i, j, 0);
393 const Real zib = zib_arr(i, j, 0);
394 amrex::ignore_unused(zib);
395 const Real t_layer = t10_eff_arr(i, j, 0);
397 const Real t_layer_v = t_layer * (
one +
epsv * moisture_fraction);
403 zval = (use_terrain_fitted_coords)
405 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
406 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
407 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
408 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
409 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
410 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
411 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
418 : amrex::max(ws2_raw,
Real(1.0));
419 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
422 Real zval0 = zval, Rib0 = Rib;
423 bool above_critical =
false;
424 while (!above_critical && ((kpbl + 1) <=
khi)) {
429 zval = (use_terrain_fitted_coords)
431 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
432 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
433 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
434 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
435 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
436 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
437 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
442 : amrex::max(ws2_raw,
Real(1.0));
443 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
444 above_critical = (Rib >= Ribcr);
447 const Real pblh_emp = (use_terrain_fitted_coords)
449 :
myhalf * gdata.CellSize(2);
450 const Real z_max = (use_terrain_fitted_coords)
452 : ((
khi +
myhalf) * gdata.CellSize(2) - zib);
453 const Real pblh_max =
Real(0.9) * z_max;
454 const Real pblh_min = amrex::max(pblh_emp,
Real(10.0));
456 if (above_critical) {
458 const Real rib_diff = Rib - Rib0;
459 if (std::abs(rib_diff) >
Real(1.0e-10)) {
460 pblh_interp = zval0 + (zval - zval0) / rib_diff * (Ribcr - Rib0);
465 pblh_pred_arr(i, j, 0) = amrex::max(amrex::min(pblh_interp, pblh_max), pblh_min);
466 pbli_arr(i, j, 0) = kpbl;
468 pblh_pred_arr(i, j, 0) = pblh_min;
469 pbli_arr(i, j, 0) = ksrf + 1;
478 constexpr
Real GAMCRQ =
Real(2.e-3);
489 ParallelFor(xybx_work, [=,zero_d=
zero] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
491 const int ksrf = ksurf_arr(i, j, 0);
492 const Real zib = zib_arr(i, j, 0);
493 amrex::ignore_unused(zib);
494 const Real t_layer = t10_eff_arr(i, j, 0);
495 Real obuk_val = ol_eff_arr(i, j, 0);
501 const Real HOL = sf * pblh_pred_arr(i, j, 0) / obuk_val;
502 const Real HOL_bounded = amrex::max(amrex::min(HOL,
Real(100.0)),
Real(-100.0));
506 const Real HOL_abs = std::abs(HOL_bounded);
507 const Real one_quarter =
Real(0.25);
508 const Real phiM = (obuk_val > 0)
509 ? (1 + 5 * HOL_bounded)
510 : std::pow(1 + 16 * HOL_abs, -one_quarter);
511 const Real phiM_safe = amrex::max(phiM,
Real(0.01));
522 const Real theta_v0 = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
523 const Real wthv0 = amrex::max(-us_eff_arr(i,j,0) * ts_eff_arr(i,j,0),
Real(0.0));
524 const Real zi = amrex::max(pblh_pred_arr(i, j, 0),
Real(10.0));
527 Real wstar_shear = us_eff_arr(i, j, 0) / phiM_safe;
531 Real wstar = std::cbrt(wstar_shear*wstar_shear*wstar_shear +
532 wstar_conv*wstar_conv*wstar_conv);
534 wstar = amrex::max(wstar,
Real(0.01));
535 wstar = amrex::min(wstar,
Real(5.0));
537 bool SFCFLG = (obuk_val <= zero_d);
538 const Real HGAMT = (SFCFLG && enable_mrf_countergradient)
539 ? amrex::min(-const_b * us_eff_arr(i, j, 0) * ts_eff_arr(i, j, 0) / wstar, GAMCRT)
543 if (SFCFLG &&
use_moisture && enable_mrf_countergradient) {
544 const Real q_star = qs_eff_arr(i, j, 0);
545 const Real HGAMQ_calc = -const_b * us_eff_arr(i, j, 0) * q_star / wstar;
546 HGAMQ = amrex::max(amrex::min(HGAMQ_calc, GAMCRQ),
Real(0));
549 bool is_land = (lmask_arr(i,j,0) == 1);
550 if (!is_land) HGAMQ = zero_d;
553 if (moisture_indices.
qv >= 0) {
554 Real qv_klo = cell_data(i, j, ksrf, moisture_indices.
qv) / cell_data(i, j, ksrf,
Rho_comp);
558 Real qsat_klo = zero_d;
560 Real rh_klo = (qsat_klo >
Real(1.0e-10)) ? (qv_klo / qsat_klo) :
Real(0);
561 if (rh_klo >
Real(0.95)) {
562 Real rh_scaling = amrex::max(zero_d, (
Real(1) - rh_klo) /
Real(0.05));
571 if (pbli_arr(i, j, 0) <= ksrf + 1 || !enable_mrf_countergradient) {
572 vpert_arr(i, j, 0) = zero_d;
574 const Real VPERT_raw = HGAMT +
epsv * t_layer * HGAMQ;
575 const Real VPERT_capped = enable_mrf_unbounded_vpert
577 : amrex::min(VPERT_raw, GAMCRT);
578 vpert_arr(i, j, 0) = amrex::max(VPERT_capped, zero_d);
591 AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
593 const int ksrf = ksurf_arr(i, j, 0);
594 const Real zib = zib_arr(i, j, 0);
595 amrex::ignore_unused(zib);
596 const Real t_layer = t10_eff_arr(i, j, 0);
599 const Real t_layer_v = t_layer * (
one +
epsv * moisture_fraction)
600 + vpert_arr(i, j, 0);
602 Real obuk_val = ol_eff_arr(i, j, 0);
610 zval = (use_terrain_fitted_coords)
612 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
613 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
614 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
615 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
616 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
617 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
618 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
622 : amrex::max(ws2_raw, one_d);
623 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
625 Real zval0 = zval, Rib0 = Rib;
627 bool above_critical =
false;
628 while (!above_critical && ((kpbl + 1) <=
khi)) {
633 zval = (use_terrain_fitted_coords)
635 : ((kpbl +
myhalf) * gdata.CellSize(2) - zib);
636 const Real theta_v =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
637 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
638 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
639 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
640 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
641 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
645 : amrex::max(ws2_raw, one_d);
646 Rib =
CONST_GRAV * zval * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
647 above_critical = (Rib >= Ribcr);
650 const Real pblh_emp = (use_terrain_fitted_coords)
652 :
myhalf * gdata.CellSize(2);
653 const Real z_max = (use_terrain_fitted_coords)
655 : ((
khi +
myhalf) * gdata.CellSize(2) - zib);
656 const Real pblh_max =
Real(0.9) * z_max;
657 const Real pblh_min = amrex::max(pblh_emp,
Real(10.0));
659 if (above_critical) {
661 const Real rib_diff = Rib - Rib0;
662 if (std::abs(rib_diff) >
Real(1.0e-10)) {
663 pblh_interp = zval0 + (zval - zval0) / rib_diff * (Ribcr - Rib0);
668 pblh_corr_arr(i, j, 0) = amrex::max(amrex::min(pblh_interp, pblh_max), pblh_min);
669 pbli_arr(i, j, 0) = kpbl;
671 pblh_corr_arr(i, j, 0) = pblh_min;
672 pbli_arr(i, j, 0) = ksrf + 1;
674 pblh_floor_arr(i, j, 0) = pblh_min;
690 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept {
691 pblh_corr_arr(i, j, 0) += zib_arr(i, j, 0);
696 geom.Domain(), geom.periodicity());
697 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept {
698 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));
708 auto pblh_out = pblh_mf.array(mfi);
709 const Box& tbx = mfi.tilebox();
714 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
715 pblh_out(i, j, k) = pblh_corr_arr(i, j, 0) + zib_arr(i, j, 0);
725 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
727 const int ksrf = ksurf_arr(i, j, 0);
728 const Real zib = zib_arr(i, j, 0);
729 amrex::ignore_unused(zib);
731 Real obuk_val = ol_eff_arr(i, j, 0);
737 const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
738 const Real HOL_bounded = amrex::max(amrex::min(HOL,
Real(100.0)),
Real(-100.0));
742 const Real HOL_abs = std::abs(HOL_bounded);
743 const Real one_quarter =
Real(0.25);
748 const Real phiM = (obuk_val > 0)
749 ? (enable_qnse_d >
Real(0.5)
750 ? (1 + qnse_am_d * HOL_bounded) / (1 + qnse_bm_d * HOL_bounded)
751 : (1 + 5 * HOL_bounded))
752 : std::pow(1 + 16 * HOL_abs, -one_quarter);
753 const Real phiM_safe = amrex::max(phiM,
Real(0.01));
758 const Real theta_v0 = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices),
Real(1.0));
759 const Real wthv0 = amrex::max(-us_eff_arr(i,j,0) * ts_eff_arr(i,j,0),
Real(0.0));
763 const Real zi = amrex::max(pblh_corr_arr(i, j, 0),
Real(10.0));
766 Real wstar_shear = us_eff_arr(i, j, 0) / phiM_safe;
770 Real wstar = std::cbrt(wstar_shear*wstar_shear*wstar_shear +
771 wstar_conv*wstar_conv*wstar_conv);
773 wstar = amrex::max(wstar,
Real(0.01));
774 wstar = amrex::min(wstar,
Real(5.0));
775 wstar_arr(i, j, 0) = wstar;
776 bool SFCFLG = (obuk_val <=
Real(0));
786 const Real HGAMT = (SFCFLG && enable_mrf_countergradient)
787 ? amrex::max(amrex::min(-const_b * us_eff_arr(i, j, 0)
788 * ts_eff_arr(i, j, 0) / wstar, GAMCRT),
Real(0))
792 if (SFCFLG &&
use_moisture && enable_mrf_countergradient) {
793 const Real q_star = qs_eff_arr(i, j, 0);
794 const Real HGAMQ_calc = -const_b * us_eff_arr(i, j, 0) * q_star / wstar;
795 HGAMQ = amrex::max(amrex::min(HGAMQ_calc, GAMCRQ),
Real(0));
798 bool is_land = (lmask_arr(i,j,0) == 1);
799 if (!is_land) HGAMQ =
Real(0);
802 if (moisture_indices.
qv >= 0) {
803 Real qv_klo = cell_data(i, j, ksrf, moisture_indices.
qv) / cell_data(i, j, ksrf,
Rho_comp);
809 Real rh_klo = (qsat_klo >
Real(1.0e-10)) ? (qv_klo / qsat_klo) :
Real(0);
810 if (rh_klo >
Real(0.95)) {
817 if (pbli_arr(i, j, 0) <= ksrf + 1) {
818 hgamt_arr(i, j, 0) =
Real(0);
819 hgamq_arr(i, j, 0) =
Real(0);
821 const Real pblh = pblh_corr_arr(i, j, 0);
822 if (pblh >
Real(1.0e-10)) {
823 hgamt_arr(i, j, 0) = (enable_mrf_countergradient) ? HGAMT / pblh :
Real(0);
824 hgamq_arr(i, j, 0) = (enable_mrf_countergradient &&
use_moisture) ? HGAMQ / pblh :
Real(0);
826 hgamt_arr(i, j, 0) =
Real(0);
827 hgamq_arr(i, j, 0) =
Real(0);
837 constexpr
Real Ribcr_zero =
Real(0);
839 AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
841 const int ksrf = ksurf_arr(i, j, 0);
842 const Real zib = zib_arr(i, j, 0);
843 amrex::ignore_unused(zib);
844 const Real t_layer = t10_eff_arr(i, j, 0);
846 const Real t_layer_v = t_layer * (
one +
epsv * moisture_fraction);
847 const Real t_layer_v_enhanced = t_layer_v + vpert_arr(i, j, 0);
849 int kpbl_zero = ksrf;
850 Real zval_zero, Rib_zero;
852 zval_zero = (use_terrain_fitted_coords)
854 : ((kpbl_zero +
myhalf) * gdata.CellSize(2) - zib);
855 const Real theta_v =
GetThetav(i, j, kpbl_zero, cell_data, moisture_indices);
856 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
857 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) *
858 (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) +
859 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) *
860 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) );
864 : amrex::max(ws2_raw, one_d);
865 Rib_zero =
CONST_GRAV * zval_zero * (theta_v - t_layer_v_enhanced) / (ws2 * theta_v_klo);
868 bool above_critical_zero =
false;
869 while (!above_critical_zero && ((kpbl_zero + 1) <=
khi)) {
871 zval_zero = (use_terrain_fitted_coords)
873 : ((kpbl_zero +
myhalf) * gdata.CellSize(2) - zib);
874 const Real theta_v =
GetThetav(i, j, kpbl_zero, cell_data, moisture_indices);
875 const Real theta_v_klo = amrex::max(
GetThetav(i, j, ksrf, cell_data, moisture_indices), one_d);
876 const Real ws2_raw =
fourth * ( (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) *
877 (uvel(i, j, kpbl_zero) + uvel(i + 1, j, kpbl_zero)) +
878 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) *
879 (vvel(i, j, kpbl_zero) + vvel(i, j + 1, kpbl_zero)) );
883 : amrex::max(ws2_raw, one_d);
884 Rib_zero =
CONST_GRAV * zval_zero * (theta_v - t_layer_v_enhanced) / (ws2 * theta_v_klo);
885 above_critical_zero = (Rib_zero >= Ribcr_zero);
888 if (above_critical_zero) {
889 pbli_zero_arr(i, j, 0) = kpbl_zero;
891 pbli_zero_arr(i, j, 0) = ksrf + 1;
897 const Array4<Real>& K_turb = eddyViscosity.array(mfi);
906 const auto&
dxInv = geom.InvCellSizeArray();
907 const Real dz_inv = geom.InvCellSize(2);
908 const int izmin = geom.Domain().smallEnd(2);
909 const int izmax = geom.Domain().bigEnd(2);
919 ParallelFor(gbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
921 const int ksrf = ksurf_arr(i, j, 0);
922 const Real zib = zib_arr(i, j, 0);
923 amrex::ignore_unused(zib);
924 Real obuk_val = ol_eff_arr(i, j, 0);
929 const Real zval = (use_terrain_fitted_coords)
931 : ((k +
myhalf) * gdata.CellSize(2) - zib);
938 if (
rho <=
Real(0) || k < ksrf) {
947 const Real met_h_zeta = (use_terrain_fitted_coords)
949 const Real dz_terrain = met_h_zeta / dz_inv;
951 constexpr
Real qc_threshold =
Real(1.0e-4);
955 if (moisture_indices.
qc >= 0) {
956 qc_mix = cell_data(i, j, k, moisture_indices.
qc) /
rho;
958 if (moisture_indices.
qi >= 0) {
959 qi_mix = cell_data(i, j, k, moisture_indices.
qi) /
rho;
962 const Real total_qcloud = qc_mix + qi_mix;
967 if (k < pbli_extent) {
968 const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
969 const Real HOL_bounded = amrex::max(amrex::min(HOL,
Real(100.0)),
Real(-100.0));
973 const Real HOL_abs = std::abs(HOL_bounded);
975 const Real one_quarter =
Real(0.25);
982 const Real phiM = (obuk_val > 0)
983 ? (enable_qnse_d >
Real(0.5)
984 ? (1 + qnse_am_d * HOL_bounded) / (1 + qnse_bm_d * HOL_bounded)
985 : (1 + 5 * HOL_bounded))
986 : std::pow(1 + 16 * HOL_abs, -one_quarter);
987 const Real phit = (obuk_val > 0)
988 ? (enable_qnse_d >
Real(0.5)
989 ? (1 + qnse_ah_d * HOL_bounded) / (1 + qnse_bh_d * HOL_bounded)
990 : (1 + 5 * HOL_bounded))
991 : std::pow(1 + 16 * HOL_abs, -
Real(0.5));
993 Real phit_cloud = phit;
994 Real phiM_cloud = phiM;
995 if (has_cloud && obuk_val >
Real(0)) {
996 Real reduction_factor =
Real(1) -
Real(0.15) * amrex::min(total_qcloud / qc_threshold,
Real(1));
998 if (enable_qnse_d >
Real(0.5)) {
999 phiM_cloud = ((1 + qnse_am_d * HOL_bounded * reduction_factor) / (1 + qnse_bm_d * HOL_bounded));
1000 phit_cloud = ((1 + qnse_ah_d * HOL_bounded * reduction_factor) / (1 + qnse_bh_d * HOL_bounded));
1002 phiM_cloud =
Real(1) +
Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1003 phit_cloud =
Real(1) +
Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1005 }
else if (has_cloud && obuk_val <=
Real(0)) {
1006 Real cloud_boost =
Real(1.0) +
Real(0.05) * amrex::min(total_qcloud / qc_threshold,
Real(1));
1007 phiM_cloud = std::pow(
Real(1) +
Real(16.0) * HOL_abs / cloud_boost, -one_quarter);
1008 phit_cloud = std::pow(
Real(1) +
Real(16.0) * HOL_abs / cloud_boost, -
Real(0.5));
1011 const Real phiM_eff = phiM_cloud;
1012 const Real phit_eff = phit_cloud;
1014 Real Prt_base = phit_eff / phiM_eff;
1015 const Real Prt = amrex::min(amrex::max(Prt_base + const_b *
KAPPA * sf, prmin), prmax);
1020 const Real wstar = wstar_arr(i, j, 0);
1033 const Real zl1 = (use_terrain_fitted_coords)
1035 : ((ksrf +
myhalf) * gdata.CellSize(2) - zib);
1036 const Real pblh = pblh_corr_arr(i, j, 0);
1041 const Real pblh_rel = amrex::max(pblh - zl1,
Real(1.0e-4));
1042 const Real zfac = amrex::max(
Real(1) - (zval - zl1) / pblh_rel,
Real(1.0e-8));
1047 }
else if (k >= pbli_extent) {
1049 const Real lscale = (
KAPPA * zval * lambda) / (
KAPPA * zval + lambda);
1050 Real dthetadz, dudz, dvdz;
1051 ComputeVerticalDerivativesPBL(i, j, k, uvel, vvel, cell_data, izmin, izmax, pbl_derivative_dz_inv(i,j,k),
1052 c_ext_dir_on_zlo, c_ext_dir_on_zhi, u_ext_dir_on_zlo,
1053 u_ext_dir_on_zhi, v_ext_dir_on_zlo, v_ext_dir_on_zhi, dthetadz,
1054 dudz, dvdz, moisture_indices);
1056 const Real dudz_safe = (k < izmax) ? dudz :
Real(0);
1057 const Real dvdz_safe = (k < izmax) ? dvdz :
Real(0);
1058 const Real wind_shear = dudz_safe * dudz_safe + dvdz_safe * dvdz_safe;
1059 const Real wind_shear_safe = std::max(wind_shear,
Real(1.0e-8));
1060 const Real theta_v = amrex::max(
GetThetav(i, j, k, cell_data, moisture_indices),
Real(1.0));
1061 const Real dtheta_v_dz = dthetadz;
1063 Real grad_Ri =
CONST_GRAV / theta_v * dtheta_v_dz / wind_shear_safe;
1064 grad_Ri = std::max(std::min(grad_Ri,
Real(100.0)), -
Real(100.0));
1066 const Real grad_Ri_safe = amrex::max(grad_Ri, -
Real(100.0));
1074 const Real sqrt_neg_Ri = std::sqrt(std::abs(grad_Ri_safe));
1076 const Real fm = (grad_Ri_safe > 0)
1078 : 1 - 8 * grad_Ri_safe / (1 +
Real(1.746) * sqrt_neg_Ri);
1079 const Real ft = (grad_Ri_safe > 0)
1081 : 1 - 8 * grad_Ri_safe / (1 +
Real(1.286) * sqrt_neg_Ri);
1082 const Real rl2wsp =
rho * lscale * lscale * std::sqrt(wind_shear);
1092 const Real Pr_mom = (grad_Ri_safe > 0) ? Pr :
Real(1);
1108 if (l_blend_length > 0.0) {
1114 l_dx, l_blend_length, l_blend_cs, l_blend_cmax,
1119 l_dx, l_blend_length, l_blend_cs, l_blend_cmax,
1126 Real rhoKmin, rhoKmax;
1129 constexpr
Real Kmax =
Real(1000.0);
1130 rhoKmin = ckz * dz_terrain *
rho;
1131 rhoKmax =
rho * Kmax;
1135 rhoKmin =
rho * Kmin;
1136 rhoKmax =
rho * Kmax;
1144 std::min(K_turb(i, j, k,
EddyDiff::Q_v), rhoKmax), rhoKmin);
1162 if (k < pbli_extent) {
1172 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int ) noexcept
1190 SurfLayer->set_pblh(level, pblh_mf);
constexpr amrex::Real epsv
Definition: ERF_Constants.H:40
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:55
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:56
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:39
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
const int klo
Definition: ERF_InitCustomPert_ABL.H:75
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:71
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
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:74
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:30
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:35
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:29
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:34
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)
Definition: ERF_PBLModels.H:281
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:515
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:751
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:190
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ yvel_bc
Definition: ERF_IndexDefines.H:106
@ cons_bc
Definition: ERF_IndexDefines.H:89
@ xvel_bc
Definition: ERF_IndexDefines.H:105
@ ext_dir
Definition: ERF_IndexDefines.H:297
@ Theta_v
Definition: ERF_IndexDefines.H:250
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:254
@ Q_v
Definition: ERF_IndexDefines.H:253
@ Mom_v
Definition: ERF_IndexDefines.H:249
@ HGAMQ_v
Definition: ERF_IndexDefines.H:261
@ HGAMT_v
Definition: ERF_IndexDefines.H:260
@ rho
Definition: ERF_Kessler.H:25
@ xvel
Definition: ERF_IndexDefines.H:215
@ yvel
Definition: ERF_IndexDefines.H:216
@ zi
Definition: ERF_AdvanceWDM6.cpp:276
int qi
cloud ice
Definition: ERF_DataStruct.H:236
int qv
water vapor
Definition: ERF_DataStruct.H:234
int qc
cloud liquid water
Definition: ERF_DataStruct.H:235
Functor for inverse vertical spacings for terrain-following grids using cell-center heights.
Definition: ERF_PBLModels.H:461
bool enable_mrf_unbounded_vpert
Whether MRF leaves VPERT unlimited by GAMCRT.
Definition: ERF_TurbStruct.H:910
amrex::Real pbl_blend_length
Boutle blending length L [m]. 0 = off.
Definition: ERF_TurbStruct.H:901
bool pbl_mrf_use_zero_ri_extent
Whether MRF uses the Ri=0 K-profile extent.
Definition: ERF_TurbStruct.H:911
amrex::Real qnse_ah
Definition: ERF_TurbStruct.H:921
bool enable_vh96_shear_correction
Whether Vogelezang & Holtslag (1996) shear-correction term is enabled.
Definition: ERF_TurbStruct.H:888
bool enable_mrf_cloud_adjustment
Whether MRF cloud-aware stability adjustments are enabled.
Definition: ERF_TurbStruct.H:908
amrex::Real pbl_mrf_const_b
MRF constant used to compute PBL height.
Definition: ERF_TurbStruct.H:896
amrex::Real pblh_smoothing_weight
Center-cell weight in PBLH smoothing stencil (must be in [0,1]).
Definition: ERF_TurbStruct.H:892
amrex::Real pbl_blend_cs
Smagorinsky coeff for K_h ceiling.
Definition: ERF_TurbStruct.H:902
amrex::Real qnse_bm
Definition: ERF_TurbStruct.H:920
amrex::Real pbl_blend_c_max
Power-law ceiling coeff [m^(2/3)/s].
Definition: ERF_TurbStruct.H:903
amrex::Real qnse_bh
Definition: ERF_TurbStruct.H:922
bool enable_qnse_stable_functions
Definition: ERF_TurbStruct.H:917
bool enable_mrf_countergradient
Whether MRF countergradient corrections are enabled.
Definition: ERF_TurbStruct.H:905
bool enable_pblh_smoothing
Whether spatial smoothing of diagnosed PBLH is enabled.
Definition: ERF_TurbStruct.H:890
int pblh_smoothing_passes
Number of PBLH smoothing iterations to apply.
Definition: ERF_TurbStruct.H:891
amrex::Real pbl_ib_z0
Definition: ERF_TurbStruct.H:907
bool pbl_ib_aware
Definition: ERF_TurbStruct.H:906
bool pbl_mrf_highres_bounds
Whether MRF applies high-resolution grid-dependent diffusivity bounds.
Definition: ERF_TurbStruct.H:909
amrex::Real vh96_shear_const_b
Vogelezang & Holtslag (1996) shear-correction constant b.
Definition: ERF_TurbStruct.H:889
amrex::Real pbl_mrf_Ribcr
Critical bulk Richardson number for the MRF PBL scheme.
Definition: ERF_TurbStruct.H:895
amrex::Real qnse_am
Definition: ERF_TurbStruct.H:919
amrex::Real pbl_mrf_sf
MRF surface flux value used to compute PBL height.
Definition: ERF_TurbStruct.H:897