34 std::vector<double>
y;
36 std::vector<double>
d2y;
52 inline double Deriv(
double x);
54 inline double Deriv2(
double x);
56 inline double Deriv3(
double x);
59 inline std::vector<double>&
Data() {
return y; }
63 inline void Init(
SimpleGrid& newGrid, std::vector<double> yvals,
double startderiv,
double endderiv)
69 std::cerr <<
"Size mismatch in CubSpline.\n";
70 std::cerr <<
"Grid Points = " << newGrid.
NumPoints() << std::endl;
71 std::cerr <<
"Y points = " << yvals.size() << std::endl;
86 Init(newGrid, yvals, 5.0e30, 5.0e30);
94 Init(newGrid, yvals, 5.0e30, 5.0e30);
101 Init(newGrid, yvals, startderiv, endderiv);
131 if (x < (X.
End() * 1.000000001))
135 std::cerr <<
"x outside grid in CubSpline.\n";
136 std::cerr <<
"x = " << x <<
" X.End = " << X.
End() <<
"\n";
154 double h = X[hi] - X[low];
155 double hinv = 1.0 / h;
156 double a = (X[hi] - x) * hinv;
157 double b = (x - X[low]) * hinv;
158 double sixinv = 0.1666666666666666666;
160 return (a *
y[low] + b *
y[hi] + ((a * a * a - a) *
d2y[low] + (b * b * b - b) *
d2y[hi]) * (h * h * sixinv));
182 double h = X[hi] - X[low];
183 double hinv = 1.0 / h;
184 double a = (X[hi] - x) * hinv;
185 double b = (x - X[low]) * hinv;
186 double sixinv = 0.1666666666666666666;
188 return ((
y[hi] -
y[low]) * hinv + (h * sixinv) * ((3.0 * b * b - 1.0) *
d2y[hi] - (3.0 * a * a - 1.0) *
d2y[low]));
210 double h = X[hi] - X[low];
211 double hinv = 1.0 / h;
212 double a = (X[hi] - x) * hinv;
213 double b = (x - X[low]) * hinv;
214 return (a *
d2y[low] + b *
d2y[hi]);
236 double h = X[hi] - X[low];
238 return ((
d2y[hi] -
d2y[low]) / h);
double & operator()(int i)
Returns a reference to the value at the ith grid point.
The CubSpline class is a third-order spline representation of a function.
std::vector< double > & Data()
double Deriv2(double x)
Returns the interpolated second derivative.
int size()
Returns the interpolated value.
CubSpline()
Trivial constructor.
bool UpToDate
This flag records whether or not the stored second derivatives are in sync with the function values...
void Init(SimpleGrid &newGrid, std::vector< double > &yvals)
Simplified form which assumes that the second derivative at both boundaries are zero.
double StartDeriv
The values of the derivative of the represented function on the boundary.
double Deriv3(double x)
Returns the interpolated third derivative.
double operator()(double x)
void Update()
Recompute the second derivatives from the function values.
CubSpline(SimpleGrid &newGrid, std::vector< double > &yvals)
Simplified constructor.
std::vector< double > d2y
The second derivatives of the function.
int ReverseMap(double r)
Returns the index of the nearest point below r.
void Init(SimpleGrid &newGrid, std::vector< double > yvals, double startderiv, double endderiv)
Initialize the cubic spline.
std::vector< double > y
The function values on the grid points.
CubSpline(SimpleGrid &newGrid, std::vector< double > &yvals, double startderiv, double endderiv)
Full constructor.
double Deriv(double x)
Returns the interpolated first derivative.
double operator()(int i) const
Returns the value of the function at the ith grid point.