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

Functions

void erf_slow_rhs_post (int level, int finest_level, int nrk, double dt_d, int n_qstate, Vector< MultiFab > &S_rhs, Vector< MultiFab > &S_old, Vector< MultiFab > &S_new, Vector< MultiFab > &S_data, const MultiFab &S_prim, MultiFab &avg_xmom, MultiFab &avg_ymom, MultiFab &avg_zmom, const MultiFab &xvel, const MultiFab &yvel, const MultiFab &zvel, const MultiFab &source, MultiFab *terrain_blank, MultiFab *terrain_blank_xface, MultiFab *terrain_blank_yface, MultiFab *terrain_blank_zface, const MultiFab *SmnSmn, const MultiFab *eddyDiffs, MultiFab *Hfx1, MultiFab *Hfx2, MultiFab *Hfx3, MultiFab *Q1fx1, MultiFab *Q1fx2, MultiFab *Q1fx3, MultiFab *Q2fx3, MultiFab *Diss, const Geometry geom, const SolverChoice &solverChoice, const Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const Gpu::DeviceVector< BCRec > &domain_bcs_type_d, const Vector< BCRec > &domain_bcs_type_h, std::unique_ptr< MultiFab > &z_phys_nd, std::unique_ptr< MultiFab > &z_phys_cc, std::unique_ptr< MultiFab > &ax, std::unique_ptr< MultiFab > &ay, std::unique_ptr< MultiFab > &az, std::unique_ptr< MultiFab > &detJ, MultiFab *detJ_new, Gpu::DeviceVector< Real > &stretched_dz_d, Vector< std::unique_ptr< MultiFab >> &mapfac, const eb_ &ebfact, ShocDriver *native_shoc_lev, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, std::unique_ptr< ReadBndryPlanes > &m_r2d, const MultiFab *cloud_chamber_base_state, const erf_cloud_chamber::Config *cloud_chamber_config, CloudChamberBudget *cloud_budget)
 

Function Documentation

◆ erf_slow_rhs_post()

