CubicSpline.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <gsl/gsl_spline.h>
7 #include <memory>
8 #include <vector>
9 
10 /// \cond
11 namespace PUP {
12 class er;
13 } // namespace PUP
14 /// \endcond
15 
16 namespace intrp {
17 /*!
18  * \ingroup NumericalAlgorithmsGroup
19  * \brief A natural cubic spline interpolation class
20  *
21  * The class builds a cubic spline interpolant with natural boundary conditions
22  * using the `x_values` and `y_values` passed into the constructor. For details
23  * on the algorithm see the GSL documentation on `gsl_interp_cspline`.
24  *
25  * Here is an example how to use this class:
26  *
27  * \snippet Test_CubicSpline.cpp interpolate_example
28  */
29 class CubicSpline {
30  public:
32  std::vector<double> y_values) noexcept;
33 
34  CubicSpline() noexcept = default;
35  CubicSpline(const CubicSpline& /*rhs*/) = delete;
36  CubicSpline& operator=(const CubicSpline& /*rhs*/) = delete;
37  CubicSpline(CubicSpline&& /*rhs*/) noexcept = default;
38  CubicSpline& operator=(CubicSpline&& rhs) noexcept = default;
39  ~CubicSpline() noexcept = default;
40 
41  double operator()(double x_to_interp_to) const noexcept;
42 
43  // clang-tidy: no runtime references
44  void pup(PUP::er& p) noexcept; // NOLINT
45 
46  private:
47  struct gsl_interp_accel_deleter {
48  void operator()(gsl_interp_accel* acc) const noexcept;
49  };
50  struct gsl_spline_deleter {
51  void operator()(gsl_spline* spline) const noexcept;
52  };
53 
54  void initialize_interpolant() noexcept;
55 
56  std::vector<double> x_values_;
57  std::vector<double> y_values_;
60 };
61 } // namespace intrp
Definition: Strahlkorper.hpp:14
Definition: AddTemporalIdsToInterpolationTarget.hpp:17
A natural cubic spline interpolation class.
Definition: CubicSpline.hpp:29