OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
LinearSpline.h
Go to the documentation of this file.
1//
2// Linear Spline Interpolation to replace GSL spline
3//
4// Copyright (c) 2023, Paul Scherrer Institute, Villigen PSI, Switzerland
5// All rights reserved
6//
7// This file is part of OPAL.
8//
9// OPAL is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// You should have received a copy of the GNU General License
15// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16//
17
18#ifndef OPALX_LINEAR_SPLINE_H
19#define OPALX_LINEAR_SPLINE_H
20
21#include <vector>
22#include "AbstractSpline.h"
23
24// \brief Linear spline interpolation class that implements an equivelent of
25// the gsl_interp_linear mode of the GSL spline class
26class LinearSpline final : public AbstractSpline {
27public:
29 LinearSpline() = default;
30
34 LinearSpline(const std::vector<double>& x, const std::vector<double>& y);
35
39 void init(const std::vector<double>& x, const std::vector<double>& y) override;
40
45 double eval(double x, Accelerator& accel) const override;
46
52 double evalIntegral(double xa, double xb, Accelerator& accel) const override;
53
54private:
57
59 void computeIntegrals();
60
65 [[nodiscard]] double integral(size_t i, double dx) const;
66
70 [[nodiscard]] double extrapolateLeft(double x) const;
71
75 [[nodiscard]] double extrapolateRight(double x) const;
76
77 // Members
78 std::vector<double> m_{}; // Gradients
79 std::vector<double> c_{}; // Constants
80 std::vector<double> integrals_{};
81};
82
83#endif // OPALX_LINEAR_SPLINE_H
Accelerator caching last interval indices.
Base class for the linear and cubic interpolation spline classes.
std::vector< double > integrals_
LinearSpline()=default
Default constructor.
std::vector< double > m_
double evalIntegral(double xa, double xb, Accelerator &accel) const override
Evaluate the integral of the spline at x.
double extrapolateRight(double x) const
Linear extrapolation to the right of the data range.
double extrapolateLeft(double x) const
Linear extrapolation to the left of the data range.
void computeCoefficients()
Compute linear spline coefficients.
std::vector< double > c_
double integral(size_t i, double dx) const
Calculate the integral from x_[i] to x_[i]+dx.
void computeIntegrals()
Compute the integrals of the intervals.
void init(const std::vector< double > &x, const std::vector< double > &y) override
Initialize from tabulated data (natural spline).
double eval(double x, Accelerator &accel) const override
Evaluate the spline at x using an accelerator.