31#ifndef OPM_DENSEAD_EVALUATION4_HPP
32#define OPM_DENSEAD_EVALUATION4_HPP
43#include <opm/common/utility/gpuDecorators.hpp>
48template <
class ValueT>
60 OPM_HOST_DEVICE
constexpr int size()
const
65 OPM_HOST_DEVICE
constexpr int length_()
const
66 {
return size() + 1; }
73 OPM_HOST_DEVICE
constexpr int dstart_()
const
76 OPM_HOST_DEVICE
constexpr int dend_()
const
84 for (
const auto& v: data_)
85 Valgrind::CheckDefined(v);
102 template <
class RhsValueType>
103 OPM_HOST_DEVICE
constexpr Evaluation(
const RhsValueType& c): data_{}
115 template <
class RhsValueType>
116 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
119 assert(0 <= varPos && varPos <
size());
124 data_[varPos +
dstart_()] = 1.0;
130 OPM_HOST_DEVICE
constexpr void clearDerivatives()
158 template <
class RhsValueType>
159 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType& value,
int varPos)
166 template <
class RhsValueType>
167 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
170 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
171 " with 4 derivatives");
178 template <
class RhsValueType>
179 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
189 template <
class RhsValueType>
190 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
193 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
194 " with 4 derivatives");
200 template <
class RhsValueType>
201 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType& value)
208 template <
class RhsValueType>
215 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
217 assert(
size() == other.size());
219 data_[1] = other.data_[1];
220 data_[2] = other.data_[2];
221 data_[3] = other.data_[3];
222 data_[4] = other.data_[4];
229 assert(
size() == other.size());
231 data_[0] += other.data_[0];
232 data_[1] += other.data_[1];
233 data_[2] += other.data_[2];
234 data_[3] += other.data_[3];
235 data_[4] += other.data_[4];
241 template <
class RhsValueType>
242 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
253 assert(
size() == other.size());
255 data_[0] -= other.data_[0];
256 data_[1] -= other.data_[1];
257 data_[2] -= other.data_[2];
258 data_[3] -= other.data_[3];
259 data_[4] -= other.data_[4];
265 template <
class RhsValueType>
266 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
277 assert(
size() == other.size());
288 data_[1] = data_[1] * v + other.data_[1] * u;
289 data_[2] = data_[2] * v + other.data_[2] * u;
290 data_[3] = data_[3] * v + other.data_[3] * u;
291 data_[4] = data_[4] * v + other.data_[4] * u;
297 template <
class RhsValueType>
298 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
312 assert(
size() == other.size());
318 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
319 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
320 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
321 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
328 template <
class RhsValueType>
329 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
345 assert(
size() == other.size());
355 template <
class RhsValueType>
356 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
368 assert(
size() == other.size());
378 template <
class RhsValueType>
379 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
394 result.data_[0] = - data_[0];
395 result.data_[1] = - data_[1];
396 result.data_[2] = - data_[2];
397 result.data_[3] = - data_[3];
398 result.data_[4] = - data_[4];
405 assert(
size() == other.size());
414 template <
class RhsValueType>
415 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
426 assert(
size() == other.size());
435 template <
class RhsValueType>
436 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
445 template <
class RhsValueType>
446 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
457 template <
class RhsValueType>
458 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
459 {
return value() == other; }
461 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
463 assert(
size() == other.size());
465 for (
int idx = 0; idx <
length_(); ++idx) {
466 if (data_[idx] != other.data_[idx]) {
473 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
474 {
return !operator==(other); }
476 template <
class RhsValueType>
477 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
478 {
return !operator==(other); }
480 template <
class RhsValueType>
481 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
482 {
return value() > other; }
484 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
486 assert(
size() == other.size());
488 return value() > other.value();
491 template <
class RhsValueType>
492 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
493 {
return value() < other; }
495 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
497 assert(
size() == other.size());
499 return value() < other.value();
502 template <
class RhsValueType>
503 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
504 {
return value() >= other; }
506 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
508 assert(
size() == other.size());
510 return value() >= other.value();
513 template <
class RhsValueType>
514 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
515 {
return value() <= other; }
517 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
519 assert(
size() == other.size());
521 return value() <= other.value();
525 OPM_HOST_DEVICE
const ValueType& value()
const
529 template <
class RhsValueType>
530 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
534 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
536 assert(0 <= varIdx && varIdx <
size());
538 return data_[
dstart_() + varIdx];
542 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
544 assert(0 <= varIdx && varIdx <
size());
546 data_[
dstart_() + varIdx] = derVal;
549 template<
class Serializer>
550 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
556 std::array<ValueT, 5> data_;
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation4.hpp:65
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation4.hpp:91
ValueT ValueType
field type
Definition Evaluation4.hpp:57
Evaluation(const Evaluation &other)=default
copy other function evaluation
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation4.hpp:70
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation4.hpp:76
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation4.hpp:60
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation4.hpp:73
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 Evaluation4.hpp:81
Represents a function evaluation and its derivatives w.r.t.
Definition Evaluation.hpp:59
ValueT ValueType
field type
Definition Evaluation.hpp:66
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:82
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation.hpp:63
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:74
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation.hpp:100
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:79
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:90
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation.hpp:69
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30