1#ifndef AMREX_RK_INTEGRATOR_H
2#define AMREX_RK_INTEGRATOR_H
51 void initialize_preset_tableau ()
74 weights = {1./6., 1./6., 2./3.};
84 {0.0, 0.0, 1.0, 0.0}};
85 weights = {1./6., 1./3., 1./3., 1./6.};
92 number_nodes = weights.
size();
95 void initialize_parameters ()
100 int _tableau_type = 0;
101 pp.
get(
"type", _tableau_type);
105 extended_weights = {};
111 pp.
queryarr(
"extended_weights", extended_weights);
120 amrex::Error(
"integration.rk.weights should be the same length as integration.rk.nodes");
122 number_nodes = weights.
size();
123 const int nTableau = (number_nodes * (number_nodes + 1)) / 2;
124 if (btable.
size() != nTableau)
126 amrex::Error(
"integration.rk.tableau incorrect length - should include the Butcher Tableau diagonal.");
132 for (
int i = 0; i < number_nodes; ++i)
135 for (
int j = 0; j <= i; ++j)
137 stage_row.push_back(btable[k]);
141 tableau.push_back(stage_row);
145 for (
const auto& astage : tableau)
147 if (astage.back() != 0.0)
149 amrex::Error(
"RKIntegrator currently only supports explicit Butcher tableaus.");
154 initialize_preset_tableau();
156 amrex::Error(
"RKIntegrator received invalid input for integration.rk.type");
160 void initialize_stages (
const T& S_data,
const amrex::Real time)
163 for (
int i = 0; i < number_nodes; ++i)
186 initialize_parameters();
187 initialize_stages(S_data, time);
200 for (
int i = 0; i < number_nodes; ++i)
212 for (
int j = 0; j < i; ++j)
229 for (
int i = 0; i < number_nodes; ++i)
251 for (
int step_number = 0; step_number <
BaseT::max_steps && !stop; ++step_number)
255 if ((time_out-time_current) < dt ||
almostEqual(time_out-time_current,dt,1000)) {
256 dt = time_out - time_current;
261 advance(*S_current[0], S_out, time_current, dt);
273 Error(
"Did not reach output time in max steps.");
298 c = timestep_fraction - 1.5 * std::pow(timestep_fraction, 2) + 2./3. * std::pow(timestep_fraction, 3);
302 c = std::pow(timestep_fraction, 2) - 2./3. * std::pow(timestep_fraction, 3);
306 c = std::pow(timestep_fraction, 2) - 2./3. * std::pow(timestep_fraction, 3);
310 c = -0.5 * std::pow(timestep_fraction, 2) + 2./3. * std::pow(timestep_fraction, 3);
315 void map_data (std::function<
void(T&)> Map)
override
317 for (
auto&
F : F_nodes) {
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
amrex::ParmParse pp
Input file parser instance for the given namespace.
Definition AMReX_HypreIJIface.cpp:15
Definition AMReX_IntegratorBase.H:164
std::function< void(T &, amrex::Real)> post_step_action
The post_step_action function is called by the integrator on the computed state just after it is comp...
Definition AMReX_IntegratorBase.H:212
int max_steps
Max number of internal steps before an error is returned (Long)
Definition AMReX_IntegratorBase.H:262
std::function< void(T &rhs, T &state, const amrex::Real time)> Rhs
Rhs is the right-hand-side function the integrator will use.
Definition AMReX_IntegratorBase.H:182
std::function< void(T &, amrex::Real)> post_stage_action
The post_stage_action function is called by the integrator on the computed stage just after it is com...
Definition AMReX_IntegratorBase.H:206
amrex::Real time_step
Current integrator time step size (Real)
Definition AMReX_IntegratorBase.H:235
amrex::Real previous_time_step
Step size of the last completed step (Real)
Definition AMReX_IntegratorBase.H:240
Parse Parameters From Command Line and Input Files.
Definition AMReX_ParmParse.H:346
void getarr(std::string_view name, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
Same as getktharr() but searches for last occurrence of name.
Definition AMReX_ParmParse.cpp:1517
int queryarr(std::string_view name, std::vector< int > &ref, int start_ix=FIRST, int num_val=ALL) const
Same as queryktharr() but searches for last occurrence of name.
Definition AMReX_ParmParse.cpp:1536
void get(std::string_view name, bool &ref, int ival=FIRST) const
Same as getkth() but searches for the last occurrence of name.
Definition AMReX_ParmParse.cpp:1433
Definition AMReX_RKIntegrator.H:22
virtual ~RKIntegrator()
Definition AMReX_RKIntegrator.H:190
void time_interpolate(const T &, const T &S_old, amrex::Real timestep_fraction, T &data) override
Definition AMReX_RKIntegrator.H:278
RKIntegrator(const T &S_data, const amrex::Real time=0.0)
Definition AMReX_RKIntegrator.H:179
void map_data(std::function< void(T &)> Map) override
Definition AMReX_RKIntegrator.H:315
amrex::Real advance(T &S_old, T &S_new, amrex::Real time, const amrex::Real dt) override
Take a single time step from (time, S_old) to (time + dt, S_new) with the given step size.
Definition AMReX_RKIntegrator.H:192
void evolve(T &S_out, const amrex::Real time_out) override
Evolve the current (internal) integrator state to time_out.
Definition AMReX_RKIntegrator.H:246
void initialize(const T &S_data, const amrex::Real time=0.0)
Definition AMReX_RKIntegrator.H:184
RKIntegrator()
Definition AMReX_RKIntegrator.H:177
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
Long size() const noexcept
Definition AMReX_Vector.H:53
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
Definition AMReX_Amr.cpp:49
__host__ __device__ std::enable_if_t< std::is_floating_point_v< T >, bool > almostEqual(T x, T y, int ulp=2)
Definition AMReX_Algorithm.H:116
void Error(const std::string &msg)
Print out message to cerr and exit via amrex::Abort().
Definition AMReX.cpp:224
ButcherTableauTypes
Definition AMReX_RKIntegrator.H:11
Definition AMReX_IntegratorBase.H:18