21#ifndef OPM_LINEARINTERPOLATION_HEADER_INCLUDED
22#define OPM_LINEARINTERPOLATION_HEADER_INCLUDED
35inline int tableIndex(
const std::vector<double>& table,
double x)
40 const auto lower = std::lower_bound(table.begin(), table.end(), x);
42 if (lower == table.end())
43 return table.size()-2;
44 else if (lower == table.begin())
47 return std::distance(table.begin(), lower)-1;
50inline std::pair<double, int>
51linearInterpolationSlope(
const std::vector<double>& xv,
52 const std::vector<double>& yv,
56 return { (yv[i + 1] - yv[i]) / (xv[i + 1] - xv[i]), i };
60inline double linearInterpolationDerivative(
const std::vector<double>& xv,
61 const std::vector<double>& yv,
double x)
64 return linearInterpolationSlope(xv, yv, x).first;
67inline double linearInterpolation(
const std::vector<double>& xv,
68 const std::vector<double>& yv,
double x)
71 const auto& [t, i] = linearInterpolationSlope(xv, yv, x);
72 return t * (x - xv[i]) + yv[i];
75inline double linearInterpolationNoExtrapolation(
const std::vector<double>& xv,
76 const std::vector<double>& yv,
double x)
86 return linearInterpolation(xv, yv, x);
89inline double linearInterpolation(
const std::vector<double>& xv,
90 const std::vector<double>& yv,
95 std::tie(t, ix1) = linearInterpolationSlope(xv, yv, x);
96 return t * (x - xv[ix1]) + yv[ix1];
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
int tableIndex(const std::vector< double > &table, double x)
Returns an index in an ordered table such that x is between table[j] and table[j+1].
Definition linearInterpolation.hpp:35