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_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 *Diss, 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)
 

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

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