ECLTableInterpolation1D.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 Statoil ASA.
3
4 This file is part of the Open Porous Media Project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_ECLTABLEINTERPOLATION1D_HEADER_INCLUDED
21#define OPM_ECLTABLEINTERPOLATION1D_HEADER_INCLUDED
22
23#include <cassert>
24#include <type_traits>
25#include <vector>
26
32
33namespace Opm { namespace Interp1D {
34
37 enum class PointCategory {
39 InRange,
40
42 LeftOfRange,
43
45 RightOfRange,
46 };
47
50 namespace PiecewisePolynomial {
51
55 namespace ExtrapolationPolicy {
57 class Constant
58 {
59 public:
85 template <class TabulatedFunction, class Index>
86 double left(const std::vector<double>& /* xi */,
87 const double /* x */,
88 const Index col ,
89 TabulatedFunction&& f) const
90 {
91 return f(0, col);
92 }
93
120 template <class TabulatedFunction, class Index>
121 double right(const std::vector<double>& xi,
122 const double /* x */,
123 const Index col,
124 TabulatedFunction&& f) const
125 {
126 return f(xi.size() - 1, col);
127 }
128 };
129
135 class Linearly
136 {
137 public:
162 template <class TabulatedFunction, class Index>
163 double left(const std::vector<double>& xi,
164 const double x,
165 const Index col,
166 TabulatedFunction&& f) const
167 {
168 // Derivative of f(i,col)
169 const auto f0 = f(0, col);
170 const auto f1 = f(1, col);
171 const auto dfdx = (f1 - f0) / (xi[1] - xi[0]);
172
173 // <= 0 if ascending range.
174 const auto dx = x - xi.front();
175
176 return f0 + (dfdx * dx);
177 }
178
203 template <class TabulatedFunction, class Index>
204 double right(const std::vector<double>& xi,
205 const double x,
206 const Index col,
207 TabulatedFunction&& f) const
208 {
209 const auto nRows = xi.size();
210
211 // Derivative of f(i,col)
212 const auto f0 = f(nRows - 2, col);
213 const auto f1 = f(nRows - 1, col);
214 const auto dfdx =
215 (f1 - f0) / (xi[nRows - 1] - xi[nRows - 2]);
216
217 // >= 0 if ascending range
218 const auto dx = x - xi.back();
219
220 return f1 + (dfdx * dx);
221 }
222 };
223
226 class LinearlyWithDerivatives
227 {
228 public:
236 explicit LinearlyWithDerivatives(const std::size_t nResCol)
237 : nResCol_(nResCol)
238 {}
239
264 template <class TabulatedFunction, class Index>
265 double left(const std::vector<double>& xi,
266 const double x,
267 const Index col,
268 TabulatedFunction&& f) const
269 {
270 // Derivative of f(i,col) in f(i, nResCol_ + col)
271 const auto dfdx = f(0, this->nResCol_ + col);
272 const auto dx = x - xi.front(); // <= 0 if ascending range
273
274 return f(0, col) + (dfdx * dx);
275 }
276
304 template <class TabulatedFunction, class Index>
305 double right(const std::vector<double>& xi,
306 const double x,
307 const Index col,
308 TabulatedFunction&& f) const
309 {
310 const auto nRows = xi.size();
311
312 // Derivative of f(i,col) in f(i, nResCol_ + col)
313 const auto dfdx = f(nRows - 1, this->nResCol_ + col);
314 const auto dx = x - xi.back(); // >= 0 if ascending range
315
316 return f(nRows - 1, col) + (dfdx * dx);
317 }
318
319 private:
322 std::size_t nResCol_;
323 };
324 } // ExtrapolationPolicy
325
328 struct LocalInterpPoint {
330 PointCategory cat;
331
345 std::vector<double>::size_type interval;
346
355 double t;
356
372 static LocalInterpPoint
373 identify(const std::vector<double>& xi,
374 const double x,
375 std::true_type is_ascending = std::true_type{});
376
394 static LocalInterpPoint
395 identify(const std::vector<double>& xi,
396 const double x,
397 std::false_type is_ascending);
398 };
399
400 } // PiecewisePolynomial
401
402}} // Opm::Interp1D
403
404#endif // OPM_ECLTABLEINTERPOLATION1D_HEADER_INCLUDED
Definition: A.hpp:4
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)