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

Macros

#define INSTANTIATE_IMPLICIT_DIFF_FOR_MOM_LU(STAGDIR)
 

Functions

void ImplicitDiffForStateLU_T (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 Array4< const Real > &z_nd, const Array4< const Real > &detJ, 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_T (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 Array4< const Real > &z_nd, const Array4< const Real > &detJ, 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_T<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 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_T()

template<int stagdir>
void ImplicitDiffForMomLU_T ( 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 Array4< const Real > &  z_nd,
const Array4< const Real > &  detJ,
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, 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.

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

void ImplicitDiffForStateLU_T ( 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 Array4< const Real > &  z_nd,
const Array4< const Real > &  detJ,
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 terrain.

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