ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ImplicitDiff_N.cpp File Reference
Include dependency graph for ERF_ImplicitDiff_N.cpp:

Macros

#define INSTANTIATE_IMPLICIT_DIFF_FOR_MOM_LU(STAGDIR)
 

Functions

void ImplicitDiffForStateLU_N (const Box &bx, const Box &domain, const int level, const int n, const double dt_d, const GpuArray< Real, AMREX_SPACEDIM *2 > &bc_neumann_vals, const Array4< Real > &cell_data, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Array4< const Real > &scalar_zflux, const Array4< const Real > &mu_turb, const SolverChoice &solverChoice, const BCRec *bc_ptr, const bool use_SurfLayer, const Real implicit_fac, const bool use_mrf_countergradient)
 
template<int stagdir>
void ImplicitDiffForMomLU_N (const Box &bx, const Box &, const int level, const double dt_d, const Array4< const Real > &cell_data, const Array4< Real > &face_data, const Array4< const Real > &tau, const Array4< const Real > &tau_corr, const GpuArray< Real, AMREX_SPACEDIM > &cellSizeInv, const Array4< const Real > &mu_turb, const SolverChoice &solverChoice, const BCRec *bc_ptr, const bool use_SurfLayer, const Real implicit_fac, const bool use_ysu_mom_countergradient)
 

Macro Definition Documentation

◆ INSTANTIATE_IMPLICIT_DIFF_FOR_MOM_LU

#define INSTANTIATE_IMPLICIT_DIFF_FOR_MOM_LU (   STAGDIR)
Value:
template void ImplicitDiffForMomLU_N<STAGDIR> ( \
const Box&, \
const Box&, \
const int, \
const double, \
const Array4<const Real>&, \
const Array4< Real>&, \
const Array4<const Real>&, \
const Array4<const Real>&, \
const GpuArray<Real, AMREX_SPACEDIM>&, \
const Array4<const Real>&, \
const SolverChoice&, \
const BCRec*, \
const bool, \
const Real, \
const bool);
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_DataStruct.H:634

Function Documentation

◆ ImplicitDiffForMomLU_N()

template<int stagdir>
void ImplicitDiffForMomLU_N ( const Box &  bx,
const Box &  ,
const int  level,
const double  dt_d,
const Array4< const Real > &  cell_data,
const Array4< Real > &  face_data,
const Array4< const Real > &  tau,
const Array4< const Real > &  tau_corr,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const Array4< const Real > &  mu_turb,
const SolverChoice solverChoice,
const BCRec *  bc_ptr,
const bool  use_SurfLayer,
const Real  implicit_fac,
const bool  use_ysu_mom_countergradient 
)

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.

