ECLPropTable.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_ECLPROPTABLE_HEADER_INCLUDED
21#define OPM_ECLPROPTABLE_HEADER_INCLUDED
22
25
26#include <functional>
27#include <vector>
28
32
33namespace Opm {
34
37 {
40 using DataVector = std::vector<double>;
41
43 using SizeType = DataVector::size_type;
44
46 using ElementIterator = DataVector::const_iterator;
47
53
59
63
69
72
76 };
77
82 template <class Interpolant>
84 {
118 template <class Factory>
119 static std::vector<Interpolant>
121 Factory&& construct)
122 {
123 auto interp = std::vector<Interpolant>{};
124
125 const auto numInterp = raw.numTables * raw.numPrimary;
126
127 // Table format: numRows*numInterp values of first column
128 // (indep. var) followed by numCols-1 dependent variable
129 // (function value result) columns of numRows*numInterp values
130 // each, one column at a time.
131 const auto colStride = raw.numRows * numInterp;
132
133 // Position column iterators (independent variable and results
134 // respectively) at beginning of each pertinent table column.
135 auto xBegin = std::begin(raw.data);
136 auto colIt = std::vector<decltype(xBegin)> {
137 xBegin + colStride
138 };
139
140 for (auto col = 0*raw.numCols + 1;
141 col < raw.numCols - 1; ++col)
142 {
143 colIt.push_back(colIt.back() + colStride);
144 }
145
146 // Construct actual interpolants by invoking the
147 // constructor/factory function on each sub-table.
148 for (auto i = 0*numInterp;
149 i < numInterp; ++i, xBegin += raw.numRows)
150 {
151 auto xEnd = xBegin + raw.numRows;
152
153 // Layering violation:
154 // The constructor is expected to advance the result
155 // column iterators across 'numRows' entries.
156 interp.push_back(construct(xBegin, xEnd, colIt));
157 }
158
159 return interp;
160 }
161 };
162
166 {
167 public:
171 {
173 using Converter = std::function<double(const double)>;
174
177
179 std::vector<Converter> column;
180 };
181
190 const ConvertUnits& convert);
191
193 struct InTable {
196 };
197
202 };
203
214 std::vector<double>
216 const ResultColumn& c,
217 const std::vector<double>& x) const;
218
220 std::vector<double> connateSat() const;
221
224 std::vector<double> criticalSat(const ResultColumn& c) const;
225
227 std::vector<double> maximumSat() const;
228
236 const std::vector<double>& saturationPoints(const InTable& t) const;
237
242 {
243 return this->table_.size();
244 }
245
246 private:
248 class SingleTable
249 {
250 public:
252
271 SingleTable(ElmIt xBegin,
272 ElmIt xEnd,
273 const ConvertUnits& convert,
274 std::vector<ElmIt>& colIt);
275
286 std::vector<double>
287 interpolate(const ResultColumn& c,
288 const std::vector<double>& x) const;
289
291 double connateSat() const;
292
295 double criticalSat(const ResultColumn& c) const;
296
298 double maximumSat() const;
299
301 const std::vector<double>& saturationPoints() const;
302
303 private:
305 using Extrap = ::Opm::Interp1D::PiecewisePolynomial::
306 ExtrapolationPolicy::Constant;
307
309 using Backend = ::Opm::Interp1D::
310 PiecewisePolynomial::Linear<Extrap>;
311
312 Backend interp_;
313 };
314
317
319 std::vector<SingleTable> table_;
320 };
321
322} // namespace Opm
323
324#endif // OPM_ECLPROPTABLE_HEADER_INCLUDED
const char *const const char *const raw
Definition: cJSON.h:264
Definition: ECLPropTable.hpp:166
std::vector< double > connateSat() const
Retrieve connate saturation from all tables.
ECLPropTableRawData::SizeType numTables() const
Definition: ECLPropTable.hpp:241
std::vector< double > interpolate(const InTable &t, const ResultColumn &c, const std::vector< double > &x) const
std::vector< double > criticalSat(const ResultColumn &c) const
const std::vector< double > & saturationPoints(const InTable &t) const
std::vector< double > maximumSat() const
Retrieve maximum saturation in all tables.
SatFuncInterpolant(const ECLPropTableRawData &raw, const ConvertUnits &convert)
not_this_one begin(...)
std::function< double(double, double)> function
Definition: Operate.hpp:28
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)
Raw table data from which to construct collection of interpolants.
Definition: ECLPropTable.hpp:37
SizeType numTables
Definition: ECLPropTable.hpp:75
DataVector::size_type SizeType
Size type for subsets of table data.
Definition: ECLPropTable.hpp:43
SizeType numRows
Definition: ECLPropTable.hpp:68
std::vector< double > DataVector
Definition: ECLPropTable.hpp:40
DataVector primaryKey
Definition: ECLPropTable.hpp:58
DataVector data
Definition: ECLPropTable.hpp:52
DataVector::const_iterator ElementIterator
Iterator to table elements. Must be random access.
Definition: ECLPropTable.hpp:46
SizeType numCols
Number of columns in this table. Varies by keyword/table.
Definition: ECLPropTable.hpp:71
SizeType numPrimary
Definition: ECLPropTable.hpp:62
Definition: ECLPropTable.hpp:84
static std::vector< Interpolant > fromRawData(const ECLPropTableRawData &raw, Factory &&construct)
Definition: ECLPropTable.hpp:120
Definition: ECLPropTable.hpp:171
std::vector< Converter > column
How to convert the dependent variates (2nd... columns).
Definition: ECLPropTable.hpp:179
Converter indep
How to convert the independent variate (1st column)
Definition: ECLPropTable.hpp:176
std::function< double(const double)> Converter
Convenience type alias for a value transformation.
Definition: ECLPropTable.hpp:173
Wrapper type to disambiguate API usage. Represents a table ID.
Definition: ECLPropTable.hpp:193
ECLPropTableRawData::SizeType i
Table ID.
Definition: ECLPropTable.hpp:195
Wrapper type to disambiguate API usage. Represents a column ID.
Definition: ECLPropTable.hpp:199
ECLPropTableRawData::SizeType i
Column ID.
Definition: ECLPropTable.hpp:201