Thermal-FIST 1.5
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
SplineFunction.h
Go to the documentation of this file.
1/*
2 * * GNU General Public License (GPLv3 or later)
3 */
4#ifndef SPLINEFUNCTION_H
5#define SPLINEFUNCTION_H
6
7#include <vector>
8#include <algorithm>
9#include <cmath>
10
11namespace thermalfist {
12
14
21 {
22 public:
26 SplineFunction() : m_vals(0) {
27 }
28
36 SplineFunction(std::vector<double> x, std::vector<double> y) : m_vals(0) {
37 for (unsigned int i = 0; i < x.size(); ++i)
38 {
39 m_vals.push_back(std::make_pair(x[i], y[i]));
40 }
41 sort(m_vals.begin(), m_vals.end());
42 }
43
52 void add_val(double x, double val)
53 {
54 m_vals.push_back(std::make_pair(x, val));
55 sort(m_vals.begin(), m_vals.end());
56 }
57
66 double f(double arg) const
67 {
68 std::pair<double, double> op = std::make_pair(arg, 0.);
69 std::vector< std::pair<double, double> >::const_iterator it = std::lower_bound(m_vals.begin(), m_vals.end(), op);
70 unsigned int ind = distance(m_vals.begin(), it);
71
72 if (ind == 0) return m_vals[0].second +
73 (arg - m_vals[0].first) *
74 (m_vals[1].second - m_vals[0].second) / (m_vals[1].first - m_vals[0].first);
75
76 if (ind == m_vals.size()) return m_vals[ind - 2].second +
77 (arg - m_vals[ind - 2].first) *
78 (m_vals[ind - 1].second - m_vals[ind - 2].second) / (m_vals[ind - 1].first - m_vals[ind - 2].first);
79
80 return m_vals[ind - 1].second +
81 (arg - m_vals[ind - 1].first) *
82 (m_vals[ind].second - m_vals[ind - 1].second) / (m_vals[ind].first - m_vals[ind - 1].first);
83 }
84
93 double df(double arg) const {
94 unsigned int ind = 0;
95 std::pair<double, double> op = std::make_pair(arg, 0.);
96 std::vector< std::pair<double, double> >::const_iterator it = std::lower_bound(m_vals.begin(), m_vals.end(), op);
97 ind = std::distance(m_vals.begin(), it);
98 if (ind == 0)
99 return (m_vals[1].second - m_vals[0].second) / (m_vals[1].first - m_vals[0].first);
100 if (ind == m_vals.size())
101 return (m_vals[ind - 1].second - m_vals[ind - 2].second) / (m_vals[ind - 1].first - m_vals[ind - 2].first);
102 return (m_vals[ind].second - m_vals[ind - 1].second) / (m_vals[ind].first - m_vals[ind - 1].first);
103 }
104
113 double fsquare(double arg) {
114 double ret = f(arg);
115 return ret * ret;
116 }
117
122 void clear() {
123 m_vals.resize(2);
124 m_vals[0].first = 0.;
125 m_vals[0].second = 0.;
126 m_vals[1].first = 1.;
127 m_vals[1].second = 0.;
128 }
129
133 void clearall() {
134 m_vals.resize(0);
135 }
136
144 void fill(std::vector<double> x, std::vector<double> y) {
145 m_vals.resize(0);
146 for (unsigned int i = 0; i < x.size(); ++i)
147 {
148 m_vals.push_back(std::make_pair(x[i], y[i]));
149 }
150 sort(m_vals.begin(), m_vals.end());
151 }
152
160 void setConstant(double val) {
161 m_vals.resize(0);
162 m_vals.push_back(std::make_pair(0., val));
163 m_vals.push_back(std::make_pair(1., val));
164 }
165
166 // TODO: Read (x,y) pairs from file.
167 //void loadFromFile(const char *file);
168
169 private:
170 std::vector< std::pair<double, double> > m_vals;
171 };
172
173} // namespace thermalfist
174
175#endif // SPLINEFUNCTION_H
double df(double arg) const
double f(double arg) const
void fill(std::vector< double > x, std::vector< double > y)
SplineFunction(std::vector< double > x, std::vector< double > y)
void add_val(double x, double val)
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9