USML
|
N-dimensional data set and its associated axes.
Supports interpolation in any number of dimensions.
DATA_TYPE | Type of data to be interpolated. Must support +,-,*,/ with itself and double precision scalars. |
NUM_DIMS | Number of dimensions in this grid. Specifying this at compile time allows for some loop un-wrapping. |
|
inlineprotected |
Default constructor for sub-classes.
|
inline |
Create data grid from its associated axes.
Allocates new memory for the data at each grid point. Initialize all of the interpolation types to GRID_INTERP_LINEAR.
axis | Axes to use for each dimension of the grid. The seq_vector::clone() routine is used to make a local copy of each axis within the data grid. |
Create data grid from an existing grid.
Allocates new memory for the data at each grid point. Copies interpolation types from the original grid.
other | Grid to be copied. |
copy_data | Copy both axes and data if true. Copy just axes and structure if false. |
|
inline |
Destroys memory area for field data.
|
inline |
Extract a reference to one of the axes.
|
inline |
Extract a data value at a specific combination of indices.
index | Index number in each dimension. |
|
inline |
Define a new data value at a specific combination of indices.
index | Index number in each dimension. |
value | Value to insert at this location. |
|
inline |
Returns the edge_limit flag for the requested dimension.
|
inline |
Set the edge_limit flag for the requested dimension.
Note: Default is true
dimension | Dimension number to be modified. |
flag | Limits locations when true. |
|
private |
Private recursion engine for multi-dimensional interpolation.
Recursion engine for multi-dimensional interpolation.
The type of interpolation for each dimension is determined using the _interp_type[] field. Interpolation coefficients are computed on the fly to make arbitrary combinations of interpolation types viable.
dim | Index of the dimension currently being processed. Recursion starts at dim=NUM_DIMS-1 and reduces to element retrieval when dim=-1. |
index | Position of the corner before the desired field point. Must have the same rank as the data grid. |
location | Location at which field value is desired. Must have the same NUM_DIM as the data grid or higher. |
deriv | Derivative for this iteration. |
deriv_vec | Results vector for derivative. Derivative not computed if NULL. |
|
inline |
Retrieve the type of interpolation for one of the axes.
|
inline |
Define the type of interpolation for one of the axes.
Modifies the axis buffer size as a side effect. Note that linear interpolation requires a minimum of 2 points; pchip requires a minimum of 4 points.
dimension | Dimension number to be modified. |
type | Type of interpolation for this dimension. |
|
inline |
Multi-dimensional interpolation with the derivative calculation.
So many calculations are shared between the determination of an interpolate value and its derivative, that it is computationally efficient to compute them both at the same time.
Limit interpolation to axis domain if _edge_limit turned on for that dimension. Allow extrapolation if _edge_limit turned off.
location | Location at which field value is desired. Must have the same rank as the data grid or higher. WARNING: The contents of the location vector may be modified if edge_limit() is true for any dimension. |
derivative | If this is not null, the first derivative of the field at this point will also be computed. |
|
inline |
Interpolation 1-D specialization where the arguments, and results, are matrix<double>.
This is used frequently in the WaveQ3D model to interpolate environmental parameters.
x | First dimension of location. |
result | Interpolated values at each location (output). |
dx | First dimension of derivative (output). |
|
inline |
Interpolation 2-D specialization where the arguments, and results, are matrix<double>.
This is used frequently in the WaveQ3D model to interpolate environmental parameters.
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). |
|
inline |
Interpolation 3-D specialization where the arguments, and results, are matrix<double>.
This is used frequently in the WaveQ3D model to interpolate environmental parameters.
x | First dimension of location. |
y | Second dimension of location. |
z | Third dimension of location. |
result | Interpolated values at each location (output). |
dx | First dimension of derivative (output). |
dy | Second dimension of derivative (output). |
dz | Third dimension of derivative (output). |
|
inlineprivate |
Perform a linear interpolation on this dimension.
dim | Index of the dimension currently being processed. |
index | Position of the corner before the desired field point. Must have the same rank as the data grid. |
location | Location at which field value is desired. Must have the same rank as the data grid or higher. |
deriv | Derivative for this iteration. Constant across the interval for linear interpolation. |
deriv_vec | Results vector for derivative. Derivative not computed if NULL. |
|
inlineprivate |
Perform a nearest neighbor interpolation on this dimension.
dim | Index of the dimension currently being processed. |
index | Position of the corner before the desired field point. Must have the same NUM_DIM as the data grid. |
location | Location at which field value is desired. Must have the same NUM_DIM as the data grid or higher. |
deriv | Derivative for this iteration. Always zero for nearest neighbor interpolation. |
deriv_vec | Results vector for derivative. Derivative not computed if NULL. |
|
inlineprivate |
Interpolate this dimension using the Piecewise Cubic Hermite Interpolation Polynomial (PCHIP) algorithm from Matlab.
Matlab uses shape preserving, "visually pleasing" version of the cubic interpolant that does not suffer from the overshooting issues prevalent in the cubic spline. Although the the first derivative of the PCHIP result is guaranteed to be continuous, the second derivative has no such guarantee.
This algorithm differs from the Matlab implementation in that is simultaneously interpolates the function value for the current dimension, and interpolates the derivative for the previous dimension.
When using a gridded data set, it is recommended that edge_limit be set to TRUE for any dimensional axis that uses the PCHIP interpolation. This is because of PCHIP allowing for extreme values when extrapolating data.
Cleve Moler, Numerical Computing in Matlab, Chapter 3 Interpolation, http://www.mathworks.com/moler/chapters.html, accessed 5/15/2012.
F. N. Fritsch and R. E. Carlson, Monotone Piecewise Cubic Interpolation, SIAM Journal on Numerical Analysis, 17 (1980), pp. 238-246.
D. Kahaner, C. Moler, and S. Nash, Numerical Methods and Software, Prentice{Hall, Englewood Cli®s, NJ, 1989.
The basic algorithm assumes that the interpolation location is in the interval [ x[k], x[k+1] ), where "k" is known as the "interval index". The result is then calculated from four unevenly spaced points, and their forward (one-sided) derivatives.
y0 = y[k-1] h0 = x[k]-x[k-1] deriv0 = (y1-y0)/h0 y1 = y[k] h1 = x[k+1]-x[k] deriv1 = (y2-y1)/h1 y2 = y[k+1] h2 = x[k+2]-x[k+1] deriv2 = (y3-y2)/h2 y3 = y[k+2] s = x - x[k]
such that
p(x) = y[k+1] * ( 3 h1 s^2 - 2 s^3 ) / h1^3 y[k] * ( h1^3 - 3 h1 s^2 - 2 s^3 ) / h1^3 slope[k+1] * ( s1^2 (s-h) ) / h1^2 slope[k] * ( s (s-h[k])^2 ) / h1^2
where:
slope[k] = weighted harmonic average of deriv0, deriv1, deriv2 terms
At the end-points, y'[0] and y'[N-1] must be estimated. This implementation uses Matlab's non-centered, shape-preserving, three-point formula for the end-point slope.
dim | Index of the dimension currently being processed. |
index | Position of the corner before the desired field point. Must have the same rank as the data grid. |
location | Location at which field value is desired. Must have the same rank as the data grid or higher. |
deriv | Derivative for this iteration. Constant across the interval for linear interpolation. |
deriv_vec | Results vector for derivative. Derivative not computed if NULL. |
|
protected |
Axis associated with each dimension of the data grid.
|
protected |
Multi-dimensional data stored as a linear array in column major order.
This format is used to support an N-dimensional data set with any number of dimensions. This memory is created in the constructor and deleted in the destructor.
|
private |
Limits locations to values inside axis when true.
|
private |
Defines the type of interpolation for each axis.
|
protected |
Used during interpolation to hold the axis offsets.