4 #include <AMReX_REAL.H>
5 #include <AMReX_Vector.H>
6 #include <AMReX_IntegratorBase.H>
25 std::function<void(
T&,
const T&,
const double,
const double)>
rhs;
26 std::function<void(
T&,
T&,
T&,
const double,
const double,
const double,
const int)>
slow_rhs_pre;
27 std::function<void(
T&,
T&,
T&,
T&,
const double,
const double,
const double,
const int)>
slow_rhs_post;
28 std::function<void(
int,
int,
int,
T&,
const T&,
T&,
T&,
const double,
const double,
29 const amrex::Real,
const double,
72 std::function<void (
T&,
T&,
T&,
const double,
const double,
int)>
no_substep;
75 amrex::Vector<std::unique_ptr<T> >
T_store;
87 const bool include_ghost =
true;
91 amrex::IntegratorOps<T>::CreateLike(
T_store, S_data, include_ghost);
93 amrex::IntegratorOps<T>::CreateLike(
T_store, S_data, include_ghost);
186 void set_slow_rhs_pre (std::function<
void(
T&,
T&,
T&,
const double,
const double,
const double,
const int)> F)
200 const double,
const double,
201 const amrex::Real,
const double,
234 std::function<void(
T&,
const T&,
const double,
const double)>
get_rhs ()
247 double advance (
T& S_old,
T& S_new,
double time,
const double time_step)
249 BL_PROFILE_REGION(
"MRI_advance");
250 using namespace amrex;
263 "MRISplitIntegrator::advance: setNoSubstepping, setAnelastic, "
264 "setForceFirstStageSingleSubstep and setNcompCons must be called before advance");
266 "MRISplitIntegrator::advance: integrator storage must be initialized before advance");
293 for (
int i(0); i<n_data; ++i)
296 MultiFab::Copy(S_new[i],S_old[i],0,0,num_vars[i],S_old[i].nGrowVect());
308 double time_stage = time;
309 double old_time_stage;
313 for (
int nrk = 0; nrk < 3; nrk++)
316 old_time_stage = time_stage;
325 nsubsteps = std::max(substep_ratio/3, 1);
335 nsubsteps = std::max(substep_ratio/2, 1);
345 nsubsteps = substep_ratio;
346 dtau =
timestep /
static_cast<double>(nsubsteps);
357 amrex::Real inv_fac =
one /
static_cast<amrex::Real
>(nsubsteps);
367 for (
int ks = 0;
ks < nsubsteps; ++
ks)
369 acoustic_substepping(
ks, nsubsteps, nrk, *
F_slow, S_old, S_new, *
S_sum, dtau,
timestep, inv_fac,
370 time +
ks*dtau, time + (
ks+1) * dtau);
405 for (
int nrk = 0; nrk < 2; nrk++)
408 old_time_stage = time_stage;
413 time_stage = time + nsubsteps * dtau;
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(axis >=0 &&axis< AMREX_SPACEDIM, "prob.axis must be 0, 1 or 2")
AMREX_ALWAYS_ASSERT(bx.length()[2]==khi+1)
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:404
constexpr amrex::Real three
Definition: ERF_NumericalConstants.H:39
constexpr amrex::Real two
Definition: ERF_NumericalConstants.H:38
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:41
Split integrator for MRI simulations handling slow and fast timescales.
Definition: ERF_MRI.H:20
T * F_slow
Definition: ERF_MRI.H:77
std::function< void(T &, const T &, const double, const double)> get_rhs()
Definition: ERF_MRI.H:234
amrex::Vector< std::unique_ptr< T > > T_store
Definition: ERF_MRI.H:75
void set_slow_rhs_post(std::function< void(T &, T &, T &, T &, const double, const double, const double, const int)> F)
Definition: ERF_MRI.H:190
void map_data(std::function< void(T &)> Map)
Apply a mapping function to all internal stored data.
Definition: ERF_MRI.H:437
void set_slow_rhs_pre(std::function< void(T &, T &, T &, const double, const double, const double, const int)> F)
Set the pre-substepping slow RHS function.
Definition: ERF_MRI.H:186
int anelastic
Should we use the two-stage integrator of anelastic and pseudo-incompressible levels (-1 until setAne...
Definition: ERF_MRI.H:51
void setNcompCons(int _ncomp_cons)
Set the number of conservative components.
Definition: ERF_MRI.H:140
MRISplitIntegrator()=default
std::function< void(T &, const T &, const double, const double)> rhs
rhs is the right-hand-side function the integrator will use.
Definition: ERF_MRI.H:25
void setForceFirstStageSingleSubstep(int _force_stage1_single_substep)
Force the first RK stage to perform only a single substep.
Definition: ERF_MRI.H:177
int force_stage1_single_substep
Do we follow the recommendation to only perform a single substep in the first RK stage (-1 until setF...
Definition: ERF_MRI.H:67
int ncomp_cons
How many components in the cell-centered MultiFab (-1 until setNcompCons is called)
Definition: ERF_MRI.H:61
void setNoSubstepping(int _no_substepping)
Set whether acoustic substepping is disabled.
Definition: ERF_MRI.H:168
double timestep
Integrator timestep size (Real)
Definition: ERF_MRI.H:35
TimesteppingType timestepping_type
Which two-stage scheme the anelastic / pseudo-incompressible integrator uses (RK2 or MidPoint)
Definition: ERF_MRI.H:56
std::function< void(T &, T &, T &, const double, const double, const double, const int)> slow_rhs_pre
Definition: ERF_MRI.H:26
void set_no_substep(std::function< void(T &, T &, T &, const double, const double, int)> F)
Set the function to be called when acoustic substepping is disabled.
Definition: ERF_MRI.H:229
void initialize(const T &S_data)
Initialize integrator storage.
Definition: ERF_MRI.H:112
MRISplitIntegrator(MRISplitIntegrator &&) noexcept=default
void setTimesteppingType(TimesteppingType _timestepping_type=TimesteppingType::RK2)
Set the level's time integrator; the anelastic / pseudo-incompressible integrator uses RK2 or MidPoin...
Definition: ERF_MRI.H:159
void initialize_data(const T &S_data)
Allocate internal storage for integrator variables.
Definition: ERF_MRI.H:83
MRISplitIntegrator(const T &S_data)
Definition: ERF_MRI.H:103
std::function< void(T &, T &, T &, T &, const double, const double, const double, const int)> slow_rhs_post
Definition: ERF_MRI.H:27
void setAnelastic(int _anelastic)
Set whether to use the anelastic / pseudo-incompressible integrator.
Definition: ERF_MRI.H:149
std::function< void(T &, T &, T &, const double, const double, int)> no_substep
The no_substep function is called when we have no acoustic substepping.
Definition: ERF_MRI.H:72
int get_slow_fast_timestep_ratio()
Get the current slow-to-fast timestep ratio.
Definition: ERF_MRI.H:220
double advance(T &S_old, T &S_new, double time, const double time_step)
Advance the state from time to time + time_step.
Definition: ERF_MRI.H:247
int slow_fast_timestep_ratio
The ratio of slow timestep size / fast timestep size (int)
Definition: ERF_MRI.H:40
void set_acoustic_substepping(std::function< void(int, int, int, T &, const T &, T &, T &, const double, const double, const amrex::Real, const double, const double)> F)
Set the acoustic substepping function.
Definition: ERF_MRI.H:199
~MRISplitIntegrator()=default
void set_slow_fast_timestep_ratio(const int timestep_ratio=1)
Set the ratio of slow to fast timestep sizes.
Definition: ERF_MRI.H:211
T * S_sum
Definition: ERF_MRI.H:76
std::function< void(int, int, int, T &, const T &, T &, T &, const double, const double, const amrex::Real, const double, const double)> acoustic_substepping
Definition: ERF_MRI.H:30
int no_substepping
Should we not do acoustic substepping (-1 until setNoSubstepping is called)
Definition: ERF_MRI.H:45
@ NumTypes
Definition: ERF_IndexDefines.H:253
@ ks
Definition: ERF_SLM.H:76
@ T
Definition: ERF_IndexDefines.H:180
Definition: ERF_ConsoleIO.cpp:17