28#include <gsl/gsl_spline.h>
34 const std::vector<double>&
times,
const std::vector<double>& values){
46 if (
acc_m !=
nullptr) {
47 gsl_interp_accel_free(
acc_m);
59 os <<
"Uninitialised SplineTimeDependence" <<
endl;
62 <<
" with " <<
times_m.size() <<
" entries" <<
endl;
68 const std::vector<double>& values) {
69 if (
times.size() != values.size()) {
71 "SplineTimeDependence::SplineTimeDependence",
72 "Times and values should be of equal length");
74 if (
times.size() <= splineOrder) {
76 "SplineTimeDependence::SplineTimeDependence",
77 "Times and values should be of length > splineOrder");
79 if (splineOrder != 1 and splineOrder != 3) {
81 "SplineTimeDependence::SplineTimeDependence",
82 "Only linear or cubic interpolation is supported");
84 for (
size_t i = 0; i <
times.size() - 1; ++i) {
87 "SplineTimeDependence::SplineTimeDependence",
88 "Times should increase monotonically");
95 if (splineOrder == 1) {
96 spline_m = gsl_spline_alloc (gsl_interp_linear,
times.size());
98 spline_m = gsl_spline_alloc (gsl_interp_cspline,
times.size());
103 if (
acc_m ==
nullptr) {
104 acc_m = gsl_interp_accel_alloc();
106 gsl_interp_accel_reset(
acc_m);
112 std::stringstream ss;
113 ss <<
"time out of spline range: " << time;
123 "time out of spline range");
Inform & endl(Inform &inf)
static TFunction2< double, double > times
Time dependence that follows a spline.
void setSpline(size_t splineOrder, const std::vector< double > ×, const std::vector< double > &values)
Set the spline, deleting any existing spline data.
Inform & print(Inform &os) const
Print summary information about the time dependence.
SplineTimeDependence * clone() override
Inheritable copy constructor.
std::vector< double > values_m
~SplineTimeDependence() override
Destructor cleans up the GSL spline stuff.
double getValue(double time) override
Return the value of the spline at a given time.
double getIntegral(double time) override
Return the integral of the spline from 0 to the given time.
std::vector< double > times_m
SplineTimeDependence()=default
Default Constructor makes a dependence of length 2 with values 0.