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 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, 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)
 

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 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,
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 
)

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