ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
MRISplitIntegrator< T > Class Template Reference

#include <ERF_MRI.H>

Collaboration diagram for MRISplitIntegrator< T >:

Public Member Functions

 MRISplitIntegrator ()=default
 
 MRISplitIntegrator (const T &S_data)
 
void initialize (const T &S_data)
 
 ~MRISplitIntegrator ()=default
 
 MRISplitIntegrator (MRISplitIntegrator &&) noexcept=default
 
MRISplitIntegratoroperator= (MRISplitIntegrator &&other) noexcept=default
 
 MRISplitIntegrator (const MRISplitIntegrator &other)=delete
 
MRISplitIntegratoroperator= (const MRISplitIntegrator &other)=delete
 
void setNcompCons (int _ncomp_cons)
 
void setAnelastic (int _anelastic)
 
void setNoSubstepping (int _no_substepping)
 
void setForceFirstStageSingleSubstep (int _force_stage1_single_substep)
 
void set_slow_rhs_pre (std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> F)
 
void set_slow_rhs_inc (std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> F)
 
void set_slow_rhs_post (std::function< void(T &, T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> F)
 
void set_fast_rhs (std::function< void(int, int, int, T &, const T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const amrex::Real)> F)
 
void set_slow_fast_timestep_ratio (const int timestep_ratio=1)
 
int get_slow_fast_timestep_ratio ()
 
void set_no_substep (std::function< void(T &, T &, T &, amrex::Real, amrex::Real, int)> F)
 
std::function< void(T &, const T &, const amrex::Real, int)> get_rhs ()
 
amrex::Real advance (T &S_old, T &S_new, amrex::Real time, const amrex::Real time_step)
 
void map_data (std::function< void(T &)> Map)
 

Private Member Functions

void initialize_data (const T &S_data)
 

Private Attributes

std::function< void(T &, const T &, const amrex::Real, const amrex::Real)> rhs
 rhs is the right-hand-side function the integrator will use. More...
 
std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> slow_rhs_pre
 
std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> slow_rhs_inc
 
std::function< void(T &, T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> slow_rhs_post
 
std::function< void(int, int, int, T &, const T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const amrex::Real)> fast_rhs
 
amrex::Real timestep
 Integrator timestep size (Real) More...
 
int slow_fast_timestep_ratio = 0
 The ratio of slow timestep size / fast timestep size (int) More...
 
int no_substepping
 Should we not do acoustic substepping. More...
 
int anelastic
 Should we use the anelastic integrator. More...
 
int ncomp_cons
 How many components in the cell-centered MultiFab. More...
 
int force_stage1_single_substep
 Do we follow the recommendation to only perform a single substep in the first RK stage. More...
 
std::function< void(T &, T &, T &, amrex::Real, amrex::Real, int)> no_substep
 The no_substep function is called when we have no acoustic substepping. More...
 
amrex::Vector< std::unique_ptr< T > > T_store
 
T * S_sum
 
T * S_scratch
 
T * F_slow
 

Constructor & Destructor Documentation

◆ MRISplitIntegrator() [1/4]

template<class T >
MRISplitIntegrator< T >::MRISplitIntegrator ( )
default

◆ MRISplitIntegrator() [2/4]

template<class T >
MRISplitIntegrator< T >::MRISplitIntegrator ( const T &  S_data)
inline
86  {
87  initialize_data(S_data);
88  }
void initialize_data(const T &S_data)
Definition: ERF_MRI.H:69
Here is the call graph for this function:

◆ ~MRISplitIntegrator()

template<class T >
MRISplitIntegrator< T >::~MRISplitIntegrator ( )
default

◆ MRISplitIntegrator() [3/4]

template<class T >
MRISplitIntegrator< T >::MRISplitIntegrator ( MRISplitIntegrator< T > &&  )
defaultnoexcept

◆ MRISplitIntegrator() [4/4]

template<class T >
MRISplitIntegrator< T >::MRISplitIntegrator ( const MRISplitIntegrator< T > &  other)
delete

Member Function Documentation

◆ advance()

template<class T >
amrex::Real MRISplitIntegrator< T >::advance ( T &  S_old,
T &  S_new,
amrex::Real  time,
const amrex::Real  time_step 
)
inline
175  {
176  BL_PROFILE_REGION("MRI_advance");
177  using namespace amrex;
178 
179  // *******************************************************************************
180  // !no_substepping: we only update the fast variables every fast timestep, then update
181  // the slow variables after the acoustic sub-stepping. This has
182  // two calls to slow_rhs so that we can update the slow variables
183  // with the velocity field after the acoustic substepping using
184  // the time-averaged velocity from the substepping
185  // no_substepping: we don't do any acoustic subcyling so we only make one call per RK
186  // stage to slow_rhs
187  // *******************************************************************************
188  timestep = time_step;
189 
190  const int substep_ratio = get_slow_fast_timestep_ratio();
191 
192  if (!no_substepping) {
193  AMREX_ALWAYS_ASSERT(substep_ratio > 1 && substep_ratio % 2 == 0);
194  }
195 
196  // Assume before advance() that S_old is valid data at the current time ("time" argument)
197  // And that if data is a MultiFab, both S_old and S_new contain ghost cells for evaluating a stencil based RHS
198  // We need this from S_old. This is convenient for S_new to have so we can use it
199  // as scratch space for stage values without creating a new scratch MultiFab with ghost cells.
200 
201  // NOTE: In the following, we use S_new to hold S*, S**, and finally, S^(n+1) at the new time
202  // DEFINITIONS:
203  // S_old = S^n
204  // S_sum = S(t)
205  // F_slow = F(S_stage)
206 
207  int n_data = IntVars::NumTypes;
208 
209  /**********************************************/
210  /* RK3 Integration with Acoustic Sub-stepping */
211  /**********************************************/
212  Vector<int> num_vars = {ncomp_cons, 1, 1, 1};
213  for (int i(0); i<n_data; ++i)
214  {
215  // Copy old -> new
216  MultiFab::Copy(S_new[i],S_old[i],0,0,num_vars[i],S_old[i].nGrowVect());
217  }
218 
219  // Timestep taken by the fast integrator
220  amrex::Real dtau;
221 
222  // How many timesteps taken by the fast integrator
223  int nsubsteps;
224 
225  // This is the final time of the full timestep (also the 3rd RK stage)
226  // Real new_time = time + timestep;
227 
228  amrex::Real time_stage = time;
229  amrex::Real old_time_stage;
230 
231  const amrex::Real sub_timestep = timestep / substep_ratio;
232 
233  if (!anelastic) {
234  // RK3 for compressible integrator
235  for (int nrk = 0; nrk < 3; nrk++)
236  {
237  // Capture the time we got to in the previous RK step
238  old_time_stage = time_stage;
239 
240  if (nrk == 0) {
242  nsubsteps = 1; dtau = timestep / 3.0;
243  } else {
244  nsubsteps = substep_ratio/3; dtau = sub_timestep ;
245  }
246  time_stage = time + timestep / 3.0;
247  }
248  if (nrk == 1) {
249  if (no_substepping) {
250  nsubsteps = 1; dtau = 0.5 * timestep;
251  } else {
252  nsubsteps = substep_ratio/2; dtau = sub_timestep;
253  }
254  time_stage = time + timestep / 2.0;
255  }
256  if (nrk == 2) {
257  if (no_substepping) {
258  nsubsteps = 1; dtau = timestep;
259  } else {
260  nsubsteps = substep_ratio; dtau = sub_timestep;
261 
262  // STRT HACK -- this hack can be used to approximate the no-substepping algorithm
263  // nsubsteps = 1; dtau = timestep;
264  // END HACK
265  }
266  time_stage = time + timestep;
267  }
268 
269  // step 1 starts with S_stage = S^n and we always start substepping at the old time
270  // step 2 starts with S_stage = S^* and we always start substepping at the old time
271  // step 3 starts with S_stage = S^** and we always start substepping at the old time
272 
273  // S_scratch also holds the average momenta over the fast iterations --
274  // to be used to update the slow variables -- we will initialize with
275  // the momenta used in the first call to the slow_rhs, then update
276  // inside fast_rhs, then use these values in the later call to slow_rhs
277 
278  slow_rhs_pre(*F_slow, S_old, S_new, *S_scratch, time, old_time_stage, time_stage, nrk);
279 
280  amrex::Real inv_fac = 1.0 / static_cast<amrex::Real>(nsubsteps);
281 
282  // ****************************************************
283  // Acoustic substepping
284  // ****************************************************
285  if (!no_substepping)
286  {
287  // *******************************************************************************
288  // Update the fast variables
289  // *******************************************************************************
290  for (int ks = 0; ks < nsubsteps; ++ks)
291  {
292  fast_rhs(ks, nsubsteps, nrk, *F_slow, S_old, S_new, *S_sum, *S_scratch, dtau, inv_fac,
293  time + ks*dtau, time + (ks+1) * dtau);
294 
295  } // ks
296 
297  } else {
298  no_substep(*S_sum, S_old, *F_slow, time + nsubsteps*dtau, nsubsteps*dtau, nrk);
299  }
300 
301  // ****************************************************
302  // Evaluate F_slow(S_stage) only for the slow variables
303  // Note that we are using the current stage versions (in S_new) of the slow variables
304  // (because we didn't update the slow variables in the substepping)
305  // but we are using the "new" versions (in S_sum) of the velocities
306  // (because we did update the fast variables in the substepping)
307  // ****************************************************
308  slow_rhs_post(*F_slow, S_old, S_new, *S_sum, *S_scratch, time, old_time_stage, time_stage, nrk);
309  } // nrk
310 
311  } else {
312  // RK2 for anelastic integrator
313  for (int nrk = 0; nrk < 2; nrk++)
314  {
315  // Capture the time we got to in the previous RK step
316  old_time_stage = time_stage;
317 
318  if (nrk == 0) { nsubsteps = 1; dtau = timestep; time_stage = time + timestep; }
319  if (nrk == 1) { nsubsteps = 1; dtau = timestep; time_stage = time + timestep; }
320 
321  // S_scratch also holds the average momenta over the fast iterations --
322  // to be used to update the slow variables -- we will initialize with
323  // the momenta used in the first call to the slow_rhs, then update
324  // inside fast_rhs, then use these values in the later call to slow_rhs
325 
326  slow_rhs_inc(*F_slow, S_old, S_new, *S_scratch, time, old_time_stage, time_stage, nrk);
327 
328  no_substep(*S_sum, S_old, *F_slow, time + nsubsteps*dtau, nsubsteps*dtau, nrk);
329 
330  // ****************************************************
331  // Evaluate F_slow(S_stage) only for the slow variables
332  // Note that we are using the current stage versions (in S_new) of the slow variables
333  // (because we didn't update the slow variables in the substepping)
334  // but we are using the "new" versions (in S_sum) of the velocities
335  // (because we did update the fast variables in the substepping)
336  // ****************************************************
337  slow_rhs_post(*F_slow, S_old, S_new, *S_sum, *S_scratch, time, old_time_stage, time_stage, nrk);
338  } // nrk
339  }
340 
341  // Return timestep
342  return timestep;
343  }
T * F_slow
Definition: ERF_MRI.H:67
std::function< void(T &, T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> slow_rhs_post
Definition: ERF_MRI.H:24
int anelastic
Should we use the anelastic integrator.
Definition: ERF_MRI.H:46
amrex::Real timestep
Integrator timestep size (Real)
Definition: ERF_MRI.H:31
std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> slow_rhs_pre
Definition: ERF_MRI.H:22
int force_stage1_single_substep
Do we follow the recommendation to only perform a single substep in the first RK stage.
Definition: ERF_MRI.H:56
int ncomp_cons
How many components in the cell-centered MultiFab.
Definition: ERF_MRI.H:51
T * S_scratch
Definition: ERF_MRI.H:66
std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)> slow_rhs_inc
Definition: ERF_MRI.H:23
std::function< void(int, int, int, T &, const T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const amrex::Real)> fast_rhs
Definition: ERF_MRI.H:26
int get_slow_fast_timestep_ratio()
Definition: ERF_MRI.H:159
std::function< void(T &, T &, T &, amrex::Real, amrex::Real, int)> no_substep
The no_substep function is called when we have no acoustic substepping.
Definition: ERF_MRI.H:61
T * S_sum
Definition: ERF_MRI.H:65
int no_substepping
Should we not do acoustic substepping.
Definition: ERF_MRI.H:41
@ NumTypes
Definition: ERF_IndexDefines.H:143
Definition: ERF_ConsoleIO.cpp:12

Referenced by ERF::advance_dycore().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_rhs()

template<class T >
std::function<void(T&, const T&, const amrex::Real, int)> MRISplitIntegrator< T >::get_rhs ( )
inline
170  {
171  return rhs;
172  }
std::function< void(T &, const T &, const amrex::Real, const amrex::Real)> rhs
rhs is the right-hand-side function the integrator will use.
Definition: ERF_MRI.H:21

◆ get_slow_fast_timestep_ratio()

template<class T >
int MRISplitIntegrator< T >::get_slow_fast_timestep_ratio ( )
inline
160  {
162  }
int slow_fast_timestep_ratio
The ratio of slow timestep size / fast timestep size (int)
Definition: ERF_MRI.H:36

Referenced by MRISplitIntegrator< T >::advance().

Here is the caller graph for this function:

◆ initialize()

template<class T >
void MRISplitIntegrator< T >::initialize ( const T &  S_data)
inline
91  {
92  initialize_data(S_data);
93  }
Here is the call graph for this function:

◆ initialize_data()

template<class T >
void MRISplitIntegrator< T >::initialize_data ( const T &  S_data)
inlineprivate
70  {
71  // TODO: We can optimize memory by making the cell-centered part of S_sum, S_scratch
72  // have only 2 components, not ncomp_cons components
73  const bool include_ghost = true;
74  amrex::IntegratorOps<T>::CreateLike(T_store, S_data, include_ghost);
75  S_sum = T_store[0].get();
76  amrex::IntegratorOps<T>::CreateLike(T_store, S_data, include_ghost);
77  S_scratch = T_store[1].get();
78  amrex::IntegratorOps<T>::CreateLike(T_store, S_data, include_ghost);
79  F_slow = T_store[2].get();
80  }
amrex::Vector< std::unique_ptr< T > > T_store
Definition: ERF_MRI.H:64

Referenced by MRISplitIntegrator< T >::initialize(), and MRISplitIntegrator< T >::MRISplitIntegrator().

Here is the caller graph for this function:

◆ map_data()

template<class T >
void MRISplitIntegrator< T >::map_data ( std::function< void(T &)>  Map)
inline
346  {
347  for (auto& F : T_store) {
348  Map(*F);
349  }
350  }

◆ operator=() [1/2]

template<class T >
MRISplitIntegrator& MRISplitIntegrator< T >::operator= ( const MRISplitIntegrator< T > &  other)
delete

◆ operator=() [2/2]

template<class T >
MRISplitIntegrator& MRISplitIntegrator< T >::operator= ( MRISplitIntegrator< T > &&  other)
defaultnoexcept

◆ set_fast_rhs()

template<class T >
void MRISplitIntegrator< T >::set_fast_rhs ( std::function< void(int, int, int, T &, const T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const amrex::Real)>  F)
inline
150  {
151  fast_rhs = F;
152  }

Referenced by ERF::advance_dycore().

Here is the caller graph for this function:

◆ set_no_substep()

template<class T >
void MRISplitIntegrator< T >::set_no_substep ( std::function< void(T &, T &, T &, amrex::Real, amrex::Real, int)>  F)
inline
165  {
166  no_substep = F;
167  }

Referenced by ERF::advance_dycore().

Here is the caller graph for this function:

◆ set_slow_fast_timestep_ratio()

template<class T >
void MRISplitIntegrator< T >::set_slow_fast_timestep_ratio ( const int  timestep_ratio = 1)
inline
155  {
156  slow_fast_timestep_ratio = timestep_ratio;
157  }

Referenced by ERF::advance_dycore().

Here is the caller graph for this function:

◆ set_slow_rhs_inc()

template<class T >
void MRISplitIntegrator< T >::set_slow_rhs_inc ( std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)>  F)
inline
139  {
140  slow_rhs_inc = F;
141  }

