1 #ifndef AMREX_TIME_INTEGRATOR_H
2 #define AMREX_TIME_INTEGRATOR_H
10 #ifdef AMREX_USE_SUNDIALS
35 std::string integrator_str;
36 pp.
get(
"type", integrator_str);
38 if (integrator_str ==
"ForwardEuler") {
40 }
else if (integrator_str ==
"RungeKutta") {
42 }
else if (integrator_str ==
"SUNDIALS") {
46 integrator_type = std::stoi(integrator_str,
nullptr);
47 }
catch (
const std::invalid_argument& ia) {
48 Print() <<
"Invalid integration.type: " << ia.what() <<
'\n';
49 Error(
"Failed to initialize AMReX TimeIntegrator class.");
56 #ifndef AMREX_USE_SUNDIALS
58 Error(
"AMReX has not been compiled with SUNDIALS. Recompile with USE_SUNDIALS=TRUE.");
68 set_rhs([](T& , T& ,
const amrex::Real ){});
70 [](T& , T& ,
const amrex::Real ){});
115 switch (integrator_type)
118 integrator_ptr = std::make_unique<FEIntegrator<T> >(S_data, time);
121 integrator_ptr = std::make_unique<RKIntegrator<T> >(S_data, time);
123 #ifdef AMREX_USE_SUNDIALS
125 integrator_ptr = std::make_unique<SundialsIntegrator<T> >(S_data, time);
129 amrex::Error(
"integrator type did not match a valid integrator type.");
134 void set_rhs (std::function<
void(T&, T&,
const amrex::Real)> F)
140 std::function<
void(T&, T&,
const amrex::Real)> Fe)
210 void advance (T& S_old, T& S_new, amrex::Real time,
const amrex::Real dt)
215 void evolve (T& S_out,
const amrex::Real time_out)
220 void integrate (T& S_old, T& S_new, amrex::Real start_time,
const amrex::Real start_timestep,
221 const amrex::Real end_time,
const int start_step,
const int max_steps)
223 amrex::Real m_time = start_time;
224 amrex::Real m_timestep = start_timestep;
226 for (
int m_step_number = start_step; m_step_number < max_steps && !stop; ++m_step_number)
228 if (end_time - m_time < m_timestep) {
229 m_timestep = end_time - m_time;
233 if (m_step_number > 0) {
241 m_time += m_timestep;
245 void time_interpolate (
const T& S_new,
const T& S_old, amrex::Real timestep_fraction, T& data)
247 integrator_ptr->time_interpolate(S_new, S_old, timestep_fraction, data);
#define AMREX_ALWAYS_ASSERT(EX)
Definition: AMReX_BLassert.H:50
amrex::ParmParse pp
Input file parser instance for the given namespace.
Definition: AMReX_HypreIJIface.cpp:15
Parse Parameters From Command Line and Input Files.
Definition: AMReX_ParmParse.H:320
void get(const char *name, bool &ref, int ival=FIRST) const
Same as getkth() but searches for the last occurrence of name.
Definition: AMReX_ParmParse.cpp:1292
This class provides the user with a few print options.
Definition: AMReX_Print.H:35
Definition: AMReX_TimeIntegrator.H:26
void set_adaptive_step()
Definition: AMReX_TimeIntegrator.H:180
void set_adaptive_fast_step()
Definition: AMReX_TimeIntegrator.H:190
void integrate(T &S_old, T &S_new, amrex::Real start_time, const amrex::Real start_timestep, const amrex::Real end_time, const int start_step, const int max_steps)
Definition: AMReX_TimeIntegrator.H:220
TimeIntegrator(const T &S_data, const amrex::Real time=0.0)
Definition: AMReX_TimeIntegrator.H:101
void set_max_steps(int steps)
Definition: AMReX_TimeIntegrator.H:195
void set_post_step_action(std::function< void(T &, amrex::Real)> A)
Definition: AMReX_TimeIntegrator.H:155
void map_data(std::function< void(T &)> Map)
Definition: AMReX_TimeIntegrator.H:250
void set_imex_rhs(std::function< void(T &, T &, const amrex::Real)> Fi, std::function< void(T &, T &, const amrex::Real)> Fe)
Definition: AMReX_TimeIntegrator.H:139
void set_fast_rhs(std::function< void(T &, T &, const amrex::Real)> F)
Definition: AMReX_TimeIntegrator.H:145
void evolve(T &S_out, const amrex::Real time_out)
Definition: AMReX_TimeIntegrator.H:215
IntegratorTypes read_parameters()
Definition: AMReX_TimeIntegrator.H:30
void set_tolerances(amrex::Real rtol, amrex::Real atol)
Definition: AMReX_TimeIntegrator.H:200
void set_post_fast_stage_action(std::function< void(T &, amrex::Real)> A)
Definition: AMReX_TimeIntegrator.H:160
TimeIntegrator()
Definition: AMReX_TimeIntegrator.H:87
void initialize_integrator(IntegratorTypes integrator_type, const T &S_data, const amrex::Real time=0.0)
Definition: AMReX_TimeIntegrator.H:113
void set_post_fast_step_action(std::function< void(T &, amrex::Real)> A)
Definition: AMReX_TimeIntegrator.H:165
void set_post_stage_action(std::function< void(T &, amrex::Real)> A)
Definition: AMReX_TimeIntegrator.H:150
void set_rhs(std::function< void(T &, T &, const amrex::Real)> F)
Definition: AMReX_TimeIntegrator.H:134
void time_interpolate(const T &S_new, const T &S_old, amrex::Real timestep_fraction, T &data)
Definition: AMReX_TimeIntegrator.H:245
std::unique_ptr< IntegratorBase< T > > integrator_ptr
Definition: AMReX_TimeIntegrator.H:28
void set_time_step(amrex::Real dt)
Definition: AMReX_TimeIntegrator.H:175
amrex::Real get_time_step()
Definition: AMReX_TimeIntegrator.H:170
virtual ~TimeIntegrator()
Definition: AMReX_TimeIntegrator.H:111
void advance(T &S_old, T &S_new, amrex::Real time, const amrex::Real dt)
Definition: AMReX_TimeIntegrator.H:210
TimeIntegrator(IntegratorTypes integrator_type, const T &S_data, const amrex::Real time=0.0)
Definition: AMReX_TimeIntegrator.H:92
void set_default_functions()
Definition: AMReX_TimeIntegrator.H:65
void set_fast_tolerances(amrex::Real rtol, amrex::Real atol)
Definition: AMReX_TimeIntegrator.H:205
void set_fast_time_step(amrex::Real dt)
Definition: AMReX_TimeIntegrator.H:185
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void swap(T &a, T &b) noexcept
Definition: AMReX_algoim_K.H:113
Definition: AMReX_Amr.cpp:49
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition: AMReX.cpp:219
IntegratorTypes
Definition: AMReX_TimeIntegrator.H:18