ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_TI_slow_rhs_post.H
Go to the documentation of this file.
1 #include "ERF_SrcHeaders.H"
2 
3  auto slow_rhs_fun_post = [&,bogus_large_value_d=bogus_large_value](Vector<MultiFab>& S_rhs,
4  Vector<MultiFab>& S_old,
5  Vector<MultiFab>& S_new,
6  Vector<MultiFab>& S_data,
7  const double old_step_time,
8  const double old_stage_time,
9  const double new_stage_time,
10  const int nrk)
11  {
12  // Note that the "old" and "new" metric terms correspond to
13  // t^n and the RK stage (either t^*, t^** or t^{n+1} that this source
14  // will be used to advance to
15  double slow_dt = new_stage_time - old_step_time;
16 
17  if (verbose) amrex::Print() << "Time integration of scalars at level " << level
18  << std::setprecision(timeprecision)
19  << " from " << old_step_time << " to " << new_stage_time
20  << " with dt = " << slow_dt
21  << " using RHS created at " << old_stage_time << std::endl;
22 
23  const GpuArray<Real, AMREX_SPACEDIM> dxInv = fine_geom.InvCellSizeArray();
24 
25  // *************************************************************************
26  // Set up flux registers if using two_way coupling
27  // *************************************************************************
28  YAFluxRegister* fr_as_crse = nullptr;
29  YAFluxRegister* fr_as_fine = nullptr;
30  if (solverChoice.coupling_type == CouplingType::TwoWay && finest_level > 0)
31  {
32  if (level < finest_level) {
33  fr_as_crse = getAdvFluxReg(level+1);
34  }
35  if (level > 0) {
36  fr_as_fine = getAdvFluxReg(level);
37  }
38  }
39 
40  MultiFab* new_detJ =
41  (solverChoice.terrain_type == TerrainType::MovingFittedMesh) ? (detJ_cc_new[level].get()) : (detJ_cc[level].get());
42 
43  // Immersed Forcing
44  MultiFab* terrain_blank = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
45  solverChoice.buildings_type == BuildingsType::ImmersedForcing) ?
46  terrain_blanking[level].get() : nullptr;
47  MultiFab* terrain_blank_xface = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
48  solverChoice.buildings_type == BuildingsType::ImmersedForcing) ?
49  terrain_blanking_xface[level].get() : nullptr;
50  MultiFab* terrain_blank_yface = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
51  solverChoice.buildings_type == BuildingsType::ImmersedForcing) ?
52  terrain_blanking_yface[level].get() : nullptr;
53  MultiFab* terrain_blank_zface = (solverChoice.terrain_type == TerrainType::ImmersedForcing ||
54  solverChoice.buildings_type == BuildingsType::ImmersedForcing) ?
55  terrain_blanking_zface[level].get() : nullptr;
56 
57  erf_slow_rhs_post(level, finest_level, nrk, slow_dt, micro->Get_Qstate_Moist_Size(),
58  S_rhs, S_old, S_new, S_data, S_prim, avg_xmom[level], avg_ymom[level], avg_zmom[level],
59  xvel_new, yvel_new, zvel_new, cc_src, terrain_blank,
60  terrain_blank_xface, terrain_blank_yface, terrain_blank_zface,
61  SmnSmn, eddyDiffs,
62  Hfx1, Hfx2, Hfx3, Q1fx1, Q1fx2, Q1fx3, Q2fx3, Diss,
63  fine_geom, solverChoice, m_SurfaceLayer, domain_bcs_type_d, domain_bcs_type,
64  z_phys_nd[level], z_phys_cc[level], ax[level], ay[level], az[level],
65  detJ_cc[level], new_detJ, stretched_dz_d[level], mapfac[level], get_eb(level),
66 #ifdef ERF_USE_EAMXX_SHOC
67  eamxx_shoc_interface[level].get(),
68 #endif
69  native_shoc_driver[level].get(),
70  fr_as_crse, fr_as_fine,
71  m_r2d, &base_state[level],
72  cloud_chamber_config.active ? &cloud_chamber_config : nullptr,
73  cloud_chamber_budget.get());
74 
75  // Implicit diffusion of moisture
76  #include "ERF_ImplicitPost.H"
77 
78  // Apply state redistribution for cons states
79 
80  if (solverChoice.terrain_type == TerrainType::EB)
81  {
82  Vector<int> is_valid_slow_var; is_valid_slow_var.resize(RhoQ1_comp+1,0);
83  if (solverChoice.turbChoice[level].use_tke) {is_valid_slow_var[ RhoKE_comp] = 1;}
84  is_valid_slow_var[RhoScalar_comp] = 1;
85  if (solverChoice.moisture_type != MoistureType::None) {
86  is_valid_slow_var[RhoQ1_comp] = 1;
87  }
88  const int num_comp_total = S_rhs[IntVars::cons].nComp();
89  const int num_grow = S_rhs[IntVars::cons].nGrow();
90  const int nvars = S_data[IntVars::cons].nComp();
91 
92  MultiFab dUdt_tmp(ba, dm, num_comp_total, num_grow, MFInfo(), EBFactory(level));
93  dUdt_tmp.setVal(0, 0, num_comp_total, num_grow);
94 
95  int start_comp;
96  int num_comp;
97 
98  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
99  {
100  if (is_valid_slow_var[ivar])
101  {
102  start_comp = ivar;
103  num_comp = 1;
104  if (ivar == RhoQ1_comp) {
105  num_comp = nvars - RhoQ1_comp;
106  } else if (ivar == RhoScalar_comp) {
107  num_comp = NSCALARS;
108  }
109  MultiFab::Copy(dUdt_tmp, S_rhs[IntVars::cons], start_comp, start_comp, num_comp, 0);
110  }
111  }
112  dUdt_tmp.FillBoundary(fine_geom.periodicity());
113  dUdt_tmp.setDomainBndry(bogus_large_value_d, 0, num_comp_total, fine_geom);
114 
115  const BCRec* bc_ptr_d = domain_bcs_type_d.data();
116 
117  // Update S_rhs by Redistribution.
118  // To-do: Currently, redistributing all the scalar variables.
119  // This needs to be redistributed only for num_comp variables starting from ivar, for efficiency.
120  redistribute_term ( num_comp_total, fine_geom, S_rhs[IntVars::cons], dUdt_tmp,
121  S_old[IntVars::cons], EBFactory(level), bc_ptr_d, slow_dt);
122 
123  // Update state using the updated S_rhs. (NOTE: redistribute_term returns RHS not state variables.)
124  for ( MFIter mfi(S_new[IntVars::cons],TilingIfNotGPU()); mfi.isValid(); ++mfi)
125  {
126  Box tbx = mfi.tilebox();
127  const Array4<Real>& snew = S_new[IntVars::cons].array(mfi);
128  const Array4<Real>& sold = S_old[IntVars::cons].array(mfi);
129  const Array4<Real>& srhs = S_rhs[IntVars::cons].array(mfi);
130  Array4<const Real> detJ_arr = EBFactory(level).getVolFrac().const_array(mfi);
131 
132  for (int ivar(RhoKE_comp); ivar<= RhoQ1_comp; ++ivar)
133  {
134  if (is_valid_slow_var[ivar])
135  {
136  start_comp = ivar;
137  num_comp = 1;
138  if (ivar == RhoQ1_comp) {
139  num_comp = nvars - RhoQ1_comp;
140  } else if (ivar == RhoScalar_comp) {
141  num_comp = NSCALARS;
142  }
143  Real sdt = static_cast<Real>(slow_dt);
144  ParallelFor(tbx, num_comp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int nn)
145  {
146  if (detJ_arr(i,j,k) > zero) {
147  const int n = start_comp + nn;
148  snew(i,j,k,n) = sold(i,j,k,n) + sdt * srhs(i,j,k,n);
149  }
150  });
151  }
152  }
153  }
154  } // EB
155 
156  // Apply boundary conditions on all the state variables that have been updated
157  // in both the fast and slow integrators
158  apply_bcs(S_new, new_stage_time, S_new[IntVars::cons].nGrow(), S_new[IntVars::xmom].nGrow(),
159  fast_only=false, vel_and_mom_synced=false);
160 
161  if (solverChoice.moisture_tight_coupling) {
162  // TODO: need iteration var for lagrangian microphysics
163  // call signature in ERF::Advance() is
164  //advance_microphysics(lev, S_new, dt_lev, iteration, time);
165  advance_microphysics(level, S_new[0], slow_dt, 123456789, old_step_time);
166  }
167  }; // end slow_rhs_fun_post
constexpr amrex::Real bogus_large_value
Definition: ERF_Constants.H:26
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
@ nvars
Definition: ERF_DataStruct.H:153
void redistribute_term(int ncomp, const Geometry &geom, MultiFab &result, MultiFab &result_tmp, MultiFab const &state, EBFactType const &ebfact, BCRec const *bc, double local_dt_d, int const igrid)
Apply EB state redistribution to result_tmp and write the redistributed result.
Definition: ERF_EBRedistribute.cpp:21
#define RhoScalar_comp
Definition: ERF_IndexDefines.H:43
#define NSCALARS
Definition: ERF_IndexDefines.H:16
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:45
#define RhoKE_comp
Definition: ERF_IndexDefines.H:41
amrex::GpuArray< Real, AMREX_SPACEDIM > dxInv
Definition: ERF_InitCustomPertVels_ParticleTests.H:17
pp get("wavelength", wavelength)
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);})
amrex::Real Real
Definition: ERF_ShocInterface.H:19
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 &, 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, 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)
Definition: ERF_SlowRhsPost.cpp:51
auto slow_rhs_fun_post
Definition: ERF_TI_slow_rhs_post.H:3
auto apply_bcs
Definition: ERF_TI_utils.H:34
@ cons
Definition: ERF_IndexDefines.H:232
@ xmom
Definition: ERF_IndexDefines.H:233
@ nn
Definition: ERF_WDM6.H:31