Referenced by ERF::advance_dycore().

Here is the caller graph for this function:

◆ set_slow_rhs_post()

template<class T >
void MRISplitIntegrator< T >::set_slow_rhs_post ( std::function< void(T &, T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)>  F)
inline
143  {
144  slow_rhs_post = F;
145  }

Referenced by ERF::advance_dycore().

Here is the caller graph for this function:

◆ set_slow_rhs_pre()

template<class T >
void MRISplitIntegrator< T >::set_slow_rhs_pre ( std::function< void(T &, T &, T &, T &, const amrex::Real, const amrex::Real, const amrex::Real, const int)>  F)
inline
135  {
136  slow_rhs_pre = F;
137  }

Referenced by ERF::advance_dycore().

Here is the caller graph for this function:

◆ setAnelastic()

template<class T >
void MRISplitIntegrator< T >::setAnelastic ( int  _anelastic)
inline
120  {
121  anelastic = _anelastic;
122  }

◆ setForceFirstStageSingleSubstep()

template<class T >
void MRISplitIntegrator< T >::setForceFirstStageSingleSubstep ( int  _force_stage1_single_substep)
inline
130  {
131  force_stage1_single_substep = _force_stage1_single_substep;
132  }

◆ setNcompCons()

template<class T >
void MRISplitIntegrator< T >::setNcompCons ( int  _ncomp_cons)
inline
115  {
116  ncomp_cons = _ncomp_cons;
117  }

