20#ifndef OPM_ECLSIMPLE1DINTERPOLANT_HEADER_INCLUDED
21#define OPM_ECLSIMPLE1DINTERPOLANT_HEADER_INCLUDED
33namespace Opm {
namespace Interp1D {
namespace PiecewisePolynomial {
50 template <
class Extrapolation,
bool IsAscendingRange = true>
64 explicit Linear(Extrapolation&& extrap)
65 : extrap_(std::forward<Extrapolation>(extrap))
106 template <
class ElmIterator,
class ValueTransform>
110 std::vector<ElmIterator>& colIt,
111 const ValueTransform& xTransform,
112 const std::vector<ValueTransform>& colTransform);
125 return LocalInterpPoint::identify(this->x_,
x, Ascending_P{});
139 const LocalInterpPoint& pt)
const
141 if (pt.cat == PointCategory::InRange) {
144 return this->interpolate(pt, col);
147 auto yval = [
this](
const std::size_t i,
148 const std::size_t j) ->
double
150 return this->y(i, j);
153 if (pt.cat == PointCategory::LeftOfRange) {
155 const auto xmin = this->x_.front();
157 return this->extrap_.left(this->x_, xmin + pt.t, col, yval);
160 assert (pt.cat == PointCategory::RightOfRange);
163 const auto xmax = this->x_.back();
164 return this->extrap_.right(this->x_, xmax + pt.t, col, yval);
183 auto result = std::vector<double>{};
185 if (col >= this->nCols_) {
186 throw std::domain_error {
187 "Result Column Identifier Ouf of Bounds"
191 result.reserve(this->x_.size());
192 for (
auto n = this->x_.size(), i = 0*n; i < n; ++i) {
193 result.push_back(this->y(i, col));
203 std::integral_constant<bool, IsAscendingRange>;
207 Extrapolation extrap_;
214 std::vector<double> x_;
219 std::vector<double> y_;
234 double interpolate(
const LocalInterpPoint& pt,
235 const std::size_t col)
const
237 assert (pt.cat == PointCategory::InRange);
238 assert (pt.interval + 1 < this->x_.size());
240 const auto left = pt.interval + 0;
241 const auto xl = this->x_[left];
242 const auto yl = this->y (left, col);
244 const auto right = pt.interval + 1;
245 const auto xr = this->x_[right];
246 const auto yr = this->y (right, col);
248 const auto t = pt.t / (xr - xl);
250 return t*yr + (1.0 -
t)*yl;
260 double y(
const std::size_t row,
261 const std::size_t col)
const
266 assert (col < this->nCols_);
267 assert (row*this->nCols_ + col < this->y_.size());
269 return this->y_[row*this->nCols_ + col];
273 template <
class Extrapolation,
bool IsAscendingRange>
274 template <
class ElmIterator,
class ValueTransform>
276 Linear(Extrapolation&& extrap,
279 std::vector<ElmIterator>& colIt,
280 const ValueTransform& xTransform,
281 const std::vector<ValueTransform>& colTransform)
282 : extrap_(std::forward<Extrapolation>(extrap))
283 , nCols_ (colIt.size())
286 assert (colIt.size() >= 1);
288 const auto nRows = std::distance(xBegin, xEnd);
290 this->x_.reserve(nRows);
291 this->y_.reserve(nRows * colIt.size());
293 auto keyValid = [](
const double xi)
300 return std::abs(xi) < 1.0e20;
303 while (xBegin != xEnd) {
307 if (keyValid(*xBegin)) {
308 this->x_.push_back(xTransform(*xBegin));
310 auto colID = 0*colTransform.size();
311 for (
auto ci : colIt) {
313 this->y_.push_back(colTransform[colID++](*ci));
324 for (
auto& ci : colIt) {
330 if (this->x_.size() <
static_cast<decltype(this-
>x_.size())>(nRows)) {
331 this->x_.shrink_to_fit();
332 this->y_.shrink_to_fit();
335 if (this->x_.size() < 2) {
340 throw std::invalid_argument {
341 "No Interpolation Intervals of Non-Zero Size"
Definition: ECLPiecewiseLinearInterpolant.hpp:52
std::vector< double > resultVariable(const std::size_t col) const
Definition: ECLPiecewiseLinearInterpolant.hpp:181
const std::vector< double > & independentVariable() const
Retrieve abscissas of interpolant's independent variate.
Definition: ECLPiecewiseLinearInterpolant.hpp:168
Linear(Extrapolation &&extrap, ElmIterator xBegin, ElmIterator xEnd, std::vector< ElmIterator > &colIt, const ValueTransform &xTransform, const std::vector< ValueTransform > &colTransform)
Definition: ECLPiecewiseLinearInterpolant.hpp:276
LocalInterpPoint classifyPoint(const double x) const
Definition: ECLPiecewiseLinearInterpolant.hpp:123
Linear(Extrapolation &&extrap)
Definition: ECLPiecewiseLinearInterpolant.hpp:64
double evaluate(const std::size_t col, const LocalInterpPoint &pt) const
Definition: ECLPiecewiseLinearInterpolant.hpp:138
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)