Function for computing the implicit contribution to the vertical diffusion of momentum, over terrain.
This function (explicitly instantiated below) handles staggering in x, y, or z through the template parameter, stagdir. NOTE: implicit diffusion of w has remains an experimental feature and has not been tested yet with terrain.
482 BL_PROFILE_VAR(
"ImplicitDiffForMom_T()",ImplicitDiffForMom_T);
493 constexpr
Real molec_fac = (stagdir == 2) ?
two :
one;
504 constexpr
int ioff = (stagdir == 0) ? 1 : 0;
505 constexpr
int joff = (stagdir == 1) ? 1 : 0;
508 int ilo = bx.smallEnd(0);
509 int ihi = bx.bigEnd(0);
510 int jlo = bx.smallEnd(1);
511 int jhi = bx.bigEnd(1);
512 int box_klo = bx.smallEnd(2);
513 int box_khi = bx.bigEnd(2);
514 amrex::ignore_unused(ilo, ihi, jlo, jhi);
519 constexpr
int knodal = (stagdir == 2) ? 1 : 0;
520 const int dom_klo = domain.smallEnd(2);
521 const int dom_khi = domain.bigEnd(2) + knodal;
525 amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
526 RHS_fab.resize(bx,1, amrex::The_Async_Arena());
527 soln_fab.resize(bx,1, amrex::The_Async_Arena());
528 coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
529 auto const& RHS_a = RHS_fab.array();
530 auto const& soln_a = soln_fab.array();
531 auto const& coeffG_a = coeffG_fab.array();
533 Real dz_inv = cellSizeInv[2];
542 amrex::ignore_unused(foextrap_on_zlo,foextrap_on_zhi);
545 "Unexpected lower BC for momentum used with implicit vertical diffusion");
547 "Unexpected upper BC for momentum used with implicit vertical diffusion");
549 Real Fact = implicit_fac * dt * dz_inv;
552 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
555 for (
int j(jlo); j<=jhi; ++j) {
556 for (
int i(ilo); i<=ihi; ++i) {
566 const int klo = amrex::max(box_klo, col_kext(i-ioff,j-joff,0,0),
567 col_kext(i ,j ,0,0));
568 const int khi = amrex::min(box_khi, col_kext(i-ioff,j-joff,0,1)+knodal,
569 col_kext(i ,j ,0,1)+knodal);
573 if (
khi <=
klo) {
return; }
575 if (
khi <=
klo) {
continue; }
616 Real rhoface, rhoAlpha_lo, rhoAlpha_hi;
617 Real detJface, met_h_zeta_lo, met_h_zeta_hi;
618 Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
620 detJface =
myhalf * (detJ(i,j,
klo) + detJ(i-ioff,j-joff,
klo));
623 cell_data, mu_turb, mu_eff,
626 if (implicit_metric) {
627 TerrainMetricMomCoeffs<stagdir>(i, j,
klo, dom_klo, dom_khi, metric_lo, metric_hi,
628 cell_data, mu_turb, mu_eff, l_consA, l_turb,
629 z_nd, cellSizeInv, mf_x, mf_y);
632 met_h_zeta_lo = MomFaceHZeta<stagdir>(i,j,
klo,ioff,joff,cellSizeInv,z_nd);
633 met_h_zeta_hi = MomFaceHZeta<stagdir>(i,j,
klo+1,ioff,joff,cellSizeInv,z_nd);
636 c_tmp = -Fact * gfac * (rhoAlpha_hi + metric_hi) * dz_inv / met_h_zeta_hi;
638 RHS_a(i,j,
klo) = detJface * face_data(i,j,
klo);
642 if (
klo != dom_klo) {
645 a_tmp = -Fact * (rhoAlpha_lo + metric_lo) * dz_inv / met_h_zeta_lo;
646 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
649 RHS_a(i,j,
klo) -= a_tmp * (face_data(i,j,
klo-1) / rho_below);
650 }
else if (ext_dir_on_zlo) {
651 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
657 a_tmp = -
two * Fact * rhoAlpha_lo * dz_inv / met_h_zeta_lo;
660 const Real wall_velocity = face_data(i,j,
klo-1) / rho_wall;
661 RHS_a(i,j,
klo) -= a_tmp * wall_velocity;
663 }
else if (use_SurfLayer) {
665 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau(i,j,
klo));
666 RHS_a(i,j,
klo) += Fact * tau(i,j,
klo);
669 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
680 if (use_ysu_mom_countergradient && stagdir < 2) {
683 const Real gam_klo =
myhalf * (mu_turb(i,j,
klo ,hgam_comp) + mu_turb(i-ioff,j-joff,
klo ,hgam_comp));
684 const Real gam_kp1 =
myhalf * (mu_turb(i,j,
klo+1,hgam_comp) + mu_turb(i-ioff,j-joff,
klo+1,hgam_comp));
685 const Real gam_hi =
myhalf * (gam_klo + gam_kp1);
686 RHS_a(i,j,
klo) -= Fact * rhoAlpha_hi * gam_hi;
689 b_tmp = detJface * rhoface - a_tmp - c_tmp;
692 RHS_a(i,j,
klo) /= b_tmp;
693 coeffG_a(i,j,
klo) = c_tmp / b_tmp;
698 for (
int k(
klo+1); k <
khi; k++) {
699 detJface =
myhalf * (detJ(i,j,k) + detJ(i-ioff,j-joff,k));
702 cell_data, mu_turb, mu_eff,
705 if (implicit_metric) {
706 TerrainMetricMomCoeffs<stagdir>(i, j, k, dom_klo, dom_khi, metric_lo, metric_hi,
707 cell_data, mu_turb, mu_eff, l_consA, l_turb,
708 z_nd, cellSizeInv, mf_x, mf_y);
711 met_h_zeta_lo = MomFaceHZeta<stagdir>(i,j,k,ioff,joff,cellSizeInv,z_nd);
712 met_h_zeta_hi = MomFaceHZeta<stagdir>(i,j,k+1,ioff,joff,cellSizeInv,z_nd);
714 a_tmp = -Fact * (rhoAlpha_lo + metric_lo) * dz_inv / met_h_zeta_lo;
715 c_tmp = -Fact * (rhoAlpha_hi + metric_hi) * dz_inv / met_h_zeta_hi;
716 b_tmp = detJface * rhoface - a_tmp - c_tmp;
717 inv_b2_tmp =
one / (b_tmp - a_tmp * coeffG_a(i,j,k-1));
719 RHS_a(i,j,k) = detJface * face_data(i,j,k);
720 RHS_a(i,j,k) += Fact * gfac * (tau_corr(i,j,k+1) - tau_corr(i,j,k));
723 if (use_ysu_mom_countergradient && stagdir < 2) {
726 const Real gam_k =
myhalf * (mu_turb(i,j,k ,hgam_comp) + mu_turb(i-ioff,j-joff,k ,hgam_comp));
727 const Real gam_km1 =
myhalf * (mu_turb(i,j,k-1,hgam_comp) + mu_turb(i-ioff,j-joff,k-1,hgam_comp));
728 const Real gam_kp1 =
myhalf * (mu_turb(i,j,k+1,hgam_comp) + mu_turb(i-ioff,j-joff,k+1,hgam_comp));
729 const Real gam_hi =
myhalf * (gam_k + gam_kp1);
730 const Real gam_lo =
myhalf * (gam_k + gam_km1);
731 RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
734 RHS_a(i,j,k) = (RHS_a(i,j,k) - a_tmp * RHS_a(i,j,k-1)) * inv_b2_tmp;
735 coeffG_a(i,j,k) = c_tmp * inv_b2_tmp;
741 detJface =
myhalf * (detJ(i,j,
khi) + detJ(i-ioff,j-joff,
khi));
744 cell_data, mu_turb, mu_eff,
747 if (implicit_metric) {
748 TerrainMetricMomCoeffs<stagdir>(i, j,
khi, dom_klo, dom_khi, metric_lo, metric_hi,
749 cell_data, mu_turb, mu_eff, l_consA, l_turb,
750 z_nd, cellSizeInv, mf_x, mf_y);
753 met_h_zeta_lo = MomFaceHZeta<stagdir>(i,j,
khi,ioff,joff,cellSizeInv,z_nd);
754 met_h_zeta_hi = MomFaceHZeta<stagdir>(i,j,
khi+1,ioff,joff,cellSizeInv,z_nd);
756 a_tmp = -Fact * gfac * (rhoAlpha_lo + metric_lo) * dz_inv / met_h_zeta_lo;
759 RHS_a(i,j,
khi) = detJface * face_data(i,j,
khi);
760 RHS_a(i,j,
khi) += Fact * gfac * (tau_corr(i,j,
khi+1) - tau_corr(i,j,
khi));
764 if (
khi != dom_khi) {
767 c_tmp = -Fact * (rhoAlpha_hi + metric_hi) * dz_inv / met_h_zeta_hi;
770 RHS_a(i,j,
khi) -= c_tmp * (face_data(i,j,
khi+1) / rho_above);
771 }
else if (ext_dir_on_zhi) {
777 c_tmp = -
two * Fact * rhoAlpha_hi * dz_inv / met_h_zeta_hi;
780 const Real wall_velocity = face_data(i,j,
khi+1) / rho_wall;
781 RHS_a(i,j,
khi) -= c_tmp * wall_velocity;
785 b_tmp = detJface * rhoface - a_tmp - c_tmp;
786 inv_b2_tmp =
one / (b_tmp - a_tmp * coeffG_a(i,j,
khi-1));
789 soln_a(i,j,
khi) = (RHS_a(i,j,
khi) - a_tmp * RHS_a(i,j,
khi-1)) * inv_b2_tmp;
794 for (
int k(
khi-1); k>=
klo; --k) {
795 soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
800 for (
int k(
klo); k<=
khi; ++k) {
802 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:24
#define Rho_comp
Definition: ERF_IndexDefines.H:42
const int klo
Definition: ERF_InitCustomPert_ABL.H:75
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
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_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
@ xvel_bc
Definition: ERF_IndexDefines.H:108
@ foextrap
Definition: ERF_IndexDefines.H:299
@ ext_dir
Definition: ERF_IndexDefines.H:300
@ ext_dir_prim
Definition: ERF_IndexDefines.H:303
@ HGAMU_v
Definition: ERF_IndexDefines.H:265
@ HGAMV_v
Definition: ERF_IndexDefines.H:266
Definition: ERF_DiffStruct.H:22
MolecDiffType molec_diff_type
Selected molecular transport model.
Definition: ERF_DiffStruct.H:94
amrex::Real dynamic_viscosity
Dynamic viscosity for momentum diffusion [kg/(m-s)].
Definition: ERF_DiffStruct.H:106
amrex::Real rho0_trans
Reference density used to compute dynamic diffusion coefficients [kg/m3].
Definition: ERF_DiffStruct.H:101
amrex::Vector< TurbChoice > turbChoice
Turbulence options for each AMR level.
Definition: ERF_DataStruct.H:2252
DiffChoice diffChoice
Diffusion-related options.
Definition: ERF_DataStruct.H:2249
Definition: ERF_TurbStruct.H:115
bool use_kturb
Whether any turbulence model is active.
Definition: ERF_TurbStruct.H:921