31 int CASADI_INTEGRATOR_ERK_EXPORT
36 plugin->version = CASADI_VERSION;
59 "Runge-Kutta method: 'rk45' (pair of order 5(4), adaptive unless step_size is set) or "
60 "'rk4' (classical, order 4, fixed steps only; default step_size (tf - t0)/20) [rk45]"}}
72 for (
auto&& op : opts) {
73 if (op.first ==
"method") {
74 method_ = op.second.to_string();
77 casadi_assert(
nz_ == 0,
"'erk' does not support algebraic states, use 'rosenbrock'");
90 void Erk::set_coefficients() {
91 if (method_ ==
"rk4") {
98 m_ = {1./6, 1./3, 1./3, 1./6};
103 2./3, -2./3, -2./3, 2./3};
107 }
else if (method_ ==
"rk45") {
109 a_ = {0, 0, 0, 0, 0, 0, 0,
110 2./9, 0, 0, 0, 0, 0, 0,
111 95./1024, 225./1024, 0, 0, 0, 0, 0,
112 595749./800000, -558657./160000, 44649./12500, 0, 0, 0, 0,
113 8133487./3056130, -547./42, 22178368./1898505, -4601000./12530133, 0, 0, 0,
114 418551./146000, -404253./29200, 197614472./16087375, -74305./320251,
115 -4991679./67174600, 0, 0,
116 629./6600, 0, 677888./1454475, 208000./337799, -453789./920200, 73./231, 0};
117 alpha_ = {0, 2./9, 5./16, 33./40, 20./21, 1, 1};
118 m_ = {629./6600, 0, 677888./1454475, 208000./337799, -453789./920200, 73./231, 0};
122 -3063./1100, 0, 1948928./484825, -1404000./337799, 2398599./460100,
124 2434./825, 0, -8982016./1454475, 520000./48257, -1426194./115025,
126 -471./440, 0, 254208./96965, -2028000./337799, 1231713./184040,
129 m_err_ = {89834./99443025, 0, -183980032./58439351025, 2874688000./122151834189,
130 -92439186./1540529825, 468368./9281349, -8./681};
133 casadi_error(
"'erk': unknown method '" + method_ +
"', expected 'rk45' or 'rk4'");
137 void Erk::set_erk_prob() {
139 casadi_int s =
alpha_.size();
141 for (casadi_int j = 0; j < s; ++j) pe_.
fsal = pe_.
fsal &&
a_[(s - 1) * s + j] ==
m_[j];
145 casadi_int*& iw,
double*& w)
const {
151 m->e_nom.prob = &pe_;
152 m->e.nom = &m->e_nom;
158 return casadi_erk(&m->d, &m->e);
163 g <<
"pe.fsal = " << pe_.
fsal <<
";\n";
164 g <<
"e.prob = &pe;\n";
166 g <<
"pen.fsal = " << pe_.
fsal <<
";\n";
167 g <<
"en.prob = &pen;\n";
168 g <<
"e.nom = &en;\n";
176 s.
unpack(
"Erk::method", method_);
186 s.
pack(
"Erk::method", method_);
Helper class for C code generation.
void add_auxiliary(Auxiliary f, const std::vector< std::string > &inst={"casadi_real"})
Add a built-in auxiliary function.
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
void version(const std::string &name, int v)
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
void init(const Dict &opts) override
Initialize.
void codegen_method(CodeGenerator &g) const override
Generate code for the problem and data of the method, variables pe and e.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
Erk(const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
Constructor.
static Integrator * creator(const std::string &name, const Function &dae, double t0, const std::vector< double > &tout)
Create a new integrator.
int kernel(RuntimeIntegratorMemory *m) const override
Call the kernel of the method: returns 1 while a task is requested.
static ProtoFunction * deserialize(DeserializingStream &s)
Deserialize into MX.
static const std::string meta_doc
A documentation string.
~Erk() override
Destructor.
static const Options options_
Options.
std::vector< double > tout_
Output time grid.
static void registerPlugin(const Plugin &plugin, bool needs_lock=true)
Register an integrator in the factory.
void clear_mem()
Clear all memory (called from destructor)
Base class of one-step integrators driven by a reverse communication kernel.
void set_ivp_prob()
Shared problem structure, from the method coefficients.
std::vector< double > m_dense_
std::vector< double > alpha_
void set_nominal_prob()
Problem of the nominal integration whose steps are replayed, if any.
void init(const Dict &opts) override
Initialize: functions of the kernel tasks.
void serialize_body(SerializingStream &s) const override
Serialize an object without type information.
void set_work(void *mem, const double **&arg, double **&res, casadi_int *&iw, double *&w) const override
Set the (persistent) work vectors.
std::vector< double > m_err_
void alloc_ivp_work()
Work vectors of the shared kernel data.
static const Options options_
Options.
Helper class for Serialization.
void version(const std::string &name, int v)
void pack(const Sparsity &e)
Serializes an object to the output stream.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
int CASADI_INTEGRATOR_ERK_EXPORT casadi_register_integrator_erk(Integrator::Plugin *plugin)
void CASADI_INTEGRATOR_ERK_EXPORT casadi_load_integrator_erk()
Options metadata for a class.