20#ifndef OPM_UNIFORMTABLELINEAR_HEADER_INCLUDED
21#define OPM_UNIFORMTABLELINEAR_HEADER_INCLUDED
29#include <opm/common/ErrorMacros.hpp>
49 const std::vector<T>& y_values);
63 std::pair<double, double>
domain();
85 enum RangePolicy {Throw = 0, ClosestValue = 1, Extrapolate = 2};
99 std::vector<T> y_values_;
102 template <
typename U>
111 UniformTableLinear<T>
112 ::UniformTableLinear()
113 : left_(ClosestValue), right_(ClosestValue)
122 const std::vector<T>& y_values)
123 : xmin_(xmin), xmax_(xmax), y_values_(y_values),
124 left_(ClosestValue), right_(ClosestValue)
127 assert(y_values.size() > 1);
128 xdelta_ = (xmax - xmin)/(y_values.size() - 1);
138 : xmin_(xmin), xmax_(xmax),
139 y_values_(y_values, y_values + num_y_values),
140 left_(ClosestValue), right_(ClosestValue)
143 assert(y_values_.size() > 1);
144 xdelta_ = (xmax - xmin)/(y_values_.size() - 1);
148 inline std::pair<double, double>
152 return std::make_pair(xmin_, xmax_);
160 xmin_ = new_domain.first;
161 xmax_ = new_domain.second;
162 xdelta_ = (xmax_ - xmin_)/(y_values_.size() - 1);
171 double x = std::min(xparam, xmax_);
172 x = std::max(x, xmin_);
175 double pos = (x - xmin_)/xdelta_;
176 double posi = std::floor(pos);
177 int left = int(posi);
178 if (left ==
int(y_values_.size()) - 1) {
180 return y_values_.back();
182 double w = pos - posi;
183 return (1.0 - w)*y_values_[left] + w*y_values_[left + 1];
194 if (xparam > xmax_ || xparam < xmin_) {
197 double x = std::min(xparam, xmax_);
198 x = std::max(x, xmin_);
200 double pos = (x - xmin_)/xdelta_;
201 double posi = std::floor(pos);
202 int left = int(posi);
203 if (left ==
int(y_values_.size()) - 1) {
207 value = (y_values_[left + 1] - y_values_[left])/xdelta_;
218 return xmin_ == other.xmin_
219 && xdelta_ == other.xdelta_
220 && y_values_ == other.y_values_
221 && left_ == other.left_
222 && right_ == other.right_;
230 if (rp != ClosestValue) {
231 OPM_THROW(std::runtime_error,
"Only ClosestValue RangePolicy implemented.");
241 if (rp != ClosestValue) {
242 OPM_THROW(std::runtime_error,
"Only ClosestValue RangePolicy implemented.");
248 template <
typename T>
251 int n = t.y_values_.size();
252 for (
int i = 0; i < n; ++i) {
253 double f = double(i)/double(n - 1);
254 os << (1.0 - f)*t.xmin_ + f*t.xmax_
255 <<
" " << t.y_values_[i] <<
'\n';
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30