17 #ifndef CUBIC_SPLINE_COMMON_H 18 #define CUBIC_SPLINE_COMMON_H 42 std::shared_ptr<Grid>
grid;
54 inline double Deriv(
double x);
56 inline double Deriv2(
double x);
58 inline double Deriv3(
double x);
64 inline void Init(std::shared_ptr<Grid>& NewGrid,
Array<double, 1> NewYs,
double startderiv,
double endderiv)
68 if (NewGrid->NumPoints != NewYs.
rows())
70 std::cerr <<
"Size mismatch in CubicSplineCommon.\n";
71 std::cerr <<
"Grid Points = " << NewGrid->NumPoints << std::endl;
72 std::cerr <<
"Y points = " << NewYs.
rows() << std::endl;
91 Init(NewGrid, NewYs, 5.0e30, 5.0e30);
97 Init(NewGrid, NewYs, startderiv, endderiv);
111 inline double Params(
int i)
const {
return (
y(i)); }
113 inline double&
Params(
int i) {
return (
y(i)); }
121 grid->Write(outSection);
168 if (x < (X.
End * 1.000000001))
172 std::cerr <<
"x outside grid in CubicSplineCommon.\n";
173 std::cerr <<
"x = " << x <<
" X.End = " << X.
End <<
"\n";
191 double h = X(hi) - X(low);
192 double hinv = 1.0 / h;
193 double a = (X(hi) - x) * hinv;
194 double b = (x - X(low)) * hinv;
195 double sixinv = 0.1666666666666666666;
197 return (a *
y(low) + b *
y(hi) + ((a * a * a - a) *
d2y(low) + (b * b * b - b) *
d2y(hi)) * (h * h * sixinv));
219 double h = X(hi) - X(low);
220 double hinv = 1.0 / h;
221 double a = (X(hi) - x) * hinv;
222 double b = (x - X(low)) * hinv;
223 double sixinv = 0.1666666666666666666;
225 return ((
y(hi) -
y(low)) * hinv + (h * sixinv) * ((3.0 * b * b - 1.0) *
d2y(hi) - (3.0 * a * a - 1.0) *
d2y(low)));
247 double h = X(hi) - X(low);
248 double hinv = 1.0 / h;
249 double a = (X(hi) - x) * hinv;
250 double b = (x - X(low)) * hinv;
251 return (a *
d2y(low) + b *
d2y(hi));
273 double h = X(hi) - X(low);
275 return ((
d2y(hi) -
d2y(low)) / h);
double Params(int i) const
Returns the value of the function at the ith grid point.
Array< double, 1 > d2y
The second derivatives of the function.
std::shared_ptr< Grid > ReadGrid(IOSectionClass &inSection)
void Write(IOSectionClass &outSection)
bool OpenSection(std::string name, int num=0)
Opens the num'th section with the given name.
double StartDeriv
The values of the derivative of the represented function on the boundary.
double Deriv2(double x)
Returns the interpolated second derivative.
Parent class for all grids.
int UpToDate
This flag records whether or not the stored second derivatives are in sync with the function values...
std::shared_ptr< Grid > grid
int NumPoints
Number of points in the grid.
void Read(IOSectionClass &inSection)
void Init(std::shared_ptr< Grid > &NewGrid, Array< double, 1 > NewYs)
Simplified form which assumes that the second derivative at both boundaries are zero.
The CubicSplineCommon class is a third-order spline representation of a function. ...
bool WriteVar(std::string name, T val)
Writes a variable under the current section.
void CloseSection()
Closes the current section.
void NewSection(std::string name)
Creates a new section of the same type as currentSection under currentSection.
void resize(const std::array< SIZET, D > &dims)
Resize the container.
Array< double, 1 > y
The function values on the grid points.
void Update()
Recompute the second derivatives from the function values.
double & operator()(int i)
Returns a reference to the value at the ith grid point.
CubicSplineCommon(std::shared_ptr< Grid > &NewGrid, Array< double, 1 > NewYs, double startderiv, double endderiv)
Full constructor.
void Init(std::shared_ptr< Grid > &NewGrid, Array< double, 1 > NewYs, double startderiv, double endderiv)
Initialize the cubic spline.
virtual int ReverseMap(double r)=0
Returns the index of the nearest point below r.
Array< double, 1 > & Data()
int size()
Returns the interpolated value.
CubicSplineCommon & operator=(const CubicSplineCommon &spline)
CubicSplineCommon(std::shared_ptr< Grid > &NewGrid, Array< double, 1 > NewYs)
Simplified constructor.
Wrapper class for IOTreeClass that gives a nearly identical interface as the OutputSectionClass.
double operator()(double x)
double operator()(int i) const
Returns the value of the function at the ith grid point.
CubicSplineCommon()
Trivial constructor.
double Deriv(double x)
Returns the interpolated first derivative.
bool ReadVar(std::string name, T &var)
Template function which reads a variable in the present section into the passed-by-reference T variab...
double & Params(int i)
Returns a reference to the value at the ith grid point.
double Deriv3(double x)
Returns the interpolated third derivative.