Template Class Interpolator1D
Defined in File Interpolator1D.hpp
Class Documentation
-
template<size_t NF = 1>
class Interpolator1D A class to handle 1D interpolation.
- Template Parameters:
NF – Number of quantities to interpolate
Public Types
-
using PostProcess = void (*)(std::array<double, NF>&)
Type of a function that post-processes the interpolated values at a point.
Takes the full array of NF interpolated values at a single point and modifies it in place – see setPostProcess().
Public Functions
-
inline Interpolator1D(const std::vector<double> &x, const std::array<std::vector<double>, NF> &f, const gsl_interp_type *interpType = gsl_interp_steffen)
Construct an Interpolator1D.
- Parameters:
x – Locations of sample points to be interpolated
f – Values of sample points to be interpolated
interpType – The type of interpolation to use
-
inline Interpolator1D(const std::vector<double> &x, const std::vector<double> &f, const gsl_interp_type *interpType = gsl_interp_steffen)
-
inline virtual ~Interpolator1D()
-
Interpolator1D(const Interpolator1D&) = delete
-
auto operator=(const Interpolator1D&) -> Interpolator1D& = delete
-
Interpolator1D(Interpolator1D&&) = delete
-
auto operator=(Interpolator1D&&) -> Interpolator1D& = delete
-
inline auto xMin() const
Get minimum allowed x.
- Returns:
Minimum allowed x
-
inline auto xMax() const
Get maximum allowed x.
- Returns:
Maximum allowed x
-
inline auto xRange() const
Get allowed range in x.
- Returns:
Allowed range in x
-
inline void setPostProcess(const PostProcess postProcess)
Set a function to apply to the interpolated values at every point.
When set, every point evaluation – operator()(x), and operator()(x, idx), which then evaluates every quantity so that postProcess sees all of them together – passes its full array of interpolated values through postProcess before returning. This exists for constraints that tie quantities together, which interpolating each quantity independently cannot respect on its own: e.g. stellar surface mass fractions, whose sum independent (even monotonicity- preserving) interpolation can push above 1 between sample points (see tracks::renormalizeSurfaceAbundances()). The integ() methods are unaffected, since a constraint on point values does not in general translate into one on integrals.
- Parameters:
postProcess – The function to apply, or nullptr (the default) for none
-
inline auto operator()(double x) const
Interpolate to a given point.
Return type is a double if NF = 1, and a std::array otherwise.
- Parameters:
x – The point to which to interpolate
- Returns:
The interpolated value(s), passed through the function set by setPostProcess(), if any
-
inline auto operator()(double x, size_t idx) const
Interpolate a single quantity to a given point.
- Parameters:
x – The point to which to interpolate
idx – Quantity to interpolate; must be <= NF
- Returns:
The interpolated value, consistent with operator()(x)[idx] – including any post-processing set by setPostProcess()
-
inline auto integ(double x0, double x1) const
Integrate the interpolant over [x0, x1].
Return type is a double if NF = 1, and a std::array otherwise – mirrors operator()(double) exactly, except that each quantity’s interpolant is integrated over [x0, x1] (via gsl_interp_eval_integ) rather than evaluated at a single point.
- Parameters:
x0 – Lower limit of integration
x1 – Upper limit of integration
- Returns:
The integral value(s)
-
inline auto integ(double x0, double x1, size_t idx) const
Integrate a single quantity’s interpolant over [x0, x1].
- Parameters:
x0 – Lower limit of integration
x1 – Upper limit of integration
idx – Quantity to integrate; must be <= NF
- Returns:
The integral value
-
inline auto integ(const Interpolator1D &g, double x0, double x1, size_t idx) const -> double
Integrate the product f(x)*g(x) over [x0, x1] for a single field.
Evaluates \(\int_{x_0}^{x_1} f_\mathrm{idx}(x)\, g_\mathrm{idx}(x)\, dx\) where \(f(x)\) is this Interpolator1D and \(g(x)\) is a second Interpolator1D. Both Interpolator1D objects are required to have the same NF – this is guaranteed at compile time by the template signature. The integration range is the intersection of [x0, x1] with both interpolators’ domains; returns 0 if that intersection is empty.
- Parameters:
g – A second Interpolator1D; must have the same NF as this one
x0 – Lower limit of integration
x1 – Upper limit of integration
idx – Field index to integrate; must be < NF
- Returns:
The integral value as a double
-
inline auto integ(const Interpolator1D &g, double x0, double x1) const
Integrate the product f(x)*g(x) over [x0, x1] for all fields.
Evaluates \(\int_{x_0}^{x_1} f(x)\, g(x)\, dx\) where \(f(x)\) is this Interpolator1D and \(g(x)\) is a second Interpolator1D. Both Interpolator1D objects are required to have the same NF – this is guaranteed at compile time by the template signature. The integration range is the intersection of [x0, x1] with both interpolators’ domains; returns 0 (or an array of zeros) if that intersection is empty. Return type mirrors integ(double, double): a double if NF = 1, a std::array<double, NF> otherwise.
- Parameters:
g – A second Interpolator1D; must have the same NF as this one
x0 – Lower limit of integration
x1 – Upper limit of integration
- Returns:
The integral value(s)