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:141

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]domainbox of the whole domain
[in]dttime step
[in]cell_dataconserved cell-centered rho
[in,out]face_dataconserved 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
244 {
245  BL_PROFILE_VAR("ImplicitDiffForMom_N()",ImplicitDiffForMom_N);
246 
247  Real dt = static_cast<Real>(dt_d);
248 
249  // setup quantities for getRhoAlphaAtFaces()
250  DiffChoice dc = solverChoice.diffChoice;
251  TurbChoice tc = solverChoice.turbChoice[level];
253  bool l_turb = tc.use_kturb;
254  Real mu_eff = (l_consA) ? two * dc.dynamic_viscosity / dc.rho0_trans
255  : two * dc.dynamic_viscosity;
256 
257  // g(S*) coefficient
258  // stagdir==0: tau_corr = myhalf * du/dz * mu_tot
259  // stagdir==1: tau_corr = myhalf * dv/dz * mu_tot
260  // stagdir==2: tau_corr = dw/dz * mu_tot
261  constexpr Real gfac = (stagdir == 2) ? two/three : one;
262 
263  // offsets used to average to faces
264  constexpr int ioff = (stagdir == 0) ? 1 : 0;
265  constexpr int joff = (stagdir == 1) ? 1 : 0;
266 
267  // Box bounds
268  int ilo = bx.smallEnd(0);
269  int ihi = bx.bigEnd(0);
270  int jlo = bx.smallEnd(1);
271  int jhi = bx.bigEnd(1);
272  int klo = bx.smallEnd(2);
273  int khi = bx.bigEnd(2);
274  amrex::ignore_unused(ilo, ihi, jlo, jhi);
275 
276  // Temporary FABs for tridiagonal solve (allocated on column)
277  // A[k] * x[k-1] + B[k] * x[k] + C[k+1] = RHS[k]
278  amrex::FArrayBox RHS_fab, soln_fab, coeffG_fab;
279  RHS_fab.resize(bx,1, amrex::The_Async_Arena());
280  soln_fab.resize(bx,1, amrex::The_Async_Arena());
281  coeffG_fab.resize(bx,1, amrex::The_Async_Arena());
282  auto const& RHS_a = RHS_fab.array();
283  auto const& soln_a = soln_fab.array();
284  auto const& coeffG_a = coeffG_fab.array();
285 
286  Real dz_inv = cellSizeInv[2];
287 
288  int bc_comp = BCVars::xvel_bc + stagdir;
289  bool ext_dir_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir ||
290  bc_ptr[bc_comp].lo(2) == ERFBCType::ext_dir_prim);
291  bool ext_dir_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir ||
292  bc_ptr[bc_comp].hi(2) == ERFBCType::ext_dir_prim);
293  bool foextrap_on_zlo = (bc_ptr[bc_comp].lo(2) == ERFBCType::foextrap);
294  bool foextrap_on_zhi = (bc_ptr[bc_comp].hi(2) == ERFBCType::foextrap);
295  amrex::ignore_unused(foextrap_on_zlo,foextrap_on_zhi);
296 
297  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zlo || ext_dir_on_zlo || use_SurfLayer,
298  "Unexpected lower BC for momentum used with implicit vertical diffusion");
299  AMREX_ASSERT_WITH_MESSAGE(foextrap_on_zhi || ext_dir_on_zhi,
300  "Unexpected upper BC for momentum used with implicit vertical diffusion");
301 
302  Real Fact = implicit_fac * dt * dz_inv;
303 
304 #ifdef AMREX_USE_GPU
305  ParallelFor(makeSlab(bx,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int)
306  {
307 #else
308  for (int j(jlo); j<=jhi; ++j) {
309  for (int i(ilo); i<=ihi; ++i) {
310 #endif
311  // Notes:
312  //
313  // - In DiffusionSrcForMom (e.g., for x-mom)
314  //
315  // Real diffContrib = ...
316  // + (tau13(i,j,k+1) - tau13(i,j,k)) / dzinv
317  // rho_u_rhs(i,j,k) -= diffContrib; // note the negative sign
318  //
319  // - We need to scale the explicit _part_ of `tau13` (for x-mom) by (1 - implicit_fac)
320  // The part that needs to be scaled is stored in `tau_corr`.
321  // E.g., tau13 = 0.5 * (du/dz + dw/dx)
322  // tau13_corr = 0.5 * du/dz
323  //
324  // - The momentum (`face_data`) was set to `S_old + S_rhs * dt`
325  // prior to including "ERF_Implicit.H". Recall that S_rhs includes
326  // sources from advection and other forcings, not just diffusion.
327  //
328  // - To correct momentum, we need to subtract `implicit_fac * diffContrib_corr`
329  // from S_rhs to recover `(1 - implicit_fac) * diffContrib_corr`,
330  // where `diffContrib_corr = -d(tau_corr)/dz`. The negative sign
331  // comes from our convention for the RHS diffusion source.
332  //
333  // Subtracting a negative gives the += below; multiply by dt to
334  // get the intermediate momentum on the RHS of the tridiagonal
335  // system.
336  //
337  // - With a surface_layer BC, tau13/23 holds the vertical flux -d_z(k*u_i)
338  // directly. We must use tau at klo (not tau_corr) with SL BCs.
339  //
340  // - Finally, the terms ~ RHS += (tau_corr_hi - tau_corr_lo) / dz (below)
341  // essentially undo the explicit diffusion update that will be
342  // handled here implicitly.
343 
344  // Bottom boundary coefficients and RHS for L decomp
345  //===================================================
346  Real rhoface, rhoAlpha_lo, rhoAlpha_hi;
347  Real a_tmp, b_tmp, c_tmp, inv_b2_tmp;
348  {
349  rhoface = myhalf * (cell_data(i,j,klo,Rho_comp) + cell_data(i-ioff,j-joff,klo,Rho_comp));
350  getRhoAlphaForFaces(i, j, klo, ioff, joff, rhoAlpha_lo, rhoAlpha_hi,
351  cell_data, mu_turb, mu_eff,
352  l_consA, l_turb);
353 
354  a_tmp = zero;
355  c_tmp = -Fact * gfac * rhoAlpha_hi * dz_inv;
356 
357  RHS_a(i,j,klo) = face_data(i,j,klo); // NOTE: this is momenta; solution is velocity
358 
359  // BCs: Dirichlet (u_i = val), slip wall (w = 0), or surface layer (w = 0)
360  if (ext_dir_on_zlo) {
361  RHS_a(i,j,klo) += Fact * gfac * (tau_corr(i,j,klo+1) - tau_corr(i,j,klo));
362  if (stagdir==2) {
363  c_tmp = zero;
364  RHS_a(i,j,klo) = zero;
365  } else {
366  // NOTE: wall is 1/2 dz away (2 dz_inv)
367  a_tmp = -two * Fact * rhoAlpha_lo * dz_inv;
368  RHS_a(i,j,klo) += two * rhoAlpha_lo * face_data(i,j,klo-1) * dz_inv * dz_inv;
369  }
370  } else if (use_SurfLayer) {
371  // NOTE: tau = -mu*d_z(u_i) w/ SL
372  RHS_a(i,j,klo) += Fact * gfac * (tau_corr(i,j,klo+1) - tau(i,j,klo));
373  RHS_a(i,j,klo) += Fact * tau(i,j,klo);
374  } else {
375  // NOTE: FOEXTRAP has zero lower flux (nothing to add to RHS)
376  RHS_a(i,j,klo) += Fact * gfac * (tau_corr(i,j,klo+1) - tau_corr(i,j,klo));
377  }
378 
379  // Add YSU momentum countergradient correction at bottom boundary
380  if (use_ysu_mom_countergradient && stagdir < 2) {
381  const int hgam_comp = (stagdir == 0) ? EddyDiff::HGAMU_v : EddyDiff::HGAMV_v;
382  const Real gam_hi = myhalf * (mu_turb(i,j,klo,hgam_comp) + mu_turb(i,j,klo+1,hgam_comp));
383  RHS_a(i,j,klo) += Fact * gfac * dz_inv * rhoAlpha_hi * gam_hi;
384  }
385 
386  b_tmp = rhoface - a_tmp - c_tmp;
387  inv_b2_tmp = one;
388 
389  RHS_a(i,j,klo) /= b_tmp; // NOTE: this is now "rho"
390  coeffG_a(i,j,klo) = c_tmp / b_tmp; // NOTE: this is now "gamma"
391  }
392 
393  // Build the coefficients and RHS for L decomp
394  //===================================================
395  for (int k(klo+1); k < khi; k++) {
396  rhoface = myhalf * (cell_data(i,j,k,Rho_comp) + cell_data(i-ioff,j-joff,k,Rho_comp));
397  getRhoAlphaForFaces(i, j, k, ioff, joff, rhoAlpha_lo, rhoAlpha_hi,
398  cell_data, mu_turb, mu_eff,
399  l_consA, l_turb);
400 
401  a_tmp = -Fact * rhoAlpha_lo * dz_inv;
402  c_tmp = -Fact * rhoAlpha_hi * dz_inv;
403  b_tmp = rhoface - a_tmp - c_tmp;
404  inv_b2_tmp = one/ (b_tmp - a_tmp * coeffG_a(i,j,k-1));
405 
406  RHS_a(i,j,k) = face_data(i,j,k); // NOTE: this is momenta; solution is velocity
407  RHS_a(i,j,k) += Fact * gfac * (tau_corr(i,j,k+1) - tau_corr(i,j,k));
408 
409  // Add YSU momentum countergradient correction
410  if (use_ysu_mom_countergradient && stagdir < 2) {
411  const int hgam_comp = (stagdir == 0) ? EddyDiff::HGAMU_v : EddyDiff::HGAMV_v;
412  const Real gam_k = mu_turb(i, j, k, hgam_comp);
413  const Real gam_km1 = mu_turb(i, j, k-1, hgam_comp);
414  const Real gam_kp1 = mu_turb(i, j, k+1, hgam_comp);
415  const Real gam_hi = myhalf * (gam_k + gam_kp1);
416  const Real gam_lo = myhalf * (gam_k + gam_km1);
417  RHS_a(i,j,k) += Fact * gfac * dz_inv * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
418  }
419 
420  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"
421  coeffG_a(i,j,k) = c_tmp * inv_b2_tmp; // NOTE: this is now "gamma"
422  } // k
423 
424  // Top boundary coefficients and RHS for L decomp
425  //===================================================
426  {
427  rhoface = myhalf * (cell_data(i,j,khi,Rho_comp) + cell_data(i-ioff,j-joff,khi,Rho_comp));
428  getRhoAlphaForFaces(i, j, khi, ioff, joff, rhoAlpha_lo, rhoAlpha_hi,
429  cell_data, mu_turb, mu_eff,
430  l_consA, l_turb);
431 
432  a_tmp = -Fact * gfac * rhoAlpha_lo * dz_inv;
433  c_tmp = zero;
434 
435  RHS_a(i,j,khi) = face_data(i,j,khi); // NOTE: this is momenta; solution is velocity
436  RHS_a(i,j,khi) += Fact * gfac * (tau_corr(i,j,khi+1) - tau_corr(i,j,khi));
437 
438  // BCs: Dirichlet (u_i = val), slip wall (w = 0)
439  if (ext_dir_on_zhi) {
440  if (stagdir==2) {
441  a_tmp = zero;
442  RHS_a(i,j,khi) = zero;
443  } else {
444  // NOTE: wall is 1/2 dz away (2 dz_inv)
445  c_tmp = -two * Fact * rhoAlpha_hi * dz_inv;
446  RHS_a(i,j,khi) += two * rhoAlpha_hi * face_data(i,j,khi+1) * dz_inv * dz_inv;
447  }
448  }
449 
450  b_tmp = rhoface - a_tmp - c_tmp;
451  inv_b2_tmp = one/ (b_tmp - a_tmp * coeffG_a(i,j,khi-1));
452 
453  // First solve
454  soln_a(i,j,khi) = (RHS_a(i,j,khi) - a_tmp * RHS_a(i,j,khi-1)) * inv_b2_tmp;
455  }
456 
457  // Back sweep the U decomp solution
458  //===================================================
459  for (int k(khi-1); k>=klo; --k) {
460  soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
461  }
462 
463  // Convert back to momenta
464  //===================================================
465  for (int k(klo); k<=khi; ++k) {
466  rhoface = myhalf * (cell_data(i,j,k,Rho_comp) + cell_data(i-ioff,j-joff,k,Rho_comp));
467  face_data(i,j,k) = rhoface * soln_a(i,j,k);
468  }
469 
470 #ifdef AMREX_USE_GPU
471  });
472 #else
473  } // i
474  } // j
475 #endif
476 }
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:5
#define Rho_comp
Definition: ERF_IndexDefines.H:36
const int khi
Definition: ERF_InitCustomPert_Bubble.H:21
ParallelFor(grown_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);})
bool l_turb
Definition: ERF_SetupVertDiff.H:9
bool l_consA
Definition: ERF_SetupVertDiff.H:8
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:247
@ ext_dir
Definition: ERF_IndexDefines.H:248
@ ext_dir_prim
Definition: ERF_IndexDefines.H:251
@ HGAMU_v
Definition: ERF_IndexDefines.H:218
@ HGAMV_v
Definition: ERF_IndexDefines.H:219
Definition: ERF_DiffStruct.H:19
amrex::Real rho0_trans
Definition: ERF_DiffStruct.H:91
MolecDiffType molec_diff_type
Definition: ERF_DiffStruct.H:84
amrex::Real dynamic_viscosity
Definition: ERF_DiffStruct.H:96
DiffChoice diffChoice
Definition: ERF_DataStruct.H:1248
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:1251
Definition: ERF_TurbStruct.H:82
bool use_kturb
Definition: ERF_TurbStruct.H:577
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]dttime 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,out]hfx_zheat 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_N()",ImplicitDiffForState_N);
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  Real dz_inv = cellSizeInv[2];
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 * dz_inv;
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 a_tmp, b_tmp, c_tmp, inv_b2_tmp;
105  {
106  getRhoAlpha(i, j, klo, rhoAlpha_lo, rhoAlpha_hi,
107  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
108  prim_index, prim_scal_index, l_consA, l_turb);
109 
110  a_tmp = zero;
111  c_tmp = -Fact * rhoAlpha_hi * dz_inv;
112  b_tmp = cell_data(i,j,klo,Rho_comp) - a_tmp - c_tmp;
113  inv_b2_tmp = one;
114 
115  RHS_a(i,j,klo) = cell_data(i,j,klo,n); // NOTE: this is rho*phi; solution is phi
116  if (use_SurfLayer && scalar_zflux) {
117  RHS_a(i,j,klo) += Fact * scalar_zflux(i,j,klo); // NOTE: scalar_zflux = -K*d_z(\phi)
118  } else if (neumann_on_zlo) {
119  RHS_a(i,j,klo) += -Fact * rhoAlpha_lo * bc_neumann_vals[2]; // NOTE: N_val = d_z(\phi)
120  }
121 
122  // Add countergradient correction to RHS at bottom boundary
123  // Only upper face contributes (no flux below surface)
124  if (use_mrf_countergradient && (n == RhoTheta_comp || n == RhoQ1_comp)) {
125  const int gam_comp = (n == RhoTheta_comp) ? EddyDiff::HGAMT_v : EddyDiff::HGAMQ_v;
126  const Real gam_hi = myhalf * (mu_turb(i, j, klo, gam_comp) + mu_turb(i, j, klo+1, gam_comp));
127  RHS_a(i,j,klo) -= Fact * rhoAlpha_hi * gam_hi;
128  }
129 
130  RHS_a(i,j,klo) /= b_tmp; // NOTE: this is now "rho"
131  coeffG_a(i,j,klo) = c_tmp / b_tmp; // NOTE: this is now "gamma"
132  }
133 
134  // Build the coefficients and RHS for L decomp
135  //===================================================
136  for (int k(klo+1); k < khi; k++) {
137  getRhoAlpha(i, j, k, rhoAlpha_lo, rhoAlpha_hi,
138  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
139  prim_index, prim_scal_index, l_consA, l_turb);
140 
141  a_tmp = -Fact * rhoAlpha_lo * dz_inv;
142  c_tmp = -Fact * rhoAlpha_hi * dz_inv;
143  b_tmp = cell_data(i,j,k,Rho_comp) - a_tmp - c_tmp;
144  inv_b2_tmp = one / (b_tmp - a_tmp * coeffG_a(i,j,k-1));
145 
146  RHS_a(i,j,k) = cell_data(i,j,k,n); // NOTE: this is rho*phi; solution is phi
147 
148  // Add countergradient correction to RHS in interior
149  if (use_mrf_countergradient && (n == RhoTheta_comp || n == RhoQ1_comp)) {
150  const int gam_comp = (n == RhoTheta_comp) ? EddyDiff::HGAMT_v : EddyDiff::HGAMQ_v;
151  const Real gam_k = mu_turb(i, j, k, gam_comp);
152  const Real gam_km1 = mu_turb(i, j, k-1, gam_comp);
153  const Real gam_kp1 = mu_turb(i, j, k+1, gam_comp);
154  const Real gam_hi = myhalf * (gam_k + gam_kp1); // at k+½
155  const Real gam_lo = myhalf * (gam_k + gam_km1); // at k-½
156  // Countergradient flux divergence (implicit contribution to RHS):
157  // -Fact * [ρα_{k+½}·γ_{k+½} - ρα_{k-½}·γ_{k-½}]
158  RHS_a(i,j,k) -= Fact * (rhoAlpha_hi * gam_hi - rhoAlpha_lo * gam_lo);
159  }
160 
161  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"
162  coeffG_a(i,j,k) = c_tmp * inv_b2_tmp; // NOTE: this is now "gamma"
163  } // k
164 
165  // Top boundary coefficients and RHS for L decomp
166  //===================================================
167  {
168  getRhoAlpha(i, j, khi, rhoAlpha_lo, rhoAlpha_hi,
169  cell_data, mu_turb, d_alpha_eff, d_eddy_diff_idz,
170  prim_index, prim_scal_index, l_consA, l_turb);
171 
172  a_tmp = -Fact * rhoAlpha_lo * dz_inv;
173  c_tmp = zero;
174  b_tmp = cell_data(i,j,khi,Rho_comp) - a_tmp - c_tmp;
175  inv_b2_tmp = one / (b_tmp - a_tmp * coeffG_a(i,j,khi-1));
176 
177  RHS_a(i,j,khi) = cell_data(i,j,khi,n); // NOTE: this is rho*phi; solution is phi
178  if (neumann_on_zhi) {
179  RHS_a(i,j,khi) -= -Fact * rhoAlpha_hi * bc_neumann_vals[5]; // NOTE: N_val = d_z(\phi)
180  }
181 
182  // First solve
183  soln_a(i,j,khi) = (RHS_a(i,j,khi) - a_tmp * RHS_a(i,j,khi-1)) * inv_b2_tmp;
184  }
185 
186  // Back sweep the U decomp solution
187  //===================================================
188  for (int k(khi-1); k>=klo; --k) {
189  soln_a(i,j,k) = RHS_a(i,j,k) - coeffG_a(i,j,k) * soln_a(i,j,k+1);
190  }
191 
192  // Convert back to rho*theta
193  //===================================================
194  for (int k(klo); k<=khi; ++k) {
195  cell_data(i,j,k,n) = cell_data(i,j,k,Rho_comp) * soln_a(i,j,k);
196  }
197 
198 #ifdef AMREX_USE_GPU
199  });
200 #else
201  } // i
202  } // j
203 #endif
204 }
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:5
#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
int * d_eddy_diff_idz
Definition: ERF_SetupVertDiff.H:99
Real * d_alpha_eff
Definition: ERF_SetupVertDiff.H:98
@ neumann
Definition: ERF_IndexDefines.H:253
@ HGAMQ_v
Definition: ERF_IndexDefines.H:217
@ HGAMT_v
Definition: ERF_IndexDefines.H:216
Here is the call graph for this function: