BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
gsl_interpolator.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of BubbleProfiler.
3  *
4  * BubbleProfiler is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * BubbleProfiler is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with BubbleProfiler. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef BUBBLEPROFILER_GSL_INTERPOLATOR_HPP_INCLUDED
19 #define BUBBLEPROFILER_GSL_INTERPOLATOR_HPP_INCLUDED
20 
26 #include <Eigen/Core>
27 
28 #include <gsl/gsl_spline.h>
29 #include <gsl/gsl_version.h>
30 
31 #include <memory>
32 
33 namespace BubbleProfiler {
34 
42 Eigen::VectorXd interpolate_f_at(const Eigen::VectorXd& x_old,
43  const Eigen::VectorXd& y_old,
44  const Eigen::VectorXd& x_new);
45 
55 Eigen::VectorXd interpolate_f_at(const Eigen::VectorXd& x_old,
56  const Eigen::VectorXd& y_old,
57  int n_old, const Eigen::VectorXd& x_new,
58  int n_new);
59 
65 public:
66  enum class Interpolation_type {
67  GSL_linear,
71  GSL_akima,
73 #ifdef GSL_MAJOR_VERSION
74 #if (GSL_MAJOR_VERSION >= 2)
75  , GSL_steffen
76 #endif
77 #endif
78  };
79 
81  ~GSL_interpolator() = default;
86 
92 
98  void construct_interpolant(const Eigen::VectorXd&, const Eigen::VectorXd&);
99 
106  void construct_interpolant(const Eigen::VectorXd&, const Eigen::VectorXd&,
107  int);
108 
114  double evaluate_at(double) const;
115 
121  double evaluate_deriv_at(double) const;
122 
128  double evaluate_second_deriv_at(double) const;
129 
130 private:
132  void operator()(gsl_interp_accel* a) const {
133  if (a) {
134  gsl_interp_accel_free(a);
135  }
136  }
137  };
138 
140  void operator()(gsl_spline* s) const {
141  if (s) {
142  gsl_spline_free(s);
143  }
144  }
145  };
146 
148  std::unique_ptr<gsl_interp_accel, GSL_accel_deleter> accelerator{nullptr};
149  std::unique_ptr<gsl_spline, GSL_spline_deleter> interpolant{nullptr};
150 
151  const gsl_interp_type* to_gsl_interp_type(Interpolation_type) const;
152  void reset(Interpolation_type, int);
153  void check_interpolant_computed() const;
154  void check_within_bounds(double) const;
155 };
156 
157 } // namespace BubbleProfiler
158 
159 #endif
std::unique_ptr< gsl_interp_accel, GSL_accel_deleter > accelerator
std::unique_ptr< gsl_spline, GSL_spline_deleter > interpolant
void set_interpolation_type(Interpolation_type t)
Sets the method used to perform interpolation.
void reset(Interpolation_type, int)
double evaluate_deriv_at(double) const
Evaluates derivative of computed interpolant at a point.
double evaluate_at(double) const
Evaluates computed interpolant at a point.
double evaluate_second_deriv_at(double) const
Evaluates second derivative of computed interpolant at a point.
void construct_interpolant(const Eigen::VectorXd &, const Eigen::VectorXd &)
Computes interpolant using given x and y values.
Eigen::VectorXd interpolate_f_at(const Eigen::VectorXd &x_old, const Eigen::VectorXd &y_old, const Eigen::VectorXd &x_new)
Computes interpolated function values at a new set of grid points.
const gsl_interp_type * to_gsl_interp_type(Interpolation_type) const
GSL_interpolator & operator=(const GSL_interpolator &)
Provides routines for carrying out 1D interpolation.