Compute vertical eddy viscosity coefficients using the Yonsei University (YSU) boundary layer scheme.
130 int klo = geom.Domain().smallEnd(2);
131 int khi = geom.Domain().bigEnd(2);
132 const int izmin =
klo;
133 const int izmax =
khi;
135 const Real
dz = geom.CellSize(2);
136 const Real dz_inv = geom.InvCellSize(2);
137 const auto&
dxInv = geom.InvCellSizeArray();
142 MultiFab pblh_mf(eddyViscosity.boxArray(), eddyViscosity.DistributionMap(), 1, 0);
157 const auto needs_widening = [&] (
const MultiFab* mf) {
158 return mf !=
nullptr && std::min(mf->nGrowVect()[0], mf->nGrowVect()[1]) < ng_pblh;
160 const auto widen_sfc = [&] (
const MultiFab* mf) -> std::unique_ptr<MultiFab> {
161 if (!needs_widening(mf)) {
return nullptr; }
163 [&] (MultiFab& wide) { SurfLayer->fill_planar_boundary(level, wide); });
165 const std::unique_ptr<MultiFab> u_star_wide = widen_sfc(SurfLayer->get_u_star(level));
166 const std::unique_ptr<MultiFab> t_star_wide = widen_sfc(SurfLayer->get_t_star(level));
167 const std::unique_ptr<MultiFab> q_star_wide = widen_sfc(SurfLayer->get_q_star(level));
168 const std::unique_ptr<MultiFab> olen_wide = widen_sfc(SurfLayer->get_olen(level));
169 const std::unique_ptr<MultiFab> z0_wide = widen_sfc(SurfLayer->get_z0(level));
170 const std::unique_ptr<MultiFab> qheat_wide = (needs_widening(qheating_rates))
172 [&] (MultiFab& wide) { wide.FillBoundary(geom.periodicity()); })
174 const MultiFab* u_star_src = (u_star_wide) ? u_star_wide.get() : SurfLayer->get_u_star(level);
176 const MultiFab* t_star_src = (t_star_wide) ? t_star_wide.get() : SurfLayer->get_t_star(level);
177 const MultiFab* q_star_src = (q_star_wide) ? q_star_wide.get() : SurfLayer->get_q_star(level);
178 const MultiFab* olen_src = (olen_wide) ? olen_wide.get() : SurfLayer->get_olen(level);
179 const MultiFab* z0_src = (z0_wide) ? z0_wide.get() : SurfLayer->get_z0(level);
180 const MultiFab* qheat_src = (qheat_wide) ? qheat_wide.get() : qheating_rates;
183 int ng_avail = std::min({cons_in.nGrowVect()[0], cons_in.nGrowVect()[1],
184 xvel.nGrowVect()[0],
xvel.nGrowVect()[1],
185 yvel.nGrowVect()[0],
yvel.nGrowVect()[1],
186 u_star_src->nGrowVect()[0], u_star_src->nGrowVect()[1],
187 olen_src->nGrowVect()[0], olen_src->nGrowVect()[1],
188 (terrain_blank) ? terrain_blank->nGrowVect()[0] : 1000,
189 (terrain_blank) ? terrain_blank->nGrowVect()[1] : 1000});
192 auto limit_by = [&ng_avail] (
const auto* mf) {
193 if (mf) { ng_avail = std::min({ng_avail, mf->nGrowVect()[0], mf->nGrowVect()[1]}); }
195 limit_by(t_star_src);
196 limit_by(q_star_src);
197 limit_by(SurfLayer->get_mac_avg(level, 3));
198 limit_by(SurfLayer->get_mac_avg(level, 4));
199 limit_by(SurfLayer->get_mac_avg(level, 6));
201 limit_by(SurfLayer->get_lmask(level));
202 limit_by(z_phys_nd.get());
203 limit_by(z_sfc_nd.get());
205 if (ng_pblh > ng_avail) {
207 +
" needs " + std::to_string(ng_pblh) +
" halo columns, but the fields the "
208 "PBLH passes read carry only " + std::to_string(ng_avail)
209 +
"; reduce erf.pblh_smoothing_passes to at most " + std::to_string(ng_avail));
214 #pragma omp parallel if (Gpu::notInLaunchRegion())
217 for (MFIter mfi(eddyViscosity,
TileNoZ()); mfi.isValid(); ++mfi) {
220 const Box& gbx = mfi.growntilebox(IntVect(1,1,0));
222 gbx.bigEnd(2) ==
khi );
240 const Box xybx = PerpendicularBox<ZDir>(gbx, IntVect{0, 0, 0});
250 ? amrex::grow(mfi.tilebox(), IntVect(ng_pblh,ng_pblh,0)) : gbx;
251 const Box xybx_work = PerpendicularBox<ZDir>(gbx_work, IntVect{0, 0, 0});
252 const Box xybx_tile = PerpendicularBox<ZDir>(mfi.tilebox(), IntVect{0, 0, 0});
253 FArrayBox pbl_height_corrector(xybx_work, 1, The_Async_Arena());
254 IArrayBox pbl_index(xybx_work, 1, The_Async_Arena());
255 IArrayBox pbl_index_zero_ri(xybx_work, 1, The_Async_Arena());
256 FArrayBox hgamt_fab(xybx_work, 1, The_Async_Arena());
257 FArrayBox hgamq_fab(xybx_work, 1, The_Async_Arena());
258 FArrayBox hgamu_fab(xybx_work, 1, The_Async_Arena());
259 FArrayBox hgamv_fab(xybx_work, 1, The_Async_Arena());
260 FArrayBox wstar_fab(xybx_work, 1, The_Async_Arena());
261 FArrayBox vpert_fab(xybx_work, 1, The_Async_Arena());
262 FArrayBox entr_fab(xybx_work, 1, The_Async_Arena());
263 IArrayBox cloud_top_fab(xybx_work, 1, The_Async_Arena());
264 FArrayBox wstar3_down_fab(xybx_work, 1, The_Async_Arena());
265 FArrayBox sflux_fab(xybx_work, 1, The_Async_Arena());
266 FArrayBox wstar3_fab(xybx_work, 1, The_Async_Arena());
267 FArrayBox zol1_fab(xybx_work, 1, The_Async_Arena());
268 FArrayBox sfcflg_fab(xybx_work, 1, The_Async_Arena());
272 vpert_fab.setVal<RunOn::Device>(
zero);
273 sflux_fab.setVal<RunOn::Device>(
zero);
274 wstar3_fab.setVal<RunOn::Device>(
zero);
275 wstar3_down_fab.setVal<RunOn::Device>(
zero);
276 sfcflg_fab.setVal<RunOn::Device>(
zero);
277 hgamt_fab.setVal<RunOn::Device>(
zero);
278 hgamq_fab.setVal<RunOn::Device>(
zero);
279 hgamu_fab.setVal<RunOn::Device>(
zero);
280 hgamv_fab.setVal<RunOn::Device>(
zero);
281 wstar_fab.setVal<RunOn::Device>(
zero);
282 entr_fab.setVal<RunOn::Device>(
zero);
283 pbl_height_corrector.setVal<RunOn::Device>(
zero);
284 const auto& pblh_corr_arr = pbl_height_corrector.array();
285 const auto& pbli_arr = pbl_index.array();
286 const auto& pbli_zero_arr = pbl_index_zero_ri.array();
287 const auto& hgamt_arr = hgamt_fab.array();
288 const auto& hgamq_arr = hgamq_fab.array();
289 const auto& hgamu_arr = hgamu_fab.array();
290 const auto& hgamv_arr = hgamv_fab.array();
291 const auto& wstar_arr = wstar_fab.array();
292 const auto& vpert_arr = vpert_fab.array();
293 const auto& entr_arr = entr_fab.array();
294 const auto& cloud_top_arr = cloud_top_fab.array();
295 const auto& wstar3_down_arr = wstar3_down_fab.array();
296 const auto& sflux_arr = sflux_fab.array();
297 const auto& wstar3_arr = wstar3_fab.array();
298 const auto& zol1_arr = zol1_fab.array();
299 const auto& sfcflg_arr = sfcflg_fab.array();
302 const auto& cell_data = cons_in.const_array(mfi);
303 const auto& uvel =
xvel.const_array(mfi);
304 const auto& vvel =
yvel.const_array(mfi);
308 const auto& u_star_arr = u_star_src->const_array(mfi);
309 const auto& t_star_arr = t_star_src->const_array(mfi);
310 const auto& q_star_arr = q_star_src->const_array(mfi);
311 const auto& l_obuk_arr = olen_src->const_array(mfi);
312 const auto& t10av_arr = SurfLayer->get_mac_avg(level, 3)->const_array(mfi);
313 const auto& q10av_arr = SurfLayer->get_mac_avg(level, 4)->const_array(mfi);
314 const auto& ws10av_arr = SurfLayer->get_mac_avg(level, 6)->const_array(mfi);
315 const auto& z0_arr = z0_src->const_array(mfi);
318 const auto& lmask_arr = (SurfLayer->get_lmask(level)) ?
319 SurfLayer->get_lmask(level)->const_array(mfi) :
332 const bool l_ib = turbChoice.
pbl_ib_aware && (terrain_blank !=
nullptr);
334 "erf.pbl_ib_aware is not supported with terrain-fitted coordinates");
335 const Array4<Real const> blank_arr = l_ib ? terrain_blank->const_array(mfi) : Array4<Real const>{};
336 IArrayBox ksurf_fab(xybx_work, 1, The_Async_Arena());
337 FArrayBox zib_fab(xybx_work, 1, The_Async_Arena());
338 FArrayBox pblh_floor_fab(xybx_work, 1, The_Async_Arena());
339 IArrayBox pbl_open_fab(xybx_work, 1, The_Async_Arena());
340 FArrayBox us_eff_fab(xybx_work, 1, The_Async_Arena()), ts_eff_fab(xybx_work, 1, The_Async_Arena());
341 FArrayBox qs_eff_fab(xybx_work, 1, The_Async_Arena()), ol_eff_fab(xybx_work, 1, The_Async_Arena());
342 FArrayBox t10_eff_fab(xybx_work, 1, The_Async_Arena()), q10_eff_fab(xybx_work, 1, The_Async_Arena());
343 FArrayBox ws10_eff_fab(xybx_work, 1, The_Async_Arena()), z0_eff_fab(xybx_work, 1, The_Async_Arena());
344 const auto& ksurf_arr = ksurf_fab.array();
345 const auto& zib_arr = zib_fab.array();
346 const auto& pblh_floor_arr = pblh_floor_fab.array();
347 const auto& pbl_open_arr = pbl_open_fab.array();
348 const auto& us_eff_arr = us_eff_fab.array();
const auto& ts_eff_arr = ts_eff_fab.array();
349 const auto& qs_eff_arr = qs_eff_fab.array();
const auto& ol_eff_arr = ol_eff_fab.array();
350 const auto& t10_eff_arr = t10_eff_fab.array();
const auto& q10_eff_arr = q10_eff_fab.array();
351 const auto& ws10_eff_arr = ws10_eff_fab.array();
const auto& z0_eff_arr = z0_eff_fab.array();
353 const Real dz_ib = geom.CellSize(2);
355 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
359 for (
int kk =
klo; kk <=
khi; ++kk) {
if (blank_arr(i, j, kk) >= Real(0.5)) {
ks = kk + 1; } }
362 ksurf_arr(i, j, 0) =
ks;
363 zib_arr(i, j, 0) = (
ks -
klo) * dz_ib;
365 const Real u_top =
myhalf * (uvel(i, j,
ks) + uvel(i + 1, j,
ks));
366 const Real v_top =
myhalf * (vvel(i, j,
ks) + vvel(i, j + 1,
ks));
367 const Real ws_top = std::sqrt(u_top * u_top + v_top * v_top);
368 us_eff_arr(i, j, 0) = amrex::max(
KAPPA * ws_top / std::log(
myhalf * dz_ib / z0_ib), Real(1.0e-3));
369 ts_eff_arr(i, j, 0) = Real(0);
370 qs_eff_arr(i, j, 0) = Real(0);
374 ? cell_data(i, j,
ks, moisture_indices.
qv) / cell_data(i, j,
ks,
Rho_comp) : Real(0);
375 ws10_eff_arr(i, j, 0) = ws_top;
376 z0_eff_arr(i, j, 0) = z0_ib;
378 us_eff_arr(i, j, 0) = u_star_arr(i, j, 0);
379 ts_eff_arr(i, j, 0) = t_star_arr(i, j, 0);
380 qs_eff_arr(i, j, 0) = q_star_arr(i, j, 0);
381 ol_eff_arr(i, j, 0) = l_obuk_arr(i, j, 0);
382 t10_eff_arr(i, j, 0) = t10av_arr(i, j, 0);
383 q10_eff_arr(i, j, 0) = q10av_arr(i, j, 0);
384 ws10_eff_arr(i, j, 0) = ws10av_arr(i, j, 0);
385 z0_eff_arr(i, j, 0) = z0_arr(i, j, 0);
389 const Array4<Real const> z_nd_arr = z_phys_nd->array(mfi);
390 const Array4<Real const> z_sfc_arr = z_sfc_nd->const_array(mfi);
393 const Array4<Real const> qheat_arr = (qheat_src !=
nullptr)
394 ? qheat_src->const_array(mfi)
395 : Array4<Real const>{};
396 const bool has_qheating_rates = (qheating_rates !=
nullptr);
407 FArrayBox rib_base_fab(gbx_work, 1, The_Async_Arena());
408 FArrayBox rib_enhan_fab(gbx_work, 1, The_Async_Arena());
409 const auto& rib_base_arr = rib_base_fab.array();
410 const auto& rib_enhan_arr = rib_enhan_fab.array();
412 BL_PROFILE_VAR(
"YSU_Rib_Precompute", prof_rib_precomp);
413 ParallelFor(gbx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
415 const int ksrf = ksurf_arr(i, j, 0);
416 const Real zib = zib_arr(i, j, 0);
417 const amrex::Real t_layer = t10_eff_arr(i, j, 0);
419 const amrex::Real t_layer_v = t_layer * (
one +
epsv * q_frac);
421 const amrex::Real t_enh = t_layer_v + vpert_arr(i,j,0);
425 const amrex::Real z_sfc = zib;
426 const amrex::Real zval = (use_terrain_fitted_coords)
429 const amrex::Real zrel = amrex::max(zval - z_sfc, amrex::Real(1.0e-4));
430 const amrex::Real theta_v =
GetThetav(i,j,k,cell_data,moisture_indices);
431 const amrex::Real theta_v_klo =
GetThetav(i,j,ksrf,cell_data,moisture_indices);
432 const amrex::Real ws2_raw =
fourth * ((uvel(i,j,k)+uvel(i+1,j,k))*(uvel(i,j,k)+uvel(i+1,j,k))
433 + (vvel(i,j,k)+vvel(i,j+1,k))*(vvel(i,j,k)+vvel(i,j+1,k)));
440 : amrex::max(ws2_raw, amrex::Real(1.0));
441 rib_base_arr(i,j,k) =
CONST_GRAV * zrel * (theta_v - t_layer_v) / (ws2 * theta_v_klo);
442 rib_enhan_arr(i,j,k) =
CONST_GRAV * zrel * (theta_v - t_enh) / (ws2 * theta_v_klo);
444 BL_PROFILE_VAR_STOP(prof_rib_precomp);
457 BL_PROFILE_VAR(
"YSU_SurfFlux_Precompute", prof_sflux_precomp);
458 ParallelFor(xybx_work, [=, zero_d=
zero] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
460 const int ksrf = ksurf_arr(i, j, 0);
461 const Real rho_sfc = cell_data(i, j, ksrf,
Rho_comp);
462 const Real t_layer = t10_eff_arr(i, j, 0);
465 const Real rhox = rho_sfc;
468 constexpr Real ep1 = amrex::Real(0.608);
469 constexpr Real cp_air = amrex::Real(1004.0);
475 const Real
ustar = us_eff_arr(i, j, 0);
476 const Real
tstar = ts_eff_arr(i, j, 0);
478 const Real hfx = -rhox * cp_air *
ustar *
tstar;
480 const Real sflux = hfx / (rhox * cp_air) + qfx / rhox * ep1 * t_layer;
481 sflux_arr(i, j, 0) = sflux;
491 const Real sflux_roundoff = Real(64.0) *
real_eps *
ustar * t_layer;
492 const bool sfcflg = (sflux >= -sflux_roundoff);
493 sfcflg_arr(i, j, 0) = sfcflg ?
one :
zero;
501 const Real pblh_guess = amrex::Real(500.0);
502 const Real bfx0 = amrex::max(sflux, zero_d);
503 const Real wstar3 = govrth * bfx0 * pblh_guess;
504 wstar3_arr(i, j, 0) = wstar3;
508 constexpr Real phifac = amrex::Real(8.0);
510 Real wscale = std::cbrt(ust3 + phifac *
KAPPA * wstar3 * amrex::Real(0.5));
512 wscale = amrex::min(wscale,
ustar * amrex::Real(16.0));
513 wscale = amrex::max(wscale,
ustar / amrex::Real(5.0));
514 wstar_arr(i, j, 0) = wscale;
519 Real obuk_val = ol_eff_arr(i, j, 0);
520 if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
521 obuk_val = (obuk_val >=
zero) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
523 const Real zl1 = (use_terrain_fitted_coords)
526 Real zol1 = zl1 / obuk_val;
527 zol1 = amrex::max(zol1, amrex::Real(-100.0));
529 zol1 = amrex::min(zol1, amrex::Real(-1.0e-8));
531 zol1 = amrex::max(zol1, amrex::Real(1.0e-8));
533 zol1_arr(i, j, 0) = zol1;
535 BL_PROFILE_VAR_STOP(prof_sflux_precomp);
547 BL_PROFILE_VAR(
"YSU_PBLH_Passes", prof_pblh);
548 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
550 const int ksrf = ksurf_arr(i, j, 0);
555 bool over_land = (!lmask_arr) || (lmask_arr(i, j, 0) == 1);
559 const Real
z0 = z0_eff_arr(i, j, 0);
560 const Real ws_layer = ws10_eff_arr(i, j, 0);
562 Ribcr = amrex::min(Real(0.16) * std::pow(Real(1.0e-7) * Rossby, -Real(0.18)), Real(0.3));
570 Real Rib = rib_base_arr(i,j,ksrf);
571 bool above_critical = (Rib >= Ribcr);
574 for (
int kk = ksrf+1; !above_critical && kk <=
khi; ++kk) {
575 if (rib_base_arr(i,j,kk) >= Ribcr) {
577 above_critical =
true;
582 pbli_arr(i, j, 0) = kpbl;
584 BL_PROFILE_VAR_STOP(prof_pblh);
668 constexpr Real GAMCRT = Real(3.0);
669 constexpr Real GAMCRQ = Real(2.e-3);
672 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
674 const int ksrf = ksurf_arr(i, j, 0);
675 const Real zib = zib_arr(i, j, 0);
680 bool over_land = (!lmask_arr) || (lmask_arr(i, j, 0) == 1);
684 const Real
z0 = z0_eff_arr(i, j, 0);
685 const Real ws_layer = ws10_eff_arr(i, j, 0);
687 Ribcr = amrex::min(Real(0.16) * std::pow(Real(1.0e-7) * Rossby, -Real(0.18)), Real(0.3));
700 const Real zl1 = (use_terrain_fitted_coords)
703 const Real dz1 = (use_terrain_fitted_coords)
706 const Real z_max = (use_terrain_fitted_coords)
709 const Real pblh_max = Real(0.9) * z_max;
716 auto rib_at = [=] (
int kk) {
return rib_enhan_arr(i,j,kk); };
717 auto z_at = [=] (
int kk) {
722 pblh_corr_arr(i, j, 0) = pbl.
pblh;
723 pbli_arr(i, j, 0) = pbl.
kpbl;
726 hgamt_arr(i, j, 0) =
zero;
727 hgamq_arr(i, j, 0) =
zero;
728 wstar_arr(i, j, 0) =
zero;
774 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
776 const int ksrf = ksurf_arr(i, j, 0);
777 cloud_top_arr(i, j, 0) = -1;
780 int kpbl = pbli_arr(i, j, 0);
781 for (
int kk = kpbl - 1; kk >= ksrf; --kk) {
782 amrex::Real qc_kk =
zero, qi_kk =
zero;
783 if (moisture_indices.
qc >= 0)
784 qc_kk = cell_data(i, j, kk, moisture_indices.
qc) / cell_data(i, j, kk,
Rho_comp);
785 if (moisture_indices.
qi >= 0)
786 qi_kk = cell_data(i, j, kk, moisture_indices.
qi) / cell_data(i, j, kk,
Rho_comp);
788 if (qc_kk + qi_kk > ysu_qcloud_threshold) {
789 cloud_top_arr(i, j, 0) = kk;
796 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
798 cloud_top_arr(i, j, 0) = -1;
804 const int ksrf = ksurf_arr(i, j, 0);
805 const Real t_layer = t10_eff_arr(i, j, 0);
806 Real obuk_val = ol_eff_arr(i, j, 0);
807 if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
808 obuk_val = (obuk_val >=
zero) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
815 const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
816 const Real HOL_bounded = amrex::max(amrex::min(HOL, Real(100.0)), Real(-100.0));
817 const Real one_quarter = Real(1.0) / Real(4.0);
818 const Real phiM = (obuk_val > 0)
819 ? (1 + 5 * HOL_bounded)
821 amrex::max(1 - 16 * HOL_bounded, Real(0.01)),
823 const Real phiM_safe = amrex::max(phiM, Real(0.01));
829 Real wscale = us_eff_arr(i, j, 0) / phiM_safe;
830 wscale = amrex::max(wscale, us_eff_arr(i, j, 0) / Real(5.0));
831 wscale = amrex::min(wscale, Real(16.0) * us_eff_arr(i, j, 0));
835 amrex::Real wstar3_down =
zero;
836 if (enable_ysu_topdown && cloud_top_arr(i, j, 0) >= ksrf) {
837 int k_cloud_top = cloud_top_arr(i, j, 0);
844 amrex::Real LRAD =
zero;
845 if (has_qheating_rates) {
848 for (
int kk = ksrf; kk <= k_cloud_top; ++kk) {
849 amrex::Real ldz = (use_terrain_fitted_coords)
850 ? (z_nd_arr(i, j, kk+1) - z_nd_arr(i, j, kk))
854 LRAD += -qheat_arr(i, j, kk, 1) * ldz;
860 amrex::Real LRAD_raw = LRAD;
861 amrex::Real LRAD_limited = LRAD;
863 if (enable_ysu_rad_tend_limiter && has_qheating_rates) {
865 if (!amrex::Math::isfinite(LRAD_raw)) {
870 const amrex::Real lim_mag = ysu_rad_tend_limiter_magnitude;
871 LRAD_limited = amrex::min(LRAD_raw, lim_mag);
872 LRAD_limited = amrex::max(LRAD_limited, -lim_mag);
880 const amrex::Real t_local = cell_data(i, j, k_cloud_top,
RhoTheta_comp)
881 / cell_data(i, j, k_cloud_top,
Rho_comp);
882 const amrex::Real rho_ct = cell_data(i, j, k_cloud_top,
Rho_comp);
883 wstar3_down = amrex::max(CONST_GRAV_d / t_local * LRAD
884 / (rho_ct * amrex::Real(1004.0))
885 * pblh_corr_arr(i, j, 0), zero_d);
887 wstar3_down_arr(i, j, 0) = wstar3_down;
890 const Real bfx0_corr = amrex::max(sflux_arr(i, j, 0), zero_d);
891 const Real t_dry = t10_eff_arr(i, j, 0);
892 const Real wstar3_corr = (
CONST_GRAV / t_dry) * bfx0_corr * pblh_corr_arr(i, j, 0);
893 wstar3_arr(i, j, 0) = wstar3_corr;
896 const Real ust3 = us_eff_arr(i, j, 0) * us_eff_arr(i, j, 0) * us_eff_arr(i, j, 0);
897 Real wscale_corr = std::cbrt(ust3 + amrex::Real(8.0) *
KAPPA * wstar3_corr * amrex::Real(0.5));
898 wscale_corr = amrex::min(wscale_corr, us_eff_arr(i, j, 0) * amrex::Real(16.0));
899 wscale_corr = amrex::max(wscale_corr, us_eff_arr(i, j, 0) / amrex::Real(5.0));
900 wstar_arr(i, j, 0) = wscale_corr;
906 bool SFCFLG = (sfcflg_arr(i, j, 0) >
zero);
907 const Real rho_sfc = cell_data(i, j, ksrf,
Rho_comp);
908 const Real hfx_col = -rho_sfc * amrex::Real(1004.0) * us_eff_arr(i, j, 0) * ts_eff_arr(i, j, 0);
909 const Real gamfac = const_b / (rho_sfc * wscale_corr);
910 const Real HGAMT = (SFCFLG && enable_ysu_countergradient)
911 ? amrex::min(gamfac * hfx_col / amrex::Real(1004.0), GAMCRT)
916 const Real qfx_col = -rho_sfc * us_eff_arr(i, j, 0) * qs_eff_arr(i, j, 0);
917 const Real HGAMQ_raw = (SFCFLG &&
use_moisture && enable_ysu_countergradient)
920 Real HGAMQ = amrex::min(amrex::max(HGAMQ_raw, zero_d), GAMCRQ);
923 if (lmask_arr && SFCFLG &&
use_moisture && enable_ysu_countergradient) {
924 bool is_land = (lmask_arr(i,j,0) == 1);
925 if (!is_land) HGAMQ =
zero;
929 if (enable_ysu_sat_limiter && moisture_indices.
qv >= 0 && SFCFLG &&
use_moisture && enable_ysu_countergradient) {
930 Real qv_klo = cell_data(i, j, ksrf, moisture_indices.
qv) / cell_data(i, j, ksrf,
Rho_comp);
935 Real qsat_klo =
zero;
937 Real rh_klo = (qsat_klo > Real(1.0e-10)) ? (qv_klo / qsat_klo) :
zero;
938 if (rh_klo > Real(0.95)) {
939 Real rh_scaling = amrex::max(zero_d, (
one - rh_klo) / Real(0.05));
946 if (pbli_arr(i, j, 0) <= ksrf + 1) {
947 hgamt_arr(i, j, 0) =
zero;
948 hgamq_arr(i, j, 0) =
zero;
949 hgamu_arr(i, j, 0) =
zero;
950 hgamv_arr(i, j, 0) =
zero;
951 vpert_arr(i, j, 0) =
zero;
953 const Real pblh = pblh_corr_arr(i, j, 0);
954 hgamt_arr(i, j, 0) = (enable_ysu_countergradient) ? HGAMT / pblh :
zero;
955 hgamq_arr(i, j, 0) = (enable_ysu_countergradient &&
use_moisture) ? HGAMQ / pblh :
zero;
969 hgamu_arr(i, j, 0) =
zero;
970 hgamv_arr(i, j, 0) =
zero;
971 if (SFCFLG && enable_ysu_countergradient) {
972 const Real wspd_sfc = ws10_eff_arr(i, j, 0);
973 const Real
ustar = us_eff_arr(i, j, 0);
974 wscale = wstar_arr(i, j, 0);
975 const Real wstar3 = wstar3_arr(i, j, 0);
977 const Real wscale4 = amrex::max(wscale * wscale * wscale * wscale,
978 amrex::Real(1.0e-10));
979 const Real brint = amrex::Real(-15.9) *
ustar *
ustar
980 / amrex::max(wspd_sfc, amrex::Real(1.0e-4))
984 const Real u_klo =
myhalf * (uvel(i, j, ksrf) + uvel(i+1, j, ksrf));
985 const Real v_klo =
myhalf * (vvel(i, j, ksrf) + vvel(i, j+1, ksrf));
986 hgamu_arr(i, j, 0) = brint * u_klo / pblh;
987 hgamv_arr(i, j, 0) = brint * v_klo / pblh;
996 if (enable_ysu_countergradient) {
999 const Real zl1_col = (use_terrain_fitted_coords)
1002 constexpr Real sfcfrac_h = amrex::Real(0.1);
1003 const Real height_lim = amrex::min(zl1_col / (sfcfrac_h * pblh), one_d);
1005 const Real VPERT_raw = HGAMT + amrex::Real(0.61) * t_layer * HGAMQ;
1006 const Real VPERT_capped = enable_ysu_unbounded_vpert
1008 : amrex::min(VPERT_raw, GAMCRT);
1009 vpert_arr(i, j, 0) = amrex::max(VPERT_capped, zero_d) * height_lim;
1011 vpert_arr(i, j, 0) =
zero;
1029 BL_PROFILE_VAR(
"YSU_Rib_Recompute", prof_rib_recomp);
1030 ParallelFor(gbx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
1032 const int ksrf = ksurf_arr(i, j, 0);
1033 const Real zib = zib_arr(i, j, 0);
1034 const amrex::Real t_layer = t10_eff_arr(i, j, 0);
1036 const amrex::Real t_layer_v = t_layer * (
one +
epsv * q_frac);
1038 const amrex::Real t_enh = t_layer_v + vpert_arr(i,j,0);
1042 const amrex::Real z_sfc = zib;
1043 const amrex::Real zval = (use_terrain_fitted_coords)
1046 const amrex::Real zrel = amrex::max(zval - z_sfc, amrex::Real(1.0e-4));
1047 const amrex::Real theta_v =
GetThetav(i,j,k,cell_data,moisture_indices);
1048 const amrex::Real theta_v_klo =
GetThetav(i,j,ksrf,cell_data,moisture_indices);
1049 const amrex::Real ws2_raw =
fourth * ((uvel(i,j,k)+uvel(i+1,j,k))*(uvel(i,j,k)+uvel(i+1,j,k))
1050 + (vvel(i,j,k)+vvel(i,j+1,k))*(vvel(i,j,k)+vvel(i,j+1,k)));
1054 : amrex::max(ws2_raw, amrex::Real(1.0));
1056 rib_enhan_arr(i,j,k) =
CONST_GRAV * zrel * (theta_v - t_enh) / (ws2 * theta_v_klo);
1058 BL_PROFILE_VAR_STOP(prof_rib_recomp);
1067 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
1069 const int ksrf = ksurf_arr(i, j, 0);
1070 const Real zib = zib_arr(i, j, 0);
1074 bool over_land = (!lmask_arr) || (lmask_arr(i, j, 0) == 1);
1078 const Real
z0 = z0_eff_arr(i, j, 0);
1079 const Real ws_layer = ws10_eff_arr(i, j, 0);
1081 Ribcr = amrex::min(Real(0.16) * std::pow(Real(1.0e-7) * Rossby, -Real(0.18)), Real(0.3));
1087 const Real zl1 = (use_terrain_fitted_coords)
1090 const Real dz1 = (use_terrain_fitted_coords)
1093 const Real z_max = (use_terrain_fitted_coords)
1096 const Real pblh_max = Real(0.9) * z_max;
1098 pblh_floor_arr(i, j, 0) = pblh_min;
1103 auto rib_at = [=] (
int kk) {
return rib_enhan_arr(i,j,kk); };
1104 auto z_at = [=] (
int kk) {
1109 pblh_corr_arr(i, j, 0) = pbl.
pblh;
1110 pbli_arr(i, j, 0) = pbl.
kpbl;
1111 pbl_open_arr(i, j, 0) = pbl.
crossed ? 0 : 1;
1124 geom.Domain(), geom.periodicity());
1129 ParallelFor(xybx_work, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept {
1130 pblh_corr_arr(i, j, 0) = amrex::max(pblh_corr_arr(i, j, 0), pblh_floor_arr(i, j, 0));
1140 auto pblh_out = pblh_mf.array(mfi);
1141 const Box& tbx = mfi.tilebox();
1142 ParallelFor(tbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept {
1143 pblh_out(i, j, k) = pblh_corr_arr(i, j, 0);
1154 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
1156 const int ksrf = ksurf_arr(i, j, 0);
1157 const Real zib = zib_arr(i, j, 0);
1158 const int kpblold = pbli_arr(i,j,0);
1159 bool definebrup =
false;
1162 const Real thermalli =
GetThetal(i, j, ksrf, cell_data, moisture_indices);
1165 for (
int kk = kpblold; kk <
khi; ++kk) {
1167 const Real ws2_raw =
fourth * ((uvel(i,j,kk)+uvel(i+1,j,kk))*(uvel(i,j,kk)+uvel(i+1,j,kk))
1168 + (vvel(i,j,kk)+vvel(i,j+1,kk))*(vvel(i,j,kk)+vvel(i,j+1,kk)));
1172 : amrex::max(ws2_raw, amrex::Real(1.0));
1176 const Real z_sfc = zib;
1177 const Real zval_kk = (use_terrain_fitted_coords)
1180 const Real zrel_kk = amrex::max(zval_kk - z_sfc, amrex::Real(1.0e-4));
1183 const Real thlix_kk =
GetThetal(i, j, kk, cell_data, moisture_indices);
1184 const Real thlix_klo =
GetThetal(i, j, ksrf, cell_data, moisture_indices);
1187 const Real bruptmp =
CONST_GRAV * zrel_kk * (thlix_kk - thermalli) / (ws2 * thlix_klo);
1190 const bool stable = (bruptmp >=
zero);
1193 pbli_arr(i,j,0) = kk;
1204 pbli_arr(i,j,0) = amrex::min(pbli_arr(i,j,0), izmax);
1230 constexpr Real Ribcr_zero =
zero;
1231 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
1233 const int ksrf = ksurf_arr(i, j, 0);
1236 int kpbl_zero = ksrf;
1237 Real Rib = rib_enhan_arr(i,j,ksrf);
1238 bool above_critical = (Rib >= Ribcr_zero);
1241 for (
int kk = ksrf+1; !above_critical && kk <=
khi; ++kk) {
1242 if (rib_enhan_arr(i,j,kk) >= Ribcr_zero) { kpbl_zero = kk; above_critical =
true;
break; }
1245 pbli_zero_arr(i, j, 0) = kpbl_zero;
1247 BL_PROFILE_VAR_STOP(prof_pblh);
1256 ParallelFor(xybx, [=, zero_d=
zero] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
1258 const int ksrf = ksurf_arr(i, j, 0);
1259 entr_arr(i,j,0) =
zero;
1260 if (!enable_ysu_entrainment)
return;
1264 if (pbl_open_arr(i,j,0) != 0)
return;
1266 const int kpbl = pbli_arr(i,j,0);
1267 const Real rho_kpbl = cell_data(i, j, kpbl,
Rho_comp);
1268 const Real pblh = pblh_corr_arr(i,j,0);
1269 const Real wscale = wstar_arr(i,j,0);
1270 const Real
ustar = us_eff_arr(i, j, 0);
1275 const Real wstar3_col = wstar3_arr(i,j,0);
1276 const Real wm3 = wstar3_col + amrex::Real(5.0) * ustar3;
1277 const Real wm2 = std::pow(wm3, amrex::Real(2.0) / amrex::Real(3.0));
1281 const Real thvx_klo =
GetThetav(i, j, ksrf, cell_data, moisture_indices);
1282 const Real bfxpbl = amrex::Real(-0.15) * thvx_klo /
CONST_GRAV * wm3 / pblh;
1286 const int kpbl_p1 = amrex::min(kpbl + 1, izmax);
1287 const Real thvx_kpbl =
GetThetav(i, j, kpbl, cell_data, moisture_indices);
1288 const Real thvx_kpbl_p1 =
GetThetav(i, j, kpbl_p1, cell_data, moisture_indices);
1289 const Real dthvx = amrex::max(thvx_kpbl_p1 - thvx_kpbl, amrex::Real(1.0e-2));
1293 const Real we = amrex::max(bfxpbl / dthvx, -std::sqrt(wm2));
1296 const Real met_h = (use_terrain_fitted_coords)
1298 const Real dz_kpbl = met_h / dz_inv;
1301 const Real K_cap = Real(5.0) * rho_kpbl * wscale *
KAPPA * pblh * Real(0.01);
1308 Real K_entr_final = (we <
zero) ? rho_kpbl * (-we) * dz_kpbl :
zero;
1311 const int k_below = amrex::max(kpbl - 1, ksrf);
1312 const Real rho_k = cell_data(i, j, k_below,
Rho_comp);
1313 Real qc_below = (moisture_indices.
qc >= 0)
1314 ? cell_data(i, j, k_below, moisture_indices.
qc) / rho_k :
zero;
1315 Real qi_below = (moisture_indices.
qi >= 0)
1316 ? cell_data(i, j, k_below, moisture_indices.
qi) / rho_k :
zero;
1318 constexpr Real cloud_thresh_entr = amrex::Real(0.01e-3);
1320 if ((qc_below + qi_below) > cloud_thresh_entr && kpbl >= ksrf + 2) {
1329 const int k_p2 = amrex::min(kpbl + 1, izmax);
1330 auto thlix_v = [=] (
int kk) {
1331 const Real rho_kk = cell_data(i, j, kk,
Rho_comp);
1332 const Real theta_kk = cell_data(i, j, kk,
RhoTheta_comp) / rho_kk;
1333 const Real qv_kk = (moisture_indices.
qv >= 0)
1334 ? cell_data(i, j, kk, moisture_indices.
qv) / rho_kk :
zero;
1335 const Real qc_kk = (moisture_indices.
qc >= 0)
1336 ? cell_data(i, j, kk, moisture_indices.
qc) / rho_kk :
zero;
1337 return GetThetal(i, j, kk, cell_data, moisture_indices)
1338 + theta_kk *
epsv * (qv_kk + qc_kk);
1340 const Real thlix_kbelow = thlix_v(k_below);
1341 const Real thlix_kp2 = thlix_v(k_p2);
1343 const Real dthvx_li = amrex::max(thlix_kp2 - thlix_kbelow, amrex::Real(0.1));
1347 constexpr Real xlv_over_cp = amrex::Real(2.5e6) / amrex::Real(1004.0);
1348 const Real ent_eff = amrex::min(amrex::Real(0.2) * amrex::Real(8.0)
1349 * xlv_over_cp * qc_below / dthvx_li,
1354 const Real we_cloud = amrex::max(bfxpbl / dthvx_li, -std::sqrt(wm2));
1358 const Real bfx0_cloud = amrex::max(sflux_arr(i, j, 0), zero_d);
1359 const Real bfxpbl_cloud = -ent_eff * bfx0_cloud;
1360 const Real we_cloud_top = amrex::max(bfxpbl_cloud / dthvx_li,
1361 -std::sqrt(std::pow(wm3, amrex::Real(2.0)/amrex::Real(3.0))));
1364 we_final = we_cloud + we_cloud_top;
1367 K_entr_final = (we_final <
zero) ? rho_kpbl * (-we_final) * dz_kpbl :
zero;
1374 entr_arr(i,j,0) = amrex::min(K_entr_final, K_cap);
1385 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
1387 const int kpbl_current = pbli_arr(i, j, 0);
1390 amrex::Real qc_kpbl =
zero, qi_kpbl =
zero;
1391 if (moisture_indices.
qc >= 0)
1392 qc_kpbl = cell_data(i, j, kpbl_current, moisture_indices.
qc) / cell_data(i, j, kpbl_current,
Rho_comp);
1393 if (moisture_indices.
qi >= 0)
1394 qi_kpbl = cell_data(i, j, kpbl_current, moisture_indices.
qi) / cell_data(i, j, kpbl_current,
Rho_comp);
1397 if ((qc_kpbl + qi_kpbl) > ysu_qcloud_threshold) {
1398 pbli_arr(i, j, 0) = amrex::min(kpbl_current + 1, izmax);
1405 FArrayBox K_down_fab(gbx, 1, The_Async_Arena());
1406 K_down_fab.setVal<RunOn::Device>(
zero);
1407 const auto& K_down_arr = K_down_fab.array();
1409 if (enable_ysu_topdown) {
1410 ParallelFor(gbx, [=, zero_d=
zero] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
1412 const int ksrf = ksurf_arr(i, j, 0);
1413 const Real zib = zib_arr(i, j, 0);
1414 K_down_arr(i,j,k) =
zero;
1415 if (k >= pbli_arr(i,j,0) || k < ksrf)
return;
1417 const amrex::Real
rho = cell_data(i,j,k,
Rho_comp);
1418 const amrex::Real pblh = pblh_corr_arr(i,j,0);
1419 const amrex::Real zval = (use_terrain_fitted_coords)
1423 const amrex::Real z_sfc = zib;
1424 const amrex::Real zrel = zval - z_sfc;
1425 const amrex::Real pblh_rel = amrex::max(pblh - z_sfc, amrex::Real(1.0e-4));
1430 const amrex::Real wstar3_down_col = wstar3_down_arr(i,j,0);
1431 const amrex::Real wstar_down_eff = (wstar3_down_col >
zero)
1432 ? std::cbrt(wstar3_down_col)
1434 const amrex::Real zfac_up = amrex::max(zrel / pblh_rel, zero_d);
1435 K_down_arr(i,j,k) =
rho * wstar_down_eff *
KAPPA
1436 * amrex::max(pblh_rel - zrel, zero_d)
1437 * zfac_up * zfac_up;
1443 const Array4<Real>& K_turb = eddyViscosity.array(mfi);
1454 BL_PROFILE_VAR(
"YSU_Kprofile", prof_kprof);
1455 ParallelFor(gbx, [=, wstar3_arr_cap=wstar3_arr, zol1_arr_cap=zol1_arr, sfcflg_arr_cap=sfcflg_arr,
1456 zero_d=
zero, one_d=
one, two_d=
two] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
1458 const int ksrf = ksurf_arr(i, j, 0);
1459 const Real zib = zib_arr(i, j, 0);
1461 const Real rho_guard = cell_data(i, j, k,
Rho_comp);
1462 if (rho_guard <= Real(0)) {
1474 Real obuk_val = ol_eff_arr(i, j, 0);
1475 if (std::abs(obuk_val) < amrex::Real(1.0e-10)) {
1476 obuk_val = (obuk_val >=
zero) ? amrex::Real(1.0e-10) : amrex::Real(-1.0e-10);
1479 const Real zval = (use_terrain_fitted_coords)
1492 const Real met_h_zeta = (use_terrain_fitted_coords)
1494 const Real dz_terrain = met_h_zeta / dz_inv;
1515 constexpr Real qc_threshold = Real(1.0e-5);
1520 if (moisture_indices.
qc >= 0) {
1521 qc_mix = cell_data(i, j, k, moisture_indices.
qc) /
rho;
1523 if (moisture_indices.
qi >= 0) {
1524 qi_mix = cell_data(i, j, k, moisture_indices.
qi) /
rho;
1527 const Real total_qcloud = qc_mix + qi_mix;
1528 const bool has_cloud = (total_qcloud > qc_threshold);
1537 if (k < pbli_extent) {
1558 bool SFCFLG = (sfcflg_arr_cap(i, j, 0) >
zero);
1564 const Real HOL = sf * pblh_corr_arr(i, j, 0) / obuk_val;
1565 const Real HOL_bounded = amrex::max(amrex::min(HOL, Real(100.0)), Real(-100.0));
1567 const Real one_quarter = Real(1.0) / Real(4.0);
1568 const Real phiM = (obuk_val > 0)
1569 ? (1 + 5 * HOL_bounded)
1571 amrex::max(1 - 16 * HOL_bounded, Real(0.01)),
1578 const Real phit = (obuk_val > 0)
1579 ? (1 + 5 * HOL_bounded)
1581 amrex::max(1 - 16 * HOL_bounded, Real(0.01)),
1590 Real phit_cloud = phit;
1591 Real phiM_cloud = phiM;
1592 if (has_cloud && obuk_val >
zero) {
1596 Real reduction_factor =
one - Real(0.15) * amrex::min(total_qcloud / qc_threshold, one_d);
1598 phiM_cloud =
one + Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1599 phit_cloud =
one + Real(5.0) * reduction_factor * sf * pblh_corr_arr(i, j, 0) / obuk_val;
1600 }
else if (has_cloud && obuk_val <=
zero) {
1604 Real cloud_boost = Real(1.0) + Real(0.05) * amrex::min(total_qcloud / qc_threshold, one_d);
1607 phiM_cloud = std::pow(
1608 amrex::max(one_d - Real(16.0) * HOL_bounded / cloud_boost, Real(0.01)),
1610 phit_cloud = std::pow(
1611 amrex::max(one_d - Real(16.0) * HOL_bounded / cloud_boost, Real(0.01)),
1616 const Real phiM_eff = phiM_cloud;
1617 const Real phit_eff = phit_cloud;
1628 constexpr Real bfac = amrex::Real(6.8);
1629 constexpr Real sfcfrac = amrex::Real(0.1);
1630 const Real conpr = bfac *
KAPPA * sfcfrac;
1633 const Real zq_kp1_prandtl = zval +
myhalf * dz_terrain;
1637 const Real prfac = SFCFLG ? conpr :
zero;
1642 const Real wstar3_col = wstar3_arr_cap(i, j, 0);
1643 const Real ust3 = us_eff_arr(i, j, 0) * us_eff_arr(i, j, 0) * us_eff_arr(i, j, 0);
1646 const Real wstar3_2 = wstar3_down_arr(i, j, 0);
1649 if (SFCFLG && ust3 > amrex::Real(1.0e-10)) {
1650 const Real wstar_tot3 = wstar3_col + wstar3_2;
1651 prfac2 = amrex::Real(15.9) * wstar_tot3 / ust3
1652 / (
one + amrex::Real(4.0) *
KAPPA * wstar_tot3 / ust3);
1658 const Real pblh = pblh_corr_arr(i, j, 0);
1659 const Real sfclayer = sfcfrac * pblh;
1660 const Real zdiff = amrex::max(zq_kp1_prandtl - sfclayer, zero_d);
1661 const Real prnumfac = amrex::Real(-3.0) * zdiff * zdiff / (pblh * pblh);
1665 constexpr Real prmin_wrf = amrex::Real(0.25);
1666 constexpr Real prmax_wrf = amrex::Real(4.0);
1667 Real prnum0 = (phit_eff / phiM_eff) + prfac;
1668 prnum0 = amrex::min(amrex::max(prnum0, prmin_wrf), prmax_wrf);
1672 Real prnum0_heat = prnum0 / (
one + prfac2 *
KAPPA * sfcfrac);
1673 prnum0_heat = amrex::min(amrex::max(prnum0_heat, prmin_wrf), prmax_wrf);
1674 const Real Prt =
one + (prnum0_heat -
one) * std::exp(prnumfac);
1678 const Real prnum_q =
one + (prnum0 -
one) * std::exp(prnumfac);
1695 const Real zq_kp1 = zval +
myhalf * dz_terrain;
1698 const Real zl1 = (use_terrain_fitted_coords)
1704 constexpr Real zfacmin = amrex::Real(1.0e-8);
1705 const Real pblh_rel = amrex::max(pblh_corr_arr(i, j, 0) - zl1, amrex::Real(1.0e-4));
1706 const Real zfac = amrex::min(
1707 amrex::max(one_d - (zq_kp1 - zl1) / pblh_rel, zfacmin), one_d);
1711 const Real ust3_wscale = us_eff_arr(i, j, 0) * us_eff_arr(i, j, 0) * us_eff_arr(i, j, 0);
1715 wscalek_val = std::cbrt(ust3_wscale + amrex::Real(8.0) *
KAPPA * wstar3_col * (
one - zfac));
1721 constexpr Real ckz_pbl = Real(0.001);
1722 const Real K_base = ckz_pbl * dz_terrain *
rho;
1723 constexpr Real pfac = amrex::Real(2.0);
1724 K_turb(i, j, k,
EddyDiff::Mom_v) = K_base +
rho * wscalek_val *
KAPPA * (zq_kp1 - zib) * std::pow(zfac, pfac);
1735 if (enable_ysu_topdown && k < pbli_arr(i, j, 0)) {
1746 const Real zq_kp1_stable = zval +
myhalf * dz_terrain;
1749 const Real zl1_stable = (use_terrain_fitted_coords)
1754 constexpr Real zfacmin_stable = amrex::Real(1.0e-8);
1755 const Real pblh_rel_stable = amrex::max(pblh_corr_arr(i, j, 0) - zl1_stable, amrex::Real(1.0e-4));
1756 const Real zfac_stable = amrex::min(
1757 amrex::max(one_d - (zq_kp1_stable - zl1_stable) / pblh_rel_stable, zfacmin_stable), one_d);
1761 const Real zol1_stable = zol1_arr_cap(i, j, 0);
1762 const Real zol_ratio = (zq_kp1_stable - zib) / (zl1_stable - zib);
1763 const Real phim_stable_arg = zol1_stable * zol_ratio;
1766 const Real qnse_am_d = turbChoice.
qnse_am;
1767 const Real qnse_bm_d = turbChoice.
qnse_bm;
1768 const Real phim_stable = (enable_qnse_d > Real(0.5))
1769 ? ((
one + qnse_am_d * phim_stable_arg) / (
one + qnse_bm_d * phim_stable_arg))
1770 : (
one + amrex::Real(5.0) * phim_stable_arg);
1771 const Real wscalek_stable = amrex::max(
1772 us_eff_arr(i, j, 0) / amrex::max(phim_stable, amrex::Real(0.01)),
1773 amrex::Real(0.001));
1776 constexpr Real ckz_pbl_stable = Real(0.001);
1777 const Real K_base_stable = ckz_pbl_stable * dz_terrain *
rho;
1778 constexpr Real pfac_stable = amrex::Real(2.0);
1779 K_turb(i, j, k,
EddyDiff::Mom_v) = K_base_stable +
rho * wscalek_stable *
KAPPA * (zq_kp1_stable - zib) * std::pow(zfac_stable, pfac_stable);
1784 const Real prnum_stable =
one + (prnum0 -
one) * std::exp(prnumfac);
1793 }
else if (k >= pbli_extent) {
1798 const Real lambda_min = Real(30.0);
1799 const Real lambda_max = Real(300.0);
1800 const Real lambdadz = amrex::min(amrex::max(Real(0.1) * dz_terrain, lambda_min), lambda_max);
1801 const Real lscale = (lambdadz *
KAPPA * zval) / (lambdadz +
KAPPA * zval);
1802 Real dthetadz, dudz, dvdz;
1803 ComputeVerticalDerivativesPBL(i, j, k, uvel, vvel, cell_data, izmin, izmax, pbl_derivative_dz_inv(i,j,k),
1804 c_ext_dir_on_zlo, c_ext_dir_on_zhi, u_ext_dir_on_zlo,
1805 u_ext_dir_on_zhi, v_ext_dir_on_zlo, v_ext_dir_on_zhi, dthetadz,
1806 dudz, dvdz, moisture_indices, pbl_strat);
1815 const Real zrel_sl = amrex::max(zval - zib, Real(1.0e-4));
1817 const Real
qv = (moisture_indices.
qv >= 0) ?
1818 cell_data(i, j, k, moisture_indices.
qv) /
rho :
zero;
1820 sl.
u_star = us_eff_arr(i, j, 0);
1825 sl.
zeta = zrel_sl / obuk_val;
1831 const Real dudz_safe = (k < izmax) ? dudz :
zero;
1832 const Real dvdz_safe = (k < izmax) ? dvdz :
zero;
1836 const Real wind_shear = dudz_safe * dudz_safe + dvdz_safe * dvdz_safe;
1837 const Real wind_shear_safe = std::max(wind_shear, Real(1.0e-8));
1843 const Real theta_v =
GetThetav(i, j, k, cell_data, moisture_indices);
1844 const Real dtheta_v_dz = dthetadz;
1857 Real grad_Ri =
CONST_GRAV / theta_v * dtheta_v_dz / wind_shear_safe;
1858 grad_Ri = std::max(std::min(grad_Ri, Real(100.0)), -Real(100.0));
1864 const Real rho_k = cell_data(i,j,k,
Rho_comp);
1865 const Real rho_kp1 = cell_data(i,j,k+1,
Rho_comp);
1866 Real qc_k = (moisture_indices.
qc >= 0) ? cell_data(i,j,k, moisture_indices.
qc)/rho_k :
zero;
1867 Real qc_kp1 = (moisture_indices.
qc >= 0) ? cell_data(i,j,k+1,moisture_indices.
qc)/rho_kp1 :
zero;
1868 Real qi_k = (moisture_indices.
qi >= 0) ? cell_data(i,j,k, moisture_indices.
qi)/rho_k :
zero;
1869 Real qi_kp1 = (moisture_indices.
qi >= 0) ? cell_data(i,j,k+1,moisture_indices.
qi)/rho_kp1 :
zero;
1871 constexpr Real cloud_thresh = amrex::Real(0.01e-3);
1872 if ((qc_k + qi_k) > cloud_thresh && (qc_kp1 + qi_kp1) > cloud_thresh) {
1879 const Real qv_k_mri = (moisture_indices.
qv >= 0)
1880 ? cell_data(i,j,k, moisture_indices.
qv) / rho_k :
zero;
1881 const Real qv_kp1_mri = (moisture_indices.
qv >= 0)
1882 ? cell_data(i,j,k+1,moisture_indices.
qv) / rho_kp1 :
zero;
1886 const Real tmean =
myhalf * (T_k + T_kp1);
1887 const Real qmean =
myhalf * (qv_k_mri + qv_kp1_mri);
1888 constexpr Real
xlv = amrex::Real(2.5e6);
1889 constexpr Real rd = amrex::Real(287.0);
1890 constexpr Real rv = amrex::Real(461.5);
1891 constexpr Real
cp = amrex::Real(1004.0);
1892 const Real
alpha =
xlv * qmean / (rd * tmean);
1893 const Real chi =
xlv *
xlv * qmean / (
cp * rv * tmean * tmean);
1898 grad_Ri = amrex::max(amrex::min(grad_Ri, amrex::Real(100.0)), amrex::Real(-100.0));
1916 const Real grad_Ri_safe = amrex::max(grad_Ri, -Real(100.0));
1917 const Real fm = (grad_Ri_safe > 0)
1918 ?
one / ((
one + Real(5.0) * grad_Ri_safe) * (
one + Real(5.0) * grad_Ri_safe))
1919 : 1 - 8 * grad_Ri_safe / (1 + Real(1.746) * std::sqrt(amrex::max(-grad_Ri_safe, zero_d)));
1920 const Real ft = (grad_Ri_safe > 0)
1921 ?
one / ((
one + Real(5.0) * grad_Ri_safe) * (
one + Real(5.0) * grad_Ri_safe))
1922 : 1 - 8 * grad_Ri_safe / (1 + Real(1.286) * std::sqrt(amrex::max(-grad_Ri_safe, zero_d)));
1923 const Real rl2wsp =
rho * lscale * lscale * std::sqrt(wind_shear);
1927 if (grad_Ri_safe > 0) {
1928 Real Pr = amrex::min(amrex::max(
one + Real(2.1) * grad_Ri, Real(0.25)), Real(4.0));
1946 if (k == pbli_arr(i,j,0)) {
1972 Real rhoKmin, rhoKmax;
1977 constexpr Real ckz = Real(0.001);
1978 constexpr Real Kmax = Real(1000.0);
1979 rhoKmin = ckz * dz_terrain *
rho;
1980 rhoKmax =
rho * Kmax;
1985 constexpr Real Kmin = Real(0.1);
1986 constexpr Real Kmax = Real(300.0);
1987 rhoKmin =
rho * Kmin;
1988 rhoKmax =
rho * Kmax;
1991 #ifdef ERF_USE_WINDFARM
2005 if (k < pbli_extent) {
2006 constexpr Real xkzminm = amrex::Real(0.1);
2007 constexpr Real xkzminh = amrex::Real(0.01);
2020 std::min(K_turb(i, j, k,
EddyDiff::Q_v), rhoKmax), rhoKmin);
2046 if (k < pbli_extent) {
2060 BL_PROFILE_VAR_STOP(prof_kprof);
2064 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int ) noexcept
2089 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:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:12
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:127
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:265
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
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real GetThetal(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:127
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 real_eps
Definition: ERF_NumericalConstants.H:34
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
std::unique_ptr< amrex::MultiFab > WidenForPBLH(const amrex::MultiFab &src, const int ng, const std::function< void(amrex::MultiFab &)> &fill)
Definition: ERF_PBLModels.H:789
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:291
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:706
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void ApplySurfaceLayerGradientsPBL(const PBLSurfaceLayerGradient &sl, amrex::Real &dthetadz, amrex::Real &dudz, amrex::Real &dvdz)
Definition: ERF_PBLModels.H:411
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real ComputeVirtualTStarPBL(amrex::Real t_star, amrex::Real q_star, amrex::Real theta, amrex::Real qv, bool use_moisture)
Definition: ERF_PBLModels.H:374
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
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_sfc_nd, const amrex::Array4< const amrex::Real > &z_nd)
Definition: ERF_TerrainMetrics.H:764
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:202
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ yvel_bc
Definition: ERF_IndexDefines.H:139
@ cons_bc
Definition: ERF_IndexDefines.H:122
@ xvel_bc
Definition: ERF_IndexDefines.H:138
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ Theta_v
Definition: ERF_IndexDefines.H:267
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:271
@ HGAMU_v
Definition: ERF_IndexDefines.H:279
@ Q_v
Definition: ERF_IndexDefines.H:270
@ Mom_v
Definition: ERF_IndexDefines.H:266
@ HGAMQ_v
Definition: ERF_IndexDefines.H:278
@ HGAMT_v
Definition: ERF_IndexDefines.H:277
@ HGAMV_v
Definition: ERF_IndexDefines.H:280
@ ustar
Definition: ERF_SLM.H:30
@ ks
Definition: ERF_SLM.H:76
@ qstar
Definition: ERF_SLM.H:32
@ tstar
Definition: ERF_SLM.H:31
@ rho
Definition: ERF_Kessler.H:25
@ theta
Definition: ERF_Kessler.H:26
@ qv
Definition: ERF_Kessler.H:31
@ alpha
Definition: ERF_SLM.H:153
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
real(c_double), parameter cp
Definition: ERF_module_model_constants.F90:22
real(c_double), parameter xlv
Definition: ERF_module_model_constants.F90:57
int qi
cloud ice
Definition: ERF_DataStruct.H:292
int qv
water vapor
Definition: ERF_DataStruct.H:290
int qc
cloud liquid water
Definition: ERF_DataStruct.H:291
Functor for inverse vertical spacings for terrain-following grids using cell-center heights.
Definition: ERF_PBLModels.H:652
Definition: ERF_PBLModels.H:353
amrex::Real tstar_v
virtual temperature scale
Definition: ERF_PBLModels.H:355
amrex::Real zeta
stability coordinate z/L
Definition: ERF_PBLModels.H:357
similarity_funs sfuns
the surface layer's similarity functions (most.stable_functions)
Definition: ERF_PBLModels.H:358
amrex::Real u_star
friction velocity
Definition: ERF_PBLModels.H:354
amrex::Real zval
height of the cell center above the surface
Definition: ERF_PBLModels.H:356
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
bool enable_mrf_unbounded_vpert
Whether MRF leaves VPERT unlimited by GAMCRT.
Definition: ERF_TurbStruct.H:1129
bool pbl_mrf_use_zero_ri_extent
Whether MRF uses the Ri=0 K-profile extent.
Definition: ERF_TurbStruct.H:1130
StratType pbl_strat_type
Definition: ERF_TurbStruct.H:951
bool enable_vh96_shear_correction
Whether Vogelezang & Holtslag (1996) shear-correction term is enabled.
Definition: ERF_TurbStruct.H:1106
bool enable_ysu_entrainment
Whether YSU entrainment-layer parameterization is enabled.
Definition: ERF_TurbStruct.H:1093
bool enable_ysu_sat_limiter
Whether YSU applies a saturation limiter to moisture countergradient terms.
Definition: ERF_TurbStruct.H:1089
bool enable_ysu_cloud_pblh
Whether the YSU PBL-top cell index is raised by one where that cell is cloudy.
Definition: ERF_TurbStruct.H:1095
amrex::Real pbl_mrf_const_b
MRF constant used to compute PBL height.
Definition: ERF_TurbStruct.H:1114
amrex::Real pblh_smoothing_weight
Center-cell weight in PBLH smoothing stencil (must be in [0,1]).
Definition: ERF_TurbStruct.H:1110
amrex::Real ysu_qcloud_threshold
Cloud water plus cloud ice threshold for YSU [kg/kg].
Definition: ERF_TurbStruct.H:1098
amrex::Real qnse_bm
Definition: ERF_TurbStruct.H:1141
bool enable_qnse_stable_functions
Definition: ERF_TurbStruct.H:1138
bool enable_ysu_countergradient
Whether YSU countergradient corrections are enabled.
Definition: ERF_TurbStruct.H:1087
bool enable_pblh_smoothing
Whether spatial smoothing of diagnosed PBLH is enabled.
Definition: ERF_TurbStruct.H:1108
int pblh_smoothing_passes
Number of PBLH smoothing iterations to apply.
Definition: ERF_TurbStruct.H:1109
amrex::Real pbl_ib_z0
Definition: ERF_TurbStruct.H:1125
bool enable_ysu_topdown
Whether YSU top-down mixing is enabled.
Definition: ERF_TurbStruct.H:1091
bool pbl_ib_aware
Definition: ERF_TurbStruct.H:1124
amrex::Real ysu_rad_tend_limiter_magnitude
Definition: ERF_TurbStruct.H:1104
amrex::Real pbl_ysu_land_Ribcr
Critical bulk Richardson number over land for stable YSU conditions.
Definition: ERF_TurbStruct.H:1085
amrex::Real vh96_shear_const_b
Vogelezang & Holtslag (1996) shear-correction constant b.
Definition: ERF_TurbStruct.H:1107
amrex::Real qnse_am
Definition: ERF_TurbStruct.H:1140
amrex::Real pbl_mrf_sf
MRF surface flux value used to compute PBL height.
Definition: ERF_TurbStruct.H:1115
bool pbl_ysunew_highres_bounds
Whether YSU applies high-resolution grid-dependent diffusivity bounds.
Definition: ERF_TurbStruct.H:1101
amrex::Real pbl_ysu_coriolis_freq
Coriolis frequency used by YSU-family PBL schemes.
Definition: ERF_TurbStruct.H:1079
bool ysu_moistvars
Whether YSU applies turbulence to moisture variables.
Definition: ERF_TurbStruct.H:1100
bool enable_ysu_rad_tend_limiter
Definition: ERF_TurbStruct.H:1103
Definition: ERF_MOSTUtils.H:84