◆ setNoSubstepping()

template<class T >
void MRISplitIntegrator< T >::setNoSubstepping ( int  _no_substepping)
inline
125  {
126  no_substepping = _no_substepping;
127  }

Member Data Documentation

◆ anelastic

template<class T >
int MRISplitIntegrator< T >::anelastic
private

Should we use the anelastic integrator.

Referenced by MRISplitIntegrator< T >::advance(), and MRISplitIntegrator< T >::setAnelastic().

◆ F_slow

template<class T >
T* MRISplitIntegrator< T >::F_slow
private

◆ fast_rhs

template<class T >
std::function<void(int, int, int, T&, const T&, T&, T&, T&, const amrex::Real, const amrex::Real, const amrex::Real, const amrex::Real)> MRISplitIntegrator< T >::fast_rhs
private

◆ force_stage1_single_substep

template<class T >
int MRISplitIntegrator< T >::force_stage1_single_substep
private

Do we follow the recommendation to only perform a single substep in the first RK stage.

Referenced by MRISplitIntegrator< T >::advance(), and MRISplitIntegrator< T >::setForceFirstStageSingleSubstep().

◆ ncomp_cons

template<class T >
int MRISplitIntegrator< T >::ncomp_cons
private

How many components in the cell-centered MultiFab.

