Function for computing the implicit contribution to the vertical diffusion of momentum, with a vertically stretched grid over flat terrain.
This function (explicitly instantiated below) handles staggering in x or y through the template parameter, stagdir.
325 BL_PROFILE_VAR(
"ImplicitDiffForMom_S()",ImplicitDiffForMom_S);
340 constexpr
int ioff = (stagdir == 0) ? 1 : 0;
341 constexpr
int joff = (stagdir == 1) ? 1 : 0;
344 int ilo = bx.smallEnd(0);
345 int ihi = bx.bigEnd(0);
346 int jlo = bx.smallEnd(1);
347 int jhi = bx.bigEnd(1);
348 int box_klo = bx.smallEnd(2);
349 int box_khi = bx.bigEnd(2);
350 amrex::ignore_unused(ilo, ihi, jlo, jhi);
354 const int dom_klo = domain.smallEnd(2);
355 const int dom_khi = domain.bigEnd(2);
359 amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
360 RHS_fab.resize(bx,1, amrex::The_Async_Arena());
361 soln_fab.resize(bx,1, amrex::The_Async_Arena());
362 coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
363 auto const& RHS_a = RHS_fab.array();
364 auto const& soln_a = soln_fab.array();
365 auto const& coeffG_a = coeffG_fab.array();
367 auto dz_ptr = stretched_dz_d.data();
376 amrex::ignore_unused(foextrap_on_zlo,foextrap_on_zhi);
379 "Unexpected lower BC for momentum used with implicit vertical diffusion");
381 "Unexpected upper BC for momentum used with implicit vertical diffusion");
383 Real Fact = implicit_fac * dt;
386 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
389 for (
int j(jlo); j<=jhi; ++j) {
390 for (
int i(ilo); i<=ihi; ++i) {
400 const int klo = amrex::max(box_klo, col_kext(i-ioff,j-joff,0,0),
401 col_kext(i ,j ,0,0));
402 const int khi = amrex::min(box_khi, col_kext(i-ioff,j-joff,0,1),
403 col_kext(i ,j ,0,1));
407 if (
khi <=
klo) {
return; }
409 if (
khi <=
klo) {
continue; }
446 Real rhoface, rhoAlpha_lo, rhoAlpha_hi;
447 Real dz_inv, dz_inv_lo, dz_inv_hi;
448 Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
452 cell_data, mu_turb, mu_eff,
455 dz_inv =
one / dz_ptr[
klo];
457 dz_inv_hi =
two / (dz_ptr[
klo] + dz_ptr[
klo+1]);
460 c_tmp = -Fact * rhoAlpha_hi * dz_inv_hi * dz_inv;
462 RHS_a(i,j,
klo) = face_data(i,j,
klo);
466 if (
klo != dom_klo) {
469 dz_inv_lo =
two / (dz_ptr[
klo] + dz_ptr[
klo-1]);
470 a_tmp = -Fact * rhoAlpha_lo * dz_inv_lo * dz_inv;
471 RHS_a(i,j,
klo) += Fact * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo)) * dz_inv;
474 RHS_a(i,j,
klo) -= a_tmp * (face_data(i,j,
klo-1) / rho_below);
475 }
else if (ext_dir_on_zlo) {
476 RHS_a(i,j,
klo) += Fact * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo)) * dz_inv;
482 a_tmp = Fact * rhoAlpha_lo * idz0 * dz_inv * wc.c_wall;
483 c_tmp += Fact * rhoAlpha_lo * idz0 * dz_inv * wc.c_1;
486 const Real wall_velocity = face_data(i,j,
klo-1) / rho_wall;
487 RHS_a(i,j,
klo) -= a_tmp * wall_velocity;
488 }
else if (use_SurfLayer) {
490 RHS_a(i,j,
klo) += Fact * (tau_corr(i,j,
klo+1) - tau(i,j,
klo)) * dz_inv;
491 RHS_a(i,j,
klo) += Fact * dz_inv * tau(i,j,
klo);
494 RHS_a(i,j,
klo) += Fact * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo)) * dz_inv;
506 if (use_ysu_mom_countergradient) {
509 const Real gam_klo =
myhalf * (mu_turb(i,j,
klo ,hgam_comp) + mu_turb(i-ioff,j-joff,
klo ,hgam_comp));
510 const Real gam_kp1 =
myhalf * (mu_turb(i,j,
klo+1,hgam_comp) + mu_turb(i-ioff,j-joff,
klo+1,hgam_comp));
511 const Real gam_hi =
myhalf * (gam_klo + gam_kp1);
512 RHS_a(i,j,
klo) -= Fact * dz_inv * rhoAlpha_hi * gam_hi;
513 if (
klo != dom_klo) {
514 const Real gam_km1 =
myhalf * (mu_turb(i,j,
klo-1,hgam_comp) + mu_turb(i-ioff,j-joff,
klo-1,hgam_comp));
515 const Real gam_lo =
myhalf * (gam_klo + gam_km1);
516 RHS_a(i,j,
klo) += Fact * dz_inv * rhoAlpha_lo * gam_lo;
520 b_tmp = rhoface - a_tmp - c_tmp;
523 RHS_a(i,j,
klo) /= b_tmp;
524 coeffG_a(i,j,
klo) = c_tmp / b_tmp;
529 for (
int k(
klo+1); k <
khi; k++) {
532 cell_data, mu_turb, mu_eff,
535 dz_inv =
one / dz_ptr[k];
536 dz_inv_lo =
two / (dz_ptr[k] + dz_ptr[k-1]);
537 dz_inv_hi =
two / (dz_ptr[k] + dz_ptr[k+1]);
539 a_tmp = -Fact * rhoAlpha_lo * dz_inv_lo * dz_inv;
540 c_tmp = -Fact * rhoAlpha_hi * dz_inv_hi * dz_inv;
541 b_tmp = rhoface - a_tmp - c_tmp;
542 inv_b2_tmp =
one / (b_tmp - a_tmp * coeffG_a(i,j,k-1));
544 RHS_a(i,j,k) = face_data(i,j,k);
545 RHS_a(i,j,k) += Fact * (tau_corr(i,j,k+1) - tau_corr(i,j,k)) * dz_inv;
548 if (use_ysu_mom_countergradient) {
551 const Real gam_k =
myhalf * (mu_turb(i,j,k ,hgam_comp) + mu_turb(i-ioff,j-joff,k ,hgam_comp));
552 const Real gam_km1 =
myhalf * (mu_turb(i,j,k-1,hgam_comp) + mu_turb(i-ioff,j-joff,k-1,hgam_comp));
553 const Real gam_kp1 =
myhalf * (mu_turb(i,j,k+1,hgam_comp) + mu_turb(i-ioff,j-joff,k+1,hgam_comp));
554 const Real gam_hi =
myhalf * (gam_k + gam_kp1);
555 const Real gam_lo =
myhalf * (gam_k + gam_km1);
556 RHS_a(i,j,k) -= Fact * dz_inv * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
559 RHS_a(i,j,k) = (RHS_a(i,j,k) - a_tmp * RHS_a(i,j,k-1)) * inv_b2_tmp;
560 coeffG_a(i,j,k) = c_tmp * inv_b2_tmp;
568 cell_data, mu_turb, mu_eff,
571 dz_inv =
one / dz_ptr[
khi];
572 dz_inv_lo =
two / (dz_ptr[
khi] + dz_ptr[
khi-1]);
575 a_tmp = -Fact * rhoAlpha_lo * dz_inv_lo * dz_inv;
578 RHS_a(i,j,
khi) = face_data(i,j,
khi);
579 RHS_a(i,j,
khi) += Fact * (tau_corr(i,j,
khi+1) - tau_corr(i,j,
khi)) * dz_inv;
583 if (
khi != dom_khi) {
586 dz_inv_hi =
two / (dz_ptr[
khi] + dz_ptr[
khi+1]);
587 c_tmp = -Fact * rhoAlpha_hi * dz_inv_hi * dz_inv;
590 RHS_a(i,j,
khi) -= c_tmp * (face_data(i,j,
khi+1) / rho_above);
591 }
else if (ext_dir_on_zhi) {
597 c_tmp = Fact * rhoAlpha_hi * idz0 * dz_inv * wc.
c_wall;
598 a_tmp += Fact * rhoAlpha_hi * idz0 * dz_inv * wc.
c_1;
601 const Real wall_velocity = face_data(i,j,
khi+1) / rho_wall;
602 RHS_a(i,j,
khi) -= c_tmp * wall_velocity;
611 if (use_ysu_mom_countergradient) {
614 const Real gam_khi =
myhalf * (mu_turb(i,j,
khi ,hgam_comp) + mu_turb(i-ioff,j-joff,
khi ,hgam_comp));
615 const Real gam_km1 =
myhalf * (mu_turb(i,j,
khi-1,hgam_comp) + mu_turb(i-ioff,j-joff,
khi-1,hgam_comp));
616 const Real gam_lo =
myhalf * (gam_khi + gam_km1);
617 RHS_a(i,j,
khi) += Fact * dz_inv * rhoAlpha_lo * gam_lo;
618 if (
khi != dom_khi) {
619 const Real gam_kp1 =
myhalf * (mu_turb(i,j,
khi+1,hgam_comp) + mu_turb(i-ioff,j-joff,
khi+1,hgam_comp));
620 const Real gam_hi =
myhalf * (gam_khi + gam_kp1);
621 RHS_a(i,j,
khi) -= Fact * dz_inv * rhoAlpha_hi * gam_hi;
625 b_tmp = rhoface - a_tmp - c_tmp;
626 inv_b2_tmp =
one / (b_tmp - a_tmp * coeffG_a(i,j,
khi-1));
629 soln_a(i,j,
khi) = (RHS_a(i,j,
khi) - a_tmp * RHS_a(i,j,
khi-1)) * inv_b2_tmp;
634 for (
int k(
khi-1); k>=
klo; --k) {
635 soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
640 for (
int k(
klo); k<=
khi; ++k) {
642 face_data(i,j,k) = rhoface * soln_a(i,j,k);
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getRhoAlphaForFaces(int i, int j, int k, int ioff, int joff, amrex::Real &rhoAlpha_lo, amrex::Real &rhoAlpha_hi, const amrex::Array4< const amrex::Real > &cell_data, const amrex::Array4< const amrex::Real > &mu_turb, const amrex::Real mu_eff, bool l_consA, bool l_turb, const int eddy_comp=EddyDiff::Mom_v)
Definition: ERF_GetRhoAlphaForFaces.H:23
#define Rho_comp
Definition: ERF_IndexDefines.H:53
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
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 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_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE WallGradCoeffs WallGradientCoeffs(const amrex::Real dz0, const amrex::Real dz1) noexcept
Definition: ERF_WallGradientCoeffs.H:33
@ xvel_bc
Definition: ERF_IndexDefines.H:126
@ foextrap
Definition: ERF_IndexDefines.H:339
@ ext_dir
Definition: ERF_IndexDefines.H:340
@ ext_dir_prim
Definition: ERF_IndexDefines.H:343
@ HGAMU_v
Definition: ERF_IndexDefines.H:302
@ HGAMV_v
Definition: ERF_IndexDefines.H:303
Definition: ERF_DiffStruct.H:24
MolecDiffType molec_diff_type
Selected molecular transport model.
Definition: ERF_DiffStruct.H:96
amrex::Real dynamic_viscosity
Dynamic viscosity for momentum diffusion [kg/(m-s)].
Definition: ERF_DiffStruct.H:108
amrex::Real rho0_trans
Reference density used to compute dynamic diffusion coefficients [kg/m3].
Definition: ERF_DiffStruct.H:103
amrex::Vector< TurbChoice > turbChoice
Turbulence options for each AMR level.
Definition: ERF_DataStruct.H:2620
DiffChoice diffChoice
Diffusion-related options.
Definition: ERF_DataStruct.H:2617
Definition: ERF_TurbStruct.H:119
bool use_kturb
Whether any turbulence model is active.
Definition: ERF_TurbStruct.H:977
Definition: ERF_WallGradientCoeffs.H:25
amrex::Real c_wall
Definition: ERF_WallGradientCoeffs.H:26
amrex::Real c_1
Definition: ERF_WallGradientCoeffs.H:28