26 #ifndef CASADI_CVODES_INTERFACE_HPP
27 #define CASADI_CVODES_INTERFACE_HPP
29 #include <casadi/interfaces/sundials/casadi_integrator_cvodes_export.h>
30 #include "sundials_interface.hpp"
31 #include <cvodes/cvodes.h>
32 #include <cvodes/cvodes_dense.h>
33 #include <cvodes/cvodes_band.h>
34 #include <cvodes/cvodes_spgmr.h>
35 #include <cvodes/cvodes_spbcgs.h>
36 #include <cvodes/cvodes_sptfqmr.h>
37 #include <cvodes/cvodes_impl.h>
58 class CvodesInterface;
61 struct CvodesMemory :
public SundialsMemory {
63 const CvodesInterface&
self;
75 CvodesMemory(
const CvodesInterface& s);
87 class CvodesInterface :
public SundialsInterface {
90 CvodesInterface(
const std::string& name,
const Function& dae,
double t0,
91 const std::vector<double>& tout);
94 static Integrator* creator(
const std::string& name,
const Function& dae,
95 double t0,
const std::vector<double>& tout) {
96 return new CvodesInterface(name, dae, t0, tout);
100 ~CvodesInterface()
override;
103 const char* plugin_name()
const override {
return "cvodes";}
106 std::string class_name()
const override {
return "CvodesInterface";}
110 static const Options options_;
111 const Options& get_options()
const override {
return options_;}
112 double min_step_size_;
113 bool always_recalculate_jacobian_;
118 void init(
const Dict& opts)
override;
121 void* alloc_mem()
const override {
return new CvodesMemory(*
this);}
124 int init_mem(
void* mem)
const override;
127 void free_mem(
void *mem)
const override {
delete static_cast<CvodesMemory*
>(mem);}
130 void reset(IntegratorMemory* mem,
131 const double* u,
const double* x,
const double* z,
const double* p)
const override;
134 void advance(IntegratorMemory* mem,
135 const double* u,
double* x,
double* z,
double* q)
const override;
138 void impulseB(IntegratorMemory* mem,
139 const double* rx,
const double* rz,
const double* rp)
const override;
142 void retreat(IntegratorMemory* mem,
const double* u,
143 double* rx,
double* rq,
double* uq)
const override;
146 static CvodesMemory* to_mem(
void *mem) {
147 CvodesMemory* m =
static_cast<CvodesMemory*
>(mem);
148 casadi_assert_dev(m);
153 static const std::string meta_doc;
158 static void ehfun(
int error_code,
const char *module,
const char *
function,
char *msg,
160 static int rhsF(
double t, N_Vector x, N_Vector xdot,
void *user_data);
161 static int rhsB(
double t, N_Vector x, N_Vector xB, N_Vector xdotB,
void *user_data);
162 static int rhsQF(
double t, N_Vector x, N_Vector qdot,
void *user_data);
163 static int rhsQB(
double t, N_Vector x, N_Vector rx, N_Vector ruqdot,
void *user_data);
164 static int jtimesF(N_Vector v, N_Vector Jv,
double t, N_Vector x, N_Vector xdot,
165 void *user_data, N_Vector tmp);
166 static int jtimesB(N_Vector vB, N_Vector JvB,
double t, N_Vector x, N_Vector xB,
167 N_Vector xdotB,
void *user_data , N_Vector tmpB);
168 static int psolveF(
double t, N_Vector x, N_Vector xdot, N_Vector r, N_Vector z,
169 double gamma,
double delta,
int lr,
void *user_data, N_Vector tmp);
170 static int psolveB(
double t, N_Vector x, N_Vector xB, N_Vector xdotB, N_Vector rvecB,
171 N_Vector zvecB,
double gammaB,
double deltaB,
172 int lr,
void *user_data, N_Vector tmpB);
173 static int psetupF(
double t, N_Vector x, N_Vector xdot, booleantype jok,
174 booleantype *jcurPtr,
double gamma,
void *user_data,
175 N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
176 static int psetupB(
double t, N_Vector x, N_Vector xB, N_Vector xdotB,
177 booleantype jokB, booleantype *jcurPtrB,
double gammaB,
178 void *user_data, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B);
179 static int lsetupF(CVodeMem cv_mem,
int convfail, N_Vector x, N_Vector xdot,
180 booleantype *jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3);
181 static int lsolveF(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector x, N_Vector xdot);
182 static int lsetupB(CVodeMem cv_mem,
int convfail, N_Vector x, N_Vector xdot,
183 booleantype *jcurPtr, N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3);
184 static int lsolveB(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector x, N_Vector xdot);
187 static void cvodes_error(
const char* module,
int flag);
195 void serialize_body(SerializingStream &s)
const override;
198 static ProtoFunction* deserialize(DeserializingStream& s) {
return new CvodesInterface(s); }
203 explicit CvodesInterface(DeserializingStream& s);
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.