ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SlowRhsPre.cpp File Reference
#include "AMReX_MultiFab.H"
#include "AMReX_iMultiFab.H"
#include "AMReX_ArrayLim.H"
#include "AMReX_BCRec.H"
#include "AMReX_GpuContainers.H"
#include "AMReX_GpuPrint.H"
#include "ERF_TI_slow_headers.H"
#include "ERF_SlowRhsPreUtils.H"
#include "ERF_ShocDriver.H"
#include "ERF_EOS.H"
#include "ERF_Utils.H"
#include "ERF_Diffusion.H"
#include "ERF_EBAdvection.H"
#include "ERF_EB.H"
#include "ERF_SurfaceLayer.H"
#include "Diffusion/ERF_CloudChamberWallFlux.H"
#include "Diffusion/ERF_CloudChamberWallStress.H"
#include "Prob/ERF_CloudChamberBudget.H"
Include dependency graph for ERF_SlowRhsPre.cpp:

Functions

void erf_slow_rhs_pre (int level, int finest_level, int nrk, double dt, Vector< MultiFab > &S_rhs, Vector< MultiFab > &S_old, Vector< MultiFab > &S_data, const MultiFab &S_prim, const MultiFab &qt, MultiFab &avg_xmom, MultiFab &avg_ymom, MultiFab &avg_zmom, const Array< const MultiFab *, AMREX_SPACEDIM > &upw_dir, MultiFab *pi_adv_rt, const MultiFab &xvel, const MultiFab &yvel, const MultiFab &zvel, std::unique_ptr< MultiFab > &z_t_mf, const MultiFab &cc_src, const MultiFab &xmom_src, const MultiFab &ymom_src, const MultiFab &zmom_src, const MultiFab &buoyancy, const MultiFab *zmom_crse_rhs, Vector< std::unique_ptr< MultiFab >> &Tau_lev, Vector< std::unique_ptr< MultiFab >> &Tau_corr_lev, Vector< Vector< std::unique_ptr< MultiFab >>> &Tau_EB, MultiFab *SmnSmn, MultiFab *eddyDiffs, MultiFab *Hfx1, MultiFab *Hfx2, MultiFab *Hfx3, MultiFab *Q1fx1, MultiFab *Q1fx2, MultiFab *Q1fx3, MultiFab *Q2fx3, MultiFab *, MultiFab *mf_surface_fluxes, MultiFab *Hfx3_EB, const Geometry geom, const SolverChoice &solverChoice, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const Gpu::DeviceVector< BCRec > &domain_bcs_type_d, const Vector< BCRec > &domain_bcs_type_h, const MultiFab &z_phys_nd, const MultiFab &z_phys_cc, const MultiFab &ax, const MultiFab &ay, const MultiFab &az, const MultiFab &detJ, Gpu::DeviceVector< Real > &stretched_dz_d, Vector< MultiFab > &gradp, Vector< std::unique_ptr< MultiFab >> &mapfac, const eb_ &ebfact, const Vector< iMultiFab > &physbnd_mask, ShocDriver *native_shoc_lev, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, const MultiFab *cloud_chamber_base_state, const erf_cloud_chamber::Config *cloud_chamber_config, CloudChamberBudget *cloud_budget, const MultiFab *ib_wall_face13, const MultiFab *ib_wall_face23, const MultiFab *ib_wall_face33, const MultiFab *ib_wall_hfx, const MultiFab *walldist)
 

Function Documentation

◆ erf_slow_rhs_pre()

void erf_slow_rhs_pre ( int  level,
int  finest_level,
int  nrk,
double  dt,
Vector< MultiFab > &  S_rhs,
Vector< MultiFab > &  S_old,
Vector< MultiFab > &  S_data,
const MultiFab &  S_prim,
const MultiFab &  qt,
MultiFab &  avg_xmom,
MultiFab &  avg_ymom,
MultiFab &  avg_zmom,
const Array< const MultiFab *, AMREX_SPACEDIM > &  upw_dir,
MultiFab *  pi_adv_rt,
const MultiFab &  xvel,
const MultiFab &  yvel,
const MultiFab &  zvel,
std::unique_ptr< MultiFab > &  z_t_mf,
const MultiFab &  cc_src,
const MultiFab &  xmom_src,
const MultiFab &  ymom_src,
const MultiFab &  zmom_src,
const MultiFab &  buoyancy,
const MultiFab *  zmom_crse_rhs,
Vector< std::unique_ptr< MultiFab >> &  Tau_lev,
Vector< std::unique_ptr< MultiFab >> &  Tau_corr_lev,
Vector< Vector< std::unique_ptr< MultiFab >>> &  Tau_EB,
MultiFab *  SmnSmn,
MultiFab *  eddyDiffs,
MultiFab *  Hfx1,
MultiFab *  Hfx2,
MultiFab *  Hfx3,
MultiFab *  Q1fx1,
MultiFab *  Q1fx2,
MultiFab *  Q1fx3,
MultiFab *  Q2fx3,
MultiFab *  ,
MultiFab *  mf_surface_fluxes,
MultiFab *  Hfx3_EB,
const Geometry  geom,
const SolverChoice &  solverChoice,
const amrex::Vector< std::unique_ptr< SurfaceLayer >> &  SurfLayer,
const Gpu::DeviceVector< BCRec > &  domain_bcs_type_d,
const Vector< BCRec > &  domain_bcs_type_h,
const MultiFab &  z_phys_nd,
const MultiFab &  z_phys_cc,
const MultiFab &  ax,
const MultiFab &  ay,
const MultiFab &  az,
const MultiFab &  detJ,
Gpu::DeviceVector< Real > &  stretched_dz_d,
Vector< MultiFab > &  gradp,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const eb_ &  ebfact,
const Vector< iMultiFab > &  physbnd_mask,
ShocDriver *  native_shoc_lev,
YAFluxRegister *  fr_as_crse,
YAFluxRegister *  fr_as_fine,
const MultiFab *  cloud_chamber_base_state,
const erf_cloud_chamber::Config *  cloud_chamber_config,
CloudChamberBudget *  cloud_budget,
const MultiFab *  ib_wall_face13,
const MultiFab *  ib_wall_face23,
const MultiFab *  ib_wall_face33,
const MultiFab *  ib_wall_hfx,
const MultiFab *  walldist 
)

Function for computing the slow RHS for the evolution equations for the density, potential temperature and momentum.

