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