Compute eddy diffusivities using the MYNN PBL model.
51 Real Lt_alpha = mynn.Lt_alpha;
54 const bool use_Lt_taper = (mynn.Lt_taper_exp >
zero);
55 const Real Lt_taper_exp = mynn.Lt_taper_exp;
56 if (use_Lt_taper && !SurfLayer->computes_pblh()) {
57 Abort(
"erf.pbl_mynn_Lt_taper_exp > 0 needs a diagnosed PBL height; "
58 "set erf.most.pblh_calc = MYNN25");
73 #pragma omp parallel if (Gpu::notInLaunchRegion())
75 for ( MFIter mfi(eddyViscosity,
TileNoZ()); mfi.isValid(); ++mfi) {
77 const Box& bx = mfi.tilebox();
78 const Array4<Real const>& cell_data = cons_in.array(mfi);
79 const Array4<Real >& K_turb = eddyViscosity.array(mfi);
80 const Array4<Real const>& uvel =
xvel.array(mfi);
81 const Array4<Real const>& vvel =
yvel.array(mfi);
86 const Box& dbx = geom.Domain();
89 const GeometryData gdata = geom.data();
91 const Box xybx = makeSlab(bx,2,0);
92 FArrayBox qturb(bx,1,The_Async_Arena());
93 FArrayBox qintegral(xybx,2,The_Async_Arena());
94 qintegral.setVal<RunOn::Device>(
zero);
95 const Array4<Real> qint = qintegral.array();
96 const Array4<Real> qvel = qturb.array();
99 if (use_terrain_fitted_coords) {
100 const Array4<Real const> &z_nd_arr = z_phys_nd->array(mfi);
101 const auto invCellSize = geom.InvCellSizeArray();
102 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
110 Gpu::Atomic::Add(&qint(i,j,0,0), Zval*qvel(i,j,k)*
dz);
111 Gpu::Atomic::Add(&qint(i,j,0,1), qvel(i,j,k)*
dz);
114 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
122 const Real Zval = (k +
myhalf)*gdata.CellSize(2);
123 Gpu::Atomic::Add(&qint(i,j,0,0), Zval*qvel(i,j,k));
124 Gpu::Atomic::Add(&qint(i,j,0,1), qvel(i,j,k));
128 int izmin = geom.Domain().smallEnd(2);
129 int izmax = geom.Domain().bigEnd(2);
135 const auto& t_mean_mf = SurfLayer->get_mac_avg(level,5);
136 const auto& q_mean_mf = SurfLayer->get_mac_avg(level,4);
137 const auto& u_star_mf = SurfLayer->get_u_star(level);
138 const auto& t_star_mf = SurfLayer->get_t_star(level);
139 const auto& q_star_mf = SurfLayer->get_q_star(level);
141 const auto& tm_arr = t_mean_mf->const_array(mfi);
142 const auto& qm_arr = q_mean_mf->const_array(mfi);
143 const auto& u_star_arr = u_star_mf->const_array(mfi);
144 const auto& t_star_arr = t_star_mf->const_array(mfi);
145 const auto& q_star_arr = (
use_moisture) ? q_star_mf->const_array(mfi) : Array4<Real>{};
147 const auto& pblh_mf = SurfLayer->get_pblh(level);
148 const auto pblh_arr = (use_Lt_taper) ? pblh_mf->const_array(mfi)
149 : Array4<const Real>{};
151 const Array4<Real const> z_nd_arr = z_phys_nd->const_array(mfi);
154 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
158 Real dthetavdz, dudz, dvdz;
160 uvel, vvel, cell_data, izmin, izmax, pbl_derivative_dz_inv(i,j,k),
161 c_ext_dir_on_zlo, c_ext_dir_on_zhi,
162 u_ext_dir_on_zlo, u_ext_dir_on_zhi,
163 v_ext_dir_on_zlo, v_ext_dir_on_zhi,
164 dthetavdz, dudz, dvdz,
165 moisture_indices, pbl_strat);
168 Real theta0 = tm_arr(i,j,0);
169 Real qv0 = qm_arr(i,j,0);
170 Real surface_heat_flux = -u_star_arr(i,j,0) * t_star_arr(i,j,0);
171 Real surface_latent_heat{0};
174 surface_latent_heat = -u_star_arr(i,j,0) * q_star_arr(i,j,0);
175 surface_heat_flux *= (
one +
epsv*qv0);
176 surface_heat_flux +=
epsv * theta0 * surface_latent_heat;
180 if (std::abs(surface_heat_flux) > eps && u_star_arr(i,j,0) > eps) {
181 l_obukhov = -( theta0 * u_star_arr(i,j,0)*u_star_arr(i,j,0)*u_star_arr(i,j,0) )
182 / ( d_kappa * d_gravity * surface_heat_flux );
184 l_obukhov = std::numeric_limits<Real>::max();
188 AMREX_ASSERT(l_obukhov != 0);
190 (k +
myhalf)*gdata.CellSize(2);
191 const Real zeta = zval/l_obukhov;
195 }
else if (zeta >= 0) {
213 sl.
u_star = u_star_arr(i,j,0);
224 if (qint(i,j,0,1) >
zero) {
225 l_T = Lt_alpha*qint(i,j,0,0)/qint(i,j,0,1);
227 l_T = std::numeric_limits<Real>::max();
233 const Real l_T_abl = l_T;
245 const Real pblh = pblh_arr(i,j,0);
248 f = (f <
Real(1.0e-4)) ?
Real(1.0e-4) : f;
249 l_T *= std::pow(f, Lt_taper_exp);
255 if (dthetavdz >
zero) {
260 l_B = (
one +
Real(5.0)*std::sqrt(
qc/(N_brunt_vaisala * l_T_abl))) * qvel(i,j,k)/N_brunt_vaisala;
262 l_B = qvel(i,j,k) / N_brunt_vaisala;
265 l_B = std::numeric_limits<Real>::max();
270 if (mynn.config == MYNNConfigType::Chen2021) {
278 Real shearProd = dudz*dudz + dvdz*dvdz;
280 Real L2_over_q2 = Lm*Lm/(qvel(i,j,k)*qvel(i,j,k));
281 Real GM = L2_over_q2 * shearProd;
282 Real GH = L2_over_q2 * buoyProd;
285 Real Rf = level2.calc_Rf(GM, GH);
286 Real SM2 = level2.calc_SM(Rf);
287 Real qe2 = mynn.B1 * Lm*Lm * SM2 * (
one-Rf) * shearProd;
288 Real qe = (qe2 <
zero) ?
zero : amrex::max(std::sqrt(qe2),eps);
291 Real alphac = (qvel(i,j,k) >= qe) ?
one : qvel(i,j,k) / qe;
295 Real lGM = std::copysign(std::max(std::fabs(GM),level2.eps),GM);
298 AllPrint() <<
"Level 2 limiter at " << IntVect(i,j,k) <<
" :"
299 <<
" ustar= " << u_star_arr(i,j,0)
300 <<
" alphac= " << alphac
301 <<
" Ri,SM2,SH2= " << Ri <<
" " << SM2 <<
" " << level2.calc_SH(Rf)
308 mynn.calc_stability_funcs(SM,SH,SQ,GM,GH,alphac);
311 SM = amrex::min(amrex::max(SM, mynn.SMmin), mynn.SMmax);
312 SH = amrex::min(amrex::max(SH, mynn.SHmin), mynn.SHmax);
313 SQ = amrex::min(amrex::max(SQ, mynn.SQmin), mynn.SQmax);
314 #if EXTRA_MYNN25_CHECKS
315 if (SM == mynn.SMmin) {
316 Warning(
"SM clipped at min val");
317 }
else if (SM == mynn.SMmax) {
318 Warning(
"SM clipped at max val");
320 if (SH == mynn.SHmin) {
321 Warning(
"SH clipped at min val");
322 }
else if (SH == mynn.SHmax) {
323 Warning(
"SH clipped at max val");
constexpr amrex::Real epsv
Definition: ERF_Constants.H:52
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:67
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:68
#define Rho_comp
Definition: ERF_IndexDefines.H:42
#define RhoKE_comp
Definition: ERF_IndexDefines.H:44
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:71
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")
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 three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
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:304
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void ApplySurfaceLayerGradientsPBL(const PBLSurfaceLayerGradient &sl, amrex::Real &dthetadz, amrex::Real &dudz, amrex::Real &dvdz)
Definition: ERF_PBLModels.H:423
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:386
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:758
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:197
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
@ yvel_bc
Definition: ERF_IndexDefines.H:109
@ cons_bc
Definition: ERF_IndexDefines.H:92
@ xvel_bc
Definition: ERF_IndexDefines.H:108
@ ext_dir
Definition: ERF_IndexDefines.H:300
@ Theta_v
Definition: ERF_IndexDefines.H:253
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:257
@ Q_v
Definition: ERF_IndexDefines.H:256
@ Mom_v
Definition: ERF_IndexDefines.H:252
@ KE_v
Definition: ERF_IndexDefines.H:254
@ rho
Definition: ERF_Kessler.H:25
@ qc
Definition: ERF_SatAdj.H:42
@ xvel
Definition: ERF_IndexDefines.H:218
@ yvel
Definition: ERF_IndexDefines.H:219
@ dz
Definition: ERF_AdvanceWDM6.cpp:272
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
Functor for inverse vertical spacings for terrain-following grids using cell-center heights.
Definition: ERF_PBLModels.H:663
Definition: ERF_PBLModels.H:366
amrex::Real tstar_v
virtual temperature scale
Definition: ERF_PBLModels.H:368
amrex::Real zeta
stability coordinate z/L
Definition: ERF_PBLModels.H:370
amrex::Real u_star
friction velocity
Definition: ERF_PBLModels.H:367
amrex::Real zval
height of the cell center above the surface
Definition: ERF_PBLModels.H:369
MYNNLevel2 pbl_mynn_level2
MYNN level-2 closure coefficients for limiting.
Definition: ERF_TurbStruct.H:918
StratType pbl_strat_type
Definition: ERF_TurbStruct.H:819
MYNNLevel25 pbl_mynn
MYNN level-2.5 closure coefficients.
Definition: ERF_TurbStruct.H:917