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.
322 BL_PROFILE_VAR(
"ImplicitDiffForMom_T()",ImplicitDiffForMom_T);
333 constexpr
Real molec_fac = (stagdir == 2) ?
two :
one;
344 constexpr
int ioff = (stagdir == 0) ? 1 : 0;
345 constexpr
int joff = (stagdir == 1) ? 1 : 0;
348 int ilo = bx.smallEnd(0);
349 int ihi = bx.bigEnd(0);
350 int jlo = bx.smallEnd(1);
351 int jhi = bx.bigEnd(1);
352 int box_klo = bx.smallEnd(2);
353 int box_khi = bx.bigEnd(2);
354 amrex::ignore_unused(ilo, ihi, jlo, jhi);
359 constexpr
int knodal = (stagdir == 2) ? 1 : 0;
360 const int dom_klo = domain.smallEnd(2);
361 const int dom_khi = domain.bigEnd(2) + knodal;
365 amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
366 RHS_fab.resize(bx,1, amrex::The_Async_Arena());
367 soln_fab.resize(bx,1, amrex::The_Async_Arena());
368 coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
369 auto const& RHS_a = RHS_fab.array();
370 auto const& soln_a = soln_fab.array();
371 auto const& coeffG_a = coeffG_fab.array();
373 Real dz_inv = cellSizeInv[2];
382 amrex::ignore_unused(foextrap_on_zlo,foextrap_on_zhi);
385 "Unexpected lower BC for momentum used with implicit vertical diffusion");
387 "Unexpected upper BC for momentum used with implicit vertical diffusion");
389 Real Fact = implicit_fac * dt * dz_inv;
392 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
395 for (
int j(jlo); j<=jhi; ++j) {
396 for (
int i(ilo); i<=ihi; ++i) {
406 const int klo = amrex::max(box_klo, col_kext(i-ioff,j-joff,0,0),
407 col_kext(i ,j ,0,0));
408 const int khi = amrex::min(box_khi, col_kext(i-ioff,j-joff,0,1)+knodal,
409 col_kext(i ,j ,0,1)+knodal);
413 if (
khi <=
klo) {
return; }
415 if (
khi <=
klo) {
continue; }
456 Real rhoface, rhoAlpha_lo, rhoAlpha_hi;
457 Real detJface, met_h_zeta_lo, met_h_zeta_hi;
458 Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
460 detJface =
myhalf * (detJ(i,j,
klo) + detJ(i-ioff,j-joff,
klo));
463 cell_data, mu_turb, mu_eff,
472 c_tmp = -Fact * gfac * rhoAlpha_hi * dz_inv / met_h_zeta_hi;
474 RHS_a(i,j,
klo) = detJface * face_data(i,j,
klo);
478 if (
klo != dom_klo) {
481 a_tmp = -Fact * rhoAlpha_lo * dz_inv / met_h_zeta_lo;
482 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
485 RHS_a(i,j,
klo) -= a_tmp * (face_data(i,j,
klo-1) / rho_below);
486 }
else if (ext_dir_on_zlo) {
487 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
493 a_tmp = -
two * Fact * rhoAlpha_lo * dz_inv / met_h_zeta_lo;
496 const Real wall_velocity = face_data(i,j,
klo-1) / rho_wall;
497 RHS_a(i,j,
klo) -= a_tmp * wall_velocity;
499 }
else if (use_SurfLayer) {
501 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau(i,j,
klo));
502 RHS_a(i,j,
klo) += Fact * tau(i,j,
klo);
505 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
516 if (use_ysu_mom_countergradient && stagdir < 2) {
519 const Real gam_klo =
myhalf * (mu_turb(i,j,
klo ,hgam_comp) + mu_turb(i-ioff,j-joff,
klo ,hgam_comp));
520 const Real gam_kp1 =
myhalf * (mu_turb(i,j,
klo+1,hgam_comp) + mu_turb(i-ioff,j-joff,
klo+1,hgam_comp));
521 const Real gam_hi =
myhalf * (gam_klo + gam_kp1);
522 RHS_a(i,j,
klo) -= Fact * rhoAlpha_hi * gam_hi;
525 b_tmp = detJface * rhoface - a_tmp - c_tmp;
528 RHS_a(i,j,
klo) /= b_tmp;
529 coeffG_a(i,j,
klo) = c_tmp / b_tmp;
534 for (
int k(
klo+1); k <
khi; k++) {
535 detJface =
myhalf * (detJ(i,j,k) + detJ(i-ioff,j-joff,k));
538 cell_data, mu_turb, mu_eff,
546 a_tmp = -Fact * rhoAlpha_lo * dz_inv / met_h_zeta_lo;
547 c_tmp = -Fact * rhoAlpha_hi * dz_inv / met_h_zeta_hi;
548 b_tmp = detJface * rhoface - a_tmp - c_tmp;
549 inv_b2_tmp =
one / (b_tmp - a_tmp * coeffG_a(i,j,k-1));
551 RHS_a(i,j,k) = detJface * face_data(i,j,k);
552 RHS_a(i,j,k) += Fact * gfac * (tau_corr(i,j,k+1) - tau_corr(i,j,k));
555 if (use_ysu_mom_countergradient && stagdir < 2) {
558 const Real gam_k =
myhalf * (mu_turb(i,j,k ,hgam_comp) + mu_turb(i-ioff,j-joff,k ,hgam_comp));
559 const Real gam_km1 =
myhalf * (mu_turb(i,j,k-1,hgam_comp) + mu_turb(i-ioff,j-joff,k-1,hgam_comp));
560 const Real gam_kp1 =
myhalf * (mu_turb(i,j,k+1,hgam_comp) + mu_turb(i-ioff,j-joff,k+1,hgam_comp));
561 const Real gam_hi =
myhalf * (gam_k + gam_kp1);
562 const Real gam_lo =
myhalf * (gam_k + gam_km1);
563 RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
566 RHS_a(i,j,k) = (RHS_a(i,j,k) - a_tmp * RHS_a(i,j,k-1)) * inv_b2_tmp;
567 coeffG_a(i,j,k) = c_tmp * inv_b2_tmp;
573 detJface =
myhalf * (detJ(i,j,
khi) + detJ(i-ioff,j-joff,
khi));
576 cell_data, mu_turb, mu_eff,
584 a_tmp = -Fact * gfac * rhoAlpha_lo * dz_inv / met_h_zeta_lo;
587 RHS_a(i,j,
khi) = detJface * face_data(i,j,
khi);
588 RHS_a(i,j,
khi) += Fact * gfac * (tau_corr(i,j,
khi+1) - tau_corr(i,j,
khi));
592 if (
khi != dom_khi) {
595 c_tmp = -Fact * rhoAlpha_hi * dz_inv / met_h_zeta_hi;
598 RHS_a(i,j,
khi) -= c_tmp * (face_data(i,j,
khi+1) / rho_above);
599 }
else if (ext_dir_on_zhi) {
605 c_tmp = -
two * Fact * rhoAlpha_hi * dz_inv / met_h_zeta_hi;
608 const Real wall_velocity = face_data(i,j,
khi+1) / rho_wall;
609 RHS_a(i,j,
khi) -= c_tmp * wall_velocity;
613 b_tmp = detJface * rhoface - a_tmp - c_tmp;
614 inv_b2_tmp =
one / (b_tmp - a_tmp * coeffG_a(i,j,
khi-1));
617 soln_a(i,j,
khi) = (RHS_a(i,j,
khi) - a_tmp * RHS_a(i,j,
khi-1)) * inv_b2_tmp;
622 for (
int k(
khi-1); k>=
klo; --k) {
623 soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
628 for (
int k(
klo); k<=
khi; ++k) {
630 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)
Definition: ERF_GetRhoAlphaForFaces.H:22
#define Rho_comp
Definition: ERF_IndexDefines.H:39
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:32
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:31
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:30
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:29
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:34
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtKface(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:409
AMREX_ASSERT_WITH_MESSAGE(wbar_cutoff_min > wbar_cutoff_max, "ERROR: wbar_cutoff_min < wbar_cutoff_max")
@ xvel_bc
Definition: ERF_IndexDefines.H:105
@ foextrap
Definition: ERF_IndexDefines.H:296
@ ext_dir
Definition: ERF_IndexDefines.H:297
@ ext_dir_prim
Definition: ERF_IndexDefines.H:300
@ HGAMU_v
Definition: ERF_IndexDefines.H:262
@ HGAMV_v
Definition: ERF_IndexDefines.H:263
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:1974
DiffChoice diffChoice
Diffusion-related options.
Definition: ERF_DataStruct.H:1971
Definition: ERF_TurbStruct.H:115
bool use_kturb
Whether any turbulence model is active.
Definition: ERF_TurbStruct.H:835