Implements fast calculations for data_grids using a non-recursive engine on interpolation.
Takes an existing data_grid and wraps it into a new data_grid_fast and overrides the interpolate function to implement the non-recursive algorithm.
Assumes that both axes of the passed data_grid both have the same interp_type.
WARNING: This wrapper is specific to 2-dimensional grids only. For 3-dimensional grids, the user should implement the data_grid_svp wrapper instead.
Since the data is passed in and referenced by this wrapper, the data is taken control of and destroyed at the end of its use cycle.
data_grid_bathy | ( | const data_grid< double, 2 > * | grid | ) | [inline] |
virtual ~data_grid_bathy | ( | ) | [inline, virtual] |
Destructor.
double data_2d | ( | size_t | row, | |
size_t | col | |||
) | [inline, private] |
Utility accessor function for data grid values.
double fast_pchip | ( | const size_t * | interp_index, | |
double * | location, | |||
double * | derivative = NULL | |||
) | [inline, private] |
A non-recursive version of the Piecewise Cubic Hermite polynomial (PCHIP) specific to the 2-dimensional grid of data.
This algorithm was generated from the below formula and by performing a linear transformation from the data set to the interval [0,1] x [0,1]:
g(x,y) = sum [i,0,3] ( sum [j,0,3] ( a_ij * x^i * y^j ) )
where (x,y) is the point of interpolation and a_ij are known as the bicubic interpolation coefficients. An inverse matrix is then constructed from the 16 equations that are generated. Using this inverse matrix and the 4 surround data points, their respective derivatives with respect to x and y, and mixed xy xy derivatives, we can construct each a_ij.
The partial and mixed derivates are computed using a centered differencing approximation, so that,
f_x(i,j) = [ f(i+1,j) - f(i-1,j) ] / [ x_(i+1) - x(i-1) ] f_y(i,j) = [ f(i,j+1) - f(i,j-1) ] / [ y_(i+1) - y(i-1) ] f_xy(i,j) = { f(i+1,j+1) - f(i+1,j-1) - f(i-1,j+1) + f(i-1,j-1) } / [ x_(i+1) - x(i-1) ] * [ y_(i+1) - y(i-1) ]
Below is a representation of the data extracted from the field and how it is stored within the matrix:
* field(1,0) * field(3,0) * (interp point)
* field(0,0) * field(2,0)
field(0,0) to field(3,0) are the data points that surrounding the interpolation point. field(4,0) to field(7,0) are the derivatives with respect to x of the extracted data points. field(8,0) to field(11,0) are the derivatives with respect to y of the extracted data points. field(12,0) to field(15,0) are the derivatives with respect to x and y of the extracted data points.
interp_index | index on the grid for the closest data point | |
location | Location of the field calculation | |
derivative | Generate the derivative at the location (output) |
void interpolate | ( | const matrix< double > & | x, | |
const matrix< double > & | y, | |||
matrix< double > * | result, | |||
matrix< double > * | dx = NULL , |
|||
matrix< double > * | dy = NULL | |||
) | [inline] |
Overrides the interpolate function within data_grid using the non-recursive formula.
Interpolate at a series of locations.
x | First dimension of location. | |
y | Second dimension of location. | |
result | Interpolated values at each location (output). | |
dx | First dimension of derivative (output). | |
dy | Second dimension of derivative (output). |
Reimplemented from data_grid< double, 2 >.
double interpolate | ( | double * | location, | |
double * | derivative = NULL | |||
) | [inline] |
Overrides the interpolate function within data_grid using the non-recursive formula.
Determines which interpolate function to based on the interp_type enumeral stored within the 0th dimensional axis.
Interpolate at a single location.
location | Location to do the interpolation at | |
derivative | Derivative at the location (output) |
Reimplemented from data_grid< double, 2 >.
c_matrix<double, 16, 1> _bicubic_coeff [private] |
Create variables that are used multiple times through out the course of multiple calls per instance.
Thus allowing these variables to be created once and used as many times as needed and save memory and time.
matrix<double> _derv_x [private] |
matrix<double> _derv_x_y [private] |
matrix<double> _derv_y [private] |
size_t _fast_index[2] [private] |
c_matrix<double, 16, 1> _field [private] |
c_matrix<double, 16, 16> _inv_bicubic_coeff [private] |
Matrix that is the inverse of the bicubic coefficients This matrix will be used to construct the bicubic coefficients.
The result will be a 16x1 matrix.
const size_t _k0max [private] |
const size_t _k1max [private] |
const size_t _kmin [private] |
c_matrix<double, 1, 1> _result_pchip [private] |
c_matrix<double, 4, 4> _value [private] |
c_matrix<double, 1, 16> _xyloc [private] |