31 #ifndef OPM_DENSEAD_EVALUATION4_HPP 32 #define OPM_DENSEAD_EVALUATION4_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()
157 template <
class RhsValueType>
158 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
165 template <
class RhsValueType>
166 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
169 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 170 " with 4 derivatives");
177 template <
class RhsValueType>
188 template <
class RhsValueType>
189 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
192 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 193 " with 4 derivatives");
199 template <
class RhsValueType>
200 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
207 template <
class RhsValueType>
214 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
216 assert(
size() == other.size());
218 data_[1] = other.data_[1];
219 data_[2] = other.data_[2];
220 data_[3] = other.data_[3];
221 data_[4] = other.data_[4];
228 assert(
size() == other.size());
230 data_[0] += other.data_[0];
231 data_[1] += other.data_[1];
232 data_[2] += other.data_[2];
233 data_[3] += other.data_[3];
234 data_[4] += other.data_[4];
240 template <
class RhsValueType>
241 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
252 assert(
size() == other.size());
254 data_[0] -= other.data_[0];
255 data_[1] -= other.data_[1];
256 data_[2] -= other.data_[2];
257 data_[3] -= other.data_[3];
258 data_[4] -= other.data_[4];
264 template <
class RhsValueType>
265 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
276 assert(
size() == other.size());
287 data_[1] = data_[1] * v + other.data_[1] * u;
288 data_[2] = data_[2] * v + other.data_[2] * u;
289 data_[3] = data_[3] * v + other.data_[3] * u;
290 data_[4] = data_[4] * v + other.data_[4] * u;
296 template <
class RhsValueType>
297 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
311 assert(
size() == other.size());
317 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
318 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
319 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
320 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
327 template <
class RhsValueType>
328 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
344 assert(
size() == other.size());
354 template <
class RhsValueType>
355 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 367 assert(
size() == other.size());
377 template <
class RhsValueType>
378 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 393 result.data_[0] = - data_[0];
394 result.data_[1] = - data_[1];
395 result.data_[2] = - data_[2];
396 result.data_[3] = - data_[3];
397 result.data_[4] = - data_[4];
404 assert(
size() == other.size());
413 template <
class RhsValueType>
414 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 425 assert(
size() == other.size());
434 template <
class RhsValueType>
435 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 444 template <
class RhsValueType>
445 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
456 template <
class RhsValueType>
457 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 458 {
return value() == other; }
460 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 462 assert(
size() == other.size());
464 for (
int idx = 0; idx <
length_(); ++idx) {
465 if (data_[idx] != other.data_[idx]) {
472 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 473 {
return !operator==(other); }
475 template <
class RhsValueType>
476 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 477 {
return !operator==(other); }
479 template <
class RhsValueType>
480 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 481 {
return value() > other; }
483 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 485 assert(
size() == other.size());
487 return value() > other.value();
490 template <
class RhsValueType>
491 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 492 {
return value() < other; }
494 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 496 assert(
size() == other.size());
498 return value() < other.value();
501 template <
class RhsValueType>
502 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 503 {
return value() >= other; }
505 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 507 assert(
size() == other.size());
509 return value() >= other.value();
512 template <
class RhsValueType>
513 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 514 {
return value() <= other; }
516 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 518 assert(
size() == other.size());
520 return value() <= other.value();
528 template <
class RhsValueType>
529 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
533 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 535 assert(0 <= varIdx && varIdx <
size());
537 return data_[
dstart_() + varIdx];
541 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
543 assert(0 <= varIdx && varIdx <
size());
545 data_[
dstart_() + varIdx] = derVal;
548 template<
class Serializer>
549 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
555 std::array<ValueT, 5> data_;
561 #endif // OPM_DENSEAD_EVALUATION4_HPP OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:87
ValueT ValueType
field type
Definition: Evaluation4.hpp:58
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 Evaluation()
default constructor
Definition: Evaluation.hpp:105
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation4.hpp:92
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:79
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation4.hpp:66
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
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:82
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 size() const
number of derivatives
Definition: Evaluation4.hpp:61
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation4.hpp:74
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 constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation4.hpp:77
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: Evaluation4.hpp:71