OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
CubicSpline.h
Go to the documentation of this file.
1//
2// Cubic 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 OPAL_CUBIC_SPLINE_HH
19#define OPAL_CUBIC_SPLINE_HH
20
21#include <vector>
22#include "AbstractSpline.h"
23
26// Simple cubic spline interpolation class to replace GSL spline
28class CubicSpline final : public AbstractSpline {
29public:
31 CubicSpline() = default;
32
36 CubicSpline(const std::vector<double>& x, const std::vector<double>& y);
37
41 void init(const std::vector<double>& x, const std::vector<double>& y) override;
42
47 double eval(double x, Accelerator& accel) const override;
48
54 double evalIntegral(double xa, double xb, Accelerator& accel) const override;
55
56private:
59
61 void computeIntegrals();
62
67 [[nodiscard]] double integral(size_t i, double dx) const;
68
72 [[nodiscard]] double extrapolateLeft(double x) const;
73
77 [[nodiscard]] double extrapolateRight(double x) const;
78
79 std::vector<double> b_; // Linear coefficients
80 std::vector<double> c_; // Quadratic coefficients
81 std::vector<double> d_; // Cubic coefficients
82 std::vector<double> integrals_;
83};
84
85#endif // OPAL_CUBIC_SPLINE_HH
Accelerator caching last interval indices.
Base class for the linear and cubic interpolation spline classes.
Natural cubic spline interpolator.
Definition CubicSpline.h:28
void computeIntegrals()
Compute the integrals of the intervals.
double evalIntegral(double xa, double xb, Accelerator &accel) const override
Evaluate the integral of the spline at x.
void init(const std::vector< double > &x, const std::vector< double > &y) override
Initialize from tabulated data (natural spline).
void computeCoefficients()
Compute natural spline coefficients.
double extrapolateLeft(double x) const
Linear extrapolation to the left of the data range.
double extrapolateRight(double x) const
Linear extrapolation to the right of the data range.
CubicSpline()=default
Default constructor.
std::vector< double > b_
Definition CubicSpline.h:79
double eval(double x, Accelerator &accel) const override
Evaluate the spline at x using an accelerator.
double integral(size_t i, double dx) const
Calculate the integral from x_[i] to x_[i]+dx.
std::vector< double > c_
Definition CubicSpline.h:80
std::vector< double > d_
Definition CubicSpline.h:81
std::vector< double > integrals_
Definition CubicSpline.h:82