31#ifndef OPM_DENSEAD_EVALUATION1_HPP
32#define OPM_DENSEAD_EVALUATION1_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()
153 template <
class RhsValueType>
154 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType& value,
int varPos)
161 template <
class RhsValueType>
162 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
165 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
166 " with 1 derivatives");
173 template <
class RhsValueType>
174 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
184 template <
class RhsValueType>
185 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
188 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
189 " with 1 derivatives");
195 template <
class RhsValueType>
196 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType& value)
203 template <
class RhsValueType>
210 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
212 assert(
size() == other.size());
214 data_[1] = other.data_[1];
221 assert(
size() == other.size());
223 data_[0] += other.data_[0];
224 data_[1] += other.data_[1];
230 template <
class RhsValueType>
231 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
242 assert(
size() == other.size());
244 data_[0] -= other.data_[0];
245 data_[1] -= other.data_[1];
251 template <
class RhsValueType>
252 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
263 assert(
size() == other.size());
274 data_[1] = data_[1] * v + other.data_[1] * u;
280 template <
class RhsValueType>
281 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
292 assert(
size() == other.size());
298 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
305 template <
class RhsValueType>
306 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
319 assert(
size() == other.size());
329 template <
class RhsValueType>
330 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
342 assert(
size() == other.size());
352 template <
class RhsValueType>
353 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
368 result.data_[0] = - data_[0];
369 result.data_[1] = - data_[1];
376 assert(
size() == other.size());
385 template <
class RhsValueType>
386 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
397 assert(
size() == other.size());
406 template <
class RhsValueType>
407 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
416 template <
class RhsValueType>
417 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
428 template <
class RhsValueType>
429 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
430 {
return value() == other; }
432 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
434 assert(
size() == other.size());
436 for (
int idx = 0; idx <
length_(); ++idx) {
437 if (data_[idx] != other.data_[idx]) {
444 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
445 {
return !operator==(other); }
447 template <
class RhsValueType>
448 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
449 {
return !operator==(other); }
451 template <
class RhsValueType>
452 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
453 {
return value() > other; }
455 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
457 assert(
size() == other.size());
459 return value() > other.value();
462 template <
class RhsValueType>
463 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
464 {
return value() < other; }
466 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
468 assert(
size() == other.size());
470 return value() < other.value();
473 template <
class RhsValueType>
474 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
475 {
return value() >= other; }
477 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
479 assert(
size() == other.size());
481 return value() >= other.value();
484 template <
class RhsValueType>
485 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
486 {
return value() <= other; }
488 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
490 assert(
size() == other.size());
492 return value() <= other.value();
496 OPM_HOST_DEVICE
const ValueType& value()
const
500 template <
class RhsValueType>
501 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
505 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
507 assert(0 <= varIdx && varIdx <
size());
509 return data_[
dstart_() + varIdx];
513 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
515 assert(0 <= varIdx && varIdx <
size());
517 data_[
dstart_() + varIdx] = derVal;
520 template<
class Serializer>
521 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
527 std::array<ValueT, 2> 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 Evaluation1.hpp:65
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation1.hpp:91
Evaluation(const Evaluation &other)=default
copy other function evaluation
ValueT ValueType
field type
Definition Evaluation1.hpp:57
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 Evaluation1.hpp:81
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation1.hpp:60
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation1.hpp:73
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation1.hpp:76
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation1.hpp:70
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation1.hpp:54
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