This class interpolates tabulated functions with a bi-cubic spline. More...
#include <BicubicSplineInterpolation.h>
Public Member Functions | |
BicubicSplineInterpolation () | |
BicubicSplineInterpolation (const std::vector< Real > &x1, const std::vector< Real > &x2, const std::vector< std::vector< Real >> &y, const std::vector< Real > &yx11=std::vector< Real >(), const std::vector< Real > &yx1n=std::vector< Real >(), const std::vector< Real > &yx21=std::vector< Real >(), const std::vector< Real > &yx2n=std::vector< Real >()) | |
In the future, may add interface that allows necessary vector of boundary conditions to be supplied for each edge of grid; however, for now we just use natural splines at the grid boundaries. More... | |
virtual | ~BicubicSplineInterpolation ()=default |
void | setData (const std::vector< Real > &x1, const std::vector< Real > &x2, const std::vector< std::vector< Real >> &y, const std::vector< Real > &yx11=std::vector< Real >(), const std::vector< Real > &yx1n=std::vector< Real >(), const std::vector< Real > &yx21=std::vector< Real >(), const std::vector< Real > &yx2n=std::vector< Real >()) |
Set the x1, x2 and y values, and first derivatives at the edges. More... | |
void | errorCheck () |
Sanity checks on input data. More... | |
Real | sample (Real x1, Real x2, Real yx11=_deriv_bound, Real yx1n=_deriv_bound) |
Samples value at point (x1, x2) More... | |
void | sampleValueAndDerivatives (Real x1, Real x2, Real &y, Real &dy1, Real &dy2, Real yx11=_deriv_bound, Real yx1n=_deriv_bound, Real yx21=_deriv_bound, Real yx2n=_deriv_bound) |
Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both value and derivatives, as it minimizes the amount of spline evaluation. More... | |
Real | sampleDerivative (Real x1, Real x2, unsigned int deriv_var, Real yp1=_deriv_bound, Real ypn=_deriv_bound) |
Samples first derivative at point (x1, x2) More... | |
Real | sample2ndDerivative (Real x1, Real x2, unsigned int deriv_var, Real yp1=_deriv_bound, Real ypn=_deriv_bound) |
Samples second derivative at point (x1, x2) More... | |
Real | sample (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const |
ADReal | sample (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, const ADReal &x_int) const |
Real | sampleDerivative (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const |
Real | sample2ndDerivative (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, Real x_int) const |
Protected Member Functions | |
void | constructRowSplineSecondDerivativeTable () |
Precompute tables of row (column) spline second derivatives and store them to reduce computational demands. More... | |
void | constructColumnSplineSecondDerivativeTable () |
void | solve () |
Calculates the tables of second derivatives. More... | |
void | constructRowSpline (Real x1, std::vector< Real > &spline_eval, std::vector< Real > &spline_second_derivs, Real yx11=_deriv_bound, Real yx1n=_deriv_bound) |
Helper functions to evaluate column splines and construct row spline for the given point. More... | |
void | constructColumnSpline (Real x2, std::vector< Real > &spline_eval, std::vector< Real > &spline_second_derivs, Real yx21=_deriv_bound, Real yx2n=_deriv_bound) |
Helper functions to evaluate row splines and construct column spline for the given point. More... | |
template<typename T > | |
T | sample (const std::vector< Real > &x, const std::vector< Real > &y, const std::vector< Real > &y2, const T &x_int, unsigned int klo, unsigned int khi) const |
Sample value at point x_int given the indices of the vector of dependent values that bound the point. More... | |
void | spline (const std::vector< Real > &x, const std::vector< Real > &y, std::vector< Real > &y2, Real yp1=_deriv_bound, Real ypn=_deriv_bound) |
This function calculates the second derivatives based on supplied x and y-vectors. More... | |
void | findInterval (const std::vector< Real > &x, Real x_int, unsigned int &klo, unsigned int &khi) const |
template<typename T > | |
void | computeCoeffs (const std::vector< Real > &x, unsigned int klo, unsigned int khi, const T &x_int, Real &h, T &a, T &b) const |
Protected Attributes | |
std::vector< Real > | _x1 |
Independent values in the x1 direction. More... | |
std::vector< Real > | _x2 |
Independent values in the x2 direction. More... | |
std::vector< std::vector< Real > > | _y |
The dependent values at (x1, x2) points. More... | |
std::vector< std::vector< Real > > | _y_trans |
Transpose of _y. More... | |
std::vector< Real > | _yx11 |
Boundary conditions. More... | |
std::vector< Real > | _yx1n |
std::vector< Real > | _yx21 |
std::vector< Real > | _yx2n |
std::vector< std::vector< Real > > | _y2_rows |
Second derivatives. More... | |
std::vector< std::vector< Real > > | _y2_columns |
std::vector< Real > | _row_spline_second_derivs |
Vectors used during sampling. More... | |
std::vector< Real > | _row_spline_eval |
std::vector< Real > | _column_spline_second_derivs |
std::vector< Real > | _column_spline_eval |
Static Protected Attributes | |
static int | _file_number = 0 |
File number for data dump. More... | |
static const Real | _deriv_bound = std::numeric_limits<Real>::max() |
This class interpolates tabulated functions with a bi-cubic spline.
Adopted from Numerical Recipes in C (section 3.6). Consistent with the terminology in Numerical Recipes, moving over a column spline means moving over the x1 coord Likewise, moving over a row spline means moving over the x2 coord
Definition at line 22 of file BicubicSplineInterpolation.h.
BicubicSplineInterpolation::BicubicSplineInterpolation | ( | ) |
Definition at line 15 of file BicubicSplineInterpolation.C.
BicubicSplineInterpolation::BicubicSplineInterpolation | ( | const std::vector< Real > & | x1, |
const std::vector< Real > & | x2, | ||
const std::vector< std::vector< Real >> & | y, | ||
const std::vector< Real > & | yx11 = std::vector<Real>() , |
||
const std::vector< Real > & | yx1n = std::vector<Real>() , |
||
const std::vector< Real > & | yx21 = std::vector<Real>() , |
||
const std::vector< Real > & | yx2n = std::vector<Real>() |
||
) |
In the future, may add interface that allows necessary vector of boundary conditions to be supplied for each edge of grid; however, for now we just use natural splines at the grid boundaries.
Definition at line 17 of file BicubicSplineInterpolation.C.
|
virtualdefault |
|
protectedinherited |
Definition at line 85 of file SplineInterpolationBase.C.
Referenced by SplineInterpolationBase::sample(), SplineInterpolationBase::sample2ndDerivative(), and SplineInterpolationBase::sampleDerivative().
|
protected |
Helper functions to evaluate row splines and construct column spline for the given point.
Definition at line 278 of file BicubicSplineInterpolation.C.
Referenced by sample(), sample2ndDerivative(), sampleDerivative(), and sampleValueAndDerivatives().
|
protected |
Definition at line 127 of file BicubicSplineInterpolation.C.
Referenced by solve().
|
protected |
Helper functions to evaluate column splines and construct row spline for the given point.
Definition at line 254 of file BicubicSplineInterpolation.C.
Referenced by sample2ndDerivative(), sampleDerivative(), and sampleValueAndDerivatives().
|
protected |
Precompute tables of row (column) spline second derivatives and store them to reduce computational demands.
Definition at line 112 of file BicubicSplineInterpolation.C.
Referenced by solve().
void BicubicSplineInterpolation::errorCheck | ( | ) |
Sanity checks on input data.
Definition at line 75 of file BicubicSplineInterpolation.C.
Referenced by BicubicSplineInterpolation(), and setData().
|
protectedinherited |
Definition at line 65 of file SplineInterpolationBase.C.
Referenced by constructColumnSpline(), constructRowSpline(), SplineInterpolationBase::sample(), SplineInterpolationBase::sample2ndDerivative(), and SplineInterpolationBase::sampleDerivative().
|
inherited |
Definition at line 101 of file SplineInterpolationBase.C.
Referenced by constructColumnSpline(), constructRowSpline(), SplineInterpolationBase::sample(), SplineInterpolation::sample(), sample(), and sampleValueAndDerivatives().
|
inherited |
Definition at line 113 of file SplineInterpolationBase.C.
Real BicubicSplineInterpolation::sample | ( | Real | x1, |
Real | x2, | ||
Real | yx11 = _deriv_bound , |
||
Real | yx1n = _deriv_bound |
||
) |
Samples value at point (x1, x2)
Definition at line 159 of file BicubicSplineInterpolation.C.
Referenced by BicubicSplineFunction::value().
|
protectedinherited |
Sample value at point x_int given the indices of the vector of dependent values that bound the point.
This method is useful in bicubic spline interpolation, where several spline evaluations are needed to sample from a 2D point.
Definition at line 157 of file SplineInterpolationBase.C.
|
inherited |
Definition at line 141 of file SplineInterpolationBase.C.
Referenced by SplineInterpolation::sample2ndDerivative(), and sample2ndDerivative().
Real BicubicSplineInterpolation::sample2ndDerivative | ( | Real | x1, |
Real | x2, | ||
unsigned int | deriv_var, | ||
Real | yp1 = _deriv_bound , |
||
Real | ypn = _deriv_bound |
||
) |
Samples second derivative at point (x1, x2)
Definition at line 202 of file BicubicSplineInterpolation.C.
Referenced by BicubicSplineFunction::secondDerivative().
|
inherited |
Definition at line 125 of file SplineInterpolationBase.C.
Referenced by SplineInterpolation::sampleDerivative(), sampleDerivative(), and sampleValueAndDerivatives().
Real BicubicSplineInterpolation::sampleDerivative | ( | Real | x1, |
Real | x2, | ||
unsigned int | deriv_var, | ||
Real | yp1 = _deriv_bound , |
||
Real | ypn = _deriv_bound |
||
) |
Samples first derivative at point (x1, x2)
Definition at line 171 of file BicubicSplineInterpolation.C.
Referenced by BicubicSplineFunction::derivative().
void BicubicSplineInterpolation::sampleValueAndDerivatives | ( | Real | x1, |
Real | x2, | ||
Real & | y, | ||
Real & | dy1, | ||
Real & | dy2, | ||
Real | yx11 = _deriv_bound , |
||
Real | yx1n = _deriv_bound , |
||
Real | yx21 = _deriv_bound , |
||
Real | yx2n = _deriv_bound |
||
) |
Samples value and first derivatives at point (x1, x2) Use this function for speed when computing both value and derivatives, as it minimizes the amount of spline evaluation.
Definition at line 233 of file BicubicSplineInterpolation.C.
void BicubicSplineInterpolation::setData | ( | const std::vector< Real > & | x1, |
const std::vector< Real > & | x2, | ||
const std::vector< std::vector< Real >> & | y, | ||
const std::vector< Real > & | yx11 = std::vector<Real>() , |
||
const std::vector< Real > & | yx1n = std::vector<Real>() , |
||
const std::vector< Real > & | yx21 = std::vector<Real>() , |
||
const std::vector< Real > & | yx2n = std::vector<Real>() |
||
) |
Set the x1, x2 and y values, and first derivatives at the edges.
Definition at line 46 of file BicubicSplineInterpolation.C.
Referenced by BicubicSplineFunction::BicubicSplineFunction().
|
protected |
Calculates the tables of second derivatives.
Definition at line 152 of file BicubicSplineInterpolation.C.
Referenced by BicubicSplineInterpolation(), and setData().
|
protectedinherited |
This function calculates the second derivatives based on supplied x and y-vectors.
Definition at line 19 of file SplineInterpolationBase.C.
Referenced by constructColumnSpline(), constructColumnSplineSecondDerivativeTable(), constructRowSpline(), constructRowSplineSecondDerivativeTable(), and SplineInterpolation::solve().
|
protected |
Definition at line 118 of file BicubicSplineInterpolation.h.
Referenced by BicubicSplineInterpolation(), constructRowSpline(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and setData().
|
protected |
Definition at line 117 of file BicubicSplineInterpolation.h.
Referenced by BicubicSplineInterpolation(), sample(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and setData().
|
staticprotectedinherited |
Definition at line 79 of file SplineInterpolationBase.h.
Referenced by errorCheck().
|
staticprotected |
File number for data dump.
Definition at line 153 of file BicubicSplineInterpolation.h.
|
protected |
Definition at line 116 of file BicubicSplineInterpolation.h.
Referenced by BicubicSplineInterpolation(), constructColumnSpline(), sample(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and setData().
|
protected |
Vectors used during sampling.
Definition at line 115 of file BicubicSplineInterpolation.h.
Referenced by BicubicSplineInterpolation(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and setData().
|
protected |
Independent values in the x1 direction.
Definition at line 91 of file BicubicSplineInterpolation.h.
Referenced by BicubicSplineInterpolation(), constructColumnSpline(), constructColumnSplineSecondDerivativeTable(), constructRowSpline(), constructRowSplineSecondDerivativeTable(), errorCheck(), sample(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and setData().
|
protected |
Independent values in the x2 direction.
Definition at line 93 of file BicubicSplineInterpolation.h.
Referenced by BicubicSplineInterpolation(), constructColumnSpline(), constructColumnSplineSecondDerivativeTable(), constructRowSpline(), constructRowSplineSecondDerivativeTable(), errorCheck(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and setData().
|
protected |
The dependent values at (x1, x2) points.
Definition at line 95 of file BicubicSplineInterpolation.h.
Referenced by constructColumnSpline(), constructColumnSplineSecondDerivativeTable(), constructRowSplineSecondDerivativeTable(), errorCheck(), and setData().
|
protected |
Definition at line 112 of file BicubicSplineInterpolation.h.
Referenced by constructColumnSplineSecondDerivativeTable(), and constructRowSpline().
|
protected |
Second derivatives.
Definition at line 111 of file BicubicSplineInterpolation.h.
Referenced by constructColumnSpline(), and constructRowSplineSecondDerivativeTable().
|
protected |
Transpose of _y.
Definition at line 97 of file BicubicSplineInterpolation.h.
Referenced by constructColumnSplineSecondDerivativeTable(), and constructRowSpline().
|
protected |
Boundary conditions.
The first index indicates the coordinate the derivative is with respect to. The second index indicates the grid index, e.g. 1 is the lower bound, and n is the upper bound
Definition at line 105 of file BicubicSplineInterpolation.h.
Referenced by constructColumnSplineSecondDerivativeTable(), errorCheck(), and setData().
|
protected |
Definition at line 106 of file BicubicSplineInterpolation.h.
Referenced by constructColumnSplineSecondDerivativeTable(), errorCheck(), and setData().
|
protected |
Definition at line 107 of file BicubicSplineInterpolation.h.
Referenced by constructRowSplineSecondDerivativeTable(), errorCheck(), and setData().
|
protected |
Definition at line 108 of file BicubicSplineInterpolation.h.
Referenced by constructRowSplineSecondDerivativeTable(), errorCheck(), and setData().