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

Macros

#define INSTANTIATE_IMPLICIT_DIFF_FOR_MOM_LU(STAGDIR)
 

Functions

void ImplicitDiffForStateLU_S (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 Gpu::DeviceVector< Real > &stretched_dz_d, 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_S (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 Gpu::DeviceVector< Real > &stretched_dz_d, 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_S<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 Gpu::DeviceVector<Real>&, \
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:241

Function Documentation

◆ ImplicitDiffForMomLU_S()

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

◆ ImplicitDiffForStateLU_S()

void ImplicitDiffForStateLU_S ( 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 Gpu::DeviceVector< Real > &  stretched_dz_d,
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 vertically stretched grid over flat terrain.

Parameters
[in]bxcell-centered box to loop over
[in]domainbox of the whole domain
[in]levelAMR level
[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]stretched_dz_darray over z of dz[k]
[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
45 {
46  BL_PROFILE_VAR("ImplicitDiffForState_S()",ImplicitDiffForState_S);
47 
48  Real dt = static_cast<Real>(dt_d);
49 
50  // setup quantities for getRhoAlpha()
51 #include "ERF_SetupVertDiff.H"
52  const int qty_index = n;
53  const int prim_index = qty_index - 1;
54  const int prim_scal_index = (qty_index >= RhoScalar_comp && qty_index < RhoScalar_comp+NSCALARS) ? PrimScalar_comp : prim_index;
55 
56  // Box bounds
57  int ilo = bx.smallEnd(0);
58  int ihi = bx.bigEnd(0);
59  int jlo = bx.smallEnd(1);
60  int jhi = bx.bigEnd(1);
61  int klo = bx.smallEnd(2);
62  int khi = bx.bigEnd(2);
63  amrex::ignore_unused(ilo, ihi, jlo, jhi);
64 
65  // Temporary FABs for tridiagonal solve (allocated on column)
66  // A[k] * x[k-1] + B[k] * x[k] + C[k+1] = RHS[k]
67 
68  // With LU decomposition, M * x = r is written as L * U * x = r with U * x = rho
69  // We then first have L * rho = r and U * x = rho
70  amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
71  RHS_fab.resize(bx,1, amrex::The_Async_Arena());
72  soln_fab.resize(bx,1, amrex::The_Async_Arena());
73  coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
74  auto const& RHS_a = RHS_fab.array();
75  auto const& soln_a = soln_fab.array();
76  auto const& coeffG_a = coeffG_fab.array();
77 
78  auto dz_ptr = stretched_dz_d.data();
79 
80  int bc_comp = qty_index;
81  bool foextrap_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::foextrap);
82  bool foextrap_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::foextrap);
83  bool neumann_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::neumann);
84  bool neumann_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::neumann);
85  amrex::ignore_unused(foextrap_on_zlo, foextrap_on_zhi);
86 
87  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zlo || neumann_on_zlo || use_SurfLayer,
88  "Unexpected lower BC for scalars used with implicit vertical diffusion");
89  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zhi || neumann_on_zhi,
90  "Unexpected upper BC for scalars used with implicit vertical diffusion");
91 
92  Real Fact = implicit_fac * dt;
93 
94 #ifdef AMREX_USE_GPU
95  ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int)
96  {
97 #else
98  for (int j(jlo); j<=jhi; ++j) {
99  for (int i(ilo); i<=ihi; ++i) {
100 #endif
101  // Bottom boundary coefficients and RHS for L decomp
102  //===================================================
103  Real rhoAlpha_lo, rhoAlpha_hi;
104  Real dz_inv, dz_inv_lo, dz_inv_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  dz_inv = one / dz_ptr[klo];
112  dz_inv_lo = dz_inv;
113  dz_inv_hi = two / (dz_ptr[klo] + dz_ptr[klo+1]);
114 
115  a_tmp = zero;
116  c_tmp = -Fact * rhoAlpha_hi * dz_inv_hi * dz_inv;
117  b_tmp = cell_data(i,j,klo,Rho_comp) - a_tmp - c_tmp;
118  inv_b2_tmp = one;
119 
120  RHS_a(i,j,klo) = cell_data(i,j,klo,n); // NOTE: this is rho*phi; solution is phi
121  if (use_SurfLayer && scalar_zflux) {
122  RHS_a(i,j,klo) += Fact * dz_inv * scalar_zflux(i,j,klo); // NOTE: scalar_zflux = -K*d_z(\phi)
123  } else if (neumann_on_zlo) {
124  RHS_a(i,j,klo) += -Fact * dz_inv * rhoAlpha_lo * bc_neumann_vals[2]; // NOTE: N_val = d_z(\phi)
125  }
126 
127  // Add countergradient correction to RHS at bottom boundary
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 * dz_inv_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  dz_inv = one / dz_ptr[k];
146  dz_inv_lo = two / (dz_ptr[k] + dz_ptr[k-1]);
147  dz_inv_hi = two / (dz_ptr[k] + dz_ptr[k+1]);
148 
149  a_tmp = -Fact * rhoAlpha_lo * dz_inv_lo * dz_inv;
150  c_tmp = -Fact * rhoAlpha_hi * dz_inv_hi * dz_inv;
151  b_tmp = cell_data(i,j,k,Rho_comp) - a_tmp - c_tmp;
152  inv_b2_tmp = one / (b_tmp - a_tmp * coeffG_a(i,j,k-1));
153 
154  RHS_a(i,j,k) = cell_data(i,j,k,n); // NOTE: this is rho*phi; solution is phi
155 
156  // Add countergradient correction to RHS in interior
157  if (use_mrf_countergradient && (n == RhoTheta_comp || n == RhoQ1_comp)) {
158  const int gam_comp = (n == RhoTheta_comp) ? EddyDiff::HGAMT_v : EddyDiff::HGAMQ_v;
159  const Real gam_k = mu_turb(i, j, k, gam_comp);
160  const Real gam_km1 = mu_turb(i, j, k-1, gam_comp);
161  const Real gam_kp1 = mu_turb(i, j, k+1, gam_comp);
162  const Real gam_hi = myhalf * (gam_k + gam_kp1); // at k+½
163  const Real gam_lo = myhalf * (gam_k + gam_km1); // at k-½
164  // Countergradient flux divergence (implicit contribution to RHS):
165  // -Fact * [ρα_{k+½}·γ_{k+½}·dz_inv_hi - ρα_{k-½}·γ_{k-½}·dz_inv_lo]
166  RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi * dz_inv_hi - rhoAlpha_lo * gam_lo * dz_inv_lo);
167  }
168 
169  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"
170  coeffG_a(i,j,k) = c_tmp * inv_b2_tmp; // NOTE: this is now "gamma"
171  } // k
172 
173  // Top boundary coefficients and RHS for L decomp
174  //===================================================
175  {
176  getRhoAlpha(i, j, khi, rhoAlpha_lo, rhoAlpha_hi,
177  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
178  prim_index, prim_scal_index, l_consA, l_turb);
179 
180  dz_inv = one / dz_ptr[khi];
181  dz_inv_lo = two / (dz_ptr[khi] + dz_ptr[khi-1]);
182  dz_inv_hi = dz_inv;
183 
184  a_tmp = -Fact * rhoAlpha_lo * dz_inv_lo * dz_inv;
185  c_tmp = zero;
186  b_tmp = cell_data(i,j,khi,Rho_comp) - a_tmp - c_tmp;
187  inv_b2_tmp = one / (b_tmp - a_tmp * coeffG_a(i,j,khi-1));
188 
189  RHS_a(i,j,khi) = cell_data(i,j,khi,n); // NOTE: this is rho*phi; solution is phi
190  if (neumann_on_zhi) {
191  RHS_a(i,j,khi) -= -Fact * dz_inv * rhoAlpha_hi * bc_neumann_vals[5]; // NOTE: N_val = d_z(\phi)
192  }
193 
194  // First solve
195  soln_a(i,j,khi) = (RHS_a(i,j,khi) - a_tmp * RHS_a(i,j,khi-1)) * inv_b2_tmp;
196  }
197 
198  // Back sweep the U decomp solution
199  //===================================================
200  for (int k(khi-1); k>=klo; --k) {
201  soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
202  }
203 
204  // Convert back to rho*theta
205  //===================================================
206  for (int k(klo); k<=khi; ++k) {
207  cell_data(i,j,k,n) = cell_data(i,j,k,Rho_comp) * soln_a(i,j,k);
208  }
209 
210 #ifdef AMREX_USE_GPU
211  });
212 #else
213  } // i
214  } // j
215 #endif
216 }
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:40
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
#define PrimScalar_comp
Definition: ERF_IndexDefines.H:57
@ neumann
Definition: ERF_IndexDefines.H:254
@ HGAMQ_v
Definition: ERF_IndexDefines.H:218
@ HGAMT_v
Definition: ERF_IndexDefines.H:217
Here is the call graph for this function: