ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SlowRhsPost.cpp File Reference
#include <AMReX.H>
#include <ERF_SrcHeaders.H>
#include <ERF_TI_slow_headers.H>
#include <ERF_EBAdvection.H>
#include <ERF_EBRedistribute.H>
Include dependency graph for ERF_SlowRhsPost.cpp:

Functions

void erf_slow_rhs_post (int level, int finest_level, int nrk, Real dt, 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 &, const MultiFab &source, 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, 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, amrex::EBFArrayBoxFactory const &ebfact, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine, std::unique_ptr< ReadBndryPlanes > &m_r2d)
 

Function Documentation

◆ erf_slow_rhs_post()

void erf_slow_rhs_post ( int  level,
int  finest_level,
int  nrk,
Real  dt,
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 &  ,
const MultiFab &  source,
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,
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,
amrex::EBFArrayBoxFactory const &  ebfact,
YAFluxRegister *  fr_as_crse,
YAFluxRegister *  fr_as_fine,
std::unique_ptr< ReadBndryPlanes > &  m_r2d 
)

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]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
93 {
94  BL_PROFILE_REGION("erf_slow_rhs_post()");
95 
96  const BCRec* bc_ptr_d = domain_bcs_type_d.data();
97  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
98 
99  AdvChoice ac = solverChoice.advChoice;
100  DiffChoice dc = solverChoice.diffChoice;
101  TurbChoice tc = solverChoice.turbChoice[level];
102 
103  const MultiFab* t_mean_mf = nullptr;
104  if (SurfLayer) { t_mean_mf = SurfLayer->get_mac_avg(level,2); }
105 
106  const bool l_use_terrain = (solverChoice.mesh_type != MeshType::ConstantDz);
107  const bool l_moving_terrain = (solverChoice.terrain_type == TerrainType::MovingFittedMesh);
108  const bool l_reflux = ( (solverChoice.coupling_type == CouplingType::TwoWay) && (nrk == 2) && (finest_level > 0) );
109  if (l_moving_terrain) AMREX_ALWAYS_ASSERT(l_use_terrain);
110 
111  const bool l_anelastic = solverChoice.anelastic[level];
112 
113  const bool l_use_KE = ( tc.use_tke );
114  const bool l_need_SmnSmn = ( tc.les_type == LESType::Deardorff ||
115  tc.rans_type == RANSType::kEqn );
116  const bool l_advect_KE = ( tc.use_tke && tc.advect_tke );
117  const bool l_use_diff = ((dc.molec_diff_type != MolecDiffType::None) ||
118  (tc.les_type != LESType::None) ||
119  (tc.rans_type != RANSType::None) ||
120  (tc.pbl_type != PBLType::None) );
121  const bool l_use_turb = tc.use_kturb;
122  const bool l_rotate = (solverChoice.use_rotate_surface_flux);
123  const bool l_do_scalar = (solverChoice.transport_scalar);
124  amrex::ignore_unused(m_r2d);
125 
126  const Box& domain = geom.Domain();
127 
128  bool l_apply_surface_layer_fluxes_in_diffusion = (SurfLayer != nullptr);
129 #ifdef ERF_USE_EAMXX_SHOC
130  if (tc.uses_eamxx_shoc()) {
131  l_apply_surface_layer_fluxes_in_diffusion = false;
132  }
133 #endif
134 #ifdef ERF_USE_NATIVE_SHOC
135  if (tc.uses_native_shoc()) {
136  AMREX_ALWAYS_ASSERT(native_shoc_lev != nullptr);
137  l_apply_surface_layer_fluxes_in_diffusion =
138  l_apply_surface_layer_fluxes_in_diffusion &&
139  native_shoc_lev->uses_host_diffusion();
140  }
141 #endif
142 
143  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
144  const Real* dx = geom.CellSize();
145 
146  // *************************************************************************
147  // Set gravity as a vector
148  // *************************************************************************
149  const Array<Real,AMREX_SPACEDIM> grav{zero, zero, -solverChoice.gravity};
150  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
151 
152  // *************************************************************************
153  // Pre-computed quantities
154  // *************************************************************************
155  int nvars = S_data[IntVars::cons].nComp();
156  const BoxArray& ba = S_data[IntVars::cons].boxArray();
157  const DistributionMapping& dm = S_data[IntVars::cons].DistributionMap();
158 
159  std::unique_ptr<MultiFab> dflux_x;
160  std::unique_ptr<MultiFab> dflux_y;
161  std::unique_ptr<MultiFab> dflux_z;
162 
163  if (l_use_diff) {
164  IntVect ng(0,0,1);
165  dflux_x = std::make_unique<MultiFab>(convert(ba,IntVect(1,0,0)), dm, 1, ng);
166  dflux_y = std::make_unique<MultiFab>(convert(ba,IntVect(0,1,0)), dm, 1, ng);
167  dflux_z = std::make_unique<MultiFab>(convert(ba,IntVect(0,0,1)), dm, 1, 0);
168  } else {
169  dflux_x = nullptr;
170  dflux_y = nullptr;
171  dflux_z = nullptr;
172  }
173 
174  // Valid vars
175  Vector<int> is_valid_slow_var; is_valid_slow_var.resize(RhoQ1_comp+1,0);
176  if (l_use_KE) { is_valid_slow_var[ RhoKE_comp] = 1; }
177  if (l_do_scalar) { is_valid_slow_var[RhoScalar_comp] = 1; }
178  if (solverChoice.moisture_type != MoistureType::None) {
179  is_valid_slow_var[RhoQ1_comp] = 1;
180  }
181 
182  // *************************************************************************
183  // Calculate cell-centered eddy viscosity & diffusivities
184  //
185  // Notes -- we fill all the data in ghost cells before calling this so
186  // that we can fill the eddy viscosity in the ghost regions and
187  // not have to call a boundary filler on this data itself
188  //
189  // LES - updates both horizontal and vertical eddy viscosityS_tmp components
190  // PBL - only updates vertical eddy viscosity components so horizontal
191  // components come from the LES model or are left as zero.
192  // *************************************************************************
193 
194  // *************************************************************************
195  // Define updates and fluxes in the current RK stage
196  // *************************************************************************
197 #ifdef _OPENMP
198 #pragma omp parallel if (Gpu::notInLaunchRegion())
199 #endif
200  {
201  std::array<FArrayBox,AMREX_SPACEDIM> flux;
202 
203  int start_comp;
204  int num_comp;
205 
206  // Cell-centered masks for EB (used for flux interpolation)
207  iMultiFab physbnd_mask;
208  bool already_on_centroids = false;
209  if (solverChoice.terrain_type == TerrainType::EB) {
210  physbnd_mask.define(S_data[IntVars::cons].boxArray(), S_data[IntVars::cons].DistributionMap(), 1, 1);
211  physbnd_mask.BuildMask(geom.Domain(), geom.periodicity(), 1, 1, 0, 1);
212  }
213 
214  for (MFIter mfi(S_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi) {
215 
216  Box tbx = mfi.tilebox();
217 
218  // *************************************************************************
219  // Define flux arrays for use in advection
220  // *************************************************************************
221  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
222  if (solverChoice.terrain_type != TerrainType::EB) {
223  flux[dir].resize(surroundingNodes(tbx,dir),nvars,The_Async_Arena());
224  } else {
225  flux[dir].resize(surroundingNodes(tbx,dir).grow(1),nvars,The_Async_Arena());
226  }
227  flux[dir].setVal<RunOn::Device>(0);
228  }
229  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
230  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
231 
232  // *************************************************************************
233  // Define Array4's
234  // *************************************************************************
235  const Array4<const Real> & old_cons = S_old[IntVars::cons].array(mfi);
236  const Array4< Real> & cell_rhs = S_rhs[IntVars::cons].array(mfi);
237 
238  const Array4< Real> & new_cons = S_new[IntVars::cons].array(mfi);
239  const Array4< Real> & new_xmom = S_new[IntVars::xmom].array(mfi);
240  const Array4< Real> & new_ymom = S_new[IntVars::ymom].array(mfi);
241  const Array4< Real> & new_zmom = S_new[IntVars::zmom].array(mfi);
242 
243  const Array4< Real> & cur_cons = S_data[IntVars::cons].array(mfi);
244  const Array4<const Real> & cur_prim = S_prim.array(mfi);
245  const Array4< Real> & cur_xmom = S_data[IntVars::xmom].array(mfi);
246  const Array4< Real> & cur_ymom = S_data[IntVars::ymom].array(mfi);
247  const Array4< Real> & cur_zmom = S_data[IntVars::zmom].array(mfi);
248 
249  Array4<Real> avg_xmom_arr = avg_xmom.array(mfi);
250  Array4<Real> avg_ymom_arr = avg_ymom.array(mfi);
251  Array4<Real> avg_zmom_arr = avg_zmom.array(mfi);
252 
253  const Array4<const Real> & u = xvel.array(mfi);
254  const Array4<const Real> & v = yvel.array(mfi);
255 
256  const Array4<const Real>& z_nd = z_phys_nd->const_array(mfi);
257  const Array4<const Real>& z_cc = z_phys_cc->const_array(mfi);
258  const Array4<const Real>& detJ_new_arr = l_moving_terrain ? detJ_new->const_array(mfi) : Array4<const Real>{};
259 
260  // Map factors
261  const Array4<const Real>& mf_mx = mapfac[MapFacType::m_x]->const_array(mfi);
262  const Array4<const Real>& mf_ux = mapfac[MapFacType::u_x]->const_array(mfi);
263  const Array4<const Real>& mf_vx = mapfac[MapFacType::v_x]->const_array(mfi);
264  const Array4<const Real>& mf_my = mapfac[MapFacType::m_y]->const_array(mfi);
265  const Array4<const Real>& mf_uy = mapfac[MapFacType::u_y]->const_array(mfi);
266  const Array4<const Real>& mf_vy = mapfac[MapFacType::v_y]->const_array(mfi);
267 
268  // SmnSmn for KE src with Deardorff or k-eqn RANS
269  const Array4<const Real>& SmnSmn_a = l_need_SmnSmn ? SmnSmn->const_array(mfi) : Array4<const Real>{};
270 
271  // **************************************************************************
272  // Here we fill the "current" data with "new" data because that is the result of the previous RK stage
273  // **************************************************************************
274  int nsv = S_old[IntVars::cons].nComp() - 2;
275  const GpuArray<int, IntVars::NumTypes> scomp_slow = { 2,0,0,0};
276  const GpuArray<int, IntVars::NumTypes> ncomp_slow = {nsv,0,0,0};
277 
278  // **************************************************************************
279  // Note that here we do copy only the "slow" variables, not (rho) or (rho theta)
280  // **************************************************************************
281  ParallelFor(tbx, ncomp_slow[IntVars::cons],
282  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) {
283  const int n = scomp_slow[IntVars::cons] + nn;
284  cur_cons(i,j,k,n) = new_cons(i,j,k,n);
285  });
286 
287  // We have projected the velocities stored in S_data but we will use
288  // the velocities stored in {avg_xmom,avg_ymom,avg_zmom} to update the scalars,
289  // so we need to copy from S_data (projected) into these
290  if (l_anelastic) {
291  Box tbx_inc = mfi.nodaltilebox(0);
292  Box tby_inc = mfi.nodaltilebox(1);
293  Box tbz_inc = mfi.nodaltilebox(2);
294 
295  ParallelFor(tbx_inc, tby_inc, tbz_inc,
296  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
297  avg_xmom_arr(i,j,k) = cur_xmom(i,j,k);
298  },
299  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
300  avg_ymom_arr(i,j,k) = cur_ymom(i,j,k);
301  },
302  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
303  avg_zmom_arr(i,j,k) = cur_zmom(i,j,k);
304  });
305  }
306 
307  // **************************************************************************
308  // Define updates in the RHS of continuity, temperature, and scalar equations
309  // **************************************************************************
310  bool l_eb_terrain_cc = false; // EB terrain on cell-centered grid
311  Array4<const int> mask_arr{};
312  Array4<const EBCellFlag> cfg_arr{};
313  Array4<const Real> ax_arr{};
314  Array4<const Real> ay_arr{};
315  Array4<const Real> az_arr{};
316  Array4<const Real> fcx_arr{};
317  Array4<const Real> fcy_arr{};
318  Array4<const Real> fcz_arr{};
319  Array4<const Real> detJ_arr{};
320  if (solverChoice.terrain_type == TerrainType::EB) {
321  EBCellFlagFab const& cfg = ebfact.getMultiEBCellFlagFab()[mfi];
322  cfg_arr = cfg.const_array();
323  if (cfg.getType(tbx) == FabType::singlevalued) {
324  l_eb_terrain_cc = true;
325  ax_arr = ebfact.getAreaFrac()[0]->const_array(mfi);
326  ay_arr = ebfact.getAreaFrac()[1]->const_array(mfi);
327  az_arr = ebfact.getAreaFrac()[2]->const_array(mfi);
328  fcx_arr = ebfact.getFaceCent()[0]->const_array(mfi);
329  fcy_arr = ebfact.getFaceCent()[1]->const_array(mfi);
330  fcz_arr = ebfact.getFaceCent()[2]->const_array(mfi);
331  detJ_arr = ebfact.getVolFrac().const_array(mfi);
332  // if (!already_on_centroids) {mask_arr = physbnd_mask.const_array(mfi);}
333  mask_arr = physbnd_mask.const_array(mfi);
334  }
335  }
336  if (!l_eb_terrain_cc) {
337  ax_arr = ax->const_array(mfi);
338  ay_arr = ay->const_array(mfi);
339  az_arr = az->const_array(mfi);
340  detJ_arr = detJ->const_array(mfi);
341  }
342 
343  AdvType horiz_adv_type, vert_adv_type;
344  Real horiz_upw_frac, vert_upw_frac;
345 
346  Array4<Real> diffflux_x, diffflux_y, diffflux_z;
347  Array4<Real> hfx_x, hfx_y, hfx_z, diss;
348  Array4<Real> q1fx_x, q1fx_y, q1fx_z, q2fx_z;
349 
350  if (l_use_diff) {
351  diffflux_x = dflux_x->array(mfi);
352  diffflux_y = dflux_y->array(mfi);
353  diffflux_z = dflux_z->array(mfi);
354 
355  hfx_x = Hfx1->array(mfi);
356  hfx_y = Hfx2->array(mfi);
357  hfx_z = Hfx3->array(mfi);
358  diss = Diss->array(mfi);
359 
360  if (Q1fx1) q1fx_x = Q1fx1->array(mfi);
361  if (Q1fx2) q1fx_y = Q1fx2->array(mfi);
362  if (Q1fx3) q1fx_z = Q1fx3->array(mfi);
363  if (Q2fx3) q2fx_z = Q2fx3->array(mfi);
364  }
365 
366  if (l_use_diff && l_use_turb) {
367  AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
368  eddyDiffs != nullptr,
369  "erf_slow_rhs_post: active turbulence requires non-null eddyDiffs");
370  }
371  const Array4<const Real>& mu_turb =
372  l_use_turb ? eddyDiffs->const_array(mfi) : Array4<const Real>{};
373 
374  //
375  // Note that we either advect and diffuse all or none of the moisture variables
376  //
377  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
378  {
379  if (is_valid_slow_var[ivar])
380  {
381  start_comp = ivar;
382  num_comp = 1;
383 
384  if (ivar == RhoQ1_comp) {
385  horiz_adv_type = ac.moistscal_horiz_adv_type;
386  vert_adv_type = ac.moistscal_vert_adv_type;
387  horiz_upw_frac = ac.moistscal_horiz_upw_frac;
388  vert_upw_frac = ac.moistscal_vert_upw_frac;
389 
390  if (ac.use_efficient_advection){
391  horiz_adv_type = EfficientAdvType(nrk,ac.moistscal_horiz_adv_type);
392  vert_adv_type = EfficientAdvType(nrk,ac.moistscal_vert_adv_type);
393  }
394 
395  num_comp = n_qstate;
396 
397  } else {
398  horiz_adv_type = ac.dryscal_horiz_adv_type;
399  vert_adv_type = ac.dryscal_vert_adv_type;
400  horiz_upw_frac = ac.dryscal_horiz_upw_frac;
401  vert_upw_frac = ac.dryscal_vert_upw_frac;
402 
403  if (ac.use_efficient_advection){
404  horiz_adv_type = EfficientAdvType(nrk,ac.dryscal_horiz_adv_type);
405  vert_adv_type = EfficientAdvType(nrk,ac.dryscal_vert_adv_type);
406  }
407 
408  if (ivar == RhoScalar_comp) {
409  num_comp = NSCALARS;
410  }
411  }
412 
413  if (( ivar != RhoKE_comp ) ||
414  ((ivar == RhoKE_comp) && l_advect_KE))
415  {
416  if (!l_eb_terrain_cc){
417  AdvectionSrcForScalars(tbx, start_comp, num_comp,
418  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
419  cur_prim, cell_rhs,
420  detJ_arr, dxInv, mf_mx, mf_my,
421  horiz_adv_type, vert_adv_type,
422  horiz_upw_frac, vert_upw_frac,
423  flx_arr, domain, bc_ptr_h);
424  } else {
425  EBAdvectionSrcForScalars(tbx, start_comp, num_comp,
426  avg_xmom_arr, avg_ymom_arr, avg_zmom_arr,
427  cur_prim, cell_rhs,
428  mask_arr, cfg_arr, ax_arr, ay_arr, az_arr,
429  fcx_arr, fcy_arr, fcz_arr,
430  detJ_arr, dxInv, mf_mx, mf_my,
431  horiz_adv_type, vert_adv_type,
432  horiz_upw_frac, vert_upw_frac,
433  flx_arr, domain, bc_ptr_h,
434  already_on_centroids);
435  }
436  }
437 
438  if (l_use_diff)
439  {
440  // Allow for implicit moisture diffusion
442  if ( (ivar == RhoKE_comp && solverChoice.implicit_ke_diffusion ) ||
443  (ivar == RhoQ1_comp && solverChoice.implicit_moisture_diffusion) ) {
444  l_vert_implicit_fac = solverChoice.vert_implicit_fac[level][nrk];
445  }
446 
447  const Array4<const Real> tm_arr = t_mean_mf ? t_mean_mf->const_array(mfi) : Array4<const Real>{};
448 
449  if (solverChoice.mesh_type == MeshType::StretchedDz && solverChoice.terrain_type != TerrainType::EB) {
450  DiffusionSrcForState_S(tbx, domain, start_comp, num_comp, u, v,
451  new_cons, cur_prim, cell_rhs,
452  diffflux_x, diffflux_y, diffflux_z,
453  stretched_dz_d, dxInv, SmnSmn_a,
454  mf_mx, mf_ux, mf_vx,
455  mf_my, mf_uy, mf_vy,
456  hfx_z, q1fx_z, q2fx_z, diss,
457  mu_turb, solverChoice, level,
458  tm_arr, grav_gpu, bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, l_vert_implicit_fac);
459  } else if (l_use_terrain) {
460  DiffusionSrcForState_T(tbx, domain, start_comp, num_comp, l_rotate, u, v,
461  new_cons, cur_prim, cell_rhs,
462  diffflux_x, diffflux_y, diffflux_z,
463  z_nd, z_cc, ax_arr, ay_arr, az_arr,
464  detJ_arr, dxInv, SmnSmn_a,
465  mf_mx, mf_ux, mf_vx,
466  mf_my, mf_uy, mf_vy,
467  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z,q2fx_z, diss,
468  mu_turb, solverChoice, level,
469  tm_arr, grav_gpu, bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, l_vert_implicit_fac);
470  } else {
471  DiffusionSrcForState_N(tbx, domain, start_comp, num_comp, u, v,
472  new_cons, cur_prim, cell_rhs,
473  diffflux_x, diffflux_y, diffflux_z, dxInv, SmnSmn_a,
474  mf_mx, mf_ux, mf_vx,
475  mf_my, mf_uy, mf_vy,
476  hfx_z, q1fx_z, q2fx_z, diss,
477  mu_turb, solverChoice, level,
478  tm_arr, grav_gpu, bc_ptr_d, l_apply_surface_layer_fluxes_in_diffusion, l_vert_implicit_fac);
479  }
480  } // use_diff
481  } // valid slow var
482  } // loop ivar
483 
484 #ifdef ERF_USE_EAMXX_SHOC
485  if (tc.uses_eamxx_shoc() && eamxx_shoc_lev) {
486  eamxx_shoc_lev->add_slow_tend(mfi,tbx,cell_rhs);
487  }
488 #endif
489 #ifdef ERF_USE_NATIVE_SHOC
490  if (tc.uses_native_shoc() && native_shoc_lev) {
491  // Native SHOC now applies its coupled increment directly to the
492  // state before the dycore; it does not add a post-RHS tendency.
493  }
494 #endif
495 
496  // This updates just the "slow" conserved variables
497  {
498  BL_PROFILE("rhs_post_8");
499 
501 
502  auto const& src_arr = source.const_array(mfi);
503 
504  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
505  {
506  if (is_valid_slow_var[ivar])
507  {
508  start_comp = ivar;
509  num_comp = 1;
510  if (ivar == RhoQ1_comp) {
511  num_comp = nvars - RhoQ1_comp;
512  } else if (ivar == RhoScalar_comp) {
513  num_comp = NSCALARS;
514  }
515 
516  if (l_moving_terrain)
517  {
518  ParallelFor(tbx, num_comp,
519  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
520  const int n = start_comp + nn;
521  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
522  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);
523  cur_cons(i,j,k,n) = temp_val / detJ_new_arr(i,j,k);
524  if (ivar == RhoKE_comp) {
525  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), eps);
526  }
527  });
528 
529  } else if (l_anelastic && (nrk == 1)) { // not moving and ( (anelastic) and second RK stage) )
530 
531  ParallelFor(tbx, num_comp,
532  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
533  const int n = start_comp + nn;
534  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
535 
536  // Re-construct the cell_rhs used in the first RK stage
537  Real dt_times_old_cell_rhs = cur_cons(i,j,k,n) - old_cons(i,j,k,n);
538 
539  // Add the time-averaged RHS to the old state
540  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));
541 
542  if (ivar == RhoKE_comp) {
543  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), eps);
544  } else if (ivar >= RhoQ1_comp) {
545  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), amrex::Real(0));
546  }
547  });
548 
549  } else { // not moving and ( (not anelastic) or (first RK stage) )
550 
551  ParallelFor(tbx, num_comp,
552  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
553  const int n = start_comp + nn;
554  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
555  cur_cons(i,j,k,n) = old_cons(i,j,k,n) + dt * cell_rhs(i,j,k,n);
556  if (ivar == RhoKE_comp) {
557  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), eps);
558  } else if (ivar >= RhoQ1_comp) {
559  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), amrex::Real(0));
560  }
561  });
562 
563  } // moving, anelastic or neither?
564 
565  } // is_valid
566  } // ivar
567  } // profile
568 
569  {
570  BL_PROFILE("rhs_post_9");
571  // This updates all the conserved variables (not just the "slow" ones)
572  int num_comp_all = S_data[IntVars::cons].nComp();
573  ParallelFor(tbx, num_comp_all,
574  [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept {
575  new_cons(i,j,k,n) = cur_cons(i,j,k,n);
576  });
577  } // end profile
578 
579  Box xtbx = mfi.nodaltilebox(0);
580  Box ytbx = mfi.nodaltilebox(1);
581  Box ztbx = mfi.nodaltilebox(2);
582 
583  {
584  BL_PROFILE("rhs_post_10()");
585  ParallelFor(xtbx, ytbx, ztbx,
586  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
587  new_xmom(i,j,k) = cur_xmom(i,j,k);
588  },
589  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
590  new_ymom(i,j,k) = cur_ymom(i,j,k);
591  },
592  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
593  new_zmom(i,j,k) = cur_zmom(i,j,k);
594  });
595  } // end profile
596 
597  {
598  BL_PROFILE("rhs_post_10");
599  // We only add to the flux registers in the final RK step
600  if (l_reflux) {
601  int strt_comp_reflux = RhoTheta_comp + 1;
602  int num_comp_reflux = nvars - strt_comp_reflux;
603  if (level < finest_level) {
604  fr_as_crse->CrseAdd(mfi,
605  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
606  dx, dt, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
607  }
608  if (level > 0) {
609  fr_as_fine->FineAdd(mfi,
610  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
611  dx, dt, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
612  }
613 
614  // This is necessary here so we don't go on to the next FArrayBox without
615  // having finished copying the fluxes into the FluxRegisters (since the fluxes
616  // are stored in temporary FArrayBox's)
617  Gpu::streamSynchronize();
618 
619  } // two-way coupling
620  } // end profile
621  } // mfi
622  } // OMP
623 }
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:281
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
@ nvars
Definition: ERF_DataStruct.H:98
@ v_x
Definition: ERF_DataStruct.H:24
@ u_y
Definition: ERF_DataStruct.H:25
@ v_y
Definition: ERF_DataStruct.H:25
@ m_y
Definition: ERF_DataStruct.H:25
@ u_x
Definition: ERF_DataStruct.H:24
@ m_x
Definition: ERF_DataStruct.H:24
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_z, 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::Real implicit_fac)
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::Real implicit_fac)
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_z, 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::Real implicit_fac)
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)
const Real l_vert_implicit_fac
Definition: ERF_ImplicitPost.H:6
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
AdvType
Definition: ERF_IndexDefines.H:255
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
const Real dx
Definition: ERF_InitCustomPert_ABL.H:23
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
ParallelFor(grown_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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ ymom
Definition: ERF_IndexDefines.H:194
@ cons
Definition: ERF_IndexDefines.H:192
@ zmom
Definition: ERF_IndexDefines.H:195
@ xmom
Definition: ERF_IndexDefines.H:193
@ ng
Definition: ERF_Morrison.H:48
@ xvel
Definition: ERF_IndexDefines.H:175
@ yvel
Definition: ERF_IndexDefines.H:176
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:19
MolecDiffType molec_diff_type
Definition: ERF_DiffStruct.H:84
static MeshType mesh_type
Definition: ERF_DataStruct.H:1211
DiffChoice diffChoice
Definition: ERF_DataStruct.H:1220
amrex::Real gravity
Definition: ERF_DataStruct.H:1299
bool implicit_ke_diffusion
Definition: ERF_DataStruct.H:1251
bool implicit_moisture_diffusion
Definition: ERF_DataStruct.H:1250
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:1223
amrex::Vector< int > anelastic
Definition: ERF_DataStruct.H:1229
AdvChoice advChoice
Definition: ERF_DataStruct.H:1219
MoistureType moisture_type
Definition: ERF_DataStruct.H:1389
static TerrainType terrain_type
Definition: ERF_DataStruct.H:1202
amrex::Vector< amrex::Vector< amrex::Real > > vert_implicit_fac
Definition: ERF_DataStruct.H:1246
bool use_rotate_surface_flux
Definition: ERF_DataStruct.H:1329
CouplingType coupling_type
Definition: ERF_DataStruct.H:1388
bool transport_scalar
Definition: ERF_DataStruct.H:1336
Definition: ERF_TurbStruct.H:82
PBLType pbl_type
Definition: ERF_TurbStruct.H:478
RANSType rans_type
Definition: ERF_TurbStruct.H:473
bool uses_eamxx_shoc() const noexcept
Definition: ERF_TurbStruct.H:480
bool advect_tke
Definition: ERF_TurbStruct.H:552
bool uses_native_shoc() const noexcept
Definition: ERF_TurbStruct.H:485
bool use_tke
Definition: ERF_TurbStruct.H:519
LESType les_type
Definition: ERF_TurbStruct.H:431
bool use_kturb
Definition: ERF_TurbStruct.H:513
Here is the call graph for this function: