3 #include <gsl/gsl_errno.h>
4 #include <gsl/gsl_spline.h>
5 #include <gsl/gsl_version.h>
11 #ifdef GSL_MAJOR_VERSION
12 #if GSL_MAJOR_VERSION == 1
73 static const std::map<Method, const gsl_interp_type *> interp_method{
103 gsl_interp_accel *acc;
109 Interp(
const std::vector<double> &x,
const std::vector<double> &y,
111 : acc(gsl_interp_accel_alloc()),
112 spline(gsl_spline_alloc(interp_method.at(method), x.size())),
115 assert(x.size() == y.size() &&
116 "In Interp, input vectors x and y must have same size");
117 assert(x.size() >= gsl_interp_type_min_size(interp_method.at(method)) &&
118 "In Interp, certain interpolation methods require a minimum number "
120 gsl_spline_init(spline, x.data(), y.data(), x.size());
123 gsl_spline_free(spline);
124 gsl_interp_accel_free(acc);
131 if (x < x0 || x > xmax)
134 return gsl_spline_eval(spline, x, acc);
138 std::vector<double>
interp(
const std::vector<double> &x)
const {
139 std::vector<double> y;
150 std::vector<double>
operator()(
const std::vector<double> &x)
const {
162 inline std::vector<double>
interpolate(
const std::vector<double> &x_in,
163 const std::vector<double> &y_in,
164 const std::vector<double> &x_out,
166 Interp i_func(x_in, y_in, method);
167 return i_func(x_out);
173 static constexpr
bool has_steffen_method() {
174 #ifndef GSL_VERSION_1
Performs interpolation using GSL (GNU Scientific Library)
Definition: Interpolator.hpp:100
std::vector< double > interp(const std::vector< double > &x) const
Evaluates interpolation function at set of points {x}. Does not extrapolate.
Definition: Interpolator.hpp:138
double interp(double x) const
Evaluates interpolation function at point x. Does not extrapolate.
Definition: Interpolator.hpp:130
double operator()(double x) const
Evaluates interpolation function at point x. Does not extrapolate.
Definition: Interpolator.hpp:147
Interp(const std::vector< double > &x, const std::vector< double > &y, Method method=Method::cspline)
x_in and y_in
Definition: Interpolator.hpp:109
std::vector< double > operator()(const std::vector< double > &x) const
Evaluates interpolation function at set of points {x}. Does not extrapolate.
Definition: Interpolator.hpp:150
Interpolates functions using cubic splines. Uses GSL: https://www.gnu.org/software/gsl/doc/html/inter...
Definition: Interpolator.hpp:19
Method
Method (type) of 1D Interpolation used.
Definition: Interpolator.hpp:55
@ polynomial
polynomial interpolation
@ akima_periodic
akima interpolation with periodic boundary condition
@ cspline_periodic
cubic b-spline interpolation with periodic boundary condition
@ linear
linear interpolation
@ cspline
cubic b-spline interpolation
@ steffen
steffen interpolation (ensure monotonicity between points). Only GSLv2+
@ akima
akima interpolation
std::vector< double > interpolate(const std::vector< double > &x_in, const std::vector< double > &y_in, const std::vector< double > &x_out, Method method=Method::cspline)
Performs interpolation using GSL (GNU Scientific Library)
Definition: Interpolator.hpp:162