6 #include <gsl/gsl_errno.h> 7 #include <gsl/gsl_odeiv2.h> 19 template<
size_t N,
bool HASCALLOP = false,
bool JACOBIAN = false>
24 using Array = std::array<double, N>;
26 static constexpr
size_t DIM =
N;
32 gsl_odeiv2_system odeSystem;
34 gsl_odeiv2_driver *odeDriver;
46 : odeSystem{
nullptr,
nullptr,
N,
static_cast<void *
>(&p) }
47 , odeDriver{
nullptr } {
48 if constexpr (!HASCALLOP) {
51 odeSystem.function = [](
double t,
54 void *params) ->
int {
55 T *myObj =
static_cast<T *
>(params);
57 return myObj->odefn(t, y, f);
62 odeSystem.function = [](
double t,
65 void *params) ->
int {
66 T *myObj =
static_cast<T *
>(params);
68 return (*myObj)(t, y,
f);
73 if constexpr (JACOBIAN ==
true) {
74 odeSystem.jacobian = [](
double t,
79 T *myObj =
static_cast<T *
>(params);
80 return myObj->getJacobian(t, y, *dfdy, dfdt);
93 inline void init(
double initstepsize,
96 const gsl_odeiv2_step_type *steptype = gsl_odeiv2_step_rkf45) {
97 odeDriver = gsl_odeiv2_driver_alloc_y_new(&odeSystem, steptype, initstepsize, abserr, relerr);
114 const gsl_odeiv2_step_type *steptype = gsl_odeiv2_step_rkf45)
116 init(istepsize, abserror, relerror, steptype);
123 if (odeDriver !=
nullptr) {
124 gsl_odeiv2_driver_free(odeDriver);
143 _status = gsl_odeiv2_driver_apply(odeDriver, ¤tTime, t, ¤tState[0]);
145 if (_status != GSL_SUCCESS) {
146 throw std::runtime_error(
nmx_msgx(std::to_string(_status)));
157 if (idx < 0 || idx >=
N) {
158 throw std::range_error(
nmx_msgx(std::to_string(idx)));
160 return currentState[idx];
167 inline constexpr
size_t size()
const {
return N; }
std::array< double, N > Array
void set_init_conditions(double t, const Array &y)
set_init_conditions lege Anfangsbedingungen fest
constexpr size_t size() const
size
Odeiv2(T &obj, double istepsize, double abserror, double relerror, const gsl_odeiv2_step_type *steptype=gsl_odeiv2_step_rkf45)
Odeiv2 Konstruktor.
The Odeiv2 class numerische Lösung eines Systems von N Differenzialgleichungen Schnittstelle zur gsl...
void solve(double t)
applyStep berechnet Lösung
double operator[](size_t idx) const
operator [] Zugriff auf einzelnen Elemente des Lösungsvektors mit Index
double f(double x, void *params)
f
static constexpr size_t DIM