Parameters
[in]bxcell-centered box to loop over
[in]levelAMR level
[in]dt_dtime step
[in]cell_dataconserved cell-centered rho
[in,out]face_dataconserved momentum
[in]taustress contribution to momentum
[in]tau_corrstress contribution to momentum that will be corrected by the implicit solve
[in]cellSizeInvinverse cell size array
[in]mu_turbturbulent viscosity
[in]solverChoicecontainer of parameters
[in]bc_ptrcontainer with boundary conditions
[in]use_SurfLayerwhether we have turned on subgrid diffusion
[in]implicit_facif 1 then fully implicit; if 0 then fully explicit
[in]use_ysu_mom_countergradientwhether to include YSU momentum countergradient correction
249 {
250  BL_PROFILE_VAR("ImplicitDiffForMom_N()",ImplicitDiffForMom_N);
251 
252  Real dt = static_cast<Real>(dt_d);
253 
254  // setup quantities for getRhoAlphaAtFaces()
255  DiffChoice dc = solverChoice.diffChoice;
256  TurbChoice tc = solverChoice.turbChoice[level];
257  bool l_consA = (dc.molec_diff_type == MolecDiffType::ConstantAlpha);
258  bool l_turb = tc.use_kturb;
259  // The off-diagonal correction strains for u/v contain a factor of 1/2,
260  // while the diagonal correction strain for w does not.
261  constexpr Real molec_fac = (stagdir == 2) ? two : one;
262  Real mu_eff = (l_consA) ? molec_fac * dc.dynamic_viscosity / dc.rho0_trans
263  : molec_fac * dc.dynamic_viscosity;
264 
265  // g(S*) coefficient
266  // stagdir==0: tau_corr = myhalf * du/dz * mu_tot
267  // stagdir==1: tau_corr = myhalf * dv/dz * mu_tot
268  // stagdir==2: tau_corr = dw/dz * mu_tot
269  constexpr Real gfac = (stagdir == 2) ? two/three : one;
270 
271  // offsets used to average to faces
272  constexpr int ioff = (stagdir == 0) ? 1 : 0;
273  constexpr int joff = (stagdir == 1) ? 1 : 0;
274 
275  // Box bounds
276  int ilo = bx.smallEnd(0);
277  int ihi = bx.bigEnd(0);
278  int jlo = bx.smallEnd(1);
279  int jhi = bx.bigEnd(1);
280  int klo = bx.smallEnd(2);
281  int khi = bx.bigEnd(2);
282  amrex::ignore_unused(ilo, ihi, jlo, jhi);
283 
284  // Temporary FABs for tridiagonal solve (allocated on column)
285  // A[k] * x[k-1] + B[k] * x[k] + C[k+1] = RHS[k]
286  amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
287  RHS_fab.resize(bx,1, amrex::The_Async_Arena());
288  soln_fab.resize(bx,1, amrex::The_Async_Arena());
289  coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
290  auto const& RHS_a = RHS_fab.array();
291  auto const& soln_a = soln_fab.array();
292  auto const& coeffG_a = coeffG_fab.array();
293 
294  Real dz_inv = cellSizeInv[2];
295 
296  int bc_comp = BCVars::xvel_bc + stagdir;
297  bool ext_dir_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir ||
298  bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim);
299  bool ext_dir_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir ||
300  bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim);
301  bool foextrap_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::foextrap);
302  bool foextrap_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::foextrap);
303  amrex::ignore_unused(foextrap_on_zlo,foextrap_on_zhi);
304 
305  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zlo || ext_dir_on_zlo || use_SurfLayer,
306  "Unexpected lower BC for momentum used with implicit vertical diffusion");
307  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zhi || ext_dir_on_zhi,
308  "Unexpected upper BC for momentum used with implicit vertical diffusion");
309 
310  Real Fact = implicit_fac * dt * dz_inv;
311 
312 #ifdef AMREX_USE_GPU
313  ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int)
314  {
315 #else
316  for (int j(jlo); j<=jhi; ++j) {
317  for (int i(ilo); i<=ihi; ++i) {
318 #endif
319  // Notes:
320  //
321  // - In DiffusionSrcForMom (e.g., for x-mom)
322  //
323  // Real diffContrib = ...
324  // + (tau13(i,j,k+1) - tau13(i,j,k)) / dzinv
325  // rho_u_rhs(i,j,k) -= diffContrib; // note the negative sign
326  //
327  // - We need to scale the explicit _part_ of `tau13` (for x-mom) by (1 - implicit_fac)
328  // The part that needs to be scaled is stored in `tau_corr`.
329  // E.g., tau13 = 0.5 * (du/dz + dw/dx)
330  // tau13_corr = 0.5 * du/dz
331  //
332  // - The momentum (`face_data`) was set to `S_old + S_rhs * dt`
333  // prior to including "ERF_Implicit.H". Recall that S_rhs includes
334  // sources from advection and other forcings, not just diffusion.
335  //
336  // - To correct momentum, we need to subtract `implicit_fac * diffContrib_corr`
337  // from S_rhs to recover `(1 - implicit_fac) * diffContrib_corr`,
338  // where `diffContrib_corr = -d(tau_corr)/dz`. The negative sign
339  // comes from our convention for the RHS diffusion source.
340  //
341  // Subtracting a negative gives the += below; multiply by dt to
342  // get the intermediate momentum on the RHS of the tridiagonal
343  // system.
344  //
345  // - With a surface_layer BC, tau13/23 holds the vertical flux -d_z(k*u_i)
346  // directly. We must use tau at klo (not tau_corr) with SL BCs.
347  //
348  // - Finally, the terms ~ RHS += (tau_corr_hi - tau_corr_lo) / dz (below)
349  // essentially undo the explicit diffusion update that will be
350  // handled here implicitly.
351 
352  // Bottom boundary coefficients and RHS for L decomp
353  //===================================================
354  Real rhoface, rhoAlpha_lo, rhoAlpha_hi;
355  Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
356  {
357  rhoface = myhalf * (cell_data(i,j,klo,Rho_comp) + cell_data(i-ioff,j-joff,klo,Rho_comp));
358  getRhoAlphaForFaces(i, j, klo, ioff, joff, rhoAlpha_lo, rhoAlpha_hi,
359  cell_data, mu_turb, mu_eff,
360  l_consA, l_turb);
361 
362  a_tmp = zero;
363  c_tmp = -Fact * gfac * rhoAlpha_hi * dz_inv;
364 
365  RHS_a(i,j,klo) = face_data(i,j,klo); // NOTE: this is momenta; solution is velocity
366 
367  // BCs: Dirichlet (u_i = val), slip wall (w = 0), or surface layer (w = 0)
368  if (ext_dir_on_zlo) {
369  RHS_a(i,j,klo) += Fact * gfac * (tau_corr(i,j,klo+1) - tau_corr(i,j,klo));
370  if (stagdir==2) {
371  c_tmp = zero;
372  RHS_a(i,j,klo) = zero;
373  } else {
374  // NOTE: wall is 1/2 dz away (2 dz_inv)
375  a_tmp = -two * Fact * rhoAlpha_lo * dz_inv;
376  const Real rho_wall = myhalf * ( cell_data(i ,j ,klo-1,Rho_comp)
377  + cell_data(i-ioff,j-joff,klo-1,Rho_comp) );
378  const Real wall_velocity = face_data(i,j,klo-1) / rho_wall;
379  RHS_a(i,j,klo) -= a_tmp * wall_velocity;
380  }
381  } else if (use_SurfLayer) {
382  // NOTE: tau = -mu*d_z(u_i) w/ SL
383  RHS_a(i,j,klo) += Fact * gfac * (tau_corr(i,j,klo+1) - tau(i,j,klo));
384  RHS_a(i,j,klo) += Fact * tau(i,j,klo);
385  } else {
386  // NOTE: FOEXTRAP has zero lower flux (nothing to add to RHS)
387  RHS_a(i,j,klo) += Fact * gfac * (tau_corr(i,j,klo+1) - tau_corr(i,j,klo));
388  }
389 
390  // Add YSU momentum countergradient correction at bottom boundary.
391  // NOTE: As for the scalars, the lower face at klo carries no
392  // countergradient flux -- the surface stress is supplied by the
393  // surface layer model or the wall BC above. Only the upper face
394  // contributes here.
395  // NOTE: The sign matches the scalar path: tau_i3 = -rho*K*(du_i/dz - gamma_i),
396  // so the countergradient piece of the flux is +rho*K*gamma_i and its
397  // divergence enters the RHS with a minus sign.
398  if (use_ysu_mom_countergradient && stagdir < 2) {
399  const int hgam_comp = (stagdir == 0) ? EddyDiff::HGAMU_v : EddyDiff::HGAMV_v;
400  // Average HGAM* to the staggered face
401  const Real gam_klo = myhalf * (mu_turb(i,j,klo ,hgam_comp) + mu_turb(i-ioff,j-joff,klo ,hgam_comp));
402  const Real gam_kp1 = myhalf * (mu_turb(i,j,klo+1,hgam_comp) + mu_turb(i-ioff,j-joff,klo+1,hgam_comp));
403  const Real gam_hi = myhalf * (gam_klo + gam_kp1);
404  RHS_a(i,j,klo) -= Fact * rhoAlpha_hi * gam_hi;
405  }
406 
407  b_tmp = rhoface - a_tmp - c_tmp;
408  inv_b2_tmp = one;
409 
410  RHS_a(i,j,klo) /= b_tmp; // NOTE: this is now "rho"
411  coeffG_a(i,j,klo) = c_tmp / b_tmp; // NOTE: this is now "gamma"
412  }
413 
414  // Build the coefficients and RHS for L decomp
415  //===================================================
416  for (int k(klo+1); k < khi; k++) {
417  rhoface = myhalf * (cell_data(i,j,k,Rho_comp) + cell_data(i-ioff,j-joff,k,Rho_comp));
418  getRhoAlphaForFaces(i, j, k, ioff, joff, rhoAlpha_lo, rhoAlpha_hi,
419  cell_data, mu_turb, mu_eff,
420  l_consA, l_turb);
421 
422  a_tmp = -Fact * rhoAlpha_lo * dz_inv;
423  c_tmp = -Fact * rhoAlpha_hi * dz_inv;
424  b_tmp = rhoface - a_tmp - c_tmp;
425  inv_b2_tmp = one/ (b_tmp - a_tmp * coeffG_a(i,j,k-1));
426 
427  RHS_a(i,j,k) = face_data(i,j,k); // NOTE: this is momenta; solution is velocity
428  RHS_a(i,j,k) += Fact * gfac * (tau_corr(i,j,k+1) - tau_corr(i,j,k));
429 
430  // Add YSU momentum countergradient correction
431  if (use_ysu_mom_countergradient && stagdir < 2) {
432  const int hgam_comp = (stagdir == 0) ? EddyDiff::HGAMU_v : EddyDiff::HGAMV_v;
433  // Average HGAM* to the staggered face
434  const Real gam_k = myhalf * (mu_turb(i,j,k ,hgam_comp) + mu_turb(i-ioff,j-joff,k ,hgam_comp));
435  const Real gam_km1 = myhalf * (mu_turb(i,j,k-1,hgam_comp) + mu_turb(i-ioff,j-joff,k-1,hgam_comp));
436  const Real gam_kp1 = myhalf * (mu_turb(i,j,k+1,hgam_comp) + mu_turb(i-ioff,j-joff,k+1,hgam_comp));
437  const Real gam_hi = myhalf * (gam_k + gam_kp1); // at k+1/2
438  const Real gam_lo = myhalf * (gam_k + gam_km1); // at k-1/2
439  RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
440  }
441 
442  RHS_a(i,j,k) = (RHS_a(i,j,k) - a_tmp * RHS_a(i,j,k-1)) * inv_b2_tmp; // NOTE: This is now "rho"
443  coeffG_a(i,j,k) = c_tmp * inv_b2_tmp; // NOTE: this is now "gamma"
444  } // k
445 
446  // Top boundary coefficients and RHS for L decomp
447  //===================================================
448  {
449  rhoface = myhalf * (cell_data(i,j,khi,Rho_comp) + cell_data(i-ioff,j-joff,khi,Rho_comp));
450  getRhoAlphaForFaces(i, j, khi, ioff, joff, rhoAlpha_lo, rhoAlpha_hi,
451  cell_data, mu_turb, mu_eff,
452  l_consA, l_turb);
453 
454  a_tmp = -Fact * gfac * rhoAlpha_lo * dz_inv;
455  c_tmp = zero;
456 
457  RHS_a(i,j,khi) = face_data(i,j,khi); // NOTE: this is momenta; solution is velocity
458  RHS_a(i,j,khi) += Fact * gfac * (tau_corr(i,j,khi+1) - tau_corr(i,j,khi));
459 
460  // BCs: Dirichlet (u_i = val), slip wall (w = 0)
461  if (ext_dir_on_zhi) {
462  if (stagdir==2) {
463  a_tmp = zero;
464  RHS_a(i,j,khi) = zero;
465  } else {
466  // NOTE: wall is 1/2 dz away (2 dz_inv)
467  c_tmp = -two * Fact * rhoAlpha_hi * dz_inv;
468  const Real rho_wall = myhalf * ( cell_data(i ,j ,khi+1,Rho_comp)
469  + cell_data(i-ioff,j-joff,khi+1,Rho_comp) );
470  const Real wall_velocity = face_data(i,j,khi+1) / rho_wall;
471  RHS_a(i,j,khi) -= c_tmp * wall_velocity;
472  }
473  }
474 
475  b_tmp = rhoface - a_tmp - c_tmp;
476  inv_b2_tmp = one/ (b_tmp - a_tmp * coeffG_a(i,j,khi-1));
477 
478  // First solve
479  soln_a(i,j,khi) = (RHS_a(i,j,khi) - a_tmp * RHS_a(i,j,khi-1)) * inv_b2_tmp;
480  }
481 
482  // Back sweep the U decomp solution
483  //===================================================
484  for (int k(khi-1); k>=klo; --k) {
485  soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
486  }
487 
488  // Convert back to momenta
489  //===================================================
490  for (int k(klo); k<=khi; ++k) {
491  rhoface = myhalf * (cell_data(i,j,k,Rho_comp) + cell_data(i-ioff,j-joff,k,Rho_comp));
492  face_data(i,j,k) = rhoface * soln_a(i,j,k);
493  }
494 
495 #ifdef AMREX_USE_GPU
496  });
497 #else
498  } // i
499  } // j
500 #endif
501 }
constexpr amrex::Real three
Definition: ERF_Constants.H:11
constexpr amrex::Real two
Definition: ERF_Constants.H:10
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
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 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);})
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:291
@ ext_dir
Definition: ERF_IndexDefines.H:292
@ ext_dir_prim
Definition: ERF_IndexDefines.H:295
@ 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:1864
DiffChoice diffChoice
Diffusion-related options.
Definition: ERF_DataStruct.H:1861
Definition: ERF_TurbStruct.H:114
bool use_kturb
Whether any turbulence model is active.
Definition: ERF_TurbStruct.H:665
Here is the call graph for this function:

