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 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, Vector< MultiFab > &S_scratch, 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< ABLMost > &most, 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 > &ax, std::unique_ptr< MultiFab > &ay, std::unique_ptr< MultiFab > &az, std::unique_ptr< MultiFab > &detJ, std::unique_ptr< MultiFab > &detJ_new, std::unique_ptr< MultiFab > &mapfac_m, std::unique_ptr< MultiFab > &mapfac_u, std::unique_ptr< MultiFab > &mapfac_v, amrex::EBFArrayBoxFactory const &ebfact, YAFluxRegister *fr_as_crse, YAFluxRegister *fr_as_fine)
 

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,
Vector< MultiFab > &  S_scratch,
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< ABLMost > &  most,
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 > &  ax,
std::unique_ptr< MultiFab > &  ay,
std::unique_ptr< MultiFab > &  az,
std::unique_ptr< MultiFab > &  detJ,
std::unique_ptr< MultiFab > &  detJ_new,
std::unique_ptr< MultiFab > &  mapfac_m,
std::unique_ptr< MultiFab > &  mapfac_u,
std::unique_ptr< MultiFab > &  mapfac_v,
amrex::EBFArrayBoxFactory const &  ebfact,
YAFluxRegister *  fr_as_crse,
YAFluxRegister *  fr_as_fine 
)

