1#ifndef ODESOLVER_HEADER
2#define ODESOLVER_HEADER
3#include <gsl/gsl_errno.h>
4#include <gsl/gsl_integration.h>
5#include <gsl/gsl_odeiv2.h>
25#ifndef ODESOLVER_FIDUCIAL_STEPPER
26#define ODESOLVER_FIDUCIAL_STEPPER gsl_odeiv2_step_rk2
33 using ODEFunction = std::function<int(
double,
const double *,
double *)>;
100 double hstart = 1e-3;
101 double abserr = 1e-7;
102 double relerr = 1e-7;
104 bool verbose =
false;
105 bool finite_difference_jacobian =
false;
108 int num_x_points = 0;
110 std::vector<DVector> data{};
111 std::vector<DVector> derivative_data{};
113 void throw_error(std::string errormessage)
const;
117 ODESolver(
double hstart,
double abserr,
double relerr);
125 const gsl_odeiv2_step_type * stepper = ODESOLVER_FIDUCIAL_STEPPER,
134 const gsl_odeiv2_step_type * stepper = ODESOLVER_FIDUCIAL_STEPPER,
144 void set_accuracy(
const double hstart,
const double abserr,
const double relerr);
This is a wrapper around the GSL library to easily solve ODEs and return the data in whatever format ...
DVector get_data_by_xindex(int ix) const
Get the data at a particular x-index y(xarr_i)
void set_finite_difference_jacobian(bool onoff)
Implicit steppers without a jacobian: compute it by forward finite differences of the ODE function (r...
DVector2D get_data() const
Get all the data z_ij = ( y_j(xarr_i) ), i.e. data[ix][icomponent].
double get_final_data_by_component(int icomponent) const
Get the solution for a given component at the end point.
DVector2D get_derivative_data() const
Get all the data for the derivatives z_ij = ( dy_j/dx(xarr_i) ), i.e.
ODESolver & operator=(const ODESolver &rhs)=delete
DVector get_derivative_data_by_component(int icomponent) const
Get the data dy_i/dx(xarr) for the derivatives for a particular component.
DVector get_data_by_component(int icomponent) const
Get the data for a particular component y_i(xarr)
DVector get_final_data() const
Get the solution at the end point.
void set_verbose(bool onoff)
Show info while solving or not.
void solve(ODEFunctionPointer ode_equation, void *parameters, const DVector &xarr, const DVector &yinitial, const gsl_odeiv2_step_type *stepper=ODESOLVER_FIDUCIAL_STEPPER, ODEFunctionPointerJacobian jacobian=nullptr)
void set_accuracy(const double hstart, const double abserr, const double relerr)
Set the accuracy parameters (first guess for the step-size, the absolute and relative error)
DVector2D get_data_transpose() const
Get all the data transposed z_ij = ( y_i(xarr_j) ), i.e. data[icomponent][ix].
ODESolver(const ODESolver &rhs)=delete
std::vector< double > DVector
std::vector< DVector > DVector2D
int(*)(double, const double[], double[], double[], void *) ODEFunctionPointerJacobian
ODEFunctionJacobian * no_jacobian_ptr
int(*)(double, const double[], double[], void *) ODEFunctionPointer
std::function< int(double, const double *, double *, double *)> ODEFunctionJacobian
std::function< int(double, const double *, double *)> ODEFunction