OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
AbstractSpline.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 OPALX_ABSTRACTSPLINE_H
19#define OPALX_ABSTRACTSPLINE_H
20
21#include <vector>
22#include "OPALTypes.h"
23
26public:
28 AbstractSpline() = default;
29
31 virtual ~AbstractSpline() = default;
32
33 // Accelerator for repeated evaluations (compatible with GSL interface)
36 public:
37 Accelerator() = default;
38 size_t last_index_{};
40 void reset() {
41 last_index_ = 0;
43 }
44 };
45
49 virtual void init(const std::vector<double>& x, const std::vector<double>& y);
50
55 virtual double eval(double x, Accelerator& accel) const = 0;
56
62 virtual double evalIntegral(double xa, double xb, Accelerator& accel) const = 0;
63
64protected:
70 size_t findInterval(double x, size_t& intervalCache) const;
71
72 // Members
73 std::vector<double> x_{};
74 std::vector<double> y_{};
75};
76
77#endif // OPALX_ABSTRACTSPLINE_H
Accelerator caching last interval indices.
Base class for the linear and cubic interpolation spline classes.
virtual double eval(double x, Accelerator &accel) const =0
Evaluate the spline at x using an accelerator.
virtual void init(const std::vector< double > &x, const std::vector< double > &y)
Initialize from tabulated data (natural spline).
size_t findInterval(double x, size_t &intervalCache) const
Return the interval index for the given x-coordinate, using the supplied cached value if possible.
AbstractSpline()=default
Default constructor.
virtual double evalIntegral(double xa, double xb, Accelerator &accel) const =0
Evaluate the integral of the spline at x.
virtual ~AbstractSpline()=default
Polymorphic destructor.
std::vector< double > x_
std::vector< double > y_