This class interpolates tabulated data with a bicubic function. More...
#include <BicubicInterpolation.h>
Public Member Functions | |
BicubicInterpolation (const std::vector< Real > &x1, const std::vector< Real > &x2, const std::vector< std::vector< Real >> &y) | |
virtual | ~BicubicInterpolation ()=default |
void | errorCheck () |
Sanity checks on input data. More... | |
Real | sample (Real x1, Real x2) |
Samples value at point (x1, x2) More... | |
void | sampleValueAndDerivatives (Real x1, Real x2, Real &y, Real &dy1, Real &dy2) |
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 time spent locating the point in the tabulated data. More... | |
Real | sampleDerivative (Real x1, Real x2, unsigned int deriv_var) |
Samples first derivative at point (x1, x2) More... | |
Real | sample2ndDerivative (Real x1, Real x2, unsigned int deriv_var) |
Samples second derivative at point (x1, x2) More... | |
void | precomputeCoefficients () |
Precompute all of the coefficients for the bicubic interpolation to avoid calculating them repeatedly. More... | |
Protected Member Functions | |
void | findInterval (const std::vector< Real > &x, Real xi, unsigned int &klo, unsigned int &khi, Real &xs) |
Find the indices of the dependent values axis which bracket the point xi. More... | |
void | tableDerivatives (std::vector< std::vector< Real >> &dy_dx1, std::vector< std::vector< Real >> &dy_dx2, std::vector< std::vector< Real >> &d2y_dx1x2) |
Provides the values of the first derivatives in each direction at all points in the table of data, as well as the mixed second derivative. More... | |
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< std::vector< std::vector< Real > > > > | _bicubic_coeffs |
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent value. More... | |
const std::vector< std::vector< int > > | _wt |
Matrix used to calculate bicubic interpolation coefficients (from Numerical Recipes) More... | |
This class interpolates tabulated data with a bicubic function.
In order to minimize the computational expense of each sample, the coefficients at each point in the tabulated data are computed once in advance, and then accessed during the interpolation.
As a result, this bicubic interpolation can be much faster than the bicubic spline interpolation method in BicubicSplineInterpolation.
Adapted from Numerical Recipes in C (section 3.6). The terminology used is consistent with that used in Numerical Recipes, where moving over a column corresponds to moving over the x1 coord. Likewise, moving over a row means moving over the x2 coord.
Definition at line 29 of file BicubicInterpolation.h.
BicubicInterpolation::BicubicInterpolation | ( | const std::vector< Real > & | x1, |
const std::vector< Real > & | x2, | ||
const std::vector< std::vector< Real >> & | y | ||
) |
Definition at line 15 of file BicubicInterpolation.C.
|
virtualdefault |
void BicubicInterpolation::errorCheck | ( | ) |
Sanity checks on input data.
Definition at line 347 of file BicubicInterpolation.C.
Referenced by BicubicInterpolation().
|
protected |
Find the indices of the dependent values axis which bracket the point xi.
Definition at line 320 of file BicubicInterpolation.C.
Referenced by sample(), sample2ndDerivative(), sampleDerivative(), and sampleValueAndDerivatives().
void BicubicInterpolation::precomputeCoefficients | ( | ) |
Precompute all of the coefficients for the bicubic interpolation to avoid calculating them repeatedly.
Definition at line 191 of file BicubicInterpolation.C.
Referenced by BicubicInterpolation().
Real BicubicInterpolation::sample | ( | Real | x1, |
Real | x2 | ||
) |
Samples value at point (x1, x2)
Definition at line 43 of file BicubicInterpolation.C.
Real BicubicInterpolation::sample2ndDerivative | ( | Real | x1, |
Real | x2, | ||
unsigned int | deriv_var | ||
) |
Samples second derivative at point (x1, x2)
Definition at line 107 of file BicubicInterpolation.C.
Real BicubicInterpolation::sampleDerivative | ( | Real | x1, |
Real | x2, | ||
unsigned int | deriv_var | ||
) |
Samples first derivative at point (x1, x2)
Definition at line 59 of file BicubicInterpolation.C.
void BicubicInterpolation::sampleValueAndDerivatives | ( | Real | x1, |
Real | x2, | ||
Real & | y, | ||
Real & | dy1, | ||
Real & | dy2 | ||
) |
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 time spent locating the point in the tabulated data.
Definition at line 155 of file BicubicInterpolation.C.
|
protected |
Provides the values of the first derivatives in each direction at all points in the table of data, as well as the mixed second derivative.
This is implemented using finite differencing, but could be supplied through other means (such as by sampling with cubic splines)
Definition at line 249 of file BicubicInterpolation.C.
Referenced by precomputeCoefficients().
|
protected |
Matrix of precomputed coefficients There are four coefficients in each direction at each dependent value.
Definition at line 98 of file BicubicInterpolation.h.
Referenced by BicubicInterpolation(), precomputeCoefficients(), sample(), sample2ndDerivative(), sampleDerivative(), and sampleValueAndDerivatives().
|
protected |
Matrix used to calculate bicubic interpolation coefficients (from Numerical Recipes)
Definition at line 102 of file BicubicInterpolation.h.
Referenced by precomputeCoefficients().
|
protected |
Independent values in the x1 direction.
Definition at line 90 of file BicubicInterpolation.h.
Referenced by BicubicInterpolation(), errorCheck(), precomputeCoefficients(), sample(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and tableDerivatives().
|
protected |
Independent values in the x2 direction.
Definition at line 92 of file BicubicInterpolation.h.
Referenced by BicubicInterpolation(), errorCheck(), precomputeCoefficients(), sample(), sample2ndDerivative(), sampleDerivative(), sampleValueAndDerivatives(), and tableDerivatives().
|
protected |
The dependent values at (x1, x2) points.
Definition at line 94 of file BicubicInterpolation.h.
Referenced by errorCheck(), precomputeCoefficients(), and tableDerivatives().