Referenced by MRISplitIntegrator< T >::advance(), and MRISplitIntegrator< T >::setNcompCons().

◆ no_substep

template<class T >
std::function<void (T&, T&, T&, amrex::Real, amrex::Real, int)> MRISplitIntegrator< T >::no_substep
private

The no_substep function is called when we have no acoustic substepping.

Referenced by MRISplitIntegrator< T >::advance(), and MRISplitIntegrator< T >::set_no_substep().

◆ no_substepping

template<class T >
int MRISplitIntegrator< T >::no_substepping
private

Should we not do acoustic substepping.

Referenced by MRISplitIntegrator< T >::advance(), and MRISplitIntegrator< T >::setNoSubstepping().

◆ rhs

template<class T >
std::function<void(T&, const T&, const amrex::Real, const amrex::Real )> MRISplitIntegrator< T >::rhs
private

rhs is the right-hand-side function the integrator will use.

Referenced by MRISplitIntegrator< T >::get_rhs().

◆ S_scratch

template<class T >
T* MRISplitIntegrator< T >::S_scratch
private

◆ S_sum

template<class T >
T* MRISplitIntegrator< T >::S_sum
private

◆ slow_fast_timestep_ratio

template<class T >
int MRISplitIntegrator< T >::slow_fast_timestep_ratio = 0
private

The ratio of slow timestep size / fast timestep size (int)

Referenced by MRISplitIntegrator< T >::get_slow_fast_timestep_ratio(), and MRISplitIntegrator< T >::set_slow_fast_timestep_ratio().

◆ slow_rhs_inc

template<class T >
std::function<void(T&, T&, T&, T&, const amrex::Real, const amrex::Real, const amrex::Real, const int)> MRISplitIntegrator< T >::slow_rhs_inc
private

◆ slow_rhs_post

template<class T >
std::function<void(T&, T&, T&, T&, T&, const amrex::Real, const amrex::Real, const amrex::Real, const int )> MRISplitIntegrator< T >::slow_rhs_post
private

◆ slow_rhs_pre

template<class T >
std::function<void(T&, T&, T&, T&, const amrex::Real, const amrex::Real, const amrex::Real, const int)> MRISplitIntegrator< T >::slow_rhs_pre
private

◆ T_store

template<class T >
amrex::Vector<std::unique_ptr<T> > MRISplitIntegrator< T >::T_store
private

◆ timestep

template<class T >
amrex::Real MRISplitIntegrator< T >::timestep
private

Integrator timestep size (Real)

Referenced by MRISplitIntegrator< T >::advance().


The documentation for this class was generated from the following file: