24 const bool use_terrain = (z_phys_nd !=
nullptr);
36 #pragma omp parallel if (Gpu::notInLaunchRegion())
38 for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
41 const Box &bx = mfi.growntilebox(1);
42 const Box &dbx = geom.Domain();
43 Box sbx(bx.smallEnd(), bx.bigEnd());
45 AMREX_ALWAYS_ASSERT(sbx.smallEnd(2) == dbx.smallEnd(2) && sbx.bigEnd(2) == dbx.bigEnd(2));
48 const auto& cell_data = cons_in.const_array(mfi);
49 const auto& uvel =
xvel.const_array(mfi);
50 const auto& vvel =
yvel.const_array(mfi);
52 const auto& z0_arr = most->get_z0(level)->const_array();
53 const auto& ws10av_arr = most->get_mac_avg(level,5)->const_array(mfi);
54 const auto& t10av_arr = most->get_mac_avg(level,2)->const_array(mfi);
55 const auto& t_surf_arr = most->get_t_surf(level)->const_array(mfi);
56 const auto& over_land_arr = (most->get_lmask(level)) ? most->get_lmask(level)->const_array(mfi) : Array4<int> {};
57 const Array4<Real const> z_nd_arr = use_terrain ? z_phys_nd->array(mfi) : Array4<Real>{};
58 const Real most_zref = most->get_zref();
61 bool invalid_zref =
false;
63 invalid_zref = most_zref != 10.0;
66 Real dz = geom.CellSize(2);
67 invalid_zref = int((most_zref - 0.5*dz)/dz) != int((10.0 - 0.5*dz)/dz);
70 Print() <<
"most_zref = " << most_zref << std::endl;
71 Abort(
"MOST Zref must be 10m for YSU PBL scheme");
75 const GeometryData gdata = geom.data();
76 const Box xybx = PerpendicularBox<ZDir>(bx, IntVect{0,0,0});
77 FArrayBox pbl_height(xybx,1);
78 IArrayBox pbl_index(xybx,1);
79 const auto& pblh_arr = pbl_height.array();
80 const auto& pbli_arr = pbl_index.array();
88 ParallelFor(xybx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int) noexcept
92 const Real t_surf = t_surf_arr(i,j,0);
93 const Real t_layer = t10av_arr(i,j,0);
94 const Real ws_layer = ws10av_arr(i,j,0);
95 const Real Rib_layer =
CONST_GRAV * most_zref / (ws_layer*ws_layer) * (t_layer - t_surf)/(t_layer);
98 if (Rib_layer < unst_Ribcr) {
99 Abort(
"For now, YSU PBL only supports stable conditions");
106 bool over_land = (over_land_arr) ? over_land_arr(i,j,0) : 1;
107 if (over_land && !force_over_water) {
112 const Real z0 = z0_arr(i,j,0);
113 const Real Rossby = ws_layer/(f0*z0);
114 Rib_cr = min(0.16*std::pow(1.0e-7*Rossby,-0.18),0.3);
117 bool above_critical =
false;
119 Real Rib_up = Rib_layer, Rib_dn;
121 while (!above_critical and bx.contains(i,j,kpbl+1)) {
123 const Real zval = use_terrain ?
Compute_Zrel_AtCellCenter(i,j,kpbl,z_nd_arr) : gdata.ProbLo(2) + (kpbl + 0.5)*gdata.CellSize(2);
124 const Real ws2_level = 0.25*( (uvel(i,j,kpbl)+uvel(i+1,j ,kpbl))*(uvel(i,j,kpbl)+uvel(i+1,j ,kpbl))
125 + (vvel(i,j,kpbl)+vvel(i ,j+1,kpbl))*(vvel(i,j,kpbl)+vvel(i ,j+1,kpbl)) );
128 Rib_up = (
theta-base_theta)/base_theta *
CONST_GRAV * zval / ws2_level;
129 above_critical = Rib_up >= Rib_cr;
133 if (Rib_dn >= Rib_cr) {
135 }
else if (Rib_up <= Rib_cr)
138 interp_fact = (Rib_cr - Rib_dn) / (Rib_up - Rib_dn);
141 const Real zval_up = use_terrain ?
Compute_Zrel_AtCellCenter(i,j,kpbl,z_nd_arr) : gdata.ProbLo(2) + (kpbl + 0.5)*gdata.CellSize(2);
142 const Real zval_dn = use_terrain ?
Compute_Zrel_AtCellCenter(i,j,kpbl-1,z_nd_arr) : gdata.ProbLo(2) + (kpbl-1 + 0.5)*gdata.CellSize(2);
143 pblh_arr(i,j,0) = zval_dn + interp_fact*(zval_up-zval_dn);
147 if (pblh_arr(i,j,0) < 0.5*(zval_0+zval_1) ) {
150 pbli_arr(i,j,0) = kpbl;
161 const auto& u_star_arr = most->get_u_star(level)->const_array(mfi);
162 const auto& l_obuk_arr = most->get_olen(level)->const_array(mfi);
163 const Array4<Real > &K_turb = eddyViscosity.array(mfi);
173 const auto& dxInv = geom.InvCellSizeArray();
174 const Real dz_inv = geom.InvCellSize(2);
175 const int izmin = geom.Domain().smallEnd(2);
176 const int izmax = geom.Domain().bigEnd(2);
178 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
180 const Real zval = use_terrain ?
Compute_Zrel_AtCellCenter(i,j,k,z_nd_arr) : gdata.ProbLo(2) + (k + 0.5)*gdata.CellSize(2);
183 const Real dz_terrain = met_h_zeta/dz_inv;
184 if (k < pbli_arr(i,j,0)) {
186 constexpr Real zfacmin = 1e-8;
187 constexpr Real phifac = 8.0;
188 constexpr Real wstar3 = 0.0;
189 constexpr Real pfac = 2.0;
190 const Real zfac = std::min(std::max(1 - zval / pblh_arr(i,j,0), zfacmin ), 1.0);
192 const Real ust3 = u_star_arr(i,j,0) * u_star_arr(i,j,0) * u_star_arr(i,j,0);
193 Real wscalek = ust3 + phifac *
KAPPA * wstar3 * (1.0 - zfac);
194 wscalek = std::pow(wscalek, 1.0/3.0);
196 const Real phi_term = 1 + 5 * zval / l_obuk_arr(i,j,0);
197 wscalek = std::max(u_star_arr(i,j,0) / phi_term, 0.001);
202 constexpr Real lam0 = 30.0;
203 constexpr Real min_richardson = -100.0;
204 constexpr Real prandtl_max = 4.0;
205 Real dthetadz, dudz, dvdz;
206 const int RhoQv_comp = -1;
207 const int RhoQc_comp = -1;
208 const int RhoQr_comp = -1;
210 uvel, vvel, cell_data, izmin, izmax, 1.0/dz_terrain,
211 c_ext_dir_on_zlo, c_ext_dir_on_zhi,
212 u_ext_dir_on_zlo, u_ext_dir_on_zhi,
213 v_ext_dir_on_zlo, v_ext_dir_on_zhi,
214 dthetadz, dudz, dvdz, RhoQv_comp, RhoQc_comp, RhoQr_comp);
215 const Real shear_squared = dudz*dudz + dvdz*dvdz + 1.0e-9;
218 const Real lambdadz = std::min(std::max(0.1*dz_terrain , lam0), 300.0);
219 const Real lengthscale = lambdadz *
KAPPA * zval / (lambdadz +
KAPPA * zval);
220 const Real turbfact = lengthscale * lengthscale * std::sqrt(shear_squared);
222 if (richardson < 0) {
223 richardson = max(richardson, min_richardson);
224 Real sqrt_richardson = std::sqrt(-richardson);
225 K_turb(i,j,k,
EddyDiff::Mom_v) =
rho * turbfact * (1.0 - 8.0 * richardson / (1.0 + 1.746 * sqrt_richardson));
226 K_turb(i,j,k,
EddyDiff::Theta_v) =
rho * turbfact * (1.0 - 8.0 * richardson / (1.0 + 1.286 * sqrt_richardson));
228 const Real oneplus5ri = 1.0 + 5.0 * richardson;
230 const Real prandtl = std::min(1.0+2.1*richardson, prandtl_max);
236 constexpr Real ckz = 0.001;
237 constexpr Real Kmax = 1000.0;
238 const Real rhoKmin = ckz * dz_terrain *
rho;
239 const Real rhoKmax =
rho * Kmax;
246 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:20
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:21
#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, const bool use_most=true)
Definition: ERF_PBLModels.H:82
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:39
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:352
@ yvel_bc
Definition: ERF_IndexDefines.H:89
@ cons_bc
Definition: ERF_IndexDefines.H:76
@ xvel_bc
Definition: ERF_IndexDefines.H:88
@ ext_dir
Definition: ERF_IndexDefines.H:180
@ Theta_v
Definition: ERF_IndexDefines.H:157
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:161
@ Mom_v
Definition: ERF_IndexDefines.H:156
@ theta
Definition: ERF_MM5.H:20
@ rho
Definition: ERF_Kessler.H:30
@ xvel
Definition: ERF_IndexDefines.H:130
@ yvel
Definition: ERF_IndexDefines.H:131
amrex::Real pbl_ysu_land_Ribcr
Definition: ERF_TurbStruct.H:211
amrex::Real pbl_ysu_coriolis_freq
Definition: ERF_TurbStruct.H:208
bool pbl_ysu_force_over_water
Definition: ERF_TurbStruct.H:210
amrex::Real pbl_ysu_unst_Ribcr
Definition: ERF_TurbStruct.H:212