4194 Print()<<
"reached mynnedmf"<<std::endl;
4203 tridiag2_cc(n,&a,&b,&c,&d,&x);
4205 printf(
"ran tridiag2_cc with n=%d and got %g %g %g %g %g",n,a,b,c,d,x);
4207 const bool use_most = (most !=
nullptr);
4223 Real eps = std::numeric_limits<Real>::epsilon();
4226 #pragma omp parallel if (Gpu::notInLaunchRegion())
4228 for ( MFIter mfi(eddyViscosity,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
4230 const Box &bx = mfi.growntilebox(1);
4231 const Array4<Real const>& cell_data = cons_in.array(mfi);
4232 const Array4<Real >& K_turb = eddyViscosity.array(mfi);
4233 const Array4<Real const>& uvel =
xvel.array(mfi);
4234 const Array4<Real const>& vvel =
yvel.array(mfi);
4239 const Box &dbx = geom.Domain();
4240 Box sbx(bx.smallEnd(), bx.bigEnd());
4242 AMREX_ALWAYS_ASSERT(sbx.smallEnd(2) == dbx.smallEnd(2) && sbx.bigEnd(2) == dbx.bigEnd(2));
4244 const GeometryData gdata = geom.data();
4246 const Box xybx = PerpendicularBox<ZDir>(bx, IntVect{0,0,0});
4247 FArrayBox qintegral(xybx,2);
4248 qintegral.setVal<RunOn::Device>(0.0);
4249 FArrayBox qturb(bx,1); FArrayBox qturb_old(bx,1);
4250 const Array4<Real> qint = qintegral.array();
4251 const Array4<Real> qvel = qturb.array();
4254 if (use_terrain_fitted_coords) {
4255 const Array4<Real const> &z_nd_arr = z_phys_nd->array(mfi);
4256 const auto invCellSize = geom.InvCellSizeArray();
4257 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
4259 qvel(i,j,k) = std::sqrt(2.0 * cell_data(i,j,k,
RhoKE_comp) / cell_data(i,j,k,
Rho_comp));
4260 AMREX_ASSERT_WITH_MESSAGE(qvel(i,j,k) > 0.0,
"KE must have a positive value");
4262 Real fac = (sbx.contains(i,j,k)) ? 1.0 : 0.0;
4265 Gpu::Atomic::Add(&qint(i,j,0,0), Zval*qvel(i,j,k)*dz*fac);
4266 Gpu::Atomic::Add(&qint(i,j,0,1), qvel(i,j,k)*dz*fac);
4269 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
4271 qvel(i,j,k) = std::sqrt(2.0 * cell_data(i,j,k,
RhoKE_comp) / cell_data(i,j,k,
Rho_comp));
4272 AMREX_ASSERT_WITH_MESSAGE(qvel(i,j,k) > 0.0,
"KE must have a positive value");
4276 Real fac = (sbx.contains(i,j,k)) ? 1.0 : 0.0;
4277 const Real Zval = gdata.ProbLo(2) + (k + 0.5)*gdata.CellSize(2);
4278 Gpu::Atomic::Add(&qint(i,j,0,0), Zval*qvel(i,j,k)*fac);
4279 Gpu::Atomic::Add(&qint(i,j,0,1), qvel(i,j,k)*fac);
4283 Real dz_inv = geom.InvCellSize(2);
4284 const auto& dxInv = geom.InvCellSizeArray();
4285 int izmin = geom.Domain().smallEnd(2);
4286 int izmax = geom.Domain().bigEnd(2);
4289 Real d_kappa =
KAPPA;
4292 const auto& t_mean_mf = most->get_mac_avg(level,4);
4293 const auto& q_mean_mf = most->get_mac_avg(level,3);
4294 const auto& u_star_mf = most->get_u_star(level);
4295 const auto& t_star_mf = most->get_t_star(level);
4296 const auto& q_star_mf = most->get_q_star(level);
4298 const auto& tm_arr = t_mean_mf->const_array(mfi);
4299 const auto& qm_arr = q_mean_mf->const_array(mfi);
4300 const auto& u_star_arr = u_star_mf->const_array(mfi);
4301 const auto& t_star_arr = t_star_mf->const_array(mfi);
4302 const auto& q_star_arr = (use_moisture) ? q_star_mf->const_array(mfi) : Array4<Real>{};
4304 const Array4<Real const> z_nd_arr = z_phys_nd->const_array(mfi);
4306 ParallelFor(bx, [=] AMREX_GPU_DEVICE (
int i,
int j,
int k) noexcept
4316 Real dthetadz, dudz, dvdz;
4318 uvel, vvel, cell_data, izmin, izmax, dz_inv/met_h_zeta,
4319 c_ext_dir_on_zlo, c_ext_dir_on_zhi,
4320 u_ext_dir_on_zlo, u_ext_dir_on_zhi,
4321 v_ext_dir_on_zlo, v_ext_dir_on_zhi,
4322 dthetadz, dudz, dvdz,
4323 RhoQv_comp, RhoQc_comp, RhoQr_comp, use_most);
4326 Real theta0 = tm_arr(i,j,0);
4327 Real qv0 = qm_arr(i,j,0);
4328 Real surface_heat_flux = -u_star_arr(i,j,0) * t_star_arr(i,j,0);
4329 Real surface_latent_heat{0};
4332 surface_latent_heat = -u_star_arr(i,j,0) * q_star_arr(i,j,0);
4333 surface_heat_flux *= (1.0 + 0.61*qv0);
4334 surface_heat_flux += 0.61 * theta0 * surface_latent_heat;
4338 if (std::abs(surface_heat_flux) > eps) {
4339 l_obukhov = -( theta0 * u_star_arr(i,j,0)*u_star_arr(i,j,0)*u_star_arr(i,j,0) )
4340 / ( d_kappa * d_gravity * surface_heat_flux );
4342 l_obukhov = std::numeric_limits<Real>::max();
4346 AMREX_ASSERT(l_obukhov != 0);
4347 int lk = amrex::max(k,0);
4349 : gdata.ProbLo(2) + (lk + 0.5)*gdata.CellSize(2);
4350 const Real zeta = zval/l_obukhov;
4353 l_S =
KAPPA*zval/3.7;
4354 }
else if (zeta >= 0) {
4355 l_S =
KAPPA*zval/(1+2.7*zeta);
4357 l_S =
KAPPA*zval*std::pow(1.0 - 100.0 * zeta, 0.2);
4362 if (qint(i,j,0,1) > 0.0) {
4363 l_T = Lt_alpha*qint(i,j,0,0)/qint(i,j,0,1);
4365 l_T = std::numeric_limits<Real>::max();
4371 Real N_brunt_vaisala = std::sqrt(
CONST_GRAV/theta0 * dthetadz);
4374 qc = std::pow(
qc,1.0/3.0);
4375 l_B = (1.0 + 5.0*std::sqrt(
qc/(N_brunt_vaisala * l_T))) * qvel(i,j,k)/N_brunt_vaisala;
4377 l_B = qvel(i,j,k) / N_brunt_vaisala;
4380 l_B = std::numeric_limits<Real>::max();
4386 Lm = std::pow(1.0/(l_S*l_S) + 1.0/(l_T*l_T) + 1.0/(l_B*l_B), -0.5);
4389 Lm = 1.0 / (1.0/l_S + 1.0/l_T + 1.0/l_B);
4393 Real shearProd = dudz*dudz + dvdz*dvdz;
4394 Real buoyProd = -(
CONST_GRAV/theta0) * dthetadz;
4395 Real L2_over_q2 = Lm*Lm/(qvel(i,j,k)*qvel(i,j,k));
4396 Real GM = L2_over_q2 * shearProd;
4397 Real GH = L2_over_q2 * buoyProd;
4400 Real Rf = level2.calc_Rf(GM, GH);
4401 Real SM2 = level2.calc_SM(Rf);
4402 Real qe2 = mynn.B1*Lm*Lm*SM2*(1.0-Rf)*shearProd;
4403 Real qe = (qe2 < 0.0) ? 0.0 : std::sqrt(qe2);
4406 Real alphac = (qvel(i,j,k) > qe) ? 1.0 : qvel(i,j,k) / (qe + eps);
4410 mynn.calc_stability_funcs(SM,SH,SQ,GM,GH,alphac);
4413 SM = amrex::min(amrex::max(SM,mynn.SMmin), mynn.SMmax);
4414 SH = amrex::min(amrex::max(SH,mynn.SHmin), mynn.SHmax);
4429 if (mynn.diffuse_moistvars) {
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 RhoKE_comp
Definition: ERF_IndexDefines.H:38
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:119
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:46
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:359
@ 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:191
@ Theta_v
Definition: ERF_IndexDefines.H:168
@ Turb_lengthscale
Definition: ERF_IndexDefines.H:172
@ Q_v
Definition: ERF_IndexDefines.H:171
@ Mom_v
Definition: ERF_IndexDefines.H:167
@ KE_v
Definition: ERF_IndexDefines.H:169
@ rho
Definition: ERF_Kessler.H:22
@ qc
Definition: ERF_SatAdj.H:36
@ xvel
Definition: ERF_IndexDefines.H:141
@ yvel
Definition: ERF_IndexDefines.H:142
MYNNLevel25 pbl_mynn
Definition: ERF_TurbStruct.H:242
MYNNLevel2 pbl_mynn_level2
Definition: ERF_TurbStruct.H:243