31#ifndef OPM_DENSEAD_EVALUATION2_HPP
32#define OPM_DENSEAD_EVALUATION2_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()
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 2 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 2 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];
225 assert(
size() == other.size());
227 data_[0] += other.data_[0];
228 data_[1] += other.data_[1];
229 data_[2] += other.data_[2];
235 template <
class RhsValueType>
236 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
247 assert(
size() == other.size());
249 data_[0] -= other.data_[0];
250 data_[1] -= other.data_[1];
251 data_[2] -= other.data_[2];
257 template <
class RhsValueType>
258 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
269 assert(
size() == other.size());
280 data_[1] = data_[1] * v + other.data_[1] * u;
281 data_[2] = data_[2] * v + other.data_[2] * u;
287 template <
class RhsValueType>
288 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
300 assert(
size() == other.size());
306 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
307 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
314 template <
class RhsValueType>
315 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
329 assert(
size() == other.size());
339 template <
class RhsValueType>
340 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
352 assert(
size() == other.size());
362 template <
class RhsValueType>
363 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
378 result.data_[0] = - data_[0];
379 result.data_[1] = - data_[1];
380 result.data_[2] = - data_[2];
387 assert(
size() == other.size());
396 template <
class RhsValueType>
397 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
408 assert(
size() == other.size());
417 template <
class RhsValueType>
418 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
427 template <
class RhsValueType>
428 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
439 template <
class RhsValueType>
440 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
441 {
return value() == other; }
443 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
445 assert(
size() == other.size());
447 for (
int idx = 0; idx <
length_(); ++idx) {
448 if (data_[idx] != other.data_[idx]) {
455 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
456 {
return !operator==(other); }
458 template <
class RhsValueType>
459 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
460 {
return !operator==(other); }
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();
495 template <
class RhsValueType>
496 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
497 {
return value() <= other; }
499 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
501 assert(
size() == other.size());
503 return value() <= other.value();
507 OPM_HOST_DEVICE
const ValueType& value()
const
511 template <
class RhsValueType>
512 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
516 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
518 assert(0 <= varIdx && varIdx <
size());
520 return data_[
dstart_() + varIdx];
524 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
526 assert(0 <= varIdx && varIdx <
size());
528 data_[
dstart_() + varIdx] = derVal;
531 template<
class Serializer>
532 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
538 std::array<ValueT, 3> data_;
Some templates to wrap the valgrind client request macros.
ValueT ValueType
field type
Definition Evaluation2.hpp:57
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation2.hpp:73
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation2.hpp:70
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation2.hpp:65
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation2.hpp:91
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 Evaluation2.hpp:81
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation2.hpp:76
Evaluation(const Evaluation &other)=default
copy other function evaluation
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation2.hpp:60
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