void erf_slow_rhs_post ( int  level,
int  finest_level,
int  nrk,
double  dt_d,
int  n_qstate,
Vector< MultiFab > &  S_rhs,
Vector< MultiFab > &  S_old,
Vector< MultiFab > &  S_new,
Vector< MultiFab > &  S_data,
const MultiFab &  S_prim,
MultiFab &  avg_xmom,
MultiFab &  avg_ymom,
MultiFab &  avg_zmom,
const MultiFab &  xvel,
const MultiFab &  yvel,
const MultiFab &  zvel,
const MultiFab &  source,
MultiFab *  terrain_blank,
MultiFab *  terrain_blank_xface,
MultiFab *  terrain_blank_yface,
MultiFab *  terrain_blank_zface,
const MultiFab *  SmnSmn,
const MultiFab *  eddyDiffs,
MultiFab *  Hfx1,
MultiFab *  Hfx2,
MultiFab *  Hfx3,
MultiFab *  Q1fx1,
MultiFab *  Q1fx2,
MultiFab *  Q1fx3,
MultiFab *  Q2fx3,
MultiFab *  Diss,
const Geometry  geom,
const SolverChoice solverChoice,
const Vector< std::unique_ptr< SurfaceLayer >> &  SurfLayer,
const Gpu::DeviceVector< BCRec > &  domain_bcs_type_d,
const Vector< BCRec > &  domain_bcs_type_h,
std::unique_ptr< MultiFab > &  z_phys_nd,
std::unique_ptr< MultiFab > &  z_phys_cc,
std::unique_ptr< MultiFab > &  ax,
std::unique_ptr< MultiFab > &  ay,
std::unique_ptr< MultiFab > &  az,
std::unique_ptr< MultiFab > &  detJ,
MultiFab *  detJ_new,
Gpu::DeviceVector< Real > &  stretched_dz_d,
Vector< std::unique_ptr< MultiFab >> &  mapfac,
const eb_ ebfact,
ShocDriver native_shoc_lev,
YAFluxRegister *  fr_as_crse,
YAFluxRegister *  fr_as_fine,
std::unique_ptr< ReadBndryPlanes > &  m_r2d,
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 scalars other than density or potential temperature

Parameters
[in]evellevel of resolution
[in]finest_levelfinest level of resolution
[in]nrkwhich RK stage
[in]dtslow time step
[out]S_rhsRHS computed here
[in]S_oldsolution at start of time step
[in]S_newsolution at end of current RK stage
[in]S_datacurrent solution
[in]S_primprimitive variables (i.e. conserved variables divided by density)
[in]avg_xmom
[in]avg_ymom
[in]avg_zmom
[in]xvelx-component of velocity
[in]yvely-component of velocity
[in]zvelz-component of velocity
[in]sourcesource terms for conserved variables
[in]terrain_blankimmersed forcing mask
[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]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 at start of time step (= 1 if use_terrain is false)
[in]detJ_newJacobian of the metric transformation at new RK stage time (= 1 if use_terrain is false)
[in]mapfacmap factors
[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
102 {
103  BL_PROFILE_REGION("erf_slow_rhs_post()");
104 
105  Real dt = static_cast<Real>(dt_d);
106 
107  const BCRec* bc_ptr_d = domain_bcs_type_d.data();
108  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
109 
110  AdvChoice ac = solverChoice.advChoice;
111  DiffChoice dc = solverChoice.diffChoice;
112  TurbChoice tc = solverChoice.turbChoice[level];
113 
114  const MultiFab* t_mean_mf = nullptr;
115  if (SurfLayer[Orientation(Direction::z, Orientation::low)]) { t_mean_mf = SurfLayer[Orientation(Direction::z, Orientation::low)]->get_mac_avg(level,3); }
116 
117  const bool l_use_terrain = (solverChoice.mesh_type != MeshType::ConstantDz);
118  const bool l_moving_terrain = (solverChoice.terrain_type == TerrainType::MovingFittedMesh);
119  if (l_moving_terrain) AMREX_ALWAYS_ASSERT(l_use_terrain);
120 
121  const bool l_anelastic = solverChoice.anelastic[level];
122  const bool l_anelastic_rk2 = (solverChoice.anelastic_type[level] == AnelasticType::RK2);
123 
124  // Only add to the flux registers on the final RK stage. The anelastic integrator
125  // takes two stages (nrk = 0,1) and the compressible one takes three (nrk = 0,1,2),
126  // so testing nrk == 2 alone would never reflux the scalar and moisture fluxes in an
127  // anelastic run. This matches the condition used in erf_slow_rhs_pre.
128  const bool l_reflux = ( (solverChoice.coupling_type == CouplingType::TwoWay) && (finest_level > 0) &&
129  ( (l_anelastic && nrk == 1) || (!l_anelastic && nrk == 2) ) );
130 
131  const bool l_use_KE = ( tc.use_tke );
132  const bool l_need_SmnSmn = ( tc.les_type == LESType::Deardorff ||
133  tc.rans_type == RANSType::kEqn );
134  // k-eqn RANS with a Dirichlet wall value: SurfaceLayer::update_fluxes
135  // writes AL01 Eq. 16 into the first cell of S_old at the start of the
136  // step; keep that value through every RK stage.
137  const bool l_dirichlet_k = ( tc.rans_type == RANSType::kEqn && tc.dirichlet_k &&
138  (SurfLayer[Orientation(Direction::z, Orientation::low)] != nullptr) );
139  // Implicit TKE dissipation: eps = c * (rho k)_new with c = diss_old / (rho k)_old,
140  // i.e. Cmu0^3 sqrt(k_old) / L; the source skips the explicit sink and the
141  // update divides by (1 + dt c).
142  const bool l_implicit_diss = ( tc.use_keqn && tc.implicit_tke_dissipation );
143  const Real l_tke_floor = tc.tke_floor;
144  const bool l_advect_KE = ( tc.use_tke && tc.advect_tke );
145  const bool l_use_diff = ((dc.molec_diff_type != MolecDiffType::None) ||
146  (tc.les_type != LESType::None) ||
147  (tc.rans_type != RANSType::None) ||
148  (tc.pbl_type != PBLType::None) );
149  const bool l_use_turb = tc.use_kturb;
150  const bool l_rotate = (solverChoice.use_rotate_surface_flux);
151  const bool l_do_scalar = (solverChoice.transport_scalar);
152  const bool l_use_eb = (solverChoice.terrain_type == TerrainType::EB);
153 
154  auto any_SurfLayer = [&SurfLayer_ = SurfLayer]() -> bool {
155  for (auto it = SurfLayer_.begin(); it != SurfLayer_.end(); it++)
156  {
157  if (*it != nullptr) { return true; }
158  }
159  return false;
160  };
161 
162  amrex::ignore_unused(m_r2d);
163 
164  const Box& domain = geom.Domain();
165 
166  bool l_apply_surface_layer_fluxes_in_diffusion = any_SurfLayer();
167 #ifdef ERF_USE_EAMXX_SHOC
168  if (tc.uses_eamxx_shoc()) {
169  l_apply_surface_layer_fluxes_in_diffusion = false;
170  }
171 #endif
172  if (tc.uses_native_shoc()) {
173  AMREX_ALWAYS_ASSERT(native_shoc_lev != nullptr);
174  l_apply_surface_layer_fluxes_in_diffusion = false;
175  }
176 
177  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
178  const Real* dx = geom.CellSize();
179 
180  // *************************************************************************
181  // Set gravity as a vector
182  // *************************************************************************
183  const Array<Real,AMREX_SPACEDIM> grav{zero, zero, -solverChoice.gravity};
184  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
185 
186  // *************************************************************************
187  // Pre-computed quantities
188  // *************************************************************************
189  int nvars = S_data[IntVars::cons].nComp();
190 
191  // Total number of q state components. This is n_qstate (the water species) plus
192  // any non-water species that the microphysics model appends after them, and is the
193  // count that the advection, diffusion, state update and reflux all work over.
194  const int n_qstate_total = nvars - RhoQ1_comp;
195 
196  const BoxArray& ba = S_data[IntVars::cons].boxArray();
197  const DistributionMapping& dm = S_data[IntVars::cons].DistributionMap();
198  const bool use_physical_chamber_wall_flux =
199  cloud_chamber_config != nullptr && cloud_chamber_base_state != nullptr &&
200  cloud_chamber_config->physical_initialization;
201  const erf_wall_thermodynamics::Boundary chamber_walls =
202  use_physical_chamber_wall_flux ? cloud_chamber_config->wall_boundary() :
204 
205  std::unique_ptr<MultiFab> dflux_x;
206  std::unique_ptr<MultiFab> dflux_y;
207  std::unique_ptr<MultiFab> dflux_z;
208 
209  if (l_use_diff) {
210  IntVect ng(0,0,1);
211  // The physical chamber needs one persistent component for each moist
212  // state even when budgets are disabled: qv and qc are corrected and
213  // retained independently. All other configurations retain ERF's
214  // established one-component reusable diffusion storage.
215  const int n_flux_components = use_physical_chamber_wall_flux ?
216  std::max(1, n_qstate_total) : 1;
217  dflux_x = std::make_unique<MultiFab>(convert(ba,IntVect(1,0,0)), dm, n_flux_components, ng);
218  dflux_y = std::make_unique<MultiFab>(convert(ba,IntVect(0,1,0)), dm, n_flux_components, ng);
219  dflux_z = std::make_unique<MultiFab>(convert(ba,IntVect(0,0,1)), dm, n_flux_components, 0);
220  // Every physical wall override reads the old face flux before
221  // replacing it; make that read deterministic regardless of budget
222  // diagnostics.
223  if (use_physical_chamber_wall_flux) {
224  dflux_x->setVal(0.0);
225  dflux_y->setVal(0.0);
226  dflux_z->setVal(0.0);
227  }
228  } else {
229  dflux_x = nullptr;
230  dflux_y = nullptr;
231  dflux_z = nullptr;
232  }
233 
234  // Valid vars
235  Vector<int> is_valid_slow_var; is_valid_slow_var.resize(RhoQ1_comp+1,0);
236  if (l_use_KE) { is_valid_slow_var[ RhoKE_comp] = 1; }
237  if (l_do_scalar) { is_valid_slow_var[RhoScalar_comp] = 1; }
238  if (solverChoice.moisture_type != MoistureType::None) {
239  is_valid_slow_var[RhoQ1_comp] = 1;
240  }
241 
242  // *************************************************************************
243  // Calculate cell-centered eddy viscosity & diffusivities
244  //
245  // Notes -- we fill all the data in ghost cells before calling this so
246  // that we can fill the eddy viscosity in the ghost regions and
247  // not have to call a boundary filler on this data itself
248  //
249  // LES - updates both horizontal and vertical eddy viscosityS_tmp components
250  // PBL - only updates vertical eddy viscosity components so horizontal
251  // components come from the LES model or are left as zero.
252  // *************************************************************************
253 
254  // EB Anelastic: Copy projected momentum with ghost-cell synchronization
255  if (l_anelastic && l_use_eb) {
256  avg_xmom.ParallelCopy(S_data[IntVars::xmom], 0, 0, 1, 0, 1, geom.periodicity());
257  avg_ymom.ParallelCopy(S_data[IntVars::ymom], 0, 0, 1, 0, 1, geom.periodicity());
258  avg_zmom.ParallelCopy(S_data[IntVars::zmom], 0, 0, 1, 0, 1, geom.periodicity());
259  }
260 
261  // Non-EB Anelastic: the slow scalars are advected with the projected momentum. Copy it
262  // before the tile loop below: a copy per tile inside that loop left the faces of the tiles
263  // not yet visited at their values from the previous stage while earlier tiles were already
264  // advecting with them, so the scalars depended on the tile size.
265  if (l_anelastic && !l_use_eb) {
266  MultiFab::Copy(avg_xmom, S_data[IntVars::xmom], 0, 0, 1, 0);
267  MultiFab::Copy(avg_ymom, S_data[IntVars::ymom], 0, 0, 1, 0);
268  MultiFab::Copy(avg_zmom, S_data[IntVars::zmom], 0, 0, 1, 0);
269  }
270 
271  // *************************************************************************
272  // Define updates and fluxes in the current RK stage
273  // *************************************************************************
274 #ifdef _OPENMP
275 #pragma omp parallel if (Gpu::notInLaunchRegion())
276 #endif
277  {
278  std::array<FArrayBox,AMREX_SPACEDIM> flux;
279 
280  int start_comp;
281  int num_comp;
282 
283  // Cell-centered masks for EB (used for flux interpolation)
284  iMultiFab physbnd_mask;
285  bool already_on_centroids = false;
286  if (l_use_eb) {
287  physbnd_mask.define(S_data[IntVars::cons].boxArray(), S_data[IntVars::cons].DistributionMap(), 1, 1);
288  physbnd_mask.BuildMask(geom.Domain(), geom.periodicity(), 1, 1, 0, 1);
289  }
290 
291  for (MFIter mfi(S_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi) {
292 
293  Box tbx = mfi.tilebox();
294 
295  // *************************************************************************
296  // Define flux arrays for use in advection
297  // *************************************************************************
298  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
299  if (!l_use_eb) {
300  flux[dir].resize(surroundingNodes(tbx,dir),nvars,The_Async_Arena());
301  } else {
302  flux[dir].resize(surroundingNodes(tbx,dir).grow(1),nvars,The_Async_Arena());
303  }
304  flux[dir].setVal<RunOn::Device>(0);
305  }
306  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
307  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
308 
309  // *************************************************************************
310  // Define Array4's
311  // *************************************************************************
312  const Array4<const Real> & old_cons = S_old[IntVars::cons].array(mfi);
313  const Array4< Real> & cell_rhs = S_rhs[IntVars::cons].array(mfi);
314 
315  const Array4< Real> & new_cons = S_new[IntVars::cons].array(mfi);
316  const Array4< Real> & new_xmom = S_new[IntVars::xmom].array(mfi);
317  const Array4< Real> & new_ymom = S_new[IntVars::ymom].array(mfi);
318  const Array4< Real> & new_zmom = S_new[IntVars::zmom].array(mfi);
319 
320  const Array4< Real> & cur_cons = S_data[IntVars::cons].array(mfi);
321  const Array4<const Real> & cur_prim = S_prim.array(mfi);
322  const Array4< Real> & cur_xmom = S_data[IntVars::xmom].array(mfi);
323  const Array4< Real> & cur_ymom = S_data[IntVars::ymom].array(mfi);
324  const Array4< Real> & cur_zmom = S_data[IntVars::zmom].array(mfi);
325 
326  Array4<Real> avg_xmom_arr = avg_xmom.array(mfi);
327  Array4<Real> avg_ymom_arr = avg_ymom.array(mfi);
328  Array4<Real> avg_zmom_arr = avg_zmom.array(mfi);
329 
330  const Array4<const Real> & u = xvel.array(mfi);
331  const Array4<const Real> & v = yvel.array(mfi);
332  const Array4<const Real> & w = zvel.array(mfi);
333 
334  const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
335  const Array4<const Real>& z_cc = z_phys_cc->const_array(mfi);
336  const Array4<const Real>& detJ_new_arr = l_moving_terrain ? detJ_new->const_array(mfi) : Array4<const Real>{};
337 
338  const Array4<const Real>& t_blank_arr = (terrain_blank) ? terrain_blank->const_array(mfi) :
339  Array4<const Real>{};
340  const Array4<const Real>& t_blank_xface_arr = (terrain_blank_xface) ? terrain_blank_xface->const_array(mfi) :
341  Array4<const Real>{};
342  const Array4<const Real>& t_blank_yface_arr = (terrain_blank_yface) ? terrain_blank_yface->const_array(mfi) :
343  Array4<const Real>{};
344  const Array4<const Real>& t_blank_zface_arr = (terrain_blank_zface) ? terrain_blank_zface->const_array(mfi) :
345  Array4<const Real>{};
346 
347  // Map factors
348  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
349  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
350  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
351  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
352  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
353  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
354 
355  // SmnSmn for KE src with Deardorff or k-eqn RANS
356  const Array4<const Real>& SmnSmn_a = l_need_SmnSmn ? SmnSmn->const_array(mfi) : Array4<const Real>{};
357 
358  // **************************************************************************
359  // Here we fill the "current" data with "new" data because that is the result of the previous RK stage
360  // **************************************************************************
361  int nsv = S_old[IntVars::cons].nComp() - 2;
362  const GpuArray<int, IntVars::NumTypes> scomp_slow = { 2,0,0,0};
363  const GpuArray<int, IntVars::NumTypes> ncomp_slow = {nsv,0,0,0};
364 
365  // **************************************************************************
366  // Note that here we do copy only the "slow" variables, not (rho) or (rho theta)
367  // **************************************************************************
368  ParallelFor(tbx, ncomp_slow[IntVars::cons],
369  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) {
370  const int n = scomp_slow[IntVars::cons] + nn;
371  cur_cons(i,j,k,n) = new_cons(i,j,k,n);
372  });
373 
374  // **************************************************************************
375  // Define updates in the RHS of continuity, temperature, and scalar equations
376  // **************************************************************************
377  bool l_eb_terrain_cc = false; // EB terrain on cell-centered grid
378  Array4<const int> mask_arr{};
379  Array4<const EBCellFlag> cfg_arr{};
380  Array4<const Real> ax_arr{};
381  Array4<const Real> ay_arr{};
382  Array4<const Real> az_arr{};
383  Array4<const Real> fcx_arr{};
384  Array4<const Real> fcy_arr{};
385  Array4<const Real> fcz_arr{};
386  Array4<const Real> detJ_arr{};
387  Array4<const Real> barea_arr{};
388  Array4<const Real> bcent_arr{};
389 
390  if (l_use_eb) {
391  EBFArrayBoxFactory const& ebfact_cc = *(ebfact.get_const_factory());
392  EBCellFlagFab const& cfg = ebfact_cc.getMultiEBCellFlagFab()[mfi];
393  cfg_arr = cfg.const_array();
394  if (cfg.getType(tbx) == FabType::singlevalued) {
395  l_eb_terrain_cc = true;
396  ax_arr = ebfact_cc.getAreaFrac()[0]->const_array(mfi);
397  ay_arr = ebfact_cc.getAreaFrac()[1]->const_array(mfi);
398  az_arr = ebfact_cc.getAreaFrac()[2]->const_array(mfi);
399  fcx_arr = ebfact_cc.getFaceCent()[0]->const_array(mfi);
400  fcy_arr = ebfact_cc.getFaceCent()[1]->const_array(mfi);
401  fcz_arr = ebfact_cc.getFaceCent()[2]->const_array(mfi);
402  detJ_arr = ebfact_cc.getVolFrac().const_array(mfi);
403  mask_arr = physbnd_mask.const_array(mfi);
404  barea_arr = ebfact_cc.getBndryArea().const_array(mfi);
405  bcent_arr = ebfact_cc.getBndryCent().const_array(mfi);
406  } else {
407  ax_arr = ax->const_array(mfi);
408  ay_arr = ay->const_array(mfi);
409  az_arr = az->const_array(mfi);
410  detJ_arr = detJ->const_array(mfi);
411  }
412  } else {
413  ax_arr = ax->const_array(mfi);
414  ay_arr = ay->const_array(mfi);
415  az_arr = az->const_array(mfi);
416  detJ_arr = detJ->const_array(mfi);
417  }
418 
419  AdvType horiz_adv_type, vert_adv_type;
420  Real horiz_upw_frac, vert_upw_frac;
421 
422  Array4<Real> diffflux_x, diffflux_y, diffflux_z;
423  Array4<Real> hfx_x, hfx_y, hfx_z, diss;
424  Array4<Real> q1fx_x, q1fx_y, q1fx_z, q2fx_z;
425  Array4<Real> hfx_EB{};
426 
427  if (l_use_diff) {
428  diffflux_x = dflux_x->array(mfi);
429  diffflux_y = dflux_y->array(mfi);
430  diffflux_z = dflux_z->array(mfi);
431 
432  hfx_x = Hfx1->array(mfi);
433  hfx_y = Hfx2->array(mfi);
434  hfx_z = Hfx3->array(mfi);
435  diss = Diss->array(mfi);
436 
437  if (Q1fx1) q1fx_x = Q1fx1->array(mfi);
438  if (Q1fx2) q1fx_y = Q1fx2->array(mfi);
439  if (Q1fx3) q1fx_z = Q1fx3->array(mfi);
440  if (Q2fx3) q2fx_z = Q2fx3->array(mfi);
441  }
442 
443  if (l_use_diff && l_use_turb) {
445  eddyDiffs != nullptr,
446  "erf_slow_rhs_post: active turbulence requires non-null eddyDiffs");
447  }
448  const Array4<const Real>& mu_turb =
449  l_use_turb ? eddyDiffs->const_array(mfi) : Array4<const Real>{};
450 
451  //
452  // Note that we either advect and diffuse all or none of the moisture variables
453  //
454  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
455  {
456 
457  if (is_valid_slow_var[ivar])
458  {
459  start_comp = ivar;
460  num_comp = 1;
461 
462  if (ivar == RhoQ1_comp) {
463  horiz_adv_type = ac.moistscal_horiz_adv_type;
464  vert_adv_type = ac.moistscal_vert_adv_type;
465  horiz_upw_frac = ac.moistscal_horiz_upw_frac;
466  vert_upw_frac = ac.moistscal_vert_upw_frac;
467 
468  if (ac.use_efficient_advection){
469  horiz_adv_type = EfficientAdvType(nrk,ac.moistscal_horiz_adv_type);
470  vert_adv_type = EfficientAdvType(nrk,ac.moistscal_vert_adv_type);
471  }
472 
473  // Every state component from RhoQ1_comp to the end of the state, not
474  // just the n_qstate water species: a microphysics model may append
475  // non-water species after those (SuperDropletsMoist does), and they
476  // are advanced by the state update below and included in the reflux.
477  // Computing residuals for only the first n_qstate would leave the
478  // rest to be updated with a residual nothing ever wrote.
479  num_comp = n_qstate_total;
480 
481  } else {
482  horiz_adv_type = ac.dryscal_horiz_adv_type;
483  vert_adv_type = ac.dryscal_vert_adv_type;
484  horiz_upw_frac = ac.dryscal_horiz_upw_frac;
485  vert_upw_frac = ac.dryscal_vert_upw_frac;
486 
487  if (ac.use_efficient_advection){
488  horiz_adv_type = EfficientAdvType(nrk,ac.dryscal_horiz_adv_type);
489  vert_adv_type = EfficientAdvType(nrk,ac.dryscal_vert_adv_type);
490  }
491 
492  if (ivar == RhoScalar_comp) {
493  num_comp = NSCALARS;
494  }
495  }
496 
497  if (( ivar != RhoKE_comp ) ||
498  ((ivar == RhoKE_comp) && l_advect_KE))
499  {
500  if (!l_eb_terrain_cc){
501  AdvectionSrcForScalars(tbx, start_comp, num_comp,
502  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
503  cur_prim, cell_rhs,
504  detJ_arr, dxInv, mf_mx, mf_my,
505  horiz_adv_type, vert_adv_type,
506  horiz_upw_frac, vert_upw_frac,
507  flx_arr, domain, bc_ptr_h);
508  } else {
509  EBAdvectionSrcForScalars(tbx, start_comp, num_comp,
510  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
511  cur_prim, cell_rhs,
512  mask_arr, cfg_arr, ax_arr, ay_arr, az_arr,
513  fcx_arr, fcy_arr, fcz_arr,
514  detJ_arr, dxInv, mf_mx, mf_my,
515  horiz_adv_type, vert_adv_type,
516  horiz_upw_frac, vert_upw_frac,
517  flx_arr, domain, bc_ptr_h,
518  already_on_centroids);
519  }
520  }
521 
522  if (l_use_diff)
523  {
524  // Allow for implicit moisture diffusion
526  if ( (ivar == RhoKE_comp && solverChoice.implicit_ke_diffusion ) ||
527  (ivar == RhoQ1_comp && solverChoice.implicit_moisture_diffusion) ) {
528  l_vert_implicit_fac = solverChoice.vert_implicit_fac[level][nrk];
529  }
530 
531  const Array4<const Real> tm_arr = t_mean_mf ? t_mean_mf->const_array(mfi) : Array4<const Real>{};
532 
533  // Only the physical chamber needs separate qv/qc calls:
534  // its wall correction must be applied to distinct flux
535  // components. Generic moisture models retain the
536  // established multi-component diffusion call.
537  const bool componentwise_moisture =
538  use_physical_chamber_wall_flux && ivar == RhoQ1_comp;
539  const int n_diff_calls = componentwise_moisture ? n_qstate_total : 1;
540  for (int qstate = 0; qstate < n_diff_calls; ++qstate) {
541  const int state_comp = componentwise_moisture ?
542  RhoQ1_comp + qstate : start_comp;
543  const int diffusion_start = state_comp;
544  const int diffusion_num = componentwise_moisture ? 1 : num_comp;
545  const int flux_comp = componentwise_moisture ? qstate : 0;
546  AMREX_ALWAYS_ASSERT(state_comp >= 0 && state_comp < nvars);
547  AMREX_ALWAYS_ASSERT(flux_comp < dflux_x->nComp());
548  AMREX_ALWAYS_ASSERT(flux_comp < dflux_y->nComp());
549  AMREX_ALWAYS_ASSERT(flux_comp < dflux_z->nComp());
550  const Array4<Real> diffusion_x = dflux_x->array(mfi, flux_comp);
551  const Array4<Real> diffusion_y = dflux_y->array(mfi, flux_comp);
552  const Array4<Real> diffusion_z = dflux_z->array(mfi, flux_comp);
553 
554  if (solverChoice.mesh_type == MeshType::StretchedDz) {
555  DiffusionSrcForState_S(tbx, domain, diffusion_start, diffusion_num, u, v,
556  new_cons, cur_prim, cell_rhs,
557  diffusion_x, diffusion_y, diffusion_z,
558  stretched_dz_d, dxInv, SmnSmn_a,
559  mf_mx, mf_ux, mf_vx,
560  mf_my, mf_uy, mf_vy,
561  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z,q2fx_z, diss,
562  mu_turb, solverChoice, level,
563  tm_arr, grav_gpu, bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer, l_vert_implicit_fac);
564  } else if (l_use_terrain) {
565  DiffusionSrcForState_T(tbx, domain, diffusion_start, diffusion_num, l_rotate, u, v,
566  new_cons, cur_prim, cell_rhs,
567  diffusion_x, diffusion_y, diffusion_z,
568  z_nd, z_cc, ax_arr, ay_arr, az_arr,
569  detJ_arr, dxInv, SmnSmn_a,
570  mf_mx, mf_ux, mf_vx,
571  mf_my, mf_uy, mf_vy,
572  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z,q2fx_z, diss,
573  mu_turb, solverChoice, level,
574  tm_arr, grav_gpu, bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer, l_vert_implicit_fac);
575  } else if (l_use_eb) {
576  DiffusionSrcForState_EB(tbx, domain, diffusion_start, diffusion_num, u, v,
577  new_cons, cur_prim, cell_rhs,
578  diffusion_x, diffusion_y, diffusion_z,
579  cfg_arr, ax_arr, ay_arr, az_arr, detJ_arr,
580  barea_arr, bcent_arr,
581  dx, dxInv,
582  hfx_z, q1fx_z, q2fx_z, hfx_EB,
583  mu_turb, solverChoice, level,
584  bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer);
585  } else {
586  DiffusionSrcForState_N(tbx, domain, diffusion_start, diffusion_num, u, v,
587  new_cons, cur_prim, cell_rhs,
588  diffusion_x, diffusion_y, diffusion_z, dxInv, SmnSmn_a,
589  mf_mx, mf_ux, mf_vx,
590  mf_my, mf_uy, mf_vy,
591  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z, q2fx_z, diss,
592  mu_turb, solverChoice, level,
593  tm_arr, grav_gpu, bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, SurfLayer, l_vert_implicit_fac);
594  }
595  if (use_physical_chamber_wall_flux) {
596  // Apply the physical wall correction immediately to
597  // the flux component just computed. This keeps the
598  // q-state diffusion path identical with budgets on
599  // and off and guarantees no stale flux is consumed.
600  // The diffusion views are component-shifted; the
601  // wall helper receives the unshifted views and the
602  // explicit flux component index.
604  tbx, domain, state_comp, flux_comp, new_cons, cur_prim,
605  cloud_chamber_base_state->const_array(mfi), u, v, w, cell_rhs,
606  diffflux_x, diffflux_y, diffflux_z, dxInv,
607  chamber_walls, dc.alpha_T, dc.alpha_C,
608  solverChoice.rdOcp, cloud_chamber_config->cloudy);
609  }
610  }
611  } // use_diff
612 
613 
614  } // valid slow var
615  } // loop ivar
616 
617 #ifdef ERF_USE_EAMXX_SHOC
618  if (tc.uses_eamxx_shoc() && eamxx_shoc_lev) {
619  eamxx_shoc_lev->add_slow_tend(mfi,tbx,cell_rhs);
620  }
621 #endif
622  // This updates just the "slow" conserved variables
623  {
624  BL_PROFILE("rhs_post_8");
625 
627 
628  auto const& src_arr = source.const_array(mfi);
629 
630  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
631  {
632  if (is_valid_slow_var[ivar])
633  {
634  start_comp = ivar;
635  num_comp = 1;
636  if (ivar == RhoQ1_comp) {
637  num_comp = n_qstate_total;
638  } else if (ivar == RhoScalar_comp) {
639  num_comp = NSCALARS;
640  }
641 
642  if (l_moving_terrain)
643  {
644  ParallelFor(tbx, num_comp,
645  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
646  const int n = start_comp + nn;
647  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
648  Real temp_val = detJ_arr(i,j,k) * old_cons(i,j,k,n) + dt * detJ_arr(i,j,k) * cell_rhs(i,j,k,n);
649  cur_cons(i,j,k,n) = temp_val / detJ_new_arr(i,j,k);
650  if (ivar == RhoKE_comp) {
651  if (l_implicit_diss) {
652  cur_cons(i,j,k,n) /= (one + dt * diss(i,j,k) / amrex::max(old_cons(i,j,k,n), eps));
653  }
654  const Real ke_floor = (l_tke_floor > zero) ? cur_cons(i,j,k,Rho_comp) * l_tke_floor : eps;
655  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), ke_floor);
656  }
657  });
658 
659  } else if (l_anelastic && l_anelastic_rk2 && (nrk == 1)) { // not moving and ( (anelastic) and second RK stage) )
660 
661  ParallelFor(tbx, num_comp,
662  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
663  const int n = start_comp + nn;
664  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
665 
666  // Re-construct the cell_rhs used in the first RK stage
667  Real dt_times_old_cell_rhs = cur_cons(i,j,k,n) - old_cons(i,j,k,n);
668 
669  // Add the time-averaged RHS to the old state
670  cur_cons(i,j,k,n) = old_cons(i,j,k,n) + myhalf * (dt_times_old_cell_rhs + dt * cell_rhs(i,j,k,n));
671 
672  if (ivar == RhoKE_comp) {
673  if (l_implicit_diss) {
674  // stage 1 of the trapezoidal update: half the step is implicit
675  cur_cons(i,j,k,n) /= (one + myhalf * dt * diss(i,j,k) / amrex::max(old_cons(i,j,k,n), eps));
676  }
677  const Real ke_floor = (l_tke_floor > zero) ? cur_cons(i,j,k,Rho_comp) * l_tke_floor : eps;
678  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), ke_floor);
679  } else if (ivar >= RhoQ1_comp) {
680  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), amrex::Real(0));
681  }
682  });
683 
684  } else { // not moving and ( (not anelastic) or (first RK stage) )
685 
686  ParallelFor(tbx, num_comp,
687  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
688  const int n = start_comp + nn;
689  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
690  cur_cons(i,j,k,n) = old_cons(i,j,k,n) + dt * cell_rhs(i,j,k,n);
691  if (ivar == RhoKE_comp) {
692  if (l_implicit_diss) {
693  cur_cons(i,j,k,n) /= (one + dt * diss(i,j,k) / amrex::max(old_cons(i,j,k,n), eps));
694  }
695  const Real ke_floor = (l_tke_floor > zero) ? cur_cons(i,j,k,Rho_comp) * l_tke_floor : eps;
696  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), ke_floor);
697  } else if (ivar >= RhoQ1_comp) {
698  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), amrex::Real(0));
699  }
700  });
701 
702  } // moving, anelastic or neither?
703 
704  } // is_valid
705  } // ivar
706 
707  // Re-impose the Dirichlet wall value of k (first cell above the wall)
708  if (l_dirichlet_k && is_valid_slow_var[RhoKE_comp]) {
709  const int klo = domain.smallEnd(2);
710  if (tbx.smallEnd(2) <= klo && tbx.bigEnd(2) >= klo) {
711  ParallelFor(makeSlab(tbx,2,klo), [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
712  // Hold k, not rho*k. Eq. 16 defines the primitive wall value, and
713  // cur_cons(Rho_comp) has already been updated for this stage (and,
714  // with moving terrain, rescaled by detJ/detJ_new along with RhoKE),
715  // so copying the conserved variable straight across would let the
716  // wall value drift by the first-cell density change every step.
717  // Both states carry the same detJ convention, so the ratio is exact.
718  cur_cons(i,j,k,RhoKE_comp) = cur_cons(i,j,k,Rho_comp) *
719  ( old_cons(i,j,k,RhoKE_comp) / old_cons(i,j,k,Rho_comp) );
720  });
721  }
722  }
723  } // profile
724 
725  {
726  BL_PROFILE("rhs_post_9");
727  // This updates all the conserved variables (not just the "slow" ones)
728  int num_comp_all = S_data[IntVars::cons].nComp();
729  ParallelFor(tbx, num_comp_all,
730  [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept {
731  new_cons(i,j,k,n) = cur_cons(i,j,k,n);
732  });
733  } // end profile
734 
735  Box xtbx = mfi.nodaltilebox(0);
736  Box ytbx = mfi.nodaltilebox(1);
737  Box ztbx = mfi.nodaltilebox(2);
738 
739  {
740  BL_PROFILE("rhs_post_10()");
741  if (l_anelastic && terrain_blank) { // explicitly set fully immersed cells to have 0 velocities for anelastic (unstable for fully compressible).
742  ParallelFor(xtbx, ytbx, ztbx,
743  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
744  // Use face-centered terrain_blanking if available, otherwise average from cell centers
745  Real t_blank = (t_blank_xface_arr) ? t_blank_xface_arr(i, j, k) :
746  myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i-1, j, k));
747  if (t_blank == one) {
748  new_xmom(i,j,k) = zero;
749  } else {
750  new_xmom(i,j,k) = cur_xmom(i,j,k);
751  }
752  },
753  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
754  // Use face-centered terrain_blanking if available, otherwise average from cell centers
755  Real t_blank = (t_blank_yface_arr) ? t_blank_yface_arr(i, j, k) :
756  myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j-1, k));
757  if (t_blank == one) {
758  new_ymom(i,j,k) = zero;
759  } else {
760  new_ymom(i,j,k) = cur_ymom(i,j,k);
761  }
762  },
763  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
764  // Use face-centered terrain_blanking if available, otherwise average from cell centers
765  Real t_blank = (t_blank_zface_arr) ? t_blank_zface_arr(i, j, k) :
766  myhalf * (t_blank_arr(i, j, k) + t_blank_arr(i, j, k-1));
767  if (t_blank == one) {
768  new_zmom(i,j,k) = zero;
769  } else {
770  new_zmom(i,j,k) = cur_zmom(i,j,k);
771  }
772  });
773  ParallelFor(tbx,
774  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
775  Real t_blank = t_blank_arr(i, j, k );
776  if (t_blank == one) { // don't update rho and theta for fully immersed cells
777  new_cons(i, j, k, Rho_comp) = old_cons(i, j, k, Rho_comp);
778  new_cons(i, j, k, RhoTheta_comp) = old_cons(i, j, k, RhoTheta_comp);
779  }
780  });
781  } else {
782  ParallelFor(xtbx, ytbx, ztbx,
783  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
784  new_xmom(i,j,k) = cur_xmom(i,j,k);
785  },
786  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
787  new_ymom(i,j,k) = cur_ymom(i,j,k);
788  },
789  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
790  new_zmom(i,j,k) = cur_zmom(i,j,k);
791  });
792  }
793  } // end profile
794 
795  {
796  BL_PROFILE("rhs_post_10");
797  // We only add to the flux registers in the final RK step
798  if (l_reflux) {
799  int strt_comp_reflux = RhoTheta_comp + 1;
800  int num_comp_reflux = nvars - strt_comp_reflux;
801  if (level < finest_level) {
802  fr_as_crse->CrseAdd(mfi,
803  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
804  dx, dt, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
805  }
806  if (level > 0) {
807  fr_as_fine->FineAdd(mfi,
808  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
809  dx, dt, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
810  }
811 
812  // This is necessary here so we don't go on to the next FArrayBox without
813  // having finished copying the fluxes into the FluxRegisters (since the fluxes
814  // are stored in temporary FArrayBox's)
815  Gpu::streamSynchronize();
816 
817  } // two-way coupling
818  } // end profile
819  } // mfi
820  } // OMP
821  if (cloud_budget && l_use_diff && n_qstate > 0) {
822  bool use_trapezoidal = (!l_anelastic || l_anelastic_rk2);
823  for (int qstate = 0; qstate < n_qstate; ++qstate) {
824  MultiFab qflux_x(*dflux_x, make_alias, qstate, 1);
825  MultiFab qflux_y(*dflux_y, make_alias, qstate, 1);
826  MultiFab qflux_z(*dflux_z, make_alias, qstate, 1);
827  cloud_budget->capture_stage(
829  nrk, static_cast<Real>(dt_d), qflux_x, qflux_y, qflux_z, geom,
830  0, use_trapezoidal);
831  }
832  }
833 }
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_GPU_HOST_DEVICE AMREX_FORCE_INLINE AdvType EfficientAdvType(int nrk, AdvType adv_type)
Definition: ERF_Advection.H:467
@ 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 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 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.
const Real l_vert_implicit_fac
Definition: ERF_ImplicitPost.H:6
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:43
#define Rho_comp
Definition: ERF_IndexDefines.H:39
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:40
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:45
AdvType
Definition: ERF_IndexDefines.H:309
#define RhoKE_comp
Definition: ERF_IndexDefines.H:41
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
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_cloud_chamber_config.active, "Cloud Chamber: initializer reached without a parsed configuration")
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
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
@ RhoQv
Definition: ERF_CloudChamberBudget.H:33
@ RhoQc
Definition: ERF_CloudChamberBudget.H:33
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory() const noexcept
Return the cell-centered EB factory.
Definition: ERF_EB.H:102
@ ymom
Definition: ERF_IndexDefines.H:234
@ cons
Definition: ERF_IndexDefines.H:232
@ zmom
Definition: ERF_IndexDefines.H:235
@ xmom
Definition: ERF_IndexDefines.H:233
@ ng
Definition: ERF_Morrison.H:50
@ nn
Definition: ERF_WDM6.H:32
@ xvel
Definition: ERF_IndexDefines.H:215
@ zvel
Definition: ERF_IndexDefines.H:217
@ yvel
Definition: ERF_IndexDefines.H:216
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
amrex::GpuArray< FaceWall, 2 *AMREX_SPACEDIM > Boundary
Definition: ERF_WallThermodynamics.H:70
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
real(c_double), private ac
Definition: ERF_module_mp_morr_two_moment.F90:181
Definition: ERF_AdvStruct.H:19
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
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
bool implicit_moisture_diffusion
Whether implicit vertical moisture diffusion is included.
Definition: ERF_DataStruct.H:2003
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
bool implicit_ke_diffusion
Whether implicit vertical TKE diffusion is included.
Definition: ERF_DataStruct.H:2004
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::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
bool transport_scalar
Whether the passive scalar component is transported.
Definition: ERF_DataStruct.H:2116
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
bool advect_tke
Whether TKE/QKE is advected.
Definition: ERF_TurbStruct.H:925
bool implicit_tke_dissipation
Definition: ERF_TurbStruct.H:765
bool use_tke
Whether any TKE or QKE closure is active.
Definition: ERF_TurbStruct.H:841
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
amrex::Real tke_floor
Definition: ERF_TurbStruct.H:761
bool uses_native_shoc() const noexcept
Query whether this level uses the native SHOC PBL scheme.
Definition: ERF_TurbStruct.H:794
bool dirichlet_k
Whether TKE uses Dirichlet boundary treatment.
Definition: ERF_TurbStruct.H:756
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: