Thermal-FIST 1.5
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
BilinearSplineFunction.h
Go to the documentation of this file.
1/*
2 * Thermal-FIST package
3 *
4 * Copyright (c) 2014-2019 Volodymyr Vovchenko
5 *
6 * GNU General Public License (GPLv3 or later)
7 */
8#ifndef BILINEARSPLINEFUNCTION_H
9#define BILINEARSPLINEFUNCTION_H
10#include <stdexcept>
11
13
14namespace thermalfist {
15
17
23 {
24 public:
28 BilinearSplineFunction(void) : m_xs(), m_xspls() {
29 m_xs.resize(0);
30 m_xspls.resize(0);
31 }
32
43 BilinearSplineFunction(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &vals)
44 : m_xs(), m_xspls() {
45 setData(x, y, vals);
46 }
47
58 void setData(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &vals) {
59 if (x.size() > 0) {
60 m_xs.resize(0);
61 m_xspls.resize(0);
62 double cx = -1e50;
63 for (unsigned int i = 0; i < x.size(); ++i) {
64 if (fabs(x[i] - cx) > 1e-6) {
65 m_xspls.push_back(SplineFunction());
66 m_xs.push_back(x[i]);
67 m_xspls[m_xspls.size() - 1].add_val(y[i], vals[i]);
68 cx = x[i];
69 }
70 else {
71 m_xspls[m_xspls.size() - 1].add_val(y[i], vals[i]);
72 }
73 }
74 }
75 }
76
78 double Eval(double x, double y) const {
79 if (m_xs.size() < 2) throw std::runtime_error("Insufficient data points for interpolation.");
80 std::vector< double >::const_iterator it = std::lower_bound(m_xs.begin(), m_xs.end(), x);
81 unsigned int indx = std::distance(m_xs.begin(), it);
82 int ind1 = 0, ind2 = 0;
83 if (indx == 0) {
84 ind1 = 0;
85 ind2 = 1;
86 }
87 else if (indx == m_xs.size()) {
88 ind1 = indx - 2;
89 ind2 = indx - 1;
90 }
91 else {
92 ind1 = indx - 1;
93 ind2 = indx;
94 }
95 double f1v = m_xspls[ind1].f(y);
96 double f2v = m_xspls[ind2].f(y);
97 return f1v + (x - m_xs[ind1]) * (f2v - f1v) / (m_xs[ind2] - m_xs[ind1]);
98 }
99
101 ~BilinearSplineFunction(void) = default;
102
103 private:
104 std::vector<double> m_xs;
105 std::vector<SplineFunction> m_xspls;
106 };
107
108} // namespace thermalfist
109
110#endif
void setData(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &vals)
BilinearSplineFunction(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &vals)
~BilinearSplineFunction(void)=default
Destructor.
double Eval(double x, double y) const
Evaluates interpolated f(x,y)
Class implementing a simple linear spline.
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9