Interpolation API¶
The simses.interpolation module provides two fast scalar interpolation helpers used on the inner-loop hot path of the simulation. They are drop-in replacements for numpy.interp (1-D) and scipy.interpolate.RegularGridInterpolator (2-D bilinear) that avoid the ~2–80 µs of per-call argument sanitisation those libraries pay for a single scalar query.
Both helpers operate on plain Python lists and use bisect for the index search. Models should convert lookup-table arrays to lists once at construction time and pass them in on every step.
Out-of-bounds inputs raise rather than clip — silent clipping would mask integration overshoot, initialisation bugs, and upstream control errors.
Functions¶
simses.interpolation.interp1d_scalar(x, xp, fp)
¶
Linear interpolation of a scalar against a sorted axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Query value. |
required |
xp
|
list[float]
|
Strictly ascending axis (Python list). |
required |
fp
|
list[float]
|
Function values at |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/simses/interpolation.py
simses.interpolation.interp2d_scalar(x, y, xp, yp, mat)
¶
Bilinear interpolation of a scalar (x, y) against a 2-D LUT.
mat is indexed as mat[i][j] with xp[i] and yp[j] as the
grid coordinates. Both axes must be strictly ascending. The result is
bit-for-bit equivalent to RegularGridInterpolator((xp, yp), mat)((x, y))
at every grid node and at all interior points (machine epsilon).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Query value along the first axis. |
required |
y
|
float
|
Query value along the second axis. |
required |
xp
|
list[float]
|
Strictly ascending first-axis values. |
required |
yp
|
list[float]
|
Strictly ascending second-axis values. |
required |
mat
|
list[list[float]]
|
2-D table; |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |