Version: SMASH-3.4
interpolation2D.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2020,2022,2026
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_INTERPOLATION2D_H_
11 #define SRC_INCLUDE_SMASH_INTERPOLATION2D_H_
12 
13 #include <vector>
14 
15 #include "gsl/gsl_spline2d.h"
16 
17 #include "smash/constants.h"
19 
20 namespace smash {
21 
22 /// Represent a bicubic spline interpolation.
24  public:
25  /**
26  * Interpolate function f given discrete samples f(x_i, y_i) = z_i.
27  * A bicubic spline interpolation is used.
28  *
29  * \param x x-values.
30  * \param y y-values.
31  * \param z z-values
32  * \param extrapolation_type Type of extrapolation for requested x_i and y_i
33  * values that are out of bounds. Extrapolation is
34  * by default disabled. Possible types are
35  * <tt>None</tt>, <tt>Zero</tt>, and
36  * <tt>Constant</tt>.
37  *
38  * \return The interpolation function.
39  * \throw std::out_of_range if values outside of the boundaries of the
40  * underlying data are tried to be accessed and
41  * extrapolation is disabled.
42  * \throw std::invalid_argument if unsupported extrapolation type is
43  * requested.
44  * \throw std::invalid_argument if product of dimensions of x and y does not
45  * equal dimension of z.
46  * \throw std::invalid_argument if less than three data points in x or y are
47  * provided.
48  * \throw std::invalid_argument if x and y are not sorted that their values
49  * strictly increase.
50  *
51  */
53  const std::vector<double>& x, const std::vector<double>& y,
54  const std::vector<double>& z,
55  ExtrapolationType extrapolation_type = ExtrapolationType::None);
56 
57  /// Destructor
59 
60  /**
61  * Calculate bicubic interpolation for given x and y.
62  *
63  * \param xi Interpolation argument in first dimension.
64  * \param yi Interpolation argument in second dimension.
65  *
66  * \return Interpolated value.
67  * \throw std::out_of_range if values outside of the boundaries of the
68  * underlying data are tried to be accessed and
69  * extrapolation is disabled.
70  */
71  double operator()(double xi, double yi) const;
72 
73  private:
74  /// Extrapolation type.
76  /// First x value of underlying data.
77  double first_x_ = smash_NaN<double>;
78  /// Last x value of underlying data.
79  double last_x_ = smash_NaN<double>;
80  /// First y value of underlying data.
81  double first_y_ = smash_NaN<double>;
82  /// Last y value of underlying data.
83  double last_y_ = smash_NaN<double>;
84 
85  /// GSL iterator for interpolation lookups in x direction.
86  gsl_interp_accel* xacc_ = nullptr;
87  /// GSL iterator for interpolation lookupin y direction.
88  gsl_interp_accel* yacc_ = nullptr;
89  /// GSL spline in 2D.
90  gsl_spline2d* spline_ = nullptr;
91 };
92 
93 } // namespace smash
94 
95 #endif // SRC_INCLUDE_SMASH_INTERPOLATION2D_H_
Represent a bicubic spline interpolation.
ExtrapolationType extrapolation_type_
Extrapolation type.
double first_y_
First y value of underlying data.
double last_y_
Last y value of underlying data.
double last_x_
Last x value of underlying data.
double operator()(double xi, double yi) const
Calculate bicubic interpolation for given x and y.
gsl_interp_accel * xacc_
GSL iterator for interpolation lookups in x direction.
InterpolateData2DSpline(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, ExtrapolationType extrapolation_type=ExtrapolationType::None)
Interpolate function f given discrete samples f(x_i, y_i) = z_i.
gsl_spline2d * spline_
GSL spline in 2D.
double first_x_
First x value of underlying data.
gsl_interp_accel * yacc_
GSL iterator for interpolation lookupin y direction.
Collection of useful constants that are known at compile time.
ExtrapolationType
Allows to specify the desired extrapolation type.
@ None
No extrapolation is done.
Definition: action.h:24