Function for computing the slow RHS for the evolution equations for the scalars other than density or potential temperature

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_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]S_scratchscratch space
[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]mostPointer to MOST 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]mapfac_mmap factor at cell centers
[in]mapfac_umap factor at x-faces
[in]mapfac_vmap factor at y-faces
[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
99 {
100  BL_PROFILE_REGION("erf_slow_rhs_post()");
101 
102  const BCRec* bc_ptr_d = domain_bcs_type_d.data();
103  const BCRec* bc_ptr_h = domain_bcs_type_h.data();
104 
105  AdvChoice ac = solverChoice.advChoice;
106  DiffChoice dc = solverChoice.diffChoice;
107  TurbChoice tc = solverChoice.turbChoice[level];
108 
109  const MultiFab* t_mean_mf = nullptr;
110  if (most) t_mean_mf = most->get_mac_avg(level,2);
111 
112  const bool l_use_terrain = (solverChoice.mesh_type != MeshType::ConstantDz);
113  const bool l_moving_terrain = (solverChoice.terrain_type == TerrainType::MovingFittedMesh);
114  const bool l_reflux = (solverChoice.coupling_type != CouplingType::OneWay);
115  if (l_moving_terrain) AMREX_ALWAYS_ASSERT(l_use_terrain);
116 
117  const bool l_use_mono_adv = solverChoice.use_mono_adv;
118  const bool l_use_KE = ( (tc.les_type == LESType::Deardorff) ||
119  (tc.rans_type == RANSType::kEqn) ||
120  (tc.pbl_type == PBLType::MYNN25) );
121  const bool l_need_SmnSmn = ( tc.les_type == LESType::Deardorff ||
122  tc.rans_type == RANSType::kEqn );
123  const bool l_advect_KE = (tc.use_KE && tc.advect_KE);
124  const bool l_use_diff = ((dc.molec_diff_type != MolecDiffType::None) ||
125  (tc.les_type != LESType::None) ||
126  (tc.rans_type != RANSType::None) ||
127  (tc.pbl_type != PBLType::None) );
128  const bool l_use_turb = ( tc.les_type == LESType::Smagorinsky ||
129  tc.les_type == LESType::Deardorff ||
130  tc.rans_type == RANSType::kEqn ||
131  tc.pbl_type == PBLType::MYNN25 ||
132  tc.pbl_type == PBLType::YSU );
133  const bool exp_most = (solverChoice.use_explicit_most);
134  const bool rot_most = (solverChoice.use_rotate_most);
135 
136  const Box& domain = geom.Domain();
137 
138  const GpuArray<Real, AMREX_SPACEDIM> dxInv = geom.InvCellSizeArray();
139  const Real* dx = geom.CellSize();
140 
141  // *************************************************************************
142  // Set gravity as a vector
143  // *************************************************************************
144  const Array<Real,AMREX_SPACEDIM> grav{0.0, 0.0, -solverChoice.gravity};
145  const GpuArray<Real,AMREX_SPACEDIM> grav_gpu{grav[0], grav[1], grav[2]};
146 
147  // *************************************************************************
148  // Pre-computed quantities
149  // *************************************************************************
150  int nvars = S_data[IntVars::cons].nComp();
151  const BoxArray& ba = S_data[IntVars::cons].boxArray();
152  const DistributionMapping& dm = S_data[IntVars::cons].DistributionMap();
153 
154  std::unique_ptr<MultiFab> dflux_x;
155  std::unique_ptr<MultiFab> dflux_y;
156  std::unique_ptr<MultiFab> dflux_z;
157 
158  if (l_use_diff) {
159  dflux_x = std::make_unique<MultiFab>(convert(ba,IntVect(1,0,0)), dm, nvars, 0);
160  dflux_y = std::make_unique<MultiFab>(convert(ba,IntVect(0,1,0)), dm, nvars, 0);
161  dflux_z = std::make_unique<MultiFab>(convert(ba,IntVect(0,0,1)), dm, nvars, 0);
162  } else {
163  dflux_x = nullptr;
164  dflux_y = nullptr;
165  dflux_z = nullptr;
166  }
167 
168  // Valid vars
169  Vector<int> is_valid_slow_var; is_valid_slow_var.resize(RhoQ1_comp+1,0);
170  if (l_use_KE) {is_valid_slow_var[ RhoKE_comp] = 1;}
171  is_valid_slow_var[RhoScalar_comp] = 1;
172  if (solverChoice.moisture_type != MoistureType::None) {
173  is_valid_slow_var[RhoQ1_comp] = 1;
174  }
175 
176  // *****************************************************************************
177  // Monotonic advection for scalars
178  // *****************************************************************************
179  int nvar = S_new[IntVars::cons].nComp();
180  Vector<Real> max_scal(nvar, 1.0e34); Gpu::DeviceVector<Real> max_scal_d(nvar);
181  Vector<Real> min_scal(nvar,-1.0e34); Gpu::DeviceVector<Real> min_scal_d(nvar);
182  if (l_use_mono_adv) {
183  auto const& ma_s_arr = S_new[IntVars::cons].const_arrays();
184  for (int ivar(RhoKE_comp); ivar<nvar; ++ivar) {
185  GpuTuple<Real,Real> mm = ParReduce(TypeList<ReduceOpMax,ReduceOpMin>{},
186  TypeList<Real, Real>{},
187  S_new[IntVars::cons], IntVect(0),
188  [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
189  -> GpuTuple<Real,Real>
190  {
191  return { ma_s_arr[box_no](i,j,k,ivar), ma_s_arr[box_no](i,j,k,ivar) };
192  });
193  max_scal[ivar] = get<0>(mm);
194  min_scal[ivar] = get<1>(mm);
195  }
196  }
197  Gpu::copy(Gpu::hostToDevice, max_scal.begin(), max_scal.end(), max_scal_d.begin());
198  Gpu::copy(Gpu::hostToDevice, min_scal.begin(), min_scal.end(), min_scal_d.begin());
199  Real* max_s_ptr = max_scal_d.data();
200  Real* min_s_ptr = min_scal_d.data();
201 
202  // *************************************************************************
203  // Calculate cell-centered eddy viscosity & diffusivities
204  //
205  // Notes -- we fill all the data in ghost cells before calling this so
206  // that we can fill the eddy viscosity in the ghost regions and
207  // not have to call a boundary filler on this data itself
208  //
209  // LES - updates both horizontal and vertical eddy viscosityS_tmp components
210  // PBL - only updates vertical eddy viscosity components so horizontal
211  // components come from the LES model or are left as zero.
212  // *************************************************************************
213 
214  // *************************************************************************
215  // Define updates and fluxes in the current RK stage
216  // *************************************************************************
217 #ifdef _OPENMP
218 #pragma omp parallel if (Gpu::notInLaunchRegion())
219 #endif
220  {
221  std::array<FArrayBox,AMREX_SPACEDIM> flux;
222  std::array<FArrayBox,AMREX_SPACEDIM> flux_tmp;
223 
224  int start_comp;
225  int num_comp;
226 
227  for ( MFIter mfi(S_data[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi) {
228 
229  Box tbx = mfi.tilebox();
230 
231  // *************************************************************************
232  // Define flux arrays for use in advection
233  // *************************************************************************
234  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
235  flux[dir].resize(surroundingNodes(tbx,dir),nvars);
236  flux[dir].setVal<RunOn::Device>(0.);
237  if (l_use_mono_adv) {
238  flux_tmp[dir].resize(surroundingNodes(tbx,dir),nvars);
239  flux_tmp[dir].setVal<RunOn::Device>(0.);
240  }
241  }
242  const GpuArray<const Array4<Real>, AMREX_SPACEDIM>
243  flx_arr{{AMREX_D_DECL(flux[0].array(), flux[1].array(), flux[2].array())}};
244  Array4<Real> tmpx = (l_use_mono_adv) ? flux_tmp[0].array() : Array4<Real>{};
245  Array4<Real> tmpy = (l_use_mono_adv) ? flux_tmp[1].array() : Array4<Real>{};
246  Array4<Real> tmpz = (l_use_mono_adv) ? flux_tmp[2].array() : Array4<Real>{};
247  const GpuArray<Array4<Real>, AMREX_SPACEDIM> flx_tmp_arr{{AMREX_D_DECL(tmpx,tmpy,tmpz)}};
248 
249  // *************************************************************************
250  // Define Array4's
251  // *************************************************************************
252  const Array4<const Real> & old_cons = S_old[IntVars::cons].array(mfi);
253  const Array4< Real> & cell_rhs = S_rhs[IntVars::cons].array(mfi);
254 
255  const Array4< Real> & new_cons = S_new[IntVars::cons].array(mfi);
256  const Array4< Real> & new_xmom = S_new[IntVars::xmom].array(mfi);
257  const Array4< Real> & new_ymom = S_new[IntVars::ymom].array(mfi);
258  const Array4< Real> & new_zmom = S_new[IntVars::zmom].array(mfi);
259 
260  const Array4< Real> & cur_cons = S_data[IntVars::cons].array(mfi);
261  const Array4<const Real> & cur_prim = S_prim.array(mfi);
262  const Array4< Real> & cur_xmom = S_data[IntVars::xmom].array(mfi);
263  const Array4< Real> & cur_ymom = S_data[IntVars::ymom].array(mfi);
264  const Array4< Real> & cur_zmom = S_data[IntVars::zmom].array(mfi);
265 
266  Array4<Real> avg_xmom = S_scratch[IntVars::xmom].array(mfi);
267  Array4<Real> avg_ymom = S_scratch[IntVars::ymom].array(mfi);
268  Array4<Real> avg_zmom = S_scratch[IntVars::zmom].array(mfi);
269 
270  const Array4<const Real> & u = xvel.array(mfi);
271  const Array4<const Real> & v = yvel.array(mfi);
272 
273  const Array4<Real const>& mu_turb = l_use_turb ? eddyDiffs->const_array(mfi) : Array4<const Real>{};
274 
275  const Array4<const Real>& z_nd = l_use_terrain ? z_phys_nd->const_array(mfi) : Array4<const Real>{};
276  const Array4<const Real>& detJ_new_arr = l_moving_terrain ? detJ_new->const_array(mfi) : Array4<const Real>{};
277 
278  // Map factors
279  const Array4<const Real>& mf_m = mapfac_m->const_array(mfi);
280  const Array4<const Real>& mf_u = mapfac_u->const_array(mfi);
281  const Array4<const Real>& mf_v = mapfac_v->const_array(mfi);
282 
283  // SmnSmn for KE src with Deardorff or k-eqn RANS
284  const Array4<const Real>& SmnSmn_a = l_need_SmnSmn ? SmnSmn->const_array(mfi) : Array4<const Real>{};
285 
286  // **************************************************************************
287  // Here we fill the "current" data with "new" data because that is the result of the previous RK stage
288  // **************************************************************************
289  int nsv = S_old[IntVars::cons].nComp() - 2;
290  const GpuArray<int, IntVars::NumTypes> scomp_slow = { 2,0,0,0};
291  const GpuArray<int, IntVars::NumTypes> ncomp_slow = {nsv,0,0,0};
292 
293  // **************************************************************************
294  // Note that here we do copy only the "slow" variables, not (rho) or (rho theta)
295  // **************************************************************************
296  ParallelFor(tbx, ncomp_slow[IntVars::cons],
297  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) {
298  const int n = scomp_slow[IntVars::cons] + nn;
299  cur_cons(i,j,k,n) = new_cons(i,j,k,n);
300  });
301 
302  // We have projected the velocities stored in S_data but we will use
303  // the velocities stored in S_scratch to update the scalars, so
304  // we need to copy from S_data (projected) into S_scratch
305  if (solverChoice.anelastic[level]) {
306  Box tbx_inc = mfi.nodaltilebox(0);
307  Box tby_inc = mfi.nodaltilebox(1);
308  Box tbz_inc = mfi.nodaltilebox(2);
309 
310  ParallelFor(tbx_inc, tby_inc, tbz_inc,
311  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
312  avg_xmom(i,j,k) = cur_xmom(i,j,k);
313  },
314  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
315  avg_ymom(i,j,k) = cur_ymom(i,j,k);
316  },
317  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
318  avg_zmom(i,j,k) = cur_zmom(i,j,k);
319  });
320  }
321 
322  // **************************************************************************
323  // Define updates in the RHS of continuity, temperature, and scalar equations
324  // **************************************************************************
325  // Metric terms
326  Array4<const Real> ax_arr;
327  Array4<const Real> ay_arr;
328  Array4<const Real> az_arr;
329  Array4<const Real> detJ_arr;
330  Array4<const EBCellFlag> cfg_arr;
331  if (solverChoice.terrain_type == TerrainType::EB) {
332  EBCellFlagFab const& cfg = ebfact.getMultiEBCellFlagFab()[mfi];
333  cfg_arr = cfg.const_array();
334  ax_arr = ebfact.getAreaFrac()[0]->const_array(mfi);
335  ay_arr = ebfact.getAreaFrac()[1]->const_array(mfi);
336  az_arr = ebfact.getAreaFrac()[2]->const_array(mfi);
337  detJ_arr = ebfact.getVolFrac().const_array(mfi);
338  } else {
339  ax_arr = ax->const_array(mfi);
340  ay_arr = ay->const_array(mfi);
341  az_arr = az->const_array(mfi);
342  detJ_arr = detJ->const_array(mfi);
343  }
344 
345  AdvType horiz_adv_type, vert_adv_type;
346  Real horiz_upw_frac, vert_upw_frac;
347 
348  Array4<Real> diffflux_x, diffflux_y, diffflux_z;
349  Array4<Real> hfx_x, hfx_y, hfx_z, diss;
350  Array4<Real> q1fx_x, q1fx_y, q1fx_z, q2fx_z;
351  const bool use_most = (most != nullptr);
352 
353  if (l_use_diff) {
354  diffflux_x = dflux_x->array(mfi);
355  diffflux_y = dflux_y->array(mfi);
356  diffflux_z = dflux_z->array(mfi);
357 
358  hfx_x = Hfx1->array(mfi);
359  hfx_y = Hfx2->array(mfi);
360  hfx_z = Hfx3->array(mfi);
361  diss = Diss->array(mfi);
362 
363  if (Q1fx1) q1fx_x = Q1fx1->array(mfi);
364  if (Q1fx2) q1fx_y = Q1fx2->array(mfi);
365  if (Q1fx3) q1fx_z = Q1fx3->array(mfi);
366  if (Q2fx3) q2fx_z = Q2fx3->array(mfi);
367  }
368 
369  //
370  // Note that we either advect and diffuse all or none of the moisture variables
371  //
372  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
373  {
374  if (is_valid_slow_var[ivar])
375  {
376  start_comp = ivar;
377 
378  if (ivar >= RhoQ1_comp) {
379  horiz_adv_type = ac.moistscal_horiz_adv_type;
380  vert_adv_type = ac.moistscal_vert_adv_type;
381  horiz_upw_frac = ac.moistscal_horiz_upw_frac;
382  vert_upw_frac = ac.moistscal_vert_upw_frac;
383 
384  if (ac.use_efficient_advection){
385  horiz_adv_type = EfficientAdvType(nrk,ac.moistscal_horiz_adv_type);
386  vert_adv_type = EfficientAdvType(nrk,ac.moistscal_vert_adv_type);
387  }
388 
389  num_comp = n_qstate;
390 
391  } else {
392  horiz_adv_type = ac.dryscal_horiz_adv_type;
393  vert_adv_type = ac.dryscal_vert_adv_type;
394  horiz_upw_frac = ac.dryscal_horiz_upw_frac;
395  vert_upw_frac = ac.dryscal_vert_upw_frac;
396 
397  if (ac.use_efficient_advection){
398  horiz_adv_type = EfficientAdvType(nrk,ac.dryscal_horiz_adv_type);
399  vert_adv_type = EfficientAdvType(nrk,ac.dryscal_vert_adv_type);
400  }
401  num_comp = 1;
402  }
403 
404  if (( ivar != RhoKE_comp ) ||
405  ((ivar == RhoKE_comp) && l_advect_KE))
406  {
407  if (solverChoice.terrain_type != TerrainType::EB){
408  AdvectionSrcForScalars(dt, tbx, start_comp, num_comp, avg_xmom, avg_ymom, avg_zmom,
409  cur_cons, cur_prim, cell_rhs,
410  l_use_mono_adv, max_s_ptr, min_s_ptr,
411  detJ_arr, dxInv, mf_m,
412  horiz_adv_type, vert_adv_type,
413  horiz_upw_frac, vert_upw_frac,
414  flx_arr, flx_tmp_arr, domain, bc_ptr_h);
415  } else {
416  EBAdvectionSrcForScalars(tbx, start_comp, num_comp,
417  avg_xmom, avg_ymom, avg_zmom,
418  cur_prim, cell_rhs,
419  cfg_arr, ax_arr, ay_arr, az_arr, detJ_arr, dxInv, mf_m,
420  horiz_adv_type, vert_adv_type,
421  horiz_upw_frac, vert_upw_frac,
422  flx_arr, domain, bc_ptr_h);
423  }
424  }
425 
426  if (l_use_diff) {
427  const Array4<const Real> tm_arr = t_mean_mf ? t_mean_mf->const_array(mfi) : Array4<const Real>{};
428  if (l_use_terrain) {
429  DiffusionSrcForState_T(tbx, domain, start_comp, num_comp, exp_most, rot_most, u, v,
430  new_cons, cur_prim, cell_rhs,
431  diffflux_x, diffflux_y, diffflux_z,
432  z_nd, ax_arr, ay_arr, az_arr, detJ_arr,
433  dxInv, SmnSmn_a, mf_m, mf_u, mf_v,
434  hfx_x, hfx_y, hfx_z, q1fx_x, q1fx_y, q1fx_z,q2fx_z, diss,
435  mu_turb, solverChoice, level,
436  tm_arr, grav_gpu, bc_ptr_d, use_most);
437  } else {
438  DiffusionSrcForState_N(tbx, domain, start_comp, num_comp, exp_most, u, v,
439  new_cons, cur_prim, cell_rhs,
440  diffflux_x, diffflux_y, diffflux_z,
441  dxInv, SmnSmn_a, mf_m, mf_u, mf_v,
442  hfx_z, q1fx_z, q2fx_z, diss,
443  mu_turb, solverChoice, level,
444  tm_arr, grav_gpu, bc_ptr_d, use_most);
445  }
446  } // use_diff
447  } // valid slow var
448  } // loop ivar
449 
450 #if defined(ERF_USE_NETCDF)
451  if (moist_set_rhs_bool)
452  {
453  Box gtbx_moist = mfi.tilebox(IntVect(0),IntVect(2,2,0));
454  const Array4<const Real> & old_cons_const = S_old[IntVars::cons].const_array(mfi);
455  const Array4<const Real> & new_cons_const = S_new[IntVars::cons].const_array(mfi);
456  moist_set_rhs(tbx, gtbx_moist, old_cons_const, new_cons_const, cell_rhs,
457  bdy_time_interval, start_bdy_time, new_stage_time, dt, width, set_width, domain,
458  bdy_data_xlo, bdy_data_xhi, bdy_data_ylo, bdy_data_yhi);
459  }
460 #endif
461 
462  // This updates just the "slow" conserved variables
463  {
464  BL_PROFILE("rhs_post_8");
465 
466  const Real eps = std::numeric_limits<Real>::epsilon();
467 
468  auto const& src_arr = source.const_array(mfi);
469 
470  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
471  {
472  if (is_valid_slow_var[ivar])
473  {
474  start_comp = ivar;
475 
476  if (ivar >= RhoQ1_comp) {
477  num_comp = nvars - RhoQ1_comp;
478  } else {
479  num_comp = 1;
480  }
481 
482  if (l_moving_terrain)
483  {
484  ParallelFor(tbx, num_comp,
485  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
486  const int n = start_comp + nn;
487  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
488  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);
489  cur_cons(i,j,k,n) = temp_val / detJ_new_arr(i,j,k);
490  if (ivar == RhoKE_comp) {
491  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), eps);
492  }
493  });
494 
495  } else {
496 
497  ParallelFor(tbx, num_comp,
498  [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn) noexcept {
499  const int n = start_comp + nn;
500  cell_rhs(i,j,k,n) += src_arr(i,j,k,n);
501  cur_cons(i,j,k,n) = old_cons(i,j,k,n) + dt * cell_rhs(i,j,k,n);
502  if (ivar == RhoKE_comp) {
503  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), eps);
504  } else if (ivar >= RhoQ1_comp) {
505  cur_cons(i,j,k,n) = amrex::max(cur_cons(i,j,k,n), 0.0);
506  }
507  });
508 
509  } // moving or not?
510 
511  } // is_valid
512  } // ivar
513  } // profile
514 
515  {
516  BL_PROFILE("rhs_post_9");
517  // This updates all the conserved variables (not just the "slow" ones)
518  int num_comp_all = S_data[IntVars::cons].nComp();
519  ParallelFor(tbx, num_comp_all,
520  [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept {
521  new_cons(i,j,k,n) = cur_cons(i,j,k,n);
522  });
523  } // end profile
524 
525  Box xtbx = mfi.nodaltilebox(0);
526  Box ytbx = mfi.nodaltilebox(1);
527  Box ztbx = mfi.nodaltilebox(2);
528 
529  {
530  BL_PROFILE("rhs_post_10()");
531  ParallelFor(xtbx, ytbx, ztbx,
532  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
533  new_xmom(i,j,k) = cur_xmom(i,j,k);
534  },
535  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
536  new_ymom(i,j,k) = cur_ymom(i,j,k);
537  },
538  [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept {
539  new_zmom(i,j,k) = cur_zmom(i,j,k);
540  });
541  } // end profile
542 
543  {
544  BL_PROFILE("rhs_post_10");
545  // We only add to the flux registers in the final RK step
546  if (l_reflux && nrk == 2) {
547  int strt_comp_reflux = RhoTheta_comp + 1;
548  int num_comp_reflux = nvars - strt_comp_reflux;
549  if (level < finest_level) {
550  fr_as_crse->CrseAdd(mfi,
551  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
552  dx, dt, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
553  }
554  if (level > 0) {
555  fr_as_fine->FineAdd(mfi,
556  {{AMREX_D_DECL(&(flux[0]), &(flux[1]), &(flux[2]))}},
557  dx, dt, strt_comp_reflux, strt_comp_reflux, num_comp_reflux, RunOn::Device);
558  }
559 
560  // This is necessary here so we don't go on to the next FArrayBox without
561  // having finished copying the fluxes into the FluxRegisters (since the fluxes
562  // are stored in temporary FArrayBox's)
563  Gpu::streamSynchronize();
564 
565  } // two-way coupling
566  } // end profile
567  } // mfi
568  } // OMP
569 }
void AdvectionSrcForScalars(const amrex::Real &dt, 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 > &cur_cons, const amrex::Array4< const amrex::Real > &cell_prim, const amrex::Array4< amrex::Real > &src, const bool &use_mono_adv, amrex::Real *max_s_ptr, amrex::Real *min_s_ptr, const amrex::Array4< const amrex::Real > &vf_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_m, 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::GpuArray< amrex::Array4< amrex::Real >, AMREX_SPACEDIM > &flx_tmp_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:254
@ nvars
Definition: ERF_DataStruct.H:74
void DiffusionSrcForState_N(const amrex::Box &bx, const amrex::Box &domain, int start_comp, int num_comp, const bool &exp_most, 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_m, const amrex::Array4< const amrex::Real > &mf_u, const amrex::Array4< const amrex::Real > &mf_v, 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_most)
void DiffusionSrcForState_T(const amrex::Box &bx, const amrex::Box &domain, int start_comp, int num_comp, const bool &exp_most, const bool &rot_most, 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 > &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_m, const amrex::Array4< const amrex::Real > &mf_u, const amrex::Array4< const amrex::Real > &mf_v, 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_most)
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 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 > &vf_arr, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &cellSizeInv, const amrex::Array4< const amrex::Real > &mf_m, 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)
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:40
#define RhoTheta_comp
Definition: ERF_IndexDefines.H:37
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:42
AdvType
Definition: ERF_IndexDefines.H:202
#define RhoKE_comp
Definition: ERF_IndexDefines.H:38
@ ymom
Definition: ERF_IndexDefines.H:152
@ cons
Definition: ERF_IndexDefines.H:150
@ zmom
Definition: ERF_IndexDefines.H:153
@ xmom
Definition: ERF_IndexDefines.H:151
@ xvel
Definition: ERF_IndexDefines.H:141
@ yvel
Definition: ERF_IndexDefines.H:142
Definition: ERF_AdvStruct.H:19
amrex::Real dryscal_vert_upw_frac
Definition: ERF_AdvStruct.H:292
AdvType moistscal_horiz_adv_type
Definition: ERF_AdvStruct.H:283
AdvType moistscal_vert_adv_type
Definition: ERF_AdvStruct.H:284
amrex::Real moistscal_vert_upw_frac
Definition: ERF_AdvStruct.H:294
bool use_efficient_advection
Definition: ERF_AdvStruct.H:278
amrex::Real moistscal_horiz_upw_frac
Definition: ERF_AdvStruct.H:293
AdvType dryscal_horiz_adv_type
Definition: ERF_AdvStruct.H:281
AdvType dryscal_vert_adv_type
Definition: ERF_AdvStruct.H:282
amrex::Real dryscal_horiz_upw_frac
Definition: ERF_AdvStruct.H:291
Definition: ERF_DiffStruct.H:19
MolecDiffType molec_diff_type
Definition: ERF_DiffStruct.H:81
bool use_explicit_most
Definition: ERF_DataStruct.H:692
static MeshType mesh_type
Definition: ERF_DataStruct.H:620
bool use_mono_adv
Definition: ERF_DataStruct.H:708
DiffChoice diffChoice
Definition: ERF_DataStruct.H:629
amrex::Real gravity
Definition: ERF_DataStruct.H:664
amrex::Vector< TurbChoice > turbChoice
Definition: ERF_DataStruct.H:631
amrex::Vector< int > anelastic
Definition: ERF_DataStruct.H:636
AdvChoice advChoice
Definition: ERF_DataStruct.H:628
MoistureType moisture_type
Definition: ERF_DataStruct.H:711
static TerrainType terrain_type
Definition: ERF_DataStruct.H:617
bool use_rotate_most
Definition: ERF_DataStruct.H:695
CouplingType coupling_type
Definition: ERF_DataStruct.H:710
Definition: ERF_TurbStruct.H:31
PBLType pbl_type
Definition: ERF_TurbStruct.H:238
bool use_KE
Definition: ERF_TurbStruct.H:252
RANSType rans_type
Definition: ERF_TurbStruct.H:235
LESType les_type
Definition: ERF_TurbStruct.H:202
bool advect_KE
Definition: ERF_TurbStruct.H:254
Here is the call graph for this function: