1 #ifndef LINEARINTERPOLATION_H 2 #define LINEARINTERPOLATION_H 38 typedef typename std::pair<OutOfBounds::boundLimits, size_type>
index_type;
49 auto sz = xinp.size();
52 throw std::runtime_error(
53 "Interpolation table contains less than 2 entries.");
58 }
else if (x > xinp[sz - 1]) {
81 auto sz = xinp.size();
82 for (
size_t i = 1; i < sz; i++) {
110 throw std::runtime_error(
"Out of bounds error in interpolation");
116 <<
"WARNING: Out of bound values encountered during interpolation" 121 yout = yinp[idx.second];
125 auto ii = idx.second;
126 if ((ii + 1) == xinp.size())
130 (yinp[ii + 1] - yinp[ii]) / (xinp[ii + 1] - xinp[ii]) *
139 T fac = (xout - xinp[j]) / (xinp[j + 1] - xinp[j]);
140 yout = (
static_cast<T
>(1.0) - fac) * yinp[j] + fac * yinp[j + 1];
boundLimits
Out of bounds limit types.
Definition: LinearInterpolation.h:16
Definition: ABLForcingAlgorithm.C:26
Clamp values to the end points.
Definition: LinearInterpolation.h:26
void linear_interp(const Array1D< T > &xinp, const Array1D< T > &yinp, const T &xout, T &yout, OutOfBounds::OobAction oob=OutOfBounds::CLAMP)
Perform a 1-D linear interpolation.
Definition: LinearInterpolation.h:96
xtgt > xarray[N]
Definition: LinearInterpolation.h:18
std::pair< OutOfBounds::boundLimits, size_type > index_type
Definition: LinearInterpolation.h:38
Array1D< T >::size_type size_type
Definition: LinearInterpolation.h:37
xtgt < xarray[0]
Definition: LinearInterpolation.h:17
InterpTraits< T >::index_type check_bounds(const Array1D< T > &xinp, const T &x)
Determine whether the given value is within the limits of the interpolation table.
Definition: LinearInterpolation.h:47
InterpTraits< T >::index_type find_index(const Array1D< T > &xinp, const T &x)
Return an index object corresponding to the x-value based on interpolation table. ...
Definition: LinearInterpolation.h:75
xarray[0] <= xtgt <= xarray[N]
Definition: LinearInterpolation.h:19
OobAction
Flags indicating action to perform on Out of Bounds situation.
Definition: LinearInterpolation.h:23
Definition: LinearInterpolation.h:35
Warn and then CLAMP.
Definition: LinearInterpolation.h:25
Extrapolate linearly based on end point.
Definition: LinearInterpolation.h:27
std::vector< T > Array1D
Definition: LinearInterpolation.h:32
Raise runtime error.
Definition: LinearInterpolation.h:24
Definition: LinearInterpolation.h:13