31 #ifndef OPM_DENSEAD_EVALUATION8_HPP 32 #define OPM_DENSEAD_EVALUATION8_HPP 43 #include <opm/common/ErrorMacros.hpp> 44 #include <opm/common/utility/gpuDecorators.hpp> 49 template <
class ValueT>
61 OPM_HOST_DEVICE constexpr
int size()
const 66 OPM_HOST_DEVICE constexpr
int length_()
const 67 {
return size() + 1; }
74 OPM_HOST_DEVICE constexpr
int dstart_()
const 77 OPM_HOST_DEVICE constexpr
int dend_()
const 85 for (
const auto& v: data_)
86 Valgrind::CheckDefined(v);
103 template <
class RhsValueType>
104 OPM_HOST_DEVICE constexpr
Evaluation(
const RhsValueType& c): data_{}
114 template <
class RhsValueType>
115 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
118 assert(0 <= varPos && varPos <
size());
123 data_[varPos +
dstart_()] = 1.0;
129 OPM_HOST_DEVICE constexpr
void clearDerivatives()
161 template <
class RhsValueType>
162 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
169 template <
class RhsValueType>
170 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
173 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 174 " with 8 derivatives");
181 template <
class RhsValueType>
192 template <
class RhsValueType>
193 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
196 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 197 " with 8 derivatives");
203 template <
class RhsValueType>
204 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
211 template <
class RhsValueType>
218 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
220 assert(
size() == other.size());
222 data_[1] = other.data_[1];
223 data_[2] = other.data_[2];
224 data_[3] = other.data_[3];
225 data_[4] = other.data_[4];
226 data_[5] = other.data_[5];
227 data_[6] = other.data_[6];
228 data_[7] = other.data_[7];
229 data_[8] = other.data_[8];
236 assert(
size() == other.size());
238 data_[0] += other.data_[0];
239 data_[1] += other.data_[1];
240 data_[2] += other.data_[2];
241 data_[3] += other.data_[3];
242 data_[4] += other.data_[4];
243 data_[5] += other.data_[5];
244 data_[6] += other.data_[6];
245 data_[7] += other.data_[7];
246 data_[8] += other.data_[8];
252 template <
class RhsValueType>
253 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
264 assert(
size() == other.size());
266 data_[0] -= other.data_[0];
267 data_[1] -= other.data_[1];
268 data_[2] -= other.data_[2];
269 data_[3] -= other.data_[3];
270 data_[4] -= other.data_[4];
271 data_[5] -= other.data_[5];
272 data_[6] -= other.data_[6];
273 data_[7] -= other.data_[7];
274 data_[8] -= other.data_[8];
280 template <
class RhsValueType>
281 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
292 assert(
size() == other.size());
303 data_[1] = data_[1] * v + other.data_[1] * u;
304 data_[2] = data_[2] * v + other.data_[2] * u;
305 data_[3] = data_[3] * v + other.data_[3] * u;
306 data_[4] = data_[4] * v + other.data_[4] * u;
307 data_[5] = data_[5] * v + other.data_[5] * u;
308 data_[6] = data_[6] * v + other.data_[6] * u;
309 data_[7] = data_[7] * v + other.data_[7] * u;
310 data_[8] = data_[8] * v + other.data_[8] * u;
316 template <
class RhsValueType>
317 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
335 assert(
size() == other.size());
341 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
342 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
343 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
344 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
345 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
346 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
347 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
348 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
355 template <
class RhsValueType>
356 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
376 assert(
size() == other.size());
386 template <
class RhsValueType>
387 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 399 assert(
size() == other.size());
409 template <
class RhsValueType>
410 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 425 result.data_[0] = - data_[0];
426 result.data_[1] = - data_[1];
427 result.data_[2] = - data_[2];
428 result.data_[3] = - data_[3];
429 result.data_[4] = - data_[4];
430 result.data_[5] = - data_[5];
431 result.data_[6] = - data_[6];
432 result.data_[7] = - data_[7];
433 result.data_[8] = - data_[8];
440 assert(
size() == other.size());
449 template <
class RhsValueType>
450 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 461 assert(
size() == other.size());
470 template <
class RhsValueType>
471 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 480 template <
class RhsValueType>
481 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
492 template <
class RhsValueType>
493 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 494 {
return value() == other; }
496 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 498 assert(
size() == other.size());
500 for (
int idx = 0; idx <
length_(); ++idx) {
501 if (data_[idx] != other.data_[idx]) {
508 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 509 {
return !operator==(other); }
511 template <
class RhsValueType>
512 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 513 {
return !operator==(other); }
515 template <
class RhsValueType>
516 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 517 {
return value() > other; }
519 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 521 assert(
size() == other.size());
523 return value() > other.value();
526 template <
class RhsValueType>
527 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 528 {
return value() < other; }
530 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 532 assert(
size() == other.size());
534 return value() < other.value();
537 template <
class RhsValueType>
538 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 539 {
return value() >= other; }
541 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 543 assert(
size() == other.size());
545 return value() >= other.value();
548 template <
class RhsValueType>
549 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 550 {
return value() <= other; }
552 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 554 assert(
size() == other.size());
556 return value() <= other.value();
564 template <
class RhsValueType>
565 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
569 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 571 assert(0 <= varIdx && varIdx <
size());
573 return data_[
dstart_() + varIdx];
577 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
579 assert(0 <= varIdx && varIdx <
size());
581 data_[
dstart_() + varIdx] = derVal;
584 template<
class Serializer>
585 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
591 std::array<ValueT, 9> data_;
597 #endif // OPM_DENSEAD_EVALUATION8_HPP OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:87
OPM_HOST_DEVICE constexpr void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation.hpp:95
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation.hpp:84
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation8.hpp:66
OPM_HOST_DEVICE constexpr void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation8.hpp:82
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation8.hpp:61
ValueT ValueType
field type
Definition: Evaluation8.hpp:58
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation.hpp:105
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:79
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation8.hpp:74
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
ValueT ValueType
field type
Definition: Evaluation.hpp:71
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation.hpp:74
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation8.hpp:77
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition: Evaluation.hpp:68
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation8.hpp:92
Some templates to wrap the valgrind client request macros.
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:63
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation8.hpp:71