33 int klo = geom.Domain().smallEnd(2);
34 int khi = geom.Domain().bigEnd(2);
37 #pragma omp parallel if (Gpu::notInLaunchRegion())
39 for (MFIter mfi(eddyViscosity,
TileNoZ()); mfi.isValid(); ++mfi) {
42 const Box& gbx = mfi.growntilebox(IntVect(1,1,0));
43 AMREX_ALWAYS_ASSERT( gbx.smallEnd(2) == klo &&
44 gbx.bigEnd(2) == khi );
49 const GeometryData gdata = geom.data();
50 const Box xybx = PerpendicularBox<ZDir>(gbx, IntVect{0, 0, 0});
51 FArrayBox pbl_height_predictor(xybx, 1, The_Async_Arena());
52 FArrayBox pbl_height_corrector(xybx, 1, The_Async_Arena());
53 IArrayBox pbl_index(xybx, 1, The_Async_Arena());
54 const auto& pblh_arr = pbl_height_predictor.array();
55 const auto& pblh_corr_arr = pbl_height_corrector.array();
56 const auto& pbli_arr = pbl_index.array();
59 const auto& cell_data = cons_in.const_array(mfi);
60 const auto& uvel =
xvel.const_array(mfi);
61 const auto& vvel =
yvel.const_array(mfi);
65 const auto& u_star_arr = SurfLayer->get_u_star(level)->const_array(mfi);
66 const auto& t_star_arr = SurfLayer->get_t_star(level)->const_array(mfi);
67 const auto& l_obuk_arr = SurfLayer->get_olen(level)->const_array(mfi);
68 const auto& t10av_arr = SurfLayer->get_mac_avg(level, 2)->const_array(mfi);
69 const auto& t_surf_arr = SurfLayer->get_t_surf(level)->const_array(mfi);
70 const Array4<Real const> z_nd_arr = z_phys_nd->array(mfi);
72 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
74 const Real t_surf = t_surf_arr(i, j, 0);
75 const Real t_layer = t10av_arr(i, j, 0);
79 bool above_critical =
false;
80 while (!above_critical && ((kpbl + 1) <= khi)) {
81 zval = (use_terrain_fitted_coords)
83 : gdata.ProbLo(2) + (kpbl + 0.5) * gdata.CellSize(2);
88 const Real ws2 = 0.25 * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
89 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
90 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
91 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
92 const Real Rib =
CONST_GRAV * zval * (
theta - t_surf) / (ws2 * t_layer);
93 above_critical = (Rib >= Ribcr);
101 const Real pblh_emp = gdata.ProbLo(2) + 0.5 * gdata.CellSize(2);
102 pblh_arr(i, j, 0) = (above_critical) ? zval : pblh_emp;
103 pbli_arr(i, j, 0) = (above_critical) ? kpbl : 1;
109 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int) noexcept
111 const Real t_layer = t10av_arr(i, j, 0);
112 const Real phiM = (l_obuk_arr(i, j, 0) > 0)
113 ? (1 + 5 * sf * pblh_arr(i, j, 0) / l_obuk_arr(i, j, 0))
115 (1 - 8 * sf * pblh_arr(i, j, 0) / l_obuk_arr(i, j, 0)),
117 const Real wstar = u_star_arr(i, j, 0) / phiM;
118 const Real t_excess = -const_b * u_star_arr(i, j, 0) * t_star_arr(i, j, 0) / wstar;
119 const Real t_surf = t_layer + std::max(std::min(t_excess, 3.0), 0.0);
123 bool above_critical =
false;
124 while (!above_critical && ((kpbl + 1) <= khi)) {
125 zval = (use_terrain_fitted_coords)
127 : gdata.ProbLo(2) + (kpbl + 0.5) * gdata.CellSize(2);
131 const Real ws2 = 0.25 * ( (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) *
132 (uvel(i, j, kpbl) + uvel(i + 1, j, kpbl)) +
133 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) *
134 (vvel(i, j, kpbl) + vvel(i, j + 1, kpbl)) );
135 const Real Rib =
CONST_GRAV * zval * (
theta - t_surf) / (ws2 * t_layer);
136 above_critical = (Rib >= Ribcr);
140 const Real pblh_emp = gdata.ProbLo(2) + 0.5 * gdata.CellSize(2);
141 pblh_corr_arr(i, j, 0) = (above_critical) ? zval : pblh_emp;
142 pbli_arr(i, j, 0) = (above_critical) ? kpbl : 1;
154 const Array4<Real>& K_turb = eddyViscosity.array(mfi);
164 const auto& dxInv = geom.InvCellSizeArray();
165 const Real dz_inv = geom.InvCellSize(2);
166 const int izmin = geom.Domain().smallEnd(2);
167 const int izmax = geom.Domain().bigEnd(2);
169 ParallelFor(gbx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k) noexcept
171 const Real zval = (use_terrain_fitted_coords)
173 : gdata.ProbLo(2) + (k + 0.5) * gdata.CellSize(2);
175 const Real met_h_zeta = (use_terrain_fitted_coords)
177 const Real dz_terrain = met_h_zeta / dz_inv;
178 if (k < pbli_arr(i, j, 0)) {
179 const Real phiM = (l_obuk_arr(i, j, 0) > 0)
180 ? (1 + 5 * sf * pblh_arr(i, j, 0) / l_obuk_arr(i, j, 0))
182 (1 - 8 * sf * pblh_arr(i, j, 0) / l_obuk_arr(i, j, 0)),
184 const Real phit = (l_obuk_arr(i, j, 0) > 0)
185 ? (1 + 5 * sf * pblh_arr(i, j, 0) / l_obuk_arr(i, j, 0))
187 (1 - 16 * sf * pblh_arr(i, j, 0) / l_obuk_arr(i, j, 0)),
189 const Real Prt = phit / phiM + const_b *
KAPPA * sf;
190 const Real wstar = u_star_arr(i, j, 0) / phiM;
192 * (1 - zval / pblh_corr_arr(i, j, 0))
193 * (1 - zval / pblh_corr_arr(i, j, 0));
196 const Real lambda = 150.0;
197 const Real lscale = (
KAPPA * zval * lambda) / (
KAPPA * zval + lambda);
198 Real dthetadz, dudz, dvdz;
199 const int RhoQv_comp = -1;
200 const int RhoQc_comp = -1;
201 const int RhoQr_comp = -1;
203 c_ext_dir_on_zlo, c_ext_dir_on_zhi, u_ext_dir_on_zlo,
204 u_ext_dir_on_zhi, v_ext_dir_on_zlo, v_ext_dir_on_zhi, dthetadz,
205 dudz, dvdz, RhoQv_comp, RhoQc_comp, RhoQr_comp);
206 const Real wind_shear = dudz * dudz + dvdz * dvdz + 1.0e-9;
208 const Real grad_Ri = std::max(
CONST_GRAV /
theta * dthetadz / wind_shear, -100.0);
221 const Real Pr = 1.0 + 2.1 * grad_Ri;
222 const Real fm = (grad_Ri > 0)
223 ? 1.0 / ((1.0 + 5.0 * grad_Ri) * (1.0 + 5.0 * grad_Ri))
224 : 1 - 8 * grad_Ri / (1 + 1.746 * std::sqrt(-grad_Ri));
225 const Real ft = (grad_Ri > 0)
226 ? 1.0 / ((1.0 + 5.0 * grad_Ri) * (1.0 + 5.0 * grad_Ri))
227 : 1 - 8 * grad_Ri / (1 + 1.286 * std::sqrt(-grad_Ri));
228 const Real rl2wsp =
rho * lscale * lscale * std::sqrt(wind_shear);
235 constexpr Real ckz = 0.001;
236 constexpr Real Kmax = 1000.0;
237 const Real rhoKmin = ckz * dz_terrain *
rho;
238 const Real rhoKmax =
rho * Kmax;
248 ParallelFor(xybx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int ) noexcept
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:20
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
TurbChoice turbChoice
Definition: ERF_DiffSetup.H:2
#define Rho_comp
Definition: ERF_IndexDefines.H:36
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
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 amrex::Real &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 int RhoQv_comp, const int RhoQc_comp, const int RhoQr_comp)
Definition: ERF_PBLModels.H:149
AMREX_FORCE_INLINE AMREX_GPU_DEVICE 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:47
AMREX_GPU_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:390
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ yvel_bc
Definition: ERF_IndexDefines.H:88
@ cons_bc
Definition: ERF_IndexDefines.H:76
@ xvel_bc
Definition: ERF_IndexDefines.H:87
@ ext_dir
Definition: ERF_IndexDefines.H:209
@ Theta_v
Definition: ERF_IndexDefines.H:176
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:180
@ Q_v
Definition: ERF_IndexDefines.H:179
@ Mom_v
Definition: ERF_IndexDefines.H:175
@ theta
Definition: ERF_MM5.H:20
@ rho
Definition: ERF_Kessler.H:22
@ xvel
Definition: ERF_IndexDefines.H:141
@ yvel
Definition: ERF_IndexDefines.H:142
amrex::Real pbl_mrf_const_b
Definition: ERF_TurbStruct.H:389
amrex::Real pbl_mrf_Ribcr
Definition: ERF_TurbStruct.H:387
amrex::Real pbl_mrf_sf
Definition: ERF_TurbStruct.H:391