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_)
102 template <
class RhsValueType>
103 OPM_HOST_DEVICE
constexpr Evaluation(
const RhsValueType& c): data_{}
113 template <
class RhsValueType>
114 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
117 assert(0 <= varPos && varPos <
size());
122 data_[varPos +
dstart_()] = 1.0;
128 OPM_HOST_DEVICE
constexpr void clearDerivatives()
156 template <
class RhsValueType>
157 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType& value,
int varPos)
164 template <
class RhsValueType>
165 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
168 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
169 " with 4 derivatives");
176 template <
class RhsValueType>
177 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
187 template <
class RhsValueType>
188 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
191 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
192 " with 4 derivatives");
198 template <
class RhsValueType>
199 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType& value)
206 template <
class RhsValueType>
213 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
215 assert(
size() == other.size());
217 data_[1] = other.data_[1];
218 data_[2] = other.data_[2];
219 data_[3] = other.data_[3];
220 data_[4] = other.data_[4];
227 assert(
size() == other.size());
229 data_[0] += other.data_[0];
230 data_[1] += other.data_[1];
231 data_[2] += other.data_[2];
232 data_[3] += other.data_[3];
233 data_[4] += other.data_[4];
239 template <
class RhsValueType>
240 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
251 assert(
size() == other.size());
253 data_[0] -= other.data_[0];
254 data_[1] -= other.data_[1];
255 data_[2] -= other.data_[2];
256 data_[3] -= other.data_[3];
257 data_[4] -= other.data_[4];
263 template <
class RhsValueType>
264 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
275 assert(
size() == other.size());
286 data_[1] = data_[1] * v + other.data_[1] * u;
287 data_[2] = data_[2] * v + other.data_[2] * u;
288 data_[3] = data_[3] * v + other.data_[3] * u;
289 data_[4] = data_[4] * v + other.data_[4] * u;
295 template <
class RhsValueType>
296 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
310 assert(
size() == other.size());
316 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
317 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
318 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
319 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
326 template <
class RhsValueType>
327 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
343 assert(
size() == other.size());
353 template <
class RhsValueType>
354 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
366 assert(
size() == other.size());
376 template <
class RhsValueType>
377 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
392 result.data_[0] = - data_[0];
393 result.data_[1] = - data_[1];
394 result.data_[2] = - data_[2];
395 result.data_[3] = - data_[3];
396 result.data_[4] = - data_[4];
403 assert(
size() == other.size());
412 template <
class RhsValueType>
413 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
424 assert(
size() == other.size());
433 template <
class RhsValueType>
434 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
443 template <
class RhsValueType>
444 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
455 template <
class RhsValueType>
456 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
457 {
return value() == other; }
459 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
461 assert(
size() == other.size());
463 for (
int idx = 0; idx <
length_(); ++idx) {
464 if (data_[idx] != other.data_[idx]) {
471 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
472 {
return !operator==(other); }
474 template <
class RhsValueType>
475 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
476 {
return !operator==(other); }
478 template <
class RhsValueType>
479 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
480 {
return value() > other; }
482 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
484 assert(
size() == other.size());
486 return value() > other.value();
489 template <
class RhsValueType>
490 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
491 {
return value() < other; }
493 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
495 assert(
size() == other.size());
497 return value() < other.value();
500 template <
class RhsValueType>
501 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
502 {
return value() >= other; }
504 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
506 assert(
size() == other.size());
508 return value() >= other.value();
511 template <
class RhsValueType>
512 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
513 {
return value() <= other; }
515 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
517 assert(
size() == other.size());
519 return value() <= other.value();
523 OPM_HOST_DEVICE
const ValueType& value()
const
527 template <
class RhsValueType>
528 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
532 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
534 assert(0 <= varIdx && varIdx <
size());
536 return data_[
dstart_() + varIdx];
540 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
542 assert(0 <= varIdx && varIdx <
size());
544 data_[
dstart_() + varIdx] = derVal;
547 template<
class Serializer>
548 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
554 std::array<ValueT, 5> data_;
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition Valgrind.hpp:76
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
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation4.hpp:54
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
ValueT ValueType
field type
Definition Evaluation.hpp:70
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:86
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:78
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation.hpp:104
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:83
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:94
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation.hpp:73
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30