int gsl_odeiv2_driver_apply_fixed_step (gsl_odeiv2_driver * d, double *t, const double h, const unsigned long int n, double y[]) { /* Alternative driver function that evolves the system from t using * n steps of size h. In the beginning vector y contains the values * of dependent variables at t. This function returns values at t = * t + n * h in y. In case of an unrecoverable error, y and t * contains the values after the last successful step. */ unsigned long int i; d->n = 0; /* Evolution loop */ for (i = 0; i < n; i++) { int s = gsl_odeiv2_evolve_apply_fixed_step (d->e, d->c, d->s, d->sys, t, h, y); if (s != GSL_SUCCESS) { return s; } d->n++; } return GSL_SUCCESS; }
double dodes(double initial_value, double start_time, double end_time, \ int (*ode_function), char *solver_type, double nequs, double eps_abs, \ double eps_rel, double step_size, int *params) { double out = 0, t = 0; //int status; out = initial_value; t = start_time; //Setup ODE related parameters gsl_odeiv2_system sys = {ode_function, NULL, nequs, NULL}; gsl_odeiv2_step *s = gsl_odeiv2_step_alloc (gsl_odeiv2_step_rkf45, nequs); gsl_odeiv2_control *c = gsl_odeiv2_control_y_new (eps_abs, eps_rel); gsl_odeiv2_evolve *e = gsl_odeiv2_evolve_alloc (nequs); while(t < end_time) { gsl_odeiv2_evolve_apply_fixed_step (e, c, s, &sys, &t, step_size, &out); } gsl_odeiv2_evolve_free (e); gsl_odeiv2_control_free (c); gsl_odeiv2_step_free (s); return out; }
void dodea(double *initial_value, double start_time, double end_time, \ int (*ode_function), char *solver_type, double nequs, double eps_abs, \ double eps_rel, double step_size, int *params, double *out) { double t = start_time; gsl_odeiv2_step_type *step_type; /*Initialise output to initial state*/ int counter = 0; for (counter = 0; counter<nequs;counter++) { out[counter] = initial_value[counter]; } /*Setup ODE related parameters*/ gsl_odeiv2_system sys = {ode_function, NULL, nequs, params}; /*Select step solver*/ if (solver_type == "adams") step_type = gsl_odeiv2_step_msadams; if (solver_type == "stiff") step_type = gsl_odeiv2_step_msbdf; if (solver_type == "rk") step_type = gsl_odeiv2_step_rk4; if (solver_type == "rkf") step_type = gsl_odeiv2_step_rkf45; if (solver_type == "root") step_type = gsl_odeiv2_step_rkck; if (solver_type == "discrete") step_type = gsl_odeiv2_step_rk8pd; else step_type = gsl_odeiv2_step_rkf45; gsl_odeiv2_step *s = gsl_odeiv2_step_alloc (step_type, nequs); gsl_odeiv2_control *c = gsl_odeiv2_control_y_new (eps_abs, eps_rel); gsl_odeiv2_evolve *e = gsl_odeiv2_evolve_alloc (nequs); while(t < end_time) { gsl_odeiv2_evolve_apply_fixed_step (e, c, s, &sys, &t, step_size, out); } gsl_odeiv2_evolve_free (e); gsl_odeiv2_control_free (c); gsl_odeiv2_step_free (s); }