Compute turbulent diffusivities using the Mellor-Yamada-Janjic (MYJ) closure model.
65 Real EPS1 = Real(1.0e-12);
67 Real EPSRS = Real(1.0e-7);
68 Real EPSRU = Real(1.0e-7);
69 Real EPSTRB = Real(1.0e-24);
70 Real EPSL = Real(0.32);
71 Real EPSQ2 = Real(0.2);
72 Real EPSQ1 = std::sqrt(EPSQ2);
73 Real ESQHF = Real(2.5);
77 Real ALPHA = Real(0.3);
78 Real BETA =
one/Real(273.);
79 Real EL0MAX = Real(1000.);
81 Real ELFC = Real(0.23);
83 Real A1 = Real( 0.659888514560862645);
84 Real A2x = Real( 0.6574209922667784586);
85 Real B1 = Real(11.87799326209552761);
86 Real B2 = Real( 7.226971804046074028);
87 Real C1 = Real( 0.000830955950095854396);
92 Real ADNH = Real(9.)*A1*A2x*A2x*(Real(12.)*A1+
three*B2)*BTG*BTG;
93 Real ADNM = Real(18.)*A1*A1*A2x*(B2-
three*A2x)*BTG;
94 Real ANMH = -Real(9.)*A1*A2x*A2x*BTG*BTG;
95 Real ANMM = -
three*A1*A2x*(
three*A2x+
three*B2*C1+Real(18.)*A1*C1-B2)*BTG;
96 Real BDNH =
three*A2x*(Real(7.)*A1+B2)*BTG;
97 Real BDNM = Real(6.)*A1*A1;
98 Real BEQH = A2x*B1*BTG+
three*A2x*(Real(7.)*A1+B2)*BTG;
99 Real BEQM = -A1*B1*(
one-
three*C1)+Real(6.)*A1*A1;
100 Real BNMH = -A2x*BTG;
102 Real BSHH = Real(9.)*A1*A2x*A2x*BTG;
103 Real BSHM = Real(18.)*A1*A1*A2x*C1;
104 Real BSMH = -
three*A1*A2x*(
three*A2x+
three*B2*C1+Real(12.)*A1*C1-B2)*BTG;
108 Real AEQH = Real(9.)*A1*A2x*A2x*B1*BTG*BTG
109 + Real(9.)*A1*A2x*A2x*(Real(12.)*A1+
three*B2)*BTG*BTG;
110 Real AEQM =
three*A1*A2x*B1*(
three*A2x+
three*B2*C1+Real(18.)*A1*C1-B2)*BTG
111 + Real(18.)*A1*A1*A2x*(B2-
three*A2x)*BTG;
113 Real REQU = -AEQH/AEQM;
114 Real EPSGH = Real(1.E-9);
115 Real EPSGM = REQU*EPSGH;
117 Real UBRYL = (Real(18.)*REQU*A1*A1*A2x*B2*C1*BTG + Real(9.)*A1*A2x*A2x*B2*BTG*BTG)
119 Real UBRY = (
one+EPSRS)*UBRYL;
120 Real UBRY3 =
three*UBRY;
122 Real AUBH = Real(27.)*A1*A2x*A2x*B2*BTG*BTG-ADNH*UBRY3;
123 Real AUBM = Real(54.)*A1*A1*A2x*B2*C1*BTG-ADNM*UBRY3;
124 Real BUBH = (Real(9.)*A1*A2x+
three*A2x*B2)*BTG-BDNH*UBRY3;
125 Real BUBM = Real(18.)*A1*A1*C1-BDNM*UBRY3;
126 Real CUBR =
one-UBRY3;
127 Real RCUBR =
one/CUBR;
130 #pragma omp parallel if (Gpu::notInLaunchRegion())
132 for (MFIter mfi(eddyViscosity,
false); mfi.isValid(); ++mfi) {
134 const Box& bx = mfi.validbox();
135 const Array4<Real >& cell_data = cons_in.array(mfi);
136 const Array4<Real >& K_turb = eddyViscosity.array(mfi);
137 const Array4<Real const>& uvel =
xvel.array(mfi);
138 const Array4<Real const>& vvel =
yvel.array(mfi);
141 const Box& dbx = geom.Domain();
145 int klo = bx.smallEnd(2);
146 int khi = bx.bigEnd(2);
147 Box planexy = makeSlab(bx,2,
klo);
150 const GeometryData gdata = geom.data();
153 const Box xybx = PerpendicularBox<ZDir>(bx, IntVect{0,0,0});
154 FArrayBox qturb(bx,1,The_Async_Arena());
155 FArrayBox qintegral(xybx,2,The_Async_Arena());
156 IArrayBox pbl_k(xybx,1,The_Async_Arena());
157 qintegral.setVal<RunOn::Device>(0);
158 pbl_k.setVal<RunOn::Device>(
khi);
159 const Array4<Real> qint = qintegral.array();
160 const Array4<Real> qvel = qturb.array();
161 const Array4<int> k_arr = pbl_k.array();
164 const Array4<Real const> &z_nd_arr = z_phys_nd->array(mfi);
165 const Array4<Real const> &z_sfc_arr = z_sfc_nd->const_array(mfi);
167 const auto&
dxInv = geom.InvCellSizeArray();
168 int izmin = geom.Domain().smallEnd(2);
169 int izmax = geom.Domain().bigEnd(2);
174 const bool surface_layer_on_zlo = (SurfLayer !=
nullptr);
175 const auto u_star_arr = (surface_layer_on_zlo) ?
176 SurfLayer->get_u_star(level)->const_array(mfi) : Array4<const Real>{};
178 const auto t_star_arr = (surface_layer_on_zlo) ?
179 SurfLayer->get_t_star(level)->const_array(mfi) : Array4<const Real>{};
180 const auto q_star_arr = (surface_layer_on_zlo &&
use_moisture) ?
181 SurfLayer->get_q_star(level)->const_array(mfi) : Array4<const Real>{};
182 const auto l_obuk_arr = (surface_layer_on_zlo) ?
183 SurfLayer->get_olen(level)->const_array(mfi) : Array4<const Real>{};
186 if (use_terrain_fitted_coords) {
187 ParallelFor(planexy, [=] AMREX_GPU_DEVICE (
int i,
int j,
int ) noexcept
190 for (
int k(
klo); k<=
khi; ++k) {
193 qvel(i,j,k) = std::sqrt(q2);
195 k_arr(i,j,0) = std::min(k,k_arr(i,j,0));
200 for (
int k(
klo); k<=k_arr(i,j,0); ++k) {
203 Gpu::Atomic::Add(&qint(i,j,0,0), Zval*qvel(i,j,k)*
dz);
204 Gpu::Atomic::Add(&qint(i,j,0,1), qvel(i,j,k)*
dz);
208 ParallelFor(planexy, [=] AMREX_GPU_DEVICE (
int i,
int j,
int ) noexcept
211 for (
int k(
klo); k<=
khi; ++k) {
214 qvel(i,j,k) = std::sqrt(q2);
216 k_arr(i,j,0) = std::min(k,k_arr(i,j,0));
221 for (
int k(
klo); k<=k_arr(i,j,0); ++k) {
223 const Real Zval = (k +
myhalf)*gdata.CellSize(2);
224 Gpu::Atomic::Add(&qint(i,j,0,0), Zval*qvel(i,j,k));
225 Gpu::Atomic::Add(&qint(i,j,0,1), qvel(i,j,k));
231 ParallelFor(planexy, [=] AMREX_GPU_DEVICE (
int i,
int j,
int ) noexcept
234 int kpbl = k_arr(i,j,0);
237 Real l0 = std::max(std::min(ALPHA*qint(i,j,0,0)/qint(i,j,0,1),EL0MAX),EL0MIN);
240 for (
int k(
klo); k<=
khi; ++k) {
243 Real dthetavdz, dudz, dvdz;
245 uvel, vvel, cell_data, izmin, izmax, pbl_derivative_dz_inv(i,j,k),
246 c_ext_dir_on_zlo, c_ext_dir_on_zhi,
247 u_ext_dir_on_zlo, u_ext_dir_on_zhi,
248 v_ext_dir_on_zlo, v_ext_dir_on_zhi,
249 dthetavdz, dudz, dvdz,
250 moisture_indices, pbl_strat);
254 if (surface_layer_on_zlo && k == izmin) {
255 const Real zval = use_terrain_fitted_coords ?
257 (k +
myhalf)*gdata.CellSize(2);
260 const Real
qv = (moisture_indices.
qv >= 0) ?
261 cell_data(i,j,k,moisture_indices.
qv) /
rho :
zero;
262 const Real l_min = Real(1.0e-10);
263 const Real l_obuk = std::copysign(std::max(std::fabs(l_obuk_arr(i,j,0)),l_min),l_obuk_arr(i,j,0));
265 sl.
u_star = u_star_arr(i,j,0);
267 (q_star_arr) ? q_star_arr(i,j,0) :
zero,
270 sl.
zeta = zval / l_obuk;
276 Real GML = std::max(dudz*dudz + dvdz*dvdz, EPSGM);
279 Real GHL = dthetavdz;
280 if (std::fabs(GHL)<=EPSGH) { GHL=EPSGH; }
285 if (GML/GHL <= REQU) {
288 Real AUBR = (AUBM*GML+AUBH*GHL)*GHL;
289 Real BUBR = BUBM*GML+BUBH*GHL;
290 Real QOL2ST = (-
myhalf*BUBR+std::sqrt(BUBR*BUBR*
fourth-AUBR*CUBR))*RCUBR;
291 Real ELOQ2X =
one/QOL2ST;
292 ELM = std::max(std::sqrt(ELOQ2X*qvel(i,j,k)*qvel(i,j,k)),EPSL);
295 Real ADEN = (ADNM*GML+ADNH*GHL)*GHL;
296 Real BDEN = BDNM*GML+BDNH*GHL;
297 Real QOL2UN = -
myhalf*BDEN+std::sqrt(BDEN*BDEN*
fourth-ADEN);
298 Real ELOQ2X =
one/(QOL2UN+EPSRU);
299 ELM = std::max(std::sqrt(ELOQ2X*qvel(i,j,k)*qvel(i,j,k)),EPSL);
305 L = std::min((met_h_zeta/
dxInv[2])*ELFC, ELM);
308 : (k +
myhalf)*gdata.CellSize(2);
309 L = std::min(l0*d_kappa*zval / (d_kappa*zval + l0), ELM);
313 Real AEQU = (AEQM*GML+AEQH*GHL)*GHL;
314 Real BEQU = BEQM*GML+BEQH*GHL;
316 Real EQOL2 = -
myhalf*BEQU+std::sqrt(BEQU*BEQU*
fourth-AEQU);
318 if ( ((GML+GHL*GHL)<=EPSTRB) ||
319 ((GHL>=EPSGH) && ((GML/GHL)<=REQU)) ||
324 Real ANUM=(ANMM*GML+ANMH*GHL)*GHL;
325 Real BNUM= BNMM*GML+BNMH*GHL;
327 Real ADEN=(ADNM*GML+ADNH*GHL)*GHL;
328 Real BDEN= BDNM*GML+BDNH*GHL;
331 Real ARHS=-(ANUM*BDEN-BNUM*ADEN)*
two;
332 Real BRHS=- ANUM*Real(4.);
333 Real CRHS=- BNUM*
two;
335 Real DLOQ1=L/qvel(i,j,k);
337 Real ELOQ21=
one/EQOL2;
338 Real ELOQ11=std::sqrt(ELOQ21);
339 Real ELOQ31=ELOQ21*ELOQ11;
340 Real ELOQ41=ELOQ21*ELOQ21;
341 Real ELOQ51=ELOQ21*ELOQ31;
343 Real RDEN1=
one/(ADEN*ELOQ41+BDEN*ELOQ21+CDEN);
345 Real RHSP1=(ARHS*ELOQ51+BRHS*ELOQ31+CRHS*ELOQ11)*RDEN1*RDEN1;
347 Real DTTURBL =
static_cast<Real
>(dt);
348 Real ELOQ12 = amrex::max(ELOQ11+(DLOQ1-ELOQ11)*std::exp(RHSP1*DTTURBL),EPS1);
350 Real ELOQ22=ELOQ12*ELOQ12;
351 Real ELOQ32=ELOQ22*ELOQ12;
352 Real ELOQ42=ELOQ22*ELOQ22;
353 Real ELOQ52=ELOQ22*ELOQ32;
355 Real RDEN2=
one/(ADEN*ELOQ42+BDEN*ELOQ22+CDEN);
356 Real RHS2 =-(ANUM*ELOQ42+BNUM*ELOQ22)*RDEN2+RB1;
357 Real RHSP2= (ARHS*ELOQ52+BRHS*ELOQ32+CRHS*ELOQ12)*RDEN2*RDEN2;
358 Real RHST2=RHS2/RHSP2;
360 Real ELOQ13 = amrex::max(ELOQ12-RHST2+(RHST2+DLOQ1-ELOQ12)*std::exp(RHSP2*DTTURBL),EPS1);
364 qvel(i,j,k) = std::max(L/ELOQN,EPSQ1);
365 if (qvel(i,j,k)==EPSQ1) {L = EPSL; }
382 cell_data(i,j,k,
RhoKE_comp) =
myhalf*cell_data(i,j,k,
Rho_comp)*qvel(i,j,k)*qvel(i,j,k);
385 Real ELOQ2 = L*L/(qvel(i,j,k)*qvel(i,j,k));
386 Real ELOQ4 = ELOQ2*ELOQ2;
389 Real ADEN=(ADNM*GML+ADNH*GHL)*GHL;
390 Real BDEN= BDNM*GML+BDNH*GHL;
397 Real BESH=BSHM*GML+BSHH*GHL;
400 Real RDEN=
one/(ADEN*ELOQ4+BDEN*ELOQ2+CDEN);
403 Real SM=(BESM*ELOQ2+CESM)*RDEN;
404 Real SH=(BESH*ELOQ2+CESH)*RDEN;
constexpr amrex::Real KAPPA
Definition: ERF_Constants.H:71
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:72
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
#define RhoKE_comp
Definition: ERF_IndexDefines.H:63
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
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
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 fourth
Definition: ERF_NumericalConstants.H:42
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:291
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 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
@ 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
@ Q_v
Definition: ERF_IndexDefines.H:270
@ Mom_v
Definition: ERF_IndexDefines.H:266
@ KE_v
Definition: ERF_IndexDefines.H:268
@ rho
Definition: ERF_Kessler.H:25
@ theta
Definition: ERF_Kessler.H:26
@ qv
Definition: ERF_Kessler.H:31
@ xvel
Definition: ERF_IndexDefines.H:232
@ yvel
Definition: ERF_IndexDefines.H:233
@ dz
Definition: ERF_AdvanceWDM6.cpp:273
int qv
water vapor
Definition: ERF_DataStruct.H:290
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
StratType pbl_strat_type
Definition: ERF_TurbStruct.H:951
Definition: ERF_MOSTUtils.H:84