Function for computing the implicit contribution to the vertical diffusion of momentum, with a uniform grid and no terrain.
This function (explicitly instantiated below) handles staggering in x, y, or z through the template parameter, stagdir.
290 BL_PROFILE_VAR(
"ImplicitDiffForMom_N()",ImplicitDiffForMom_N);
301 constexpr
Real molec_fac = (stagdir == 2) ?
two :
one;
312 constexpr
int ioff = (stagdir == 0) ? 1 : 0;
313 constexpr
int joff = (stagdir == 1) ? 1 : 0;
316 int ilo = bx.smallEnd(0);
317 int ihi = bx.bigEnd(0);
318 int jlo = bx.smallEnd(1);
319 int jhi = bx.bigEnd(1);
320 int box_klo = bx.smallEnd(2);
321 int box_khi = bx.bigEnd(2);
322 amrex::ignore_unused(ilo, ihi, jlo, jhi);
327 constexpr
int knodal = (stagdir == 2) ? 1 : 0;
328 const int dom_klo = domain.smallEnd(2);
329 const int dom_khi = domain.bigEnd(2) + knodal;
333 amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
334 RHS_fab.resize(bx,1, amrex::The_Async_Arena());
335 soln_fab.resize(bx,1, amrex::The_Async_Arena());
336 coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
337 auto const& RHS_a = RHS_fab.array();
338 auto const& soln_a = soln_fab.array();
339 auto const& coeffG_a = coeffG_fab.array();
341 Real dz_inv = cellSizeInv[2];
350 amrex::ignore_unused(foextrap_on_zlo,foextrap_on_zhi);
353 "Unexpected lower BC for momentum used with implicit vertical diffusion");
355 "Unexpected upper BC for momentum used with implicit vertical diffusion");
357 Real Fact = implicit_fac * dt * dz_inv;
360 ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (
int i,
int j,
int)
363 for (
int j(jlo); j<=jhi; ++j) {
364 for (
int i(ilo); i<=ihi; ++i) {
374 const int klo = amrex::max(box_klo, col_kext(i-ioff,j-joff,0,0),
375 col_kext(i ,j ,0,0));
376 const int khi = amrex::min(box_khi, col_kext(i-ioff,j-joff,0,1)+knodal,
377 col_kext(i ,j ,0,1)+knodal);
381 if (
khi <=
klo) {
return; }
383 if (
khi <=
klo) {
continue; }
420 Real rhoface, rhoAlpha_lo, rhoAlpha_hi;
421 Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
425 cell_data, mu_turb, mu_eff,
429 c_tmp = -Fact * gfac * rhoAlpha_hi * dz_inv;
431 RHS_a(i,j,
klo) = face_data(i,j,
klo);
435 if (
klo != dom_klo) {
438 a_tmp = -Fact * rhoAlpha_lo * dz_inv;
439 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
442 RHS_a(i,j,
klo) -= a_tmp * (face_data(i,j,
klo-1) / rho_below);
443 }
else if (ext_dir_on_zlo) {
444 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
450 a_tmp = -
two * Fact * rhoAlpha_lo * dz_inv;
453 const Real wall_velocity = face_data(i,j,
klo-1) / rho_wall;
454 RHS_a(i,j,
klo) -= a_tmp * wall_velocity;
456 }
else if (use_SurfLayer) {
458 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau(i,j,
klo));
459 RHS_a(i,j,
klo) += Fact * tau(i,j,
klo);
462 RHS_a(i,j,
klo) += Fact * gfac * (tau_corr(i,j,
klo+1) - tau_corr(i,j,
klo));
473 if (use_ysu_mom_countergradient && stagdir < 2) {
476 const Real gam_klo =
myhalf * (mu_turb(i,j,
klo ,hgam_comp) + mu_turb(i-ioff,j-joff,
klo ,hgam_comp));
477 const Real gam_kp1 =
myhalf * (mu_turb(i,j,
klo+1,hgam_comp) + mu_turb(i-ioff,j-joff,
klo+1,hgam_comp));
478 const Real gam_hi =
myhalf * (gam_klo + gam_kp1);
479 RHS_a(i,j,
klo) -= Fact * rhoAlpha_hi * gam_hi;
482 b_tmp = rhoface - a_tmp - c_tmp;
485 RHS_a(i,j,
klo) /= b_tmp;
486 coeffG_a(i,j,
klo) = c_tmp / b_tmp;
491 for (
int k(
klo+1); k <
khi; k++) {
494 cell_data, mu_turb, mu_eff,
497 a_tmp = -Fact * rhoAlpha_lo * dz_inv;
498 c_tmp = -Fact * rhoAlpha_hi * dz_inv;
499 b_tmp = rhoface - a_tmp - c_tmp;
500 inv_b2_tmp =
one/ (b_tmp - a_tmp * coeffG_a(i,j,k-1));
502 RHS_a(i,j,k) = face_data(i,j,k);
503 RHS_a(i,j,k) += Fact * gfac * (tau_corr(i,j,k+1) - tau_corr(i,j,k));
506 if (use_ysu_mom_countergradient && stagdir < 2) {
509 const Real gam_k =
myhalf * (mu_turb(i,j,k ,hgam_comp) + mu_turb(i-ioff,j-joff,k ,hgam_comp));
510 const Real gam_km1 =
myhalf * (mu_turb(i,j,k-1,hgam_comp) + mu_turb(i-ioff,j-joff,k-1,hgam_comp));
511 const Real gam_kp1 =
myhalf * (mu_turb(i,j,k+1,hgam_comp) + mu_turb(i-ioff,j-joff,k+1,hgam_comp));
512 const Real gam_hi =
myhalf * (gam_k + gam_kp1);
513 const Real gam_lo =
myhalf * (gam_k + gam_km1);
514 RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
517 RHS_a(i,j,k) = (RHS_a(i,j,k) - a_tmp * RHS_a(i,j,k-1)) * inv_b2_tmp;
518 coeffG_a(i,j,k) = c_tmp * inv_b2_tmp;
526 cell_data, mu_turb, mu_eff,
529 a_tmp = -Fact * gfac * rhoAlpha_lo * dz_inv;
532 RHS_a(i,j,
khi) = face_data(i,j,
khi);
533 RHS_a(i,j,
khi) += Fact * gfac * (tau_corr(i,j,
khi+1) - tau_corr(i,j,
khi));
537 if (
khi != dom_khi) {
540 c_tmp = -Fact * rhoAlpha_hi * dz_inv;
543 RHS_a(i,j,
khi) -= c_tmp * (face_data(i,j,
khi+1) / rho_above);
544 }
else if (ext_dir_on_zhi) {
550 c_tmp = -
two * Fact * rhoAlpha_hi * dz_inv;
553 const Real wall_velocity = face_data(i,j,
khi+1) / rho_wall;
554 RHS_a(i,j,
khi) -= c_tmp * wall_velocity;
558 b_tmp = rhoface - a_tmp - c_tmp;
559 inv_b2_tmp =
one/ (b_tmp - a_tmp * coeffG_a(i,j,
khi-1));
562 soln_a(i,j,
khi) = (RHS_a(i,j,
khi) - a_tmp * RHS_a(i,j,
khi-1)) * inv_b2_tmp;
567 for (
int k(
khi-1); k>=
klo; --k) {
568 soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
573 for (
int k(
klo); k<=
khi; ++k) {
575 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_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