26 #ifndef CASADI_IDAS_INTERFACE_HPP
27 #define CASADI_IDAS_INTERFACE_HPP
29 #include <casadi/interfaces/sundials/casadi_integrator_idas_export.h>
30 #include "sundials_interface.hpp"
31 #include <idas/idas.h>
32 #include <idas/idas_dense.h>
33 #include <idas/idas_band.h>
34 #include <idas/idas_spgmr.h>
35 #include <idas/idas_spbcgs.h>
36 #include <idas/idas_sptfqmr.h>
37 #include <idas/idas_impl.h>
57 struct IdasMemory :
public SundialsMemory {
59 const IdasInterface&
self;
71 IdasMemory(
const IdasInterface& s);
85 class IdasInterface :
public SundialsInterface {
89 IdasInterface(
const std::string& name,
const Function& dae,
90 double t0,
const std::vector<double>& tout);
93 static Integrator* creator(
const std::string& name,
const Function& dae,
94 double t0,
const std::vector<double>& tout) {
95 return new IdasInterface(name, dae, t0, tout);
99 ~IdasInterface()
override;
102 const char* plugin_name()
const override {
return "idas";}
105 std::string class_name()
const override {
return "IdasInterface";}
109 static const Options options_;
110 const Options& get_options()
const override {
return options_;}
114 void init(
const Dict& opts)
override;
117 void* alloc_mem()
const override {
return new IdasMemory(*
this);}
120 int init_mem(
void* mem)
const override;
123 void free_mem(
void *mem)
const override {
delete static_cast<IdasMemory*
>(mem);}
126 void reset(IntegratorMemory* mem,
127 const double* u,
const double* x,
const double* z,
const double* p)
const override;
130 void advance(IntegratorMemory* mem,
131 const double* u,
double* x,
double* z,
double* q)
const override;
134 void resetB(IntegratorMemory* mem)
const override;
137 void z_impulseB(IdasMemory* m,
const double* rz)
const;
140 int solve_transposed(IdasMemory* m,
double t,
const double* xz,
const double* rxz,
141 const double* rhs,
double* sol)
const;
144 void impulseB(IntegratorMemory* mem,
145 const double* rx,
const double* rz,
const double* rp)
const override;
148 void retreat(IntegratorMemory* mem,
const double* u,
149 double* rx,
double* rq,
double* uq)
const override;
152 static IdasMemory* to_mem(
void *mem) {
153 IdasMemory* m =
static_cast<IdasMemory*
>(mem);
154 casadi_assert_dev(m);
159 static const std::string meta_doc;
164 static int resF(
double t, N_Vector xz, N_Vector xzdot, N_Vector rr,
void *user_data);
165 static int resB(
double t, N_Vector xz, N_Vector xzdot, N_Vector rxz, N_Vector rxzdot,
166 N_Vector rr,
void *user_data);
167 static void ehfun(
int error_code,
const char *module,
const char *
function,
char *msg,
169 static int jtimesF(
double t, N_Vector xz, N_Vector xzdot, N_Vector rr, N_Vector v,
170 N_Vector Jv,
double cj,
void *user_data, N_Vector tmp1, N_Vector tmp2);
171 static int jtimesB(
double t, N_Vector xz, N_Vector xzdot, N_Vector xzB, N_Vector xzdotB,
172 N_Vector resvalB, N_Vector vB, N_Vector JvB,
double cjB,
173 void *user_data, N_Vector tmp1B, N_Vector tmp2B);
174 static int rhsQF(
double t, N_Vector xz, N_Vector xzdot, N_Vector qdot,
void *user_data);
175 static int rhsQB(
double t, N_Vector xz, N_Vector xzdot, N_Vector rxz,
176 N_Vector rxzdot, N_Vector ruqdot,
void *user_data);
177 static int psolveF(
double t, N_Vector xz, N_Vector xzdot, N_Vector rr, N_Vector rvec,
178 N_Vector zvec,
double cj,
double delta,
void *user_data, N_Vector tmp);
179 static int psetupF(
double t, N_Vector xz, N_Vector xzdot, N_Vector rr,
double cj,
180 void* user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
181 static int psolveB(
double t, N_Vector xz, N_Vector xzdot, N_Vector rxz, N_Vector rxzdot,
182 N_Vector resvalB, N_Vector rvecB, N_Vector zvecB,
double cjB,
183 double deltaB,
void *user_dataB, N_Vector tmpB);
184 static int psetupB(
double t, N_Vector xz, N_Vector xzdot, N_Vector rxz, N_Vector rxzdot,
185 N_Vector resvalB,
double cjB,
void *user_dataB,
186 N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B);
187 static int lsetupF(IDAMem IDA_mem, N_Vector xz, N_Vector xzdot, N_Vector resp,
188 N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3);
189 static int lsolveF(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur,
190 N_Vector xzdotcur, N_Vector rescur);
191 static int lsetupB(IDAMem IDA_mem, N_Vector xz, N_Vector xzdot, N_Vector resp,
192 N_Vector vtemp1, N_Vector vtemp2, N_Vector vtemp3);
193 static int lsolveB(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur,
194 N_Vector xzdotcur, N_Vector rescur);
198 static void idas_error(
const char* module,
int flag);
204 bool suppress_algebraic_;
205 std::vector<double> abstolv_;
209 std::vector<casadi_int> y_c_;
212 std::vector<double> init_xdot_;
215 void serialize_body(SerializingStream &s)
const override;
218 static ProtoFunction* deserialize(DeserializingStream& s) {
return new IdasInterface(s); }
222 explicit IdasInterface(DeserializingStream& s);
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.