*This page is for the current JSim version 2.0 and higher. Click here for the earlier JSim 1.6 version.*

This specification is preliminary and subject to change. Last revised: 06 Sep 2006.

## Implementation Specification

The RealNData.realVal(double[] xvals) method implements N-dimensional interpolation based on grid values (not grid array indexes). Various interpolation algorithms may be implemented, subject to the following guidelines.

The method may be called concurrently by several threads, (even on the same RealNData), and so must be reentrant.

Interpolation must efficiently support both regular and irregular grids. Currently all model data is defined on regular grids, but this may change in the future. Data curves in project datasets is often defined on irregular grids. GridData.nearestInx(double xval) should be used to find the surrounding grid indexes for an xval in an efficient manner. Note that IrregularGridData.nearestInx() currently (Sep 06) uses an inefficient low-to-high search strategy. This should be replaced by an efficient binary search at some point in the future.

Interpolation algorithms may use as many or as few nearby grid points as is appropriate. A linear algorithm may use as few as 2, or as many as 2^N nearest neighbors. A spline or other smooth algorithm may use even more by drawing on non-nearest neighbors. This specification is silent on the number of neighbors used for interpolation. However, in does require robustness when NaN's are encountered in one or more neighbors. All model data arrays (RealNData) in initialized to NaNs at the start of a run. Values are calculated in an unpredictable order, depending upon the planner/compiler. When interpolation is requested, data values for some neighbor grid points may be NaNs. Currently (due to compiler limitations) all JSim model loops move from low index to high index, but this should not be assumed by interpolation algorithms as other calculation orders will, no doubt, be implemented in the future.

Linear algorithms assign weight factors for each of the 2^N nearest neighbors based on distance to the query xvals[], with the returned value being a summation of data values times weights. Algorithms should not add zero weights to summation in case the associated data value is NaN (IEEE spec says 0*NaN gives NaN). Furthermore, weights that are very nearly zero should be set to zero. Here "very nearly zero" mean abs(x) < THRESH where THRESH is a static parameter currently recommended to have value 1e-7.

Note: As AS points out, the current THRESH is 1e-7 times the minimum grid delta, which is unit incompatible with the dimensionless weights. Therefore, the current threshold is non-sensical.

How to extend this NaN-protection policy to non-linear algorithms that sample non-nearest neighbors has yet to be defined.

It may be assumed that the GridData's overwhich the queried RealNData assumes values have non-NaN values.

xvals[] query outside grid bounds but within one grid delta should return values at grid bounds. When the query is more than one delta outside grid bounds, this the value returned may be either NaN or the value at grid bounds. Future versions of this spec will probably pick one or the other but, as of this writing, it is not completely clear which is best.

### Verification Specification

There are 3 types of verification required: accuraccy, robustness and performance.

#### Accuraccy verification

AS will provide model/project files that demonstrate smooth and correct interpolation behaviour for NaN-less RealNData objects. These files will be incorporated into the JSIMSRC/VERIFY/interp suite.

#### Robustness

EB will provide model files that check for undesirable NaNs generated at run-time. These files will be incorporated into the JSIMSRC/VERIFY/interp suite. AS should feel free to contribute any additional NaN problem models he discovers during testing.

#### Performance

EB will provide a JSim/data/InterpTest.java for assessing algorithm performance. Run via $JSIMSRC/build/jsinterpperf

Comments or Questions?

**Model development and archiving support at https://www.imagwiki.nibib.nih.gov/physiome provided by the following grants:** NIH U01HL122199 Analyzing the Cardiac Power Grid, 09/15/2015 - 05/31/2020, NIH/NIBIB BE08407 Software Integration, JSim and SBW 6/1/09-5/31/13; NIH/NHLBI T15 HL88516-01 Modeling for Heart, Lung and Blood: From Cell to Organ, 4/1/07-3/31/11; NSF BES-0506477 Adaptive Multi-Scale Model Simulation, 8/15/05-7/31/08; NIH/NHLBI R01 HL073598 Core 3: 3D Imaging and Computer Modeling of the Respiratory Tract, 9/1/04-8/31/09; as well as prior support from NIH/NCRR P41 RR01243 Simulation Resource in Circulatory Mass Transport and Exchange, 12/1/1980-11/30/01 and NIH/NIBIB R01 EB001973 JSim: A Simulation Analysis Platform, 3/1/02-2/28/07.