Parameters
[in]levellevel of resolution
[in]finest_levelfinest level of resolution
[in]nrkwhich RK stage
[in]dtslow time step
[out]S_rhsRHS computed here
[in]S_oldold-time solution – used only for anelastic or pseudo-incompressible
[in]S_datacurrent solution
[in]S_primprimitive variables (i.e. conserved variables divided by density)
[in,out]avg_xmom
[in,out]avg_ymom
[in,out]avg_zmom
[in]upw_dirupwind direction on the faces set by the latest projection, on a pseudo-incompressible level (nullptr otherwise: the mass flux picks it)
[out]pi_adv_rtadvective tendency of (rho theta) in this stage (averaged with the previous stage's where the RHS is averaged), on a pseudo-incompressible level (nullptr otherwise)
[in]xvelx-component of velocity
[in]yvely-component of velocity
[in]zvelz-component of velocity
[in]z_t_mf rate of change of grid height – only relevant for moving terrain
[in]cc_srcsource terms for conserved variables
[in]xmom_srcsource terms for x-momentum
[in]ymom_srcsource terms for y-momentum
[in]zmom_srcsource terms for z-momentum
[in]buoyancybuoyancy source term for z-momentum
[in]zmom_crse_rhsupdate term from coarser level for z-momentum; non-zero on c/f boundary only
[in]Tau_levcomponents of stress tensor
[in]SmnSmnstrain rate magnitude
[in]eddyDiffsdiffusion coefficients for LES turbulence models
[in]Hfx3heat flux in z-dir
[in]Dissdissipation of turbulent kinetic energy
[in]geomContainer for geometric information
[in]solverChoiceContainer for solver parameters
[in]SurfLayerPointer to SurfaceLayer class for Monin-Obukhov Similarity Theory boundary condition
[in]domain_bcs_type_ddevice vector for domain boundary conditions
[in]domain_bcs_type_hhost vector for domain boundary conditions
[in]z_phys_ndheight coordinate at nodes
[in]axarea fractions on x-faces
[in]ayarea fractions on y-faces
[in]azarea fractions on z-faces
[in]detJJacobian of the metric transformation (= 1 if use_terrain_fitted_coords is false)
[in]gradppressure gradient
[in]mapfacmap factors
[in]ebfactEB factories for cell- and face-centered variables
[in]physbnd_maskEB only: masks of the physical-boundary ghost cells of each variable
[in,out]fr_as_crseYAFluxRegister at level l at level l / l+1 interface
[in,out]fr_as_fineYAFluxRegister at level l at level l-1 / l interface
135 {
136  BL_PROFILE_REGION("erf_slow_rhs_pre()");
137 
138  const BCRec* bc_ptr_d = domain_bcs_type_d.data();
139  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
140 
141  DiffChoice dc = solverChoice.diffChoice;
142  TurbChoice tc = solverChoice.turbChoice[level];
143 
144  const Box& domain = geom.Domain();
145  const bool use_physical_chamber_wall_flux =
146  cloud_chamber_config != nullptr && cloud_chamber_base_state != nullptr &&
147  cloud_chamber_config->physical_initialization;
148  const erf_wall_thermodynamics::Boundary chamber_walls =
149  use_physical_chamber_wall_flux ? cloud_chamber_config->transport_boundary() :
151  const auto chamber_bands = use_physical_chamber_wall_flux ? cloud_chamber_config->temperature_band_views() :
153  int klo = domain.smallEnd(2);
154  int khi = domain.bigEnd(2);
155 
156  const AdvType l_horiz_adv_type = solverChoice.advChoice.dycore_horiz_adv_type;
157  const AdvType l_vert_adv_type = solverChoice.advChoice.dycore_vert_adv_type;
158  const Real l_horiz_upw_frac = solverChoice.advChoice.dycore_horiz_upw_frac;
159  const Real l_vert_upw_frac = solverChoice.advChoice.dycore_vert_upw_frac;
160  const bool l_use_stretched_dz = (solverChoice.mesh_type == MeshType::StretchedDz);
161  const bool l_use_terrain_fitted_coords = (solverChoice.mesh_type == MeshType::VariableDz);
162  const bool l_moving_terrain = (solverChoice.terrain_type == TerrainType::MovingFittedMesh);
163  if (l_moving_terrain) AMREX_ALWAYS_ASSERT (l_use_stretched_dz || l_use_terrain_fitted_coords);
164 
165  const bool l_use_diff = ( (dc.molec_diff_type != MolecDiffType::None) ||
166  (tc.les_type != LESType::None) ||
167  (tc.rans_type != RANSType::None) ||
168  (tc.pbl_type != PBLType::None) );
169  const bool l_use_turb = tc.use_kturb;
170 
171  const Real l_vert_implicit_fac = (solverChoice.implicit_thermal_diffusion) ?
172  solverChoice.vert_implicit_fac[level][nrk] : zero;
173 
174  const bool l_use_moisture = (solverChoice.moisture_type != MoistureType::None);
175 
176  auto any_SurfLayer = [&SurfLayer_ = SurfLayer]() -> bool {
177  for (auto it = SurfLayer_.begin(); it != SurfLayer_.end(); it++)
178  {
179  if (*it != nullptr) { return true; }
180  }
181  return false;
182  };
183 
184  const bool l_use_SurfLayer = any_SurfLayer();
185  bool l_apply_surface_layer_fluxes_in_diffusion = l_use_SurfLayer;
186  const bool l_rotate = (solverChoice.use_rotate_surface_flux);
187 
188  const bool l_anelastic = (solverChoice.compressibility_type[level] != CompressibilityType::FullyCompressible);
189  const bool l_fixed_rho = (solverChoice.fixed_density[level] == 1);
190 
191  const bool l_anelastic_rk2 = (solverChoice.timestepping_type[level] == TimesteppingType::RK2);
192 
193  const bool l_reflux = IsRefluxStage(solverChoice, level, finest_level, nrk);
194  const Real l_reflux_dt = RefluxStageWeight(solverChoice, level, finest_level, nrk) * static_cast<Real>(dt);
195 
196  const bool l_use_eb = (solverChoice.terrain_type == TerrainType::EB);
197 
198  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
199  const Real* dx = geom.CellSize();
200 
201  // **************************************************************************************
202  // If doing advection with EB we need the extra values for tangential interpolation
203  // **************************************************************************************
204  if (l_use_eb) {
205  S_data[IntVars::xmom].FillBoundary(geom.periodicity());
206  S_data[IntVars::ymom].FillBoundary(geom.periodicity());
207  S_data[IntVars::zmom].FillBoundary(geom.periodicity());
208  }
209 
210  // *****************************************************************************
211  // Pre-computed quantities
212  // *****************************************************************************
213  int nvars = S_data[IntVars::cons].nComp();
214  const BoxArray& ba = S_data[IntVars::cons].boxArray();
215  const DistributionMapping& dm = S_data[IntVars::cons].DistributionMap();
216 
217  int nGhost = (l_use_eb) ? 2 : 1;
218  MultiFab Omega(convert(ba,IntVect(0,0,1)), dm, 1, nGhost);
219 
220  std::unique_ptr<MultiFab> expr;
221  std::unique_ptr<MultiFab> dflux_x;
222  std::unique_ptr<MultiFab> dflux_y;
223  std::unique_ptr<MultiFab> dflux_z;
224 
225  if (l_use_diff) {
226  if (tc.uses_native_shoc()) {
227  AMREX_ALWAYS_ASSERT(native_shoc_lev != nullptr);
228  // Native SHOC owns the scalar fluxes and does not hand momentum
229  // stresses back to the generic host diffusion path.
230  l_apply_surface_layer_fluxes_in_diffusion = false;
231  native_shoc_lev->set_eddy_diffs();
232  }
233 
234  erf_make_tau_terms(level,nrk,domain_bcs_type_h,z_phys_nd,
235  S_data,xvel,yvel,zvel,
236  Tau_lev,Tau_corr_lev,
237  SmnSmn,eddyDiffs,geom,solverChoice,SurfLayer,
238  stretched_dz_d, detJ,mapfac, ax, ay, az, ebfact,
239  ib_wall_face13, ib_wall_face23, walldist);
240 
241  IntVect ng(0,0,1);
242  dflux_x = std::make_unique<MultiFab>(convert(ba,IntVect(1,0,0)), dm, nvars, ng);
243  dflux_y = std::make_unique<MultiFab>(convert(ba,IntVect(0,1,0)), dm, nvars, ng);
244  dflux_z = std::make_unique<MultiFab>(convert(ba,IntVect(0,0,1)), dm, nvars, 0);
245  // The physical theta wall override consumes the just-computed face
246  // flux. Initialize its storage independently of diagnostics so a
247  // budget switch cannot change the state update.
248  if (use_physical_chamber_wall_flux) {
249  dflux_x->setVal(0.0);
250  dflux_y->setVal(0.0);
251  dflux_z->setVal(0.0);
252  }
253 
254  bool surface_layer_handled = false;
255  if (tc.uses_native_shoc()) {
256  AMREX_ALWAYS_ASSERT(native_shoc_lev != nullptr);
257  surface_layer_handled = true;
258  }
259  if (!surface_layer_handled && l_use_SurfLayer) {
260  Vector<const MultiFab*> mfs = {&S_data[IntVars::cons], &xvel, &yvel, &zvel};
261  if (!l_use_eb) {
262  for (OrientationIter oit; oit; ++oit) {
263  Orientation ori = oit();
264  if (SurfLayer[ori]) {
265  SurfLayer[ori]->impose_SurfaceLayer_bcs(level, mfs, Tau_lev,
266  Hfx1, Hfx2, Hfx3,
267  Q1fx1, Q1fx2, Q1fx3,
268  &z_phys_nd,
269  mf_surface_fluxes);
270  }
271  }
272 
273  //if (l_vert_implicit_fac > 0 && solverChoice.implicit_momentum_diffusion) {
274  // copy_surface_tau_for_implicit(Tau_lev, Tau_corr_lev);
275  //}
276  } else {
277  SurfLayer[Orientation(Direction::z,Orientation::low)]->impose_SurfaceLayer_bcs_EB(level, mfs, Tau_EB,
278  Hfx1, Hfx2, Hfx3_EB,
279  Q1fx1, Q1fx2, Q1fx3);
280  }
281  }
282  if (tc.uses_native_shoc() && native_shoc_lev) {
283  // SHOC-owned scalar fluxes must not be reused by the host
284  // diffusion source, even if the host SurfaceLayer path was also
285  // evaluated for momentum stress ownership.
286  native_shoc_lev->set_diff_stresses();
287  }
288  } // l_use_diff
289 
290  // This is just cautionary to deal with grid boundaries that aren't domain boundaries
291  S_rhs[IntVars::zmom].setVal(0);
292 
293  // *****************************************************************************
294  // Define updates and fluxes in the current RK stage
295  // *****************************************************************************
296  // Cell-centered masks for EB (used for flux interpolation)
297  bool already_on_centroids = false;
298 
299 #ifdef _OPENMP
300 #pragma omp parallel if (Gpu::notInLaunchRegion())
301 #endif
302  {
303  BL_PROFILE("slow_rhs_making_omega");
304  for ( MFIter mfi(S_data[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
305  {
306  IntVect nGrowVect = (l_use_eb)
307  ? IntVect(AMREX_D_DECL(2, 2, 2)) : IntVect(AMREX_D_DECL(1, 1, 1));
308 
309  //
310  // NOTE: grownnodaltilebox, not surroundingNodes(tilebox,2) grown by hand. The latter
311  // grows every tile past its own share of the grid, so once the grid is tiled two
312  // tiles write the same Omega cells -- under OpenMP that is a concurrent write to
313  // the same memory, i.e. a data race, even though both threads happen to store the
314  // same value. grownnodaltilebox hands each tile a disjoint piece of the grown
315  // nodal box, and is identical to the old expression when there is one tile per grid.
316  //
317  Box gbxo = mfi.grownnodaltilebox(2,nGrowVect);
318 
319  const Array4<const Real>& rho_u = S_data[IntVars::xmom].array(mfi);
320  const Array4<const Real>& rho_v = S_data[IntVars::ymom].array(mfi);
321  const Array4<const Real>& rho_w = S_data[IntVars::zmom].array(mfi);
322  const Array4< Real>& omega_arr = Omega.array(mfi);
323 
324  //
325  // Now create Omega with momentum (not velocity) with z_t subtracted if moving terrain
326  // ONLY if not doing anelastic or pseudo-incompressible + terrain -- in that case Omega
327  // will be defined coming out of the projection
328  //
329  if (!l_use_terrain_fitted_coords) {
330  ParallelFor(gbxo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
331  omega_arr(i,j,k) = rho_w(i,j,k);
332  });
333 
334  } else {
335 
336  Box gbxo_lo = gbxo; gbxo_lo.setBig(2,domain.smallEnd(2));
337  int lo_z_face = domain.smallEnd(2);
338  if (gbxo_lo.smallEnd(2) <= lo_z_face) {
339  ParallelFor(gbxo_lo, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
340  omega_arr(i,j,k) = zero;
341  });
342  }
343  // Omega = rho w on the top face assumes the top of the domain is flat
344  // (enforced at setup by validate_flat_top)
345  Box gbxo_hi = gbxo; gbxo_hi.setSmall(2,gbxo.bigEnd(2));
346  int hi_z_face = domain.bigEnd(2)+1;
347  if (gbxo_hi.bigEnd(2) >= hi_z_face) {
348  ParallelFor(gbxo_hi, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
349  omega_arr(i,j,k) = rho_w(i,j,k);
350  });
351  }
352 
353  const Array4<const Real>& z_nd = z_phys_nd.const_array(mfi);
354  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
355  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
356 
357  if (z_t_mf) { // Note we never do anelastic or pseudo-incompressible with moving terrain
358  Box gbxo_mid = gbxo;
359  if (gbxo_mid.smallEnd(2) <= domain.smallEnd(2)) { gbxo_mid.setSmall(2,1); }
360  if (gbxo_mid.bigEnd(2) >= domain.bigEnd(2)+1) { gbxo_mid.setBig(2,gbxo.bigEnd(2)-1); }
361  Array4<const Real> z_t = z_t_mf->array(mfi);
362  const Array4<const Real>& cell_data = S_data[IntVars::cons].array(mfi);
363  ParallelFor(gbxo_mid, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
364  // We define rho on the z-face the same way as in MomentumToVelocity/VelocityToMomentum
365  Real rho_at_face = myhalf * (cell_data(i,j,k,Rho_comp) + cell_data(i,j,k-1,Rho_comp));
366  omega_arr(i,j,k) = OmegaFromW(i,j,k,rho_w(i,j,k),
367  rho_u,rho_v,mf_ux,mf_vy,z_nd,dxInv) -
368  rho_at_face * z_t(i,j,k);
369  });
370  } else {
371  Box gbxo_mid = gbxo;
372  if (gbxo_mid.smallEnd(2) <= domain.smallEnd(2)) {
373  gbxo_mid.setSmall(2,1);
374  }
375  if (gbxo_mid.bigEnd(2) >= domain.bigEnd(2)+1) {
376  gbxo_mid.setBig(2,gbxo.bigEnd(2)-1);
377  }
378  ParallelFor(gbxo_mid, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
379  omega_arr(i,j,k) = OmegaFromW(i,j,k,rho_w(i,j,k),
380  rho_u,rho_v,mf_ux,mf_vy,z_nd,dxInv);
381  });
382  }
383  }
384  } // mfi
385  } // OMP
386 
387  // We need extra values of Omega in the vertical if grids are decomposed vertically
388  Omega.FillBoundary(geom.periodicity());
389 
390 #ifdef _OPENMP
391 #pragma omp parallel if (Gpu::notInLaunchRegion())
392 #endif
393  {
394  for ( MFIter mfi(S_data[IntVars::cons],TileNoZ()); mfi.isValid(); ++mfi)
395  {
396  Box bx = mfi.tilebox();
397  Box tbx = mfi.nodaltilebox(0);
398  Box tby = mfi.nodaltilebox(1);
399  Box tbz = mfi.nodaltilebox(2);
400 
401  // Boxes for momentum fluxes
402  Vector<Box> tbx_grown(AMREX_SPACEDIM);
403  Vector<Box> tby_grown(AMREX_SPACEDIM);
404  Vector<Box> tbz_grown(AMREX_SPACEDIM);
405  if (l_use_eb) {
406  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
407  tbx_grown[dir] = tbx;
408  tby_grown[dir] = tby;
409  tbz_grown[dir] = tbz;
410  IntVect iv(1, 1, 1);
411  iv[dir] = 0;
412  tbx_grown[dir] = (tbx_grown[dir].growHi(dir,1)).grow(iv);
413  tby_grown[dir] = (tby_grown[dir].growHi(dir,1)).grow(iv);
414  tbz_grown[dir] = (tbz_grown[dir].growHi(dir,1)).grow(iv);
415  }
416  }
417 
418  // We don't compute a source term for z-momentum on the bottom or top domain boundary
419  tbz = ShrinkZmomBoxAtDomainEnds(tbz, domain);
420 
421  const Array4<const Real> & cell_data = S_data[IntVars::cons].array(mfi);
422  const Array4<const Real> & cell_prim = S_prim.array(mfi);
423  const Array4<Real> & cell_rhs = S_rhs[IntVars::cons].array(mfi);
424 
425  const Array4<const Real> & cell_old = S_old[IntVars::cons].array(mfi);
426 
427  const Array4<Real const>& xmom_src_arr = xmom_src.const_array(mfi);
428  const Array4<Real const>& ymom_src_arr = ymom_src.const_array(mfi);
429  const Array4<Real const>& zmom_src_arr = zmom_src.const_array(mfi);
430  const Array4<Real const>& buoyancy_arr = buoyancy.const_array(mfi);
431 
432  const Array4<Real const>& gpx_arr = gradp[GpVars::gpx].const_array(mfi);
433  const Array4<Real const>& gpy_arr = gradp[GpVars::gpy].const_array(mfi);
434  const Array4<Real const>& gpz_arr = gradp[GpVars::gpz].const_array(mfi);
435 
436  const Array4<Real const>& qt_arr = qt.const_array(mfi);
437 
438  const Array4<Real>& rho_u_old = S_old[IntVars::xmom].array(mfi);
439  const Array4<Real>& rho_v_old = S_old[IntVars::ymom].array(mfi);
440  const Array4<Real>& rho_w_old = S_old[IntVars::zmom].array(mfi);
441 
442  if (l_anelastic) {
443  // When anelastic or pseudo-incompressible we must reset these to 0 each RK step
444  avg_xmom[mfi].template setVal<RunOn::Device>(0,tbx);
445  avg_ymom[mfi].template setVal<RunOn::Device>(0,tby);
446  avg_zmom[mfi].template setVal<RunOn::Device>(0,tbz);
447  }
448 
449  Array4<Real> avg_xmom_arr = avg_xmom.array(mfi);
450  Array4<Real> avg_ymom_arr = avg_ymom.array(mfi);
451  Array4<Real> avg_zmom_arr = avg_zmom.array(mfi);
452  // Pseudo-incompressible: the upwind side is the one the projection picked
453  const Array4<const Real> upw_x_arr = upw_dir[0] ? upw_dir[0]->const_array(mfi) : avg_xmom.const_array(mfi);
454  const Array4<const Real> upw_y_arr = upw_dir[1] ? upw_dir[1]->const_array(mfi) : avg_ymom.const_array(mfi);
455  const Array4<const Real> upw_z_arr = upw_dir[2] ? upw_dir[2]->const_array(mfi) : avg_zmom.const_array(mfi);
456 
457  const Array4<const Real> & u = xvel.array(mfi);
458  const Array4<const Real> & v = yvel.array(mfi);
459  const Array4<const Real> & w = zvel.array(mfi);
460 
461  const Array4<const Real>& rho_u = S_data[IntVars::xmom].array(mfi);
462  const Array4<const Real>& rho_v = S_data[IntVars::ymom].array(mfi);
463  const Array4<const Real>& rho_w = S_data[IntVars::zmom].array(mfi);
464 
465  // Map factors
466  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
467  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
468  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
469  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
470  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
471  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
472 
473  const Array4< Real>& omega_arr = Omega.array(mfi);
474 
475  const Array4<Real>& rho_u_rhs = S_rhs[IntVars::xmom].array(mfi);
476  const Array4<Real>& rho_v_rhs = S_rhs[IntVars::ymom].array(mfi);
477  const Array4<Real>& rho_w_rhs = S_rhs[IntVars::zmom].array(mfi);
478 
479  const Array4<Real const>& mu_turb = l_use_turb ? eddyDiffs->const_array(mfi) : Array4<const Real>{};
480 
481  // Terrain metrics
482  const Array4<const Real>& z_nd = z_phys_nd.const_array(mfi);
483  const Array4<const Real>& z_cc = z_phys_cc.const_array(mfi);
484 
485  // *****************************************************************************
486  // Define flux arrays for use in advection
487  // *****************************************************************************
488  std::array<FArrayBox,AMREX_SPACEDIM> flux;
489  std::array<FArrayBox,AMREX_SPACEDIM> flux_u;
490  std::array<FArrayBox,AMREX_SPACEDIM> flux_v;
491  std::array<FArrayBox,AMREX_SPACEDIM> flux_w;
492 
493  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
494  if (!l_use_eb) {
495  flux[dir].resize(surroundingNodes(bx,dir),2,The_Async_Arena());
496  } else {
497  flux[dir].resize(surroundingNodes(bx,dir).grow(1),2,The_Async_Arena());
498  }
499  flux[dir].setVal<RunOn::Device>(0);
500  }
501  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
502  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
503 
504  // In the stage whose fluxes are refluxed, the diffusion of (rho theta)
505  // adds its face fluxes to flux[] too, so that the flux registers see the diffusive as well as
506  // the advective transport (EB diffusion does not do this), as in erf_slow_rhs_post
507  const ScalarDiffusionRefluxViews* l_reflux_diffusion =
508  (l_reflux && !l_use_eb) ? &flx_arr : nullptr;
509 
510  // Define flux arrays for momentum variables (used only for EB now)
511  GpuArray<Array4<Real>, AMREX_SPACEDIM> flx_u_arr{};
512  GpuArray<Array4<Real>, AMREX_SPACEDIM> flx_v_arr{};
513  GpuArray<Array4<Real>, AMREX_SPACEDIM> flx_w_arr{};
514 
515  if (l_use_eb) {
516  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
517  flux_u[dir].resize(tbx_grown[dir],1,The_Async_Arena());
518  flux_v[dir].resize(tby_grown[dir],1,The_Async_Arena());
519  flux_w[dir].resize(tbz_grown[dir],1,The_Async_Arena());
520  flux_u[dir].setVal<RunOn::Device>(0);
521  flux_v[dir].setVal<RunOn::Device>(0);
522  flux_w[dir].setVal<RunOn::Device>(0);
523  flx_u_arr[dir] = flux_u[dir].array();
524  flx_v_arr[dir] = flux_v[dir].array();
525  flx_w_arr[dir] = flux_w[dir].array();
526  }
527  }
528 
529  // *****************************************************************************
530  // Diffusive terms (pre-computed above)
531  // *****************************************************************************
532  // No terrain diffusion
533  Array4<Real> tau11,tau22,tau33;
534  Array4<Real> tau12,tau13,tau23;
535  if (Tau_lev[TauType::tau11]) {
536  tau11 = Tau_lev[TauType::tau11]->array(mfi); tau22 = Tau_lev[TauType::tau22]->array(mfi);
537  tau33 = Tau_lev[TauType::tau33]->array(mfi); tau12 = Tau_lev[TauType::tau12]->array(mfi);
538  tau13 = Tau_lev[TauType::tau13]->array(mfi); tau23 = Tau_lev[TauType::tau23]->array(mfi);
539  } else {
540  tau11 = Array4<Real>{}; tau22 = Array4<Real>{}; tau33 = Array4<Real>{};
541  tau12 = Array4<Real>{}; tau13 = Array4<Real>{}; tau23 = Array4<Real>{};
542  }
543  // Terrain diffusion
544  Array4<Real> tau21,tau31,tau32;
545  tau21 = (Tau_lev[TauType::tau21]) ? Tau_lev[TauType::tau21]->array(mfi) : Array4<Real>{};
546  tau31 = (Tau_lev[TauType::tau31]) ? Tau_lev[TauType::tau31]->array(mfi) : Array4<Real>{};
547  tau32 = (Tau_lev[TauType::tau32]) ? Tau_lev[TauType::tau32]->array(mfi) : Array4<Real>{};
548 
549  // EB surface layer fluxes
550  Array4<Real> u_tau_eb13, u_tau_eb23;
551  Array4<Real> v_tau_eb13, v_tau_eb23;
552  Array4<Real> w_tau_eb13, w_tau_eb23;
553  if (l_use_eb) {
554  EBChoice ebChoice = solverChoice.ebChoice;
556  u_tau_eb13 = Tau_EB[EBTauType::tau_eb13][EBGridType::xface]->array(mfi);
557  u_tau_eb23 = Tau_EB[EBTauType::tau_eb23][EBGridType::xface]->array(mfi);
558  v_tau_eb13 = Tau_EB[EBTauType::tau_eb13][EBGridType::yface]->array(mfi);
559  v_tau_eb23 = Tau_EB[EBTauType::tau_eb23][EBGridType::yface]->array(mfi);
560  w_tau_eb13 = Tau_EB[EBTauType::tau_eb13][EBGridType::zface]->array(mfi);
561  w_tau_eb23 = Tau_EB[EBTauType::tau_eb23][EBGridType::zface]->array(mfi);
562  }
563  }
564 
565  // *****************************************************************************
566  // Define updates in the RHS of continuity and potential temperature equations
567  // *****************************************************************************
568  bool l_eb_terrain_cc = false; // EB terrain on cell-centered grid
569  Array4<const int> mask_arr{};
570  Array4<const EBCellFlag> cfg_arr{};
571  Array4<const Real> ax_arr{};
572  Array4<const Real> ay_arr{};
573  Array4<const Real> az_arr{};
574  Array4<const Real> fcx_arr{};
575  Array4<const Real> fcy_arr{};
576  Array4<const Real> fcz_arr{};
577  Array4<const Real> detJ_arr{};
578  Array4<const Real> barea_arr{};
579  Array4<const Real> bcent_arr{};
580 
581  if (l_use_eb) {
582  const auto& eb_cc_factory = ebfact.get_const_factory();
583 
584  EBCellFlagFab const& cfg = eb_cc_factory->getMultiEBCellFlagFab()[mfi];
585  cfg_arr = cfg.const_array();
586  if (cfg.getType(bx) == FabType::singlevalued) {
587  l_eb_terrain_cc = true;
588  ax_arr = eb_cc_factory->getAreaFrac()[0]->const_array(mfi);
589  ay_arr = eb_cc_factory->getAreaFrac()[1]->const_array(mfi);
590  az_arr = eb_cc_factory->getAreaFrac()[2]->const_array(mfi);
591  fcx_arr = eb_cc_factory->getFaceCent()[0]->const_array(mfi);
592  fcy_arr = eb_cc_factory->getFaceCent()[1]->const_array(mfi);
593  fcz_arr = eb_cc_factory->getFaceCent()[2]->const_array(mfi);
594  detJ_arr = eb_cc_factory->getVolFrac().const_array(mfi);
595  mask_arr = physbnd_mask[IntVars::cons].const_array(mfi);
596  barea_arr = eb_cc_factory->getBndryArea().const_array(mfi);
597  bcent_arr = eb_cc_factory->getBndryCent().const_array(mfi);
598  } else {
599  ax_arr = ax.const_array(mfi);
600  ay_arr = ay.const_array(mfi);
601  az_arr = az.const_array(mfi);
602  detJ_arr = detJ.const_array(mfi);
603  }
604  } else {
605  ax_arr = ax.const_array(mfi);
606  ay_arr = ay.const_array(mfi);
607  az_arr = az.const_array(mfi);
608  detJ_arr = detJ.const_array(mfi);
609  }
610 
611  int icomp = RhoTheta_comp; int ncomp = 1;
612  if (!l_eb_terrain_cc){
613  AdvectionSrcForRho( bx, cell_rhs,
614  rho_u, rho_v, omega_arr, // these are being used to build the fluxes
615  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr, // these are being defined from the fluxes
616  ax_arr, ay_arr, az_arr, detJ_arr,
617  dxInv, mf_mx, mf_my, mf_uy, mf_vx,
618  flx_arr, l_fixed_rho);
619  AdvectionSrcForScalars(bx, icomp, ncomp,
620  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
621  upw_x_arr, upw_y_arr, upw_z_arr,
622  cell_prim, cell_rhs,
623  detJ_arr, dxInv, mf_mx, mf_my,
624  l_horiz_adv_type, l_vert_adv_type,
625  l_horiz_upw_frac, l_vert_upw_frac,
626  flx_arr, domain, bc_ptr_h);
627  // Pseudo-incompressible: keep the advective part of the (rho theta) RHS, so that the
628  // rest of it (diffusion and sources) can go into the constraint (see project_momenta).
629  // Where the RHS is averaged with the previous stage's below, so is this.
630  if (pi_adv_rt) {
631  const Array4<Real> adv_arr = pi_adv_rt->array(mfi);
632  const bool l_avg = l_anelastic && l_anelastic_rk2 && (nrk == 1);
633  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
634  {
635  adv_arr(i,j,k) = l_avg ? myhalf * (adv_arr(i,j,k) + cell_rhs(i,j,k,RhoTheta_comp))
636  : cell_rhs(i,j,k,RhoTheta_comp);
637  });
638  }
639  } else {
640  EBAdvectionSrcForRho(bx, cell_rhs,
641  rho_u, rho_v, omega_arr,
642  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
643  mask_arr, cfg_arr,
644  ax_arr, ay_arr, az_arr,
645  fcx_arr, fcy_arr, fcz_arr, detJ_arr,
646  dxInv, mf_mx, mf_my, mf_uy, mf_vx,
647  flx_arr, l_fixed_rho,
648  already_on_centroids);
649  EBAdvectionSrcForScalars(bx, icomp, ncomp,
650  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
651  cell_prim, cell_rhs,
652  mask_arr, cfg_arr, ax_arr, ay_arr, az_arr,
653  fcx_arr, fcy_arr, fcz_arr,
654  detJ_arr, dxInv, mf_mx, mf_my,
655  l_horiz_adv_type, l_vert_adv_type,
656  l_horiz_upw_frac, l_vert_upw_frac,
657  flx_arr, domain, bc_ptr_h,
658  already_on_centroids);
659  }
660 
661  if (l_use_diff) {
662  Array4<Real> diffflux_x = dflux_x->array(mfi);
663  Array4<Real> diffflux_y = dflux_y->array(mfi);
664  Array4<Real> diffflux_z = dflux_z->array(mfi);
665 
666  Array4<Real> hfx_x = Hfx1->array(mfi);
667  Array4<Real> hfx_y = Hfx2->array(mfi);
668  Array4<Real> hfx_z = Hfx3->array(mfi);
669  Array4<Real> hfx_EB{};
670  if (l_use_eb) {
671  hfx_EB = Hfx3_EB->array(mfi);
672  }
673 
674  Array4<Real> q1fx_x = (Q1fx1) ? Q1fx1->array(mfi) : Array4<Real>{};
675  Array4<Real> q1fx_y = (Q1fx2) ? Q1fx2->array(mfi) : Array4<Real>{};
676  Array4<Real> q1fx_z = (Q1fx3) ? Q1fx3->array(mfi) : Array4<Real>{};
677 
678  Array4<Real> q2fx_z = (Q2fx3) ? Q2fx3->array(mfi) : Array4<Real>{};
679 
680  // NOTE: No diffusion for continuity, so n starts at one
681  int n_start = RhoTheta_comp;
682  int n_comp = 1;
683 
684  // For l_vert_implicit_fac > 0, we scale the rho*theta contribution
685  // by (1 - implicit_fac) and add in the implicit contribution with
686  // ERF_Implicit.H
687  if (l_use_stretched_dz) {
688  DiffusionSrcForState_S(bx, domain, n_start, n_comp, u, v,
689  cell_data, cell_prim, cell_rhs,
690  diffflux_x, diffflux_y, diffflux_z,
691  stretched_dz_d, dxInv,
692  mf_mx, mf_ux, mf_vx,
693  mf_my, mf_uy, mf_vy,
694  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z, q2fx_z,
695  mu_turb, solverChoice, level,
696  bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer, l_vert_implicit_fac,
697  l_reflux_diffusion);
698  } else if (l_use_terrain_fitted_coords) {
699  DiffusionSrcForState_T(bx, domain, n_start, n_comp, l_rotate, u, v,
700  cell_data, cell_prim, cell_rhs,
701  diffflux_x, diffflux_y, diffflux_z,
702  z_nd, z_cc, ax_arr, ay_arr, az_arr, detJ_arr,
703  dxInv,
704  mf_mx, mf_ux, mf_vx,
705  mf_my, mf_uy, mf_vy,
706  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z, q2fx_z,
707  mu_turb, solverChoice, level,
708  bc_ptr_d, bc_ptr_h, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer, l_vert_implicit_fac,
709  l_reflux_diffusion);
710  } else if (l_use_eb) {
711  DiffusionSrcForState_EB(bx, domain, n_start, n_comp, u, v,
712  cell_data, cell_prim, cell_rhs,
713  diffflux_x, diffflux_y, diffflux_z,
714  cfg_arr, ax_arr, ay_arr, az_arr, detJ_arr,
715  barea_arr, bcent_arr,
716  dx, dxInv,
717  hfx_z, q1fx_z, q2fx_z, hfx_EB,
718  mu_turb, solverChoice, level,
719  bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer);
720  } else {
721  DiffusionSrcForState_N(bx, domain, n_start, n_comp, u, v,
722  cell_data, cell_prim, cell_rhs,
723  diffflux_x, diffflux_y, diffflux_z,
724  dxInv,
725  mf_mx, mf_ux, mf_vx,
726  mf_my, mf_uy, mf_vy,
727  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z, q2fx_z,
728  mu_turb, solverChoice, level,
729  bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer, l_vert_implicit_fac,
730  l_reflux_diffusion,
731  (ib_wall_face33) ? ib_wall_face33->const_array(mfi) : Array4<const Real>{},
732  (ib_wall_hfx) ? ib_wall_hfx->const_array(mfi) : Array4<const Real>{});
733  }
734  if (use_physical_chamber_wall_flux) {
736  bx, domain, RhoTheta_comp, 0, cell_data, cell_prim,
737  cloud_chamber_base_state->const_array(mfi), u, v, w, cell_rhs,
738  diffflux_x, diffflux_y, diffflux_z, dxInv,
739  chamber_walls, dc.alpha_T, dc.alpha_C,
740  solverChoice.rdOcp, cloud_chamber_config->has_moisture, chamber_bands);
741  }
742  }
743 
744  const Array4<Real const>& source_arr = cc_src.const_array(mfi);
745  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
746  {
747  cell_rhs(i,j,k,Rho_comp) += source_arr(i,j,k,Rho_comp);
748  cell_rhs(i,j,k,RhoTheta_comp) += source_arr(i,j,k,RhoTheta_comp);
749  });
750 
751  Real half_dt = static_cast<Real>(myhalf/dt);
752 
753  // If anelastic or pseudo-incompressible with RK2 and in second RK stage, take average of
754  // old-time and new-time source
755  if ( l_anelastic && l_anelastic_rk2 && (nrk == 1) )
756  {
757  ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
758  {
759  cell_rhs(i,j,k, Rho_comp) *= myhalf;
760  cell_rhs(i,j,k,RhoTheta_comp) *= myhalf;
761 
762  cell_rhs(i,j,k, Rho_comp) += half_dt * (cell_data(i,j,k, Rho_comp) - cell_old(i,j,k, Rho_comp));
763  cell_rhs(i,j,k,RhoTheta_comp) += half_dt * (cell_data(i,j,k,RhoTheta_comp) - cell_old(i,j,k,RhoTheta_comp));
764  });
765  }
766 
767  // *****************************************************************************
768  // Define updates in the RHS of {x, y, z}-momentum equations
769  // *****************************************************************************
770  int lo_z_face = domain.smallEnd(2);
771  int hi_z_face = domain.bigEnd(2)+1;
772 
773  AdvectionSrcForMom(mfi, tbx, tby, tbz, tbx_grown, tby_grown, tbz_grown,
774  rho_u_rhs, rho_v_rhs, rho_w_rhs,
775  cell_data, u, v, w,
776  rho_u, rho_v, omega_arr,
777  z_nd, ax_arr, ay_arr, az_arr,
778  detJ_arr, stretched_dz_d,
779  dxInv, mf_mx, mf_ux, mf_vx, mf_my, mf_uy, mf_vy,
780  l_horiz_adv_type, l_vert_adv_type,
781  l_horiz_upw_frac, l_vert_upw_frac,
782  solverChoice.mesh_type, solverChoice.terrain_type,
783  ebfact, flx_u_arr, flx_v_arr, flx_w_arr,
784  physbnd_mask, already_on_centroids,
785  lo_z_face, hi_z_face, domain, bc_ptr_h);
786 
787  if (l_use_diff) {
788  if (!l_use_eb && use_physical_chamber_wall_flux &&
791  bx, domain, cell_data,
792  cloud_chamber_base_state->const_array(mfi), u, v, w,
793  tau12, tau13, tau23, dxInv, chamber_walls,
794  solverChoice.rdOcp, cloud_chamber_config->has_moisture);
795  }
796 
797  // Note: tau** were calculated with calls to
798  // ComputeStress[Cons|Var]Visc_[N|S|T] in which ConsVisc ("constant
799  // viscosity") means that there is no contribution from a
800  // turbulence model. However, whether this field truly is constant
801  // depends on whether MolecDiffType is Constant or ConstantAlpha.
802  if (!l_use_eb) {
803  DiffusionSrcForMom(tbx, tby, tbz,
804  rho_u_rhs, rho_v_rhs, rho_w_rhs,
805  tau11, tau22, tau33,
807  detJ_arr, stretched_dz_d, dxInv,
808  mf_mx, mf_ux, mf_vx,
809  mf_my, mf_uy, mf_vy,
810  l_use_stretched_dz,
811  l_use_terrain_fitted_coords);
812  } else {
813  DiffusionSrcForMom_EB(mfi, domain, tbx, tby, tbz,
814  rho_u_rhs, rho_v_rhs, rho_w_rhs,
815  u, v, w,
816  tau11, tau22, tau33,
817  tau12, tau13, tau23,
818  u_tau_eb13, u_tau_eb23, v_tau_eb13, v_tau_eb23, w_tau_eb13, w_tau_eb23,
819  dx, dxInv,
820  mf_mx, mf_ux, mf_vx,
821  mf_my, mf_uy, mf_vy,
822  solverChoice, ebfact, bc_ptr_d);
823  }
824  }
825 
826  auto abl_pressure_grad = solverChoice.abl_pressure_grad;
827 
828  ParallelFor(tbx, tby,
829  [=] AMREX_GPU_DEVICE (int i, int j, int k)
830  { // x-momentum equation
831 
832  // Note that gradp arrays now carry the map factor in them
833 
834  Real q = (l_use_moisture) ? myhalf * (qt_arr(i,j,k) + qt_arr(i-1,j,k)) : zero;
835 
836  rho_u_rhs(i, j, k) += (-gpx_arr(i,j,k) - abl_pressure_grad[0]) / (one + q) + xmom_src_arr(i,j,k);
837 
838  if (l_moving_terrain) {
839  Real h_zeta = Compute_h_zeta_AtIface(i, j, k, dxInv, z_nd);
840  rho_u_rhs(i, j, k) *= h_zeta;
841  }
842 
843  if ( l_anelastic && l_anelastic_rk2 && (nrk == 1) ) {
844  rho_u_rhs(i,j,k) *= myhalf;
845  rho_u_rhs(i,j,k) += half_dt * (rho_u(i,j,k) - rho_u_old(i,j,k));
846  }
847  },
848  [=] AMREX_GPU_DEVICE (int i, int j, int k)
849  { // y-momentum equation
850 
851  // Note that gradp arrays now carry the map factor in them
852 
853  Real q = (l_use_moisture) ? myhalf * (qt_arr(i,j,k) + qt_arr(i,j-1,k)) : zero;
854 
855  rho_v_rhs(i, j, k) += (-gpy_arr(i,j,k) - abl_pressure_grad[1]) / (one + q) + ymom_src_arr(i,j,k);
856 
857  if (l_moving_terrain) {
858  Real h_zeta = Compute_h_zeta_AtJface(i, j, k, dxInv, z_nd);
859  rho_v_rhs(i, j, k) *= h_zeta;
860  }
861 
862  if ( l_anelastic && l_anelastic_rk2 && (nrk == 1) ) {
863  rho_v_rhs(i,j,k) *= myhalf;
864  rho_v_rhs(i,j,k) += half_dt * (rho_v(i,j,k) - rho_v_old(i,j,k));
865  }
866  });
867 
868  // *****************************************************************************
869  // Zero out source terms for x- and y- momenta if at walls or inflow
870  // We need to do this -- even though we call the boundary conditions later --
871  // because the slow source is used to update the state in the fast interpolater.
872  // *****************************************************************************
873  if (bx.smallEnd(0) == domain.smallEnd(0)) {
874  Box lo_x_dom_face(bx); lo_x_dom_face.setBig(0,bx.smallEnd(0));
875  if (bc_ptr_h[BCVars::xvel_bc].lo(0) == ERFBCType::ext_dir) {
876  ParallelFor(lo_x_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
877  rho_u_rhs(i,j,k) = zero;
878  });
879  } else if (bc_ptr_h[BCVars::xvel_bc].lo(0) == ERFBCType::ext_dir_upwind) {
880  ParallelFor(lo_x_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
881  if (u(i,j,k) >= zero) {
882  rho_u_rhs(i,j,k) = zero;
883  }
884  });
885  }
886  }
887  if (bx.bigEnd(0) == domain.bigEnd(0)) {
888  Box hi_x_dom_face(bx); hi_x_dom_face.setSmall(0,bx.bigEnd(0)+1); hi_x_dom_face.setBig(0,bx.bigEnd(0)+1);
889  if (bc_ptr_h[BCVars::xvel_bc].hi(0) == ERFBCType::ext_dir) {
890  ParallelFor(hi_x_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
891  rho_u_rhs(i,j,k) = zero;
892  });
893  } else if (bc_ptr_h[BCVars::xvel_bc].hi(0) == ERFBCType::ext_dir_upwind) {
894  ParallelFor(hi_x_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
895  if (u(i,j,k) <= zero) {
896  rho_u_rhs(i,j,k) = zero;
897  }
898  });
899  }
900  }
901  if (bx.smallEnd(1) == domain.smallEnd(1)) {
902  Box lo_y_dom_face(bx); lo_y_dom_face.setBig(1,bx.smallEnd(1));
903  if (bc_ptr_h[BCVars::yvel_bc].lo(1) == ERFBCType::ext_dir) {
904  ParallelFor(lo_y_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
905  rho_v_rhs(i,j,k) = zero;
906  });
907  } else if (bc_ptr_h[BCVars::yvel_bc].lo(1) == ERFBCType::ext_dir_upwind) {
908  ParallelFor(lo_y_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
909  if (v(i,j,k) >= zero) {
910  rho_v_rhs(i,j,k) = zero;
911  }
912  });
913  }
914  }
915  if (bx.bigEnd(1) == domain.bigEnd(1)) {
916  Box hi_y_dom_face(bx); hi_y_dom_face.setSmall(1,bx.bigEnd(1)+1); hi_y_dom_face.setBig(1,bx.bigEnd(1)+1);
917  if (bc_ptr_h[BCVars::yvel_bc].hi(1) == ERFBCType::ext_dir) {
918  ParallelFor(hi_y_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
919  rho_v_rhs(i,j,k) = zero;
920  });
921  } else if (bc_ptr_h[BCVars::yvel_bc].hi(1) == ERFBCType::ext_dir_upwind) {
922  ParallelFor(hi_y_dom_face, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
923  if (v(i,j,k) <= zero) {
924  rho_v_rhs(i,j,k) = zero;
925  }
926  });
927  }
928  }
929 
930  ParallelFor(tbz, [=] AMREX_GPU_DEVICE (int i, int j, int k)
931  { // z-momentum equation
932 
933  Real gpz = gpz_arr(i,j,k);
934 
935  rho_w_rhs(i, j, k) += slow_rhs_pre_z_pressure_buoyancy(
936  qt_arr, i, j, k, l_use_moisture, gpz, abl_pressure_grad[2],
937  buoyancy_arr(i,j,k)) + zmom_src_arr(i,j,k);
938 
939  if (l_moving_terrain) {
940  rho_w_rhs(i, j, k) *= myhalf * (detJ_arr(i,j,k) + detJ_arr(i,j,k-1));
941  }
942 
943  if ( l_anelastic && l_anelastic_rk2 && (nrk == 1) ) {
944  rho_w_rhs(i,j,k) *= myhalf;
945  rho_w_rhs(i,j,k) += half_dt * (rho_w(i,j,k) - rho_w_old(i,j,k));
946  }
947  });
948 
949  auto const lo = lbound(bx);
950  auto const hi = ubound(bx);
951 
952  // Note: the logic below assumes no tiling in z!
953  if (level > 0) {
954 
955  const Array4<const Real>& rho_w_rhs_crse = zmom_crse_rhs->const_array(mfi);
956 
957  Box b2d = bx; b2d.setRange(2,0);
958 
959  if (lo.z > klo) {
960  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int ) // bottom of box but not of domain
961  {
962  rho_w_rhs(i,j,lo.z) = rho_w_rhs_crse(i,j,lo.z);
963  });
964  }
965 
966  if (hi.z < khi+1) {
967  ParallelFor(b2d, [=] AMREX_GPU_DEVICE (int i, int j, int ) // top of box but not of domain
968  {
969  rho_w_rhs(i,j,hi.z+1) = rho_w_rhs_crse(i,j,hi.z+1);
970  });
971  }
972  }
973 
974  {
975  BL_PROFILE("slow_rhs_pre_fluxreg");
976  // We add to the flux registers only in the stages whose fluxes the step's update applies,
977  // weighted as in that update (RefluxStageWeight)
978  // On anelastic levels we reflux (rho theta); the density is fixed so there is no density flux.
979  // On pseudo-incompressible levels the density evolves, so we reflux rho and (rho theta).
980  // On compressible levels we reflux (rho theta): its flux here is the part carried by the
981  // stage momenta, and the acoustic substeps register the rest; their density is not refluxed
982  // (see ERF::post_timestep).
983  // The flux components are indexed by conserved state component, which is why srccomp and
984  // destcomp below are both the state component being refluxed.
985  if (l_reflux) {
986  int strt_comp_reflux = (l_fixed_rho || !l_anelastic) ? RhoTheta_comp : Rho_comp;
987  int num_comp_reflux = RhoTheta_comp + 1 - strt_comp_reflux;
988  if (level < finest_level) {
989  fr_as_crse->CrseAdd(mfi, {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
990  dx, l_reflux_dt, strt_comp_reflux, strt_comp_reflux,
991  num_comp_reflux, RunOn::Device);
992  }
993  if (level > 0) {
994  fr_as_fine->FineAdd(mfi, {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
995  dx, l_reflux_dt, strt_comp_reflux, strt_comp_reflux,
996  num_comp_reflux, RunOn::Device);
997  }
998 
999  } // two-way coupling
1000  } // end profile
1001  } // mfi
1002  } // OMP
1003  if (cloud_budget && l_use_diff) {
1004  bool use_trapezoidal = (!l_anelastic || l_anelastic_rk2);
1005  cloud_budget->capture_stage(CloudChamberBudget::RhoTheta, nrk,
1006  static_cast<Real>(dt), *dflux_x, *dflux_y,
1007  *dflux_z, geom, 0, use_trapezoidal);
1008  }
1009 }
GpuArray< Real, AMREX_SPACEDIM > dx
Definition: ERF_ActuatorSpreading.cpp:131
void AdvectionSrcForMom(const amrex::MFIter &mfi, const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Vector< amrex::Box > &bxx_grown, const amrex::Vector< amrex::Box > &bxy_grown, const amrex::Vector< amrex::Box > &bxz_grown, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &rho, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &Omega, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &az, const amrex::Array4< const amrex::Real > &detJ, amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, MeshType &mesh_type, TerrainType &terrain_type, const eb_ &ebfact, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_u_arr, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_v_arr, amrex::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_w_arr, const amrex::Vector< amrex::iMultiFab > &physbnd_mask, const bool already_on_centroids, const int lo_z_face, const int hi_z_face, const amrex::Box &domain, const amrex::BCRec *bc_ptr_h)
void AdvectionSrcForRho(const amrex::Box &bx, const amrex::Array4< amrex::Real > &src, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &omega, const amrex::Array4< amrex::Real > &avg_xmom, const amrex::Array4< amrex::Real > &avg_ymom, const amrex::Array4< amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &ax_arr, const amrex::Array4< const amrex::Real > &ay_arr, const amrex::Array4< const amrex::Real > &az_arr, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const bool fixed_rho)
void AdvectionSrcForScalars(const amrex::Box &bx, const int icomp, const int ncomp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &upw_x, const amrex::Array4< const amrex::Real > &upw_y, const amrex::Array4< const amrex::Real > &upw_z, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &src, const amrex::Array4< const amrex::Real > &vf_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const amrex::Box &domain, const amrex::BCRec *bc_ptr_h)
amrex::Box ShrinkZmomBoxAtDomainEnds(amrex::Box b, const amrex::Box &domain)
Definition: ERF_Advection.H:206
@ tau12
Definition: ERF_DataStruct.H:51
@ tau23
Definition: ERF_DataStruct.H:51
@ tau33
Definition: ERF_DataStruct.H:51
@ tau22
Definition: ERF_DataStruct.H:51
@ tau11
Definition: ERF_DataStruct.H:51
@ tau32
Definition: ERF_DataStruct.H:51
@ tau31
Definition: ERF_DataStruct.H:51
@ tau21
Definition: ERF_DataStruct.H:51
@ tau13
Definition: ERF_DataStruct.H:51
@ nvars
Definition: ERF_DataStruct.H:235
@ v_x
Definition: ERF_DataStruct.H:40
@ u_y
Definition: ERF_DataStruct.H:41
@ v_y
Definition: ERF_DataStruct.H:41
@ m_y
Definition: ERF_DataStruct.H:41
@ u_x
Definition: ERF_DataStruct.H:40
@ m_x
Definition: ERF_DataStruct.H:40
void DiffusionSrcForMom(const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &tau11, const amrex::Array4< const amrex::Real > &tau22, const amrex::Array4< const amrex::Real > &tau33, const amrex::Array4< const amrex::Real > &tau12, const amrex::Array4< const amrex::Real > &tau21, const amrex::Array4< const amrex::Real > &tau13, const amrex::Array4< const amrex::Real > &tau31, const amrex::Array4< const amrex::Real > &tau23, const amrex::Array4< const amrex::Real > &tau32, const amrex::Array4< const amrex::Real > &detJ_arr, const amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const bool use_stretched_dz, const bool use_variable_dz)
Add stress-divergence diffusion source terms to the momentum RHS.
void DiffusionSrcForState_EB(const amrex::Box &bx, const amrex::Box &domain, int start_comp, int num_comp, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &cell_data, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &cell_rhs, const amrex::Array4< amrex::Real > &xflux, const amrex::Array4< amrex::Real > &yflux, const amrex::Array4< amrex::Real > &zflux, const amrex::Array4< const amrex::EBCellFlag > &cfg_arr, const amrex::Array4< const amrex::Real > &ax_arr, const amrex::Array4< const amrex::Real > &ay_arr, const amrex::Array4< const amrex::Real > &az_arr, const amrex::Array4< const amrex::Real > &detJ, const amrex::Array4< const amrex::Real > &barea_arr, const amrex::Array4< const amrex::Real > &bcent_arr, const amrex::Real *dx_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, amrex::Array4< amrex::Real > &hfx_z, amrex::Array4< amrex::Real > &qfx1_z, amrex::Array4< amrex::Real > &qfx2_z, amrex::Array4< amrex::Real > &hfx_EB, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const int level, const amrex::BCRec *bc_ptr, const bool use_SurfLayer, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer)
Add state diffusion source terms for embedded-boundary cells.
void DiffusionSrcForState_S(const amrex::Box &bx, const amrex::Box &domain, int start_comp, int num_comp, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &cell_data, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &cell_rhs, const amrex::Array4< amrex::Real > &xflux, const amrex::Array4< amrex::Real > &yflux, const amrex::Array4< amrex::Real > &zflux, const amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, amrex::Array4< amrex::Real > &hfx_x, amrex::Array4< amrex::Real > &hfx_y, amrex::Array4< amrex::Real > &hfx_z, amrex::Array4< amrex::Real > &qfx1_x, amrex::Array4< amrex::Real > &qfx1_y, amrex::Array4< amrex::Real > &qfx1_z, amrex::Array4< amrex::Real > &qfx2_z, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const int level, const amrex::BCRec *bc_ptr, const bool use_SurfLayer, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const amrex::Real implicit_fac, const ScalarDiffusionRefluxViews *reflux_flx=nullptr)
Native adapter for regular scalar diffusion on a vertically stretched grid.
void DiffusionSrcForMom_EB(const amrex::MFIter &mfi, [[maybe_unused]] const amrex::Box &domain, const amrex::Box &bxx, const amrex::Box &bxy, const amrex::Box &bxz, const amrex::Array4< amrex::Real > &rho_u_rhs, const amrex::Array4< amrex::Real > &rho_v_rhs, const amrex::Array4< amrex::Real > &rho_w_rhs, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &w_arr, const amrex::Array4< const amrex::Real > &tau11, const amrex::Array4< const amrex::Real > &tau22, const amrex::Array4< const amrex::Real > &tau33, const amrex::Array4< const amrex::Real > &tau12, const amrex::Array4< const amrex::Real > &tau13, const amrex::Array4< const amrex::Real > &tau23, const amrex::Array4< const amrex::Real > &u_tau_eb13, const amrex::Array4< const amrex::Real > &u_tau_eb23, const amrex::Array4< const amrex::Real > &v_tau_eb13, const amrex::Array4< const amrex::Real > &v_tau_eb23, const amrex::Array4< const amrex::Real > &w_tau_eb13, const amrex::Array4< const amrex::Real > &w_tau_eb23, const amrex::Real *dx_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, const SolverChoice &solverChoice, const eb_ &ebfact, [[maybe_unused]] const amrex::BCRec *bc_ptr)
Add embedded-boundary stress-divergence diffusion source terms to the momentum RHS.
void DiffusionSrcForState_N(const amrex::Box &bx, const amrex::Box &domain, int start_comp, int num_comp, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &cell_data, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &cell_rhs, const amrex::Array4< amrex::Real > &xflux, const amrex::Array4< amrex::Real > &yflux, const amrex::Array4< amrex::Real > &zflux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, amrex::Array4< amrex::Real > &hfx_x, amrex::Array4< amrex::Real > &hfx_y, amrex::Array4< amrex::Real > &hfx_z, amrex::Array4< amrex::Real > &qfx1_x, amrex::Array4< amrex::Real > &qfx1_y, amrex::Array4< amrex::Real > &qfx1_z, amrex::Array4< amrex::Real > &qfx2_z, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const int level, const amrex::BCRec *bc_ptr, const bool use_SurfLayer, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const amrex::Real implicit_fac, const ScalarDiffusionRefluxViews *reflux_flx=nullptr, const amrex::Array4< const amrex::Real > &wall_face33=amrex::Array4< const amrex::Real >{}, const amrex::Array4< const amrex::Real > &wall_hfx=amrex::Array4< const amrex::Real >{}, const amrex::Array4< const amrex::Real > &wall_qfx=amrex::Array4< const amrex::Real >{})
Add regular-grid state diffusion on a uniform grid without terrain.
void DiffusionSrcForState_T(const amrex::Box &bx, const amrex::Box &domain, int start_comp, int num_comp, const bool &rotate, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &cell_data, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &cell_rhs, const amrex::Array4< amrex::Real > &xflux, const amrex::Array4< amrex::Real > &yflux, const amrex::Array4< amrex::Real > &zflux, const amrex::Array4< const amrex::Real > &z_nd, const amrex::Array4< const amrex::Real > &z_cc, const amrex::Array4< const amrex::Real > &ax, const amrex::Array4< const amrex::Real > &ay, const amrex::Array4< const amrex::Real > &az, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vy, amrex::Array4< amrex::Real > &hfx_x, amrex::Array4< amrex::Real > &hfx_y, amrex::Array4< amrex::Real > &hfx_z, amrex::Array4< amrex::Real > &qfx1_x, amrex::Array4< amrex::Real > &qfx1_y, amrex::Array4< amrex::Real > &qfx1_z, amrex::Array4< amrex::Real > &qfx2_z, const amrex::Array4< const amrex::Real > &mu_turb, const SolverChoice &solverChoice, const int level, const amrex::BCRec *bc_ptr, const amrex::BCRec *bc_ptr_h, const bool use_SurfLayer, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const amrex::Real implicit_fac, const ScalarDiffusionRefluxViews *reflux_flx=nullptr)
Native adapter for regular scalar diffusion on terrain-following coordinates.
void EBAdvectionSrcForScalars(const amrex::Box &bx, const int icomp, const int ncomp, const amrex::Array4< const amrex::Real > &avg_xmom, const amrex::Array4< const amrex::Real > &avg_ymom, const amrex::Array4< const amrex::Real > &avg_zmom, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &src, const amrex::Array4< const int > &mask_arr, const amrex::Array4< const amrex::EBCellFlag > &cfg_arr, const amrex::Array4< const amrex::Real > &ax_arr, const amrex::Array4< const amrex::Real > &ay_arr, const amrex::Array4< const amrex::Real > &az_arr, const amrex::Array4< const amrex::Real > &fcx_arr, const amrex::Array4< const amrex::Real > &fcy_arr, const amrex::Array4< const amrex::Real > &fcz_arr, const amrex::Array4< const amrex::Real > &vf_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const AdvType horiz_adv_type, const AdvType vert_adv_type, const amrex::Real horiz_upw_frac, const amrex::Real vert_upw_frac, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const amrex::Box &domain, const amrex::BCRec *bc_ptr_h, bool already_on_centroids)
Compute EB advection tendency for scalars other than density.
void EBAdvectionSrcForRho(const amrex::Box &bx, const amrex::Array4< amrex::Real > &src, const amrex::Array4< const amrex::Real > &rho_u, const amrex::Array4< const amrex::Real > &rho_v, const amrex::Array4< const amrex::Real > &omega, const amrex::Array4< amrex::Real > &avg_xmom, const amrex::Array4< amrex::Real > &avg_ymom, const amrex::Array4< amrex::Real > &avg_zmom, const amrex::Array4< const int > &mask_arr, const amrex::Array4< const amrex::EBCellFlag > &cfg_arr, const amrex::Array4< const amrex::Real > &ax_arr, const amrex::Array4< const amrex::Real > &ay_arr, const amrex::Array4< const amrex::Real > &az_arr, const amrex::Array4< const amrex::Real > &fcx_arr, const amrex::Array4< const amrex::Real > &fcy_arr, const amrex::Array4< const amrex::Real > &fcz_arr, const amrex::Array4< const amrex::Real > &detJ, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_mx, const amrex::Array4< const amrex::Real > &mf_my, const amrex::Array4< const amrex::Real > &mf_uy, const amrex::Array4< const amrex::Real > &mf_vx, const amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_arr, const bool fixed_rho, bool already_on_centroids)
Compute EB advection tendency for density and potential temperature.
@ tau_eb23
Definition: ERF_EBStruct.H:22
@ tau_eb13
Definition: ERF_EBStruct.H:22
@ yface
Definition: ERF_EBStruct.H:29
@ zface
Definition: ERF_EBStruct.H:29
@ xface
Definition: ERF_EBStruct.H:29
const Real l_vert_implicit_fac
Definition: ERF_ImplicitPost.H:6
#define Rho_comp
Definition: ERF_IndexDefines.H:61
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:62
AdvType
Definition: ERF_IndexDefines.H:329
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:16
const int khi
Definition: ERF_InitCustomPert_Bubble.H:25
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
const int klo
Definition: ERF_InitCustomPert_KE.H:9
void erf_make_tau_terms(int level, int nrk, const Vector< BCRec > &domain_bcs_type_h, const MultiFab &z_phys_nd, Vector< MultiFab > &S_data, const MultiFab &xvel, const MultiFab &yvel, const MultiFab &zvel, Vector< std::unique_ptr< MultiFab >> &Tau_lev, Vector< std::unique_ptr< MultiFab >> &Tau_corr_lev, MultiFab *SmnSmn, MultiFab *eddyDiffs, const Geometry geom, const SolverChoice &solverChoice, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, Gpu::DeviceVector< Real > &stretched_dz_d, const MultiFab &detJ, Vector< std::unique_ptr< MultiFab >> &mapfac, const MultiFab &ax, const MultiFab &ay, const MultiFab &az, const eb_ &ebfact, const MultiFab *ib_wall_face13, const MultiFab *ib_wall_face23, const MultiFab *walldist)
Definition: ERF_MakeTauTerms.cpp:13
ParallelFor(fab_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
amrex::GpuArray< const amrex::Array4< amrex::Real >, AMREX_SPACEDIM > ScalarDiffusionRefluxViews
Definition: ERF_ScalarDiffusion.H:1750
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real slow_rhs_pre_z_pressure_buoyancy(const amrex::Array4< const amrex::Real > &qt_arr, int i, int j, int k, bool use_moisture, amrex::Real gpz, amrex::Real abl_pressure_grad_z, amrex::Real buoyancy)
Definition: ERF_SlowRhsPreUtils.H:18
bool IsRefluxStage(const SolverChoice &solverChoice, int level, int finest_level, int nrk)
Definition: ERF_TI_slow_headers.H:91
amrex::Real RefluxStageWeight(const SolverChoice &solverChoice, int level, int finest_level, int nrk)
Definition: ERF_TI_slow_headers.H:78
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtIface(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:281
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real OmegaFromW(int &i, int &j, int &k, amrex::Real w, const amrex::Array4< const amrex::Real > &u_arr, const amrex::Array4< const amrex::Real > &v_arr, const amrex::Array4< const amrex::Real > &mf_ux, const amrex::Array4< const amrex::Real > &mf_vy, const amrex::Array4< const amrex::Real > &z_nd, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxInv)
Definition: ERF_TerrainMetrics.H:802
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real Compute_h_zeta_AtJface(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:351
AMREX_FORCE_INLINE amrex::IntVect TileNoZ()
Definition: ERF_TileNoZ.H:11
void capture_stage(int scalar, int nrk, amrex::Real dt, const amrex::MultiFab &xflux, const amrex::MultiFab &yflux, const amrex::MultiFab &zflux, const amrex::Geometry &geom, int flux_comp=0, bool trapezoidal=true)
Definition: ERF_CloudChamberBudget.H:94
@ RhoTheta
Definition: ERF_CloudChamberBudget.H:33
void set_diff_stresses() const
Definition: ERF_ShocDriver.cpp:825
void set_eddy_diffs() const
Definition: ERF_ShocDriver.cpp:813
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory() const noexcept
Return the cell-centered EB factory.
Definition: ERF_EB.H:110
@ yvel_bc
Definition: ERF_IndexDefines.H:139
@ xvel_bc
Definition: ERF_IndexDefines.H:138
@ ext_dir
Definition: ERF_IndexDefines.H:317
@ ext_dir_upwind
Definition: ERF_IndexDefines.H:325
@ gpz
Definition: ERF_IndexDefines.H:243
@ gpy
Definition: ERF_IndexDefines.H:242
@ gpx
Definition: ERF_IndexDefines.H:241
@ ymom
Definition: ERF_IndexDefines.H:251
@ cons
Definition: ERF_IndexDefines.H:249
@ zmom
Definition: ERF_IndexDefines.H:252
@ xmom
Definition: ERF_IndexDefines.H:250
@ None
Definition: ERF_LSM_Types.H:6
@ qt
Definition: ERF_Kessler.H:30
@ ng
Definition: ERF_Morrison.H:51
@ xvel
Definition: ERF_IndexDefines.H:232
@ zvel
Definition: ERF_IndexDefines.H:234
@ yvel
Definition: ERF_IndexDefines.H:233
@ q
Definition: ERF_WSM6.H:296
void apply(const amrex::Box &bx, const amrex::Box &domain, const int quantity, const int flux_comp, const amrex::Array4< const amrex::Real > &state, const amrex::Array4< const amrex::Real > &prim, const amrex::Array4< const amrex::Real > &base_state, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< amrex::Real > &rhs, const amrex::Array4< amrex::Real > &xflux, const amrex::Array4< amrex::Real > &yflux, const amrex::Array4< amrex::Real > &zflux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dx_inv, const erf_wall_thermodynamics::Boundary &walls, const amrex::Real alpha_T, const amrex::Real alpha_C, const amrex::Real rdOcp, const bool cloudy=false, const erf_wall_thermodynamics::SidewallBandViews &bands={})
Definition: ERF_CloudChamberWallFlux.H:1278
void apply(const Box &bx, const Box &domain, const Array4< const Real > &state, const Array4< const Real > &base_state, const Array4< const Real > &u, const Array4< const Real > &v, const Array4< const Real > &w, const Array4< Real > &tau12, const Array4< Real > &tau13, const Array4< Real > &tau23, const GpuArray< Real, AMREX_SPACEDIM > &dx_inv, const erf_wall_thermodynamics::Boundary &walls, const Real rdOcp, const bool cloudy)
Definition: ERF_CloudChamberWallStress.H:195
bool has_momentum_wall(const erf_wall_thermodynamics::Boundary &walls) noexcept
Definition: ERF_CloudChamberWallStress.H:245
amrex::GpuArray< TemperatureBandView, 4 > SidewallBandViews
Definition: ERF_WallThermodynamics.H:63
amrex::GpuArray< FaceWall, 2 *AMREX_SPACEDIM > Boundary
Definition: ERF_WallThermodynamics.H:133
AdvType dycore_vert_adv_type
Vertical advection scheme for dynamical-core variables.
Definition: ERF_AdvStruct.H:404
AdvType dycore_horiz_adv_type
Horizontal advection scheme for dynamical-core variables.
Definition: ERF_AdvStruct.H:403
amrex::Real dycore_vert_upw_frac
Upwind blending fraction for vertical dynamical-core advection.
Definition: ERF_AdvStruct.H:414
amrex::Real dycore_horiz_upw_frac
Upwind blending fraction for horizontal dynamical-core advection.
Definition: ERF_AdvStruct.H:413
Definition: ERF_DiffStruct.H:25
MolecDiffType molec_diff_type
Selected molecular transport model.
Definition: ERF_DiffStruct.H:97
amrex::Real alpha_C
Kinematic scalar diffusivity [m2/s].
Definition: ERF_DiffStruct.H:101
amrex::Real alpha_T
Kinematic temperature diffusivity [m2/s].
Definition: ERF_DiffStruct.H:100
Definition: ERF_EBStruct.H:36
EBBoundaryType eb_boundary_type
Boundary condition model applied on embedded-boundary surfaces.
Definition: ERF_EBStruct.H:88
amrex::Vector< int > fixed_density
Per-level flag selecting fixed-density treatment; always 1 at an anelastic level and 0 at a pseudo-in...
Definition: ERF_DataStruct.H:3030
amrex::Vector< TurbChoice > turbChoice
Turbulence options for each AMR level.
Definition: ERF_DataStruct.H:3020
amrex::Vector< TimesteppingType > timestepping_type
Per-level time integrator (RK3_ImplicitSubstep, RK3_NoSubstepping, RK2 or MidPoint).
Definition: ERF_DataStruct.H:3029
MoistureType moisture_type
Moisture or microphysics model.
Definition: ERF_DataStruct.H:3433
bool use_rotate_surface_flux
Whether MOST surface fluxes are rotated with terrain.
Definition: ERF_DataStruct.H:3196
EBChoice ebChoice
Embedded-boundary options.
Definition: ERF_DataStruct.H:3021
bool implicit_thermal_diffusion
Whether implicit vertical thermal diffusion is included.
Definition: ERF_DataStruct.H:3061
amrex::Real rdOcp
Ratio of dry-air gas constant to c_p.
Definition: ERF_DataStruct.H:3150
static MeshType mesh_type
Vertical mesh representation.
Definition: ERF_DataStruct.H:3004
AdvChoice advChoice
Advection-related options.
Definition: ERF_DataStruct.H:3016
amrex::Vector< CompressibilityType > compressibility_type
Per-level compressibility (FullyCompressible, Anelastic or PseudoIncompressible).
Definition: ERF_DataStruct.H:3028
amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > abl_pressure_grad
Applied ABL pressure-gradient forcing vector.
Definition: ERF_DataStruct.H:3494
amrex::Vector< amrex::Vector< amrex::Real > > vert_implicit_fac
Per-level, per-stage implicit vertical diffusion factors.
Definition: ERF_DataStruct.H:3058
static TerrainType terrain_type
Terrain or immersed-boundary representation.
Definition: ERF_DataStruct.H:2989
DiffChoice diffChoice
Diffusion-related options.
Definition: ERF_DataStruct.H:3017
Definition: ERF_TurbStruct.H:129
RANSType rans_type
Selected RANS closure.
Definition: ERF_TurbStruct.H:960
bool uses_native_shoc() const noexcept
Query whether this level uses the native SHOC PBL scheme.
Definition: ERF_TurbStruct.H:1009
LESType les_type
Selected LES closure.
Definition: ERF_TurbStruct.H:909
bool use_kturb
Whether any turbulence model is active.
Definition: ERF_TurbStruct.H:1061
PBLType pbl_type
Selected PBL closure.
Definition: ERF_TurbStruct.H:1003
erf_wall_thermodynamics::SidewallBandViews temperature_band_views() const &noexcept
Definition: ERF_CloudChamber.H:65
const erf_wall_thermodynamics::Boundary & transport_boundary() const &
Definition: ERF_CloudChamber.H:59
bool has_moisture
Definition: ERF_CloudChamber.H:41
bool physical_initialization
Definition: ERF_CloudChamber.H:42
Here is the call graph for this function: