ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_TI_slow_headers.H
Go to the documentation of this file.
1 #ifndef ERF_SLOW_INTEGRATION_H_
2 #define ERF_SLOW_INTEGRATION_H_
3 
4 #include "AMReX_MultiFab.H"
5 #include "AMReX_BCRec.H"
6 #include "AMReX_YAFluxRegister.H"
7 #include "AMReX_MultiCutFab.H"
8 #include "AMReX_EBMultiFabUtil.H"
9 
10 #include "ERF_DataStruct.H"
11 #include "ERF_IndexDefines.H"
12 #include "ERF_SurfaceLayer.H"
13 #include "ERF_Advection.H"
14 #include "ERF_Diffusion.H"
15 #include "ERF_EddyViscosity.H"
16 #include "ERF_TerrainMetrics.H"
17 #include "ERF_TileNoZ.H"
18 #include "ERF_EB.H"
19 #include "ERF_ReadBndryPlanes.H"
20 #include "Prob/ERF_CloudChamber.H"
21 
22 /**
23  * @brief Budget tracking for the cloud chamber simulation.
24  */
25 class CloudChamberBudget;
26 
27 namespace erf_auxiliary { class AuxiliaryInertTracer; }
28 namespace erf_sbm {
29 class SBMStateManager;
30 class SBMTransport;
31 struct SBMAMRStageParent;
32 }
33 
34 /**
35  * @brief Driver for the SHOC physics model.
36  */
37 class ShocDriver;
38 
39 /**
40  * The weight of the fluxes of RK stage nrk at this level in the update the step ends with. The
41  * compressible integrator and the MidPoint integrator of anelastic and pseudo-incompressible
42  * levels update from their final stage alone (nrk = 2 and nrk = 1), which takes weight 1. The
43  * RK2 integrator of those levels is Heun's,
44  * S^{n+1} = S^n + dt (R0 + R1) / 2, so both of its stages take weight 1/2.
45  *
46  * @param[in] solverChoice the solver options
47  * @param[in] level the level being advanced
48  * @param[in] nrk the RK stage
49  */
50 inline amrex::Real
51 StageFluxWeight (const SolverChoice& solverChoice, int level, int nrk)
52 {
53  if (solverChoice.compressibility_type[level] != CompressibilityType::FullyCompressible) {
54  if (solverChoice.timestepping_type[level] == TimesteppingType::RK2) {
55  return amrex::Real(0.5);
56  }
57  return (nrk == 1) ? amrex::Real(1.) : amrex::Real(0.);
58  }
59  return (nrk == 2) ? amrex::Real(1.) : amrex::Real(0.);
60 }
61 
62 /**
63  * The weight with which the fluxes of RK stage nrk at this level go into the flux registers:
64  * the weight of that stage's fluxes in the update the step ends with, or zero if they are not
65  * registered. Only with two-way coupling and more than one level. The compressible integrator
66  * and the MidPoint integrator of anelastic and pseudo-incompressible levels update from their final
67  * stage alone (nrk = 2 and nrk = 1), which takes weight 1. The RK2 integrator of those levels is
68  * Heun's, S^{n+1} = S^n + dt (R0 + R1) / 2,
69  * so both of its stages take weight 1/2. Every stage that adds fluxes to the registers must use
70  * this, so that the registers hold the fluxes the update applied.
71  *
72  * @param[in] solverChoice the solver options
73  * @param[in] level the level being advanced
74  * @param[in] finest_level the finest level
75  * @param[in] nrk the RK stage
76  */
77 inline amrex::Real
78 RefluxStageWeight (const SolverChoice& solverChoice, int level, int finest_level, int nrk)
79 {
80  if (solverChoice.coupling_type != CouplingType::TwoWay || finest_level == 0) {
81  return amrex::Real(0.);
82  }
83  return StageFluxWeight(solverChoice, level, nrk);
84 }
85 
86 /**
87  * Whether the fluxes of RK stage nrk at this level go into the flux registers
88  * (RefluxStageWeight is not zero).
89  */
90 inline bool
91 IsRefluxStage (const SolverChoice& solverChoice, int level, int finest_level, int nrk)
92 {
93  return RefluxStageWeight(solverChoice, level, finest_level, nrk) > amrex::Real(0.);
94 }
95 
96 void erf_make_tau_terms (int level, int nrk,
97  const amrex::Vector<amrex::BCRec>& domain_bcs_type,
98  const amrex::MultiFab& z_phys_nd,
99  amrex::Vector<amrex::MultiFab>& S_data,
100  const amrex::MultiFab& xvel,
101  const amrex::MultiFab& yvel,
102  const amrex::MultiFab& zvel,
103  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
104  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_corr_lev,
105  amrex::MultiFab* SmnSmn,
106  amrex::MultiFab* eddyDiffs,
107  const amrex::Geometry geom,
108  const SolverChoice& solverChoice,
109  const amrex::Vector<std::unique_ptr<SurfaceLayer>>& SurfLayer,
110  amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_d,
111  const amrex::MultiFab& detJ,
112  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& mapfac,
113  const amrex::MultiFab& ax,
114  const amrex::MultiFab& ay,
115  const amrex::MultiFab& az,
116  const eb_& ebfact,
117  const amrex::MultiFab* ib_wall_face13 = nullptr,
118  const amrex::MultiFab* ib_wall_face23 = nullptr,
119  const amrex::MultiFab* walldist = nullptr);
120 
121 void copy_surface_tau_for_implicit (amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
122  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_corr_lev);
123 
124 /**
125  * Function for computing the slow RHS for the evolution equations for the density, potential temperature and momentum.
126  *
127  */
128 void erf_slow_rhs_pre (int level, int finest_level, int nrk,
129  double dt,
130  amrex::Vector<amrex::MultiFab>& S_rhs,
131  amrex::Vector<amrex::MultiFab>& S_old,
132  amrex::Vector<amrex::MultiFab>& S_data,
133  const amrex::MultiFab & S_prim,
134  const amrex::MultiFab & qt,
135  amrex::MultiFab& avg_xmom,
136  amrex::MultiFab& avg_ymom,
137  amrex::MultiFab& avg_zmom,
138  const amrex::Array<const amrex::MultiFab*,AMREX_SPACEDIM>& upw_dir,
139  amrex::MultiFab* pi_adv_rt,
140  const amrex::MultiFab& xvel,
141  const amrex::MultiFab& yvel,
142  const amrex::MultiFab& zvel,
143  std::unique_ptr<amrex::MultiFab>& z_t,
144  const amrex::MultiFab& cc_src,
145  const amrex::MultiFab& xmom_src,
146  const amrex::MultiFab& ymom_src,
147  const amrex::MultiFab& zmom_src,
148  const amrex::MultiFab& buoyancy,
149  const amrex::MultiFab* zmom_crse_rhs,
150  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_lev,
151  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& Tau_corr_lev,
152  amrex::Vector<amrex::Vector<std::unique_ptr<amrex::MultiFab>>>& Tau_EB,
153  amrex::MultiFab* SmnSmn,
154  amrex::MultiFab* eddyDiffs,
155  amrex::MultiFab* Hfx1,
156  amrex::MultiFab* Hfx2,
157  amrex::MultiFab* Hfx3,
158  amrex::MultiFab* Q1fx1,
159  amrex::MultiFab* Q1fx2,
160  amrex::MultiFab* Q1fx3,
161  amrex::MultiFab* Q2fx3,
162  amrex::MultiFab* Diss,
163  amrex::MultiFab* mf_surface_fluxes,
164  amrex::MultiFab* Hfx3_EB,
165  const amrex::Geometry geom,
166  const SolverChoice& solverChoice,
167  const amrex::Vector<std::unique_ptr<SurfaceLayer>>& SurfLayer,
168  const amrex::Gpu::DeviceVector<amrex::BCRec>& domain_bcs_type_d,
169  const amrex::Vector<amrex::BCRec>& domain_bcs_type,
170  const amrex::MultiFab& z_phys_nd,
171  const amrex::MultiFab& z_phys_cc,
172  const amrex::MultiFab& ax,
173  const amrex::MultiFab& ay,
174  const amrex::MultiFab& az,
175  const amrex::MultiFab& dJ,
176  amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_d,
177  amrex::Vector<amrex::MultiFab>& gradp,
178  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& mapfac,
179  const eb_& ebfact,
180  const amrex::Vector<amrex::iMultiFab>& physbnd_mask,
181  ShocDriver* native_shoc_lev,
182  amrex::YAFluxRegister* fr_as_crse,
183  amrex::YAFluxRegister* fr_as_fine,
184  const amrex::MultiFab* cloud_chamber_base_state,
185  const erf_cloud_chamber::Config* cloud_chamber_config,
186  CloudChamberBudget* cloud_budget,
187  const amrex::MultiFab* ib_wall_face13 = nullptr,
188  const amrex::MultiFab* ib_wall_face23 = nullptr,
189  const amrex::MultiFab* ib_wall_face33 = nullptr,
190  const amrex::MultiFab* ib_wall_hfx = nullptr,
191  const amrex::MultiFab* walldist = nullptr);
192 
193 /**
194  * Function for computing the slow RHS for the evolution equations for the scalars other than density or potential temperature
195  *
196  */
197 void erf_slow_rhs_post (int level, int finest_level, int nrk,
198  double step_old_time,
199  double input_time,
200  double target_time,
201  double dt,
202  int n_qstate,
203  amrex::Vector<amrex::MultiFab>& S_rhs,
204  amrex::Vector<amrex::MultiFab>& S_old,
205  amrex::Vector<amrex::MultiFab>& S_new,
206  amrex::Vector<amrex::MultiFab>& S_data,
207  const amrex::MultiFab& S_prim,
208  amrex::MultiFab& avg_xmom,
209  amrex::MultiFab& avg_ymom,
210  amrex::MultiFab& avg_zmom,
211  const amrex::Array<const amrex::MultiFab*,AMREX_SPACEDIM>& upw_dir,
212  const amrex::MultiFab& xvel,
213  const amrex::MultiFab& yvel,
214  const amrex::MultiFab& zvel,
215  const amrex::MultiFab& source,
216  amrex::MultiFab* terrain_blank,
217  amrex::MultiFab* terrain_blank_xface,
218  amrex::MultiFab* terrain_blank_yface,
219  amrex::MultiFab* terrain_blank_zface,
220  const amrex::MultiFab* SmnSmn,
221  const amrex::MultiFab* eddyDiffs,
222  amrex::MultiFab* Hfx1,
223  amrex::MultiFab* Hfx2,
224  amrex::MultiFab* Hfx3,
225  amrex::MultiFab* Q1fx1,
226  amrex::MultiFab* Q1fx2,
227  amrex::MultiFab* Q1fx3,
228  amrex::MultiFab* Q2fx3,
229  amrex::MultiFab* Diss,
230  amrex::MultiFab* Tau13,
231  amrex::MultiFab* Tau23,
232  const amrex::Geometry geom,
233  const SolverChoice& solverChoice,
234  const amrex::Vector<std::unique_ptr<SurfaceLayer>>& SurfLayer,
235  const amrex::Gpu::DeviceVector<amrex::BCRec>& domain_bcs_type_d,
236  const amrex::Vector<amrex::BCRec>& domain_bcs_type,
237  std::unique_ptr<amrex::MultiFab>& z_phys_nd,
238  std::unique_ptr<amrex::MultiFab>& z_phys_cc,
239  std::unique_ptr<amrex::MultiFab>& ax,
240  std::unique_ptr<amrex::MultiFab>& ay,
241  std::unique_ptr<amrex::MultiFab>& az,
242  std::unique_ptr<amrex::MultiFab>& dJ_old,
243  amrex::MultiFab* dJ_new,
244  amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_d,
245  amrex::Vector<std::unique_ptr<amrex::MultiFab>>& mapfac,
246  const eb_& ebfact,
247  const amrex::iMultiFab& physbnd_mask,
248  ShocDriver* native_shoc_lev,
249  amrex::YAFluxRegister* fr_as_crse,
250  amrex::YAFluxRegister* fr_as_fine,
251  std::unique_ptr<ReadBndryPlanes>& m_r2d,
252  const amrex::MultiFab* cloud_chamber_base_state,
253  const erf_cloud_chamber::Config* cloud_chamber_config,
254  CloudChamberBudget* cloud_budget,
255  erf_auxiliary::AuxiliaryInertTracer* auxiliary_inert_tracer,
256  erf_sbm::SBMStateManager* sbm_state_manager,
257  erf_sbm::SBMTransport* sbm_transport,
258  const amrex::MultiFab* ib_wall_face33 = nullptr,
259  const amrex::MultiFab* ib_wall_ktarget = nullptr,
260  const amrex::MultiFab* ib_wall_qfx = nullptr,
261  const erf_sbm::SBMAMRStageParent* sbm_parent_stage = nullptr);
262 
263 #endif
Declares the embedded-boundary factory manager used by ERF levels.
bool IsRefluxStage(const SolverChoice &solverChoice, int level, int finest_level, int nrk)
Definition: ERF_TI_slow_headers.H:91
amrex::Real StageFluxWeight(const SolverChoice &solverChoice, int level, int nrk)
Definition: ERF_TI_slow_headers.H:51
void erf_slow_rhs_pre(int level, int finest_level, int nrk, double dt, amrex::Vector< amrex::MultiFab > &S_rhs, amrex::Vector< amrex::MultiFab > &S_old, amrex::Vector< amrex::MultiFab > &S_data, const amrex::MultiFab &S_prim, const amrex::MultiFab &qt, amrex::MultiFab &avg_xmom, amrex::MultiFab &avg_ymom, amrex::MultiFab &avg_zmom, const amrex::Array< const amrex::MultiFab *, AMREX_SPACEDIM > &upw_dir, amrex::MultiFab *pi_adv_rt, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, const amrex::MultiFab &zvel, std::unique_ptr< amrex::MultiFab > &z_t, const amrex::MultiFab &cc_src, const amrex::MultiFab &xmom_src, const amrex::MultiFab &ymom_src, const amrex::MultiFab &zmom_src, const amrex::MultiFab &buoyancy, const amrex::MultiFab *zmom_crse_rhs, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_corr_lev, amrex::Vector< amrex::Vector< std::unique_ptr< amrex::MultiFab >>> &Tau_EB, amrex::MultiFab *SmnSmn, amrex::MultiFab *eddyDiffs, amrex::MultiFab *Hfx1, amrex::MultiFab *Hfx2, amrex::MultiFab *Hfx3, amrex::MultiFab *Q1fx1, amrex::MultiFab *Q1fx2, amrex::MultiFab *Q1fx3, amrex::MultiFab *Q2fx3, amrex::MultiFab *Diss, amrex::MultiFab *mf_surface_fluxes, amrex::MultiFab *Hfx3_EB, const amrex::Geometry geom, const SolverChoice &solverChoice, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const amrex::Gpu::DeviceVector< amrex::BCRec > &domain_bcs_type_d, const amrex::Vector< amrex::BCRec > &domain_bcs_type, const amrex::MultiFab &z_phys_nd, const amrex::MultiFab &z_phys_cc, const amrex::MultiFab &ax, const amrex::MultiFab &ay, const amrex::MultiFab &az, const amrex::MultiFab &dJ, amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, amrex::Vector< amrex::MultiFab > &gradp, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &mapfac, const eb_ &ebfact, const amrex::Vector< amrex::iMultiFab > &physbnd_mask, ShocDriver *native_shoc_lev, amrex::YAFluxRegister *fr_as_crse, amrex::YAFluxRegister *fr_as_fine, const amrex::MultiFab *cloud_chamber_base_state, const erf_cloud_chamber::Config *cloud_chamber_config, CloudChamberBudget *cloud_budget, const amrex::MultiFab *ib_wall_face13=nullptr, const amrex::MultiFab *ib_wall_face23=nullptr, const amrex::MultiFab *ib_wall_face33=nullptr, const amrex::MultiFab *ib_wall_hfx=nullptr, const amrex::MultiFab *walldist=nullptr)
void copy_surface_tau_for_implicit(amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_corr_lev)
amrex::Real RefluxStageWeight(const SolverChoice &solverChoice, int level, int finest_level, int nrk)
Definition: ERF_TI_slow_headers.H:78
void erf_make_tau_terms(int level, int nrk, const amrex::Vector< amrex::BCRec > &domain_bcs_type, const amrex::MultiFab &z_phys_nd, amrex::Vector< amrex::MultiFab > &S_data, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, const amrex::MultiFab &zvel, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_lev, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &Tau_corr_lev, amrex::MultiFab *SmnSmn, amrex::MultiFab *eddyDiffs, const amrex::Geometry geom, const SolverChoice &solverChoice, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, const amrex::MultiFab &detJ, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &mapfac, const amrex::MultiFab &ax, const amrex::MultiFab &ay, const amrex::MultiFab &az, const eb_ &ebfact, const amrex::MultiFab *ib_wall_face13=nullptr, const amrex::MultiFab *ib_wall_face23=nullptr, const amrex::MultiFab *walldist=nullptr)
void erf_slow_rhs_post(int level, int finest_level, int nrk, double step_old_time, double input_time, double target_time, double dt, int n_qstate, amrex::Vector< amrex::MultiFab > &S_rhs, amrex::Vector< amrex::MultiFab > &S_old, amrex::Vector< amrex::MultiFab > &S_new, amrex::Vector< amrex::MultiFab > &S_data, const amrex::MultiFab &S_prim, amrex::MultiFab &avg_xmom, amrex::MultiFab &avg_ymom, amrex::MultiFab &avg_zmom, const amrex::Array< const amrex::MultiFab *, AMREX_SPACEDIM > &upw_dir, const amrex::MultiFab &xvel, const amrex::MultiFab &yvel, const amrex::MultiFab &zvel, const amrex::MultiFab &source, amrex::MultiFab *terrain_blank, amrex::MultiFab *terrain_blank_xface, amrex::MultiFab *terrain_blank_yface, amrex::MultiFab *terrain_blank_zface, const amrex::MultiFab *SmnSmn, const amrex::MultiFab *eddyDiffs, amrex::MultiFab *Hfx1, amrex::MultiFab *Hfx2, amrex::MultiFab *Hfx3, amrex::MultiFab *Q1fx1, amrex::MultiFab *Q1fx2, amrex::MultiFab *Q1fx3, amrex::MultiFab *Q2fx3, amrex::MultiFab *Diss, amrex::MultiFab *Tau13, amrex::MultiFab *Tau23, const amrex::Geometry geom, const SolverChoice &solverChoice, const amrex::Vector< std::unique_ptr< SurfaceLayer >> &SurfLayer, const amrex::Gpu::DeviceVector< amrex::BCRec > &domain_bcs_type_d, const amrex::Vector< amrex::BCRec > &domain_bcs_type, std::unique_ptr< amrex::MultiFab > &z_phys_nd, std::unique_ptr< amrex::MultiFab > &z_phys_cc, std::unique_ptr< amrex::MultiFab > &ax, std::unique_ptr< amrex::MultiFab > &ay, std::unique_ptr< amrex::MultiFab > &az, std::unique_ptr< amrex::MultiFab > &dJ_old, amrex::MultiFab *dJ_new, amrex::Gpu::DeviceVector< amrex::Real > &stretched_dz_d, amrex::Vector< std::unique_ptr< amrex::MultiFab >> &mapfac, const eb_ &ebfact, const amrex::iMultiFab &physbnd_mask, ShocDriver *native_shoc_lev, amrex::YAFluxRegister *fr_as_crse, amrex::YAFluxRegister *fr_as_fine, std::unique_ptr< ReadBndryPlanes > &m_r2d, const amrex::MultiFab *cloud_chamber_base_state, const erf_cloud_chamber::Config *cloud_chamber_config, CloudChamberBudget *cloud_budget, erf_auxiliary::AuxiliaryInertTracer *auxiliary_inert_tracer, erf_sbm::SBMStateManager *sbm_state_manager, erf_sbm::SBMTransport *sbm_transport, const amrex::MultiFab *ib_wall_face33=nullptr, const amrex::MultiFab *ib_wall_ktarget=nullptr, const amrex::MultiFab *ib_wall_qfx=nullptr, const erf_sbm::SBMAMRStageParent *sbm_parent_stage=nullptr)
Definition: ERF_CloudChamberBudget.H:31
Definition: ERF_ShocDriver.H:40
Owns and exposes cell-centered and face-centered EB factories.
Definition: ERF_EB.H:26
Definition: ERF_AuxiliaryInertTracer.H:17
Definition: ERF_SBMStateManager.H:17
Definition: ERF_SBMTransport.H:146
@ qt
Definition: ERF_Kessler.H:30
@ xvel
Definition: ERF_IndexDefines.H:232
@ zvel
Definition: ERF_IndexDefines.H:234
@ yvel
Definition: ERF_IndexDefines.H:233
Definition: ERF_AuxiliaryDiffusion.cpp:10
Definition: ERF.H:128
Definition: ERF_DataStruct.H:743
amrex::Vector< TimesteppingType > timestepping_type
Per-level time integrator (RK3_ImplicitSubstep, RK3_NoSubstepping, RK2 or MidPoint).
Definition: ERF_DataStruct.H:3029
CouplingType coupling_type
Multilevel coupling strategy.
Definition: ERF_DataStruct.H:3432
amrex::Vector< CompressibilityType > compressibility_type
Per-level compressibility (FullyCompressible, Anelastic or PseudoIncompressible).
Definition: ERF_DataStruct.H:3028
Definition: ERF_CloudChamber.H:56
Definition: ERF_SBMTransport.H:68