◆ ImplicitDiffForStateLU_N()

void ImplicitDiffForStateLU_N ( const Box &  bx,
const Box &  domain,
const int  level,
const int  n,
const double  dt_d,
const GpuArray< Real, AMREX_SPACEDIM *2 > &  bc_neumann_vals,
const Array4< Real > &  cell_data,
const GpuArray< Real, AMREX_SPACEDIM > &  cellSizeInv,
const Array4< const Real > &  scalar_zflux,
const Array4< const Real > &  mu_turb,
const SolverChoice solverChoice,
const BCRec *  bc_ptr,
const bool  use_SurfLayer,
const Real  implicit_fac,
const bool  use_mrf_countergradient 
)

Function for computing the implicit contribution to the vertical diffusion of theta, with a uniform grid, no terrain, and LU decomposition.

Parameters
[in]bxcell-centered box to loop over
[in]levelAMR level
[in]domainbox of the whole domain
[in]nconserved component index
[in]dt_dtime step
[in]bc_neumann_valsvalues of derivatives if bc_type == Neumann
[in,out]cell_dataconserved cell-centered rho, rho theta
[in]cellSizeInvinverse cell size array
[in]scalar_zfluxscalar vertical flux in z-dir
[in]mu_turbturbulent viscosity
[in]solverChoicecontainer of parameters
[in]bc_ptrcontainer with boundary conditions
[in]use_SurfLayerwhether we have turned on subgrid diffusion
[in]implicit_facif 1 then fully implicit; if 0 then fully explicit
[in]use_mrf_countergradientwhether to include MRF countergradient correction
46 {
47  BL_PROFILE_VAR("ImplicitDiffForState_N()",ImplicitDiffForState_N);
48 
49  Real dt = static_cast<Real>(dt_d);
50 
51  // setup quantities for getRhoAlpha()
52 #include "ERF_SetupVertDiff.H"
53  const int qty_index = n;
54  const int prim_index = qty_index - 1;
55  const int prim_scal_index = (qty_index >= RhoScalar_comp && qty_index < RhoScalar_comp+NSCALARS) ? PrimScalar_comp : prim_index;
56 
57  // Box bounds
58  int ilo = bx.smallEnd(0);
59  int ihi = bx.bigEnd(0);
60  int jlo = bx.smallEnd(1);
61  int jhi = bx.bigEnd(1);
62  int klo = bx.smallEnd(2);
63  int khi = bx.bigEnd(2);
64  amrex::ignore_unused(ilo, ihi, jlo, jhi);
65 
66  // Temporary FABs for tridiagonal solve (allocated on column)
67  // A[k] * x[k-1] + B[k] * x[k] + C[k+1] = RHS[k]
68 
69  // With LU decomposition, M * x = r is written as L * U * x = r with U * x = rho
70  // We then first have L * rho = r and U * x = rho
71  amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
72  RHS_fab.resize(bx,1, amrex::The_Async_Arena());
73  soln_fab.resize(bx,1, amrex::The_Async_Arena());
74  coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
75  auto const& RHS_a = RHS_fab.array();
76  auto const& soln_a = soln_fab.array();
77  auto const& coeffG_a = coeffG_fab.array();
78 
79  Real dz_inv = cellSizeInv[2];
80 
81  int bc_comp = qty_index;
82  bool foextrap_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::foextrap);
83  bool foextrap_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::foextrap);
84  bool neumann_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::neumann);
85  bool neumann_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::neumann);
86  amrex::ignore_unused(foextrap_on_zlo, foextrap_on_zhi);
87 
88  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zlo || neumann_on_zlo || use_SurfLayer,
89  "Unexpected lower BC for scalars used with implicit vertical diffusion");
90  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zhi || neumann_on_zhi,
91  "Unexpected upper BC for scalars used with implicit vertical diffusion");
92 
93  Real Fact = implicit_fac * dt * dz_inv;
94 
95 #ifdef AMREX_USE_GPU
96  ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int)
97  {
98 #else
99  for (int j(jlo); j<=jhi; ++j) {
100  for (int i(ilo); i<=ihi; ++i) {
101 #endif
102  // Bottom boundary coefficients and RHS for L decomp
103  //===================================================
104  Real rhoAlpha_lo, rhoAlpha_hi;
105  Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
106  {
107  getRhoAlpha(i, j, klo, rhoAlpha_lo, rhoAlpha_hi,
108  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
109  prim_index, prim_scal_index, l_consA, l_turb);
110 
111  a_tmp = zero;
112  c_tmp = -Fact * rhoAlpha_hi * dz_inv;
113  b_tmp = cell_data(i,j,klo,Rho_comp) - a_tmp - c_tmp;
114  inv_b2_tmp = one;
115 
116  RHS_a(i,j,klo) = cell_data(i,j,klo,n); // NOTE: this is rho*phi; solution is phi
117  if (use_SurfLayer && scalar_zflux) {
118  RHS_a(i,j,klo) += Fact * scalar_zflux(i,j,klo); // NOTE: scalar_zflux = -K*d_z(\phi)
119  } else if (neumann_on_zlo) {
120  RHS_a(i,j,klo) += -Fact * rhoAlpha_lo * bc_neumann_vals[2]; // NOTE: N_val = d_z(\phi)
121  }
122 
123  // Add countergradient correction to RHS at bottom boundary.
124  // NOTE: The lower face at klo carries no countergradient flux -- the
125  // total surface flux is supplied by the surface layer model or the
126  // Neumann BC, while gamma represents nonlocal transport interior to
127  // the PBL. Only the upper face contributes here.
128  if (use_mrf_countergradient && (n == RhoTheta_comp || n == RhoQ1_comp)) {
129  const int gam_comp = (n == RhoTheta_comp) ? EddyDiff::HGAMT_v : EddyDiff::HGAMQ_v;
130  const Real gam_hi = myhalf * (mu_turb(i, j, klo, gam_comp) + mu_turb(i, j, klo+1, gam_comp));
131  RHS_a(i,j,klo) -= Fact * rhoAlpha_hi * gam_hi;
132  }
133 
134  RHS_a(i,j,klo) /= b_tmp; // NOTE: this is now "rho"
135  coeffG_a(i,j,klo) = c_tmp / b_tmp; // NOTE: this is now "gamma"
136  }
137 
138  // Build the coefficients and RHS for L decomp
139  //===================================================
140  for (int k(klo+1); k < khi; k++) {
141  getRhoAlpha(i, j, k, rhoAlpha_lo, rhoAlpha_hi,
142  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
143  prim_index, prim_scal_index, l_consA, l_turb);
144 
145  a_tmp = -Fact * rhoAlpha_lo * dz_inv;
146  c_tmp = -Fact * rhoAlpha_hi * dz_inv;
147  b_tmp = cell_data(i,j,k,Rho_comp) - a_tmp - c_tmp;
148  inv_b2_tmp = one / (b_tmp - a_tmp * coeffG_a(i,j,k-1));
149 
150  RHS_a(i,j,k) = cell_data(i,j,k,n); // NOTE: this is rho*phi; solution is phi
151 
152  // Add countergradient correction to RHS in interior
153  if (use_mrf_countergradient && (n == RhoTheta_comp || n == RhoQ1_comp)) {
154  const int gam_comp = (n == RhoTheta_comp) ? EddyDiff::HGAMT_v : EddyDiff::HGAMQ_v;
155  const Real gam_k = mu_turb(i, j, k, gam_comp);
156  const Real gam_km1 = mu_turb(i, j, k-1, gam_comp);
157  const Real gam_kp1 = mu_turb(i, j, k+1, gam_comp);
158  const Real gam_hi = myhalf * (gam_k + gam_kp1); // at k+½
159  const Real gam_lo = myhalf * (gam_k + gam_km1); // at k-½
160  // Countergradient flux divergence (implicit contribution to RHS):
161  // -Fact * [ρα_{k+½}·γ_{k+½} - ρα_{k-½}·γ_{k-½}]
162  RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
163  }
164 
165  RHS_a(i,j,k) = (RHS_a(i,j,k) - a_tmp * RHS_a(i,j,k-1)) * inv_b2_tmp; // NOTE: This is now "rho"
166  coeffG_a(i,j,k) = c_tmp * inv_b2_tmp; // NOTE: this is now "gamma"
167  } // k
168 
169  // Top boundary coefficients and RHS for L decomp
170  //===================================================
171  {
172  getRhoAlpha(i, j, khi, rhoAlpha_lo, rhoAlpha_hi,
173  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
174  prim_index, prim_scal_index, l_consA, l_turb);
175 
176  a_tmp = -Fact * rhoAlpha_lo * dz_inv;
177  c_tmp = zero;
178  b_tmp = cell_data(i,j,khi,Rho_comp) - a_tmp - c_tmp;
179  inv_b2_tmp = one / (b_tmp - a_tmp * coeffG_a(i,j,khi-1));
180 
181  RHS_a(i,j,khi) = cell_data(i,j,khi,n); // NOTE: this is rho*phi; solution is phi
182  if (neumann_on_zhi) {
183  RHS_a(i,j,khi) -= -Fact * rhoAlpha_hi * bc_neumann_vals[5]; // NOTE: N_val = d_z(\phi)
184  }
185 
186  // First solve
187  soln_a(i,j,khi) = (RHS_a(i,j,khi) - a_tmp * RHS_a(i,j,khi-1)) * inv_b2_tmp;
188  }
189 
190  // Back sweep the U decomp solution
191  //===================================================
192  for (int k(khi-1); k>=klo; --k) {
193  soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
194  }
195 
196  // Convert back to rho*theta
197  //===================================================
198  for (int k(klo); k<=khi; ++k) {
199  cell_data(i,j,k,n) = cell_data(i,j,k,Rho_comp) * soln_a(i,j,k);
200  }
201 
202 #ifdef AMREX_USE_GPU
203  });
204 #else
205  } // i
206  } // j
207 #endif
208 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void getRhoAlpha(int i, int j, int k, 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 *d_alpha_eff, const int *d_eddy_diff_idz, int prim_index, int prim_scal_index, bool l_consA, bool l_turb)
Definition: ERF_GetRhoAlpha.H:20
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:43
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:45
#define PrimScalar_comp
Definition: ERF_IndexDefines.H:60
@ neumann
Definition: ERF_IndexDefines.H:297
@ HGAMQ_v
Definition: ERF_IndexDefines.H:261
@ HGAMT_v
Definition: ERF_IndexDefines.H:260
Here is the call graph for this function: