31 #ifndef OPM_DENSEAD_EVALUATION2_HPP 32 #define OPM_DENSEAD_EVALUATION2_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()
155 template <
class RhsValueType>
156 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
163 template <
class RhsValueType>
164 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
167 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 168 " with 2 derivatives");
175 template <
class RhsValueType>
186 template <
class RhsValueType>
187 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
190 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 191 " with 2 derivatives");
197 template <
class RhsValueType>
198 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
205 template <
class RhsValueType>
212 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
214 assert(
size() == other.size());
216 data_[1] = other.data_[1];
217 data_[2] = other.data_[2];
224 assert(
size() == other.size());
226 data_[0] += other.data_[0];
227 data_[1] += other.data_[1];
228 data_[2] += other.data_[2];
234 template <
class RhsValueType>
235 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
246 assert(
size() == other.size());
248 data_[0] -= other.data_[0];
249 data_[1] -= other.data_[1];
250 data_[2] -= other.data_[2];
256 template <
class RhsValueType>
257 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
268 assert(
size() == other.size());
279 data_[1] = data_[1] * v + other.data_[1] * u;
280 data_[2] = data_[2] * v + other.data_[2] * u;
286 template <
class RhsValueType>
287 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
299 assert(
size() == other.size());
305 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
306 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
313 template <
class RhsValueType>
314 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
328 assert(
size() == other.size());
338 template <
class RhsValueType>
339 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 351 assert(
size() == other.size());
361 template <
class RhsValueType>
362 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 377 result.data_[0] = - data_[0];
378 result.data_[1] = - data_[1];
379 result.data_[2] = - data_[2];
386 assert(
size() == other.size());
395 template <
class RhsValueType>
396 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 407 assert(
size() == other.size());
416 template <
class RhsValueType>
417 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 426 template <
class RhsValueType>
427 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
438 template <
class RhsValueType>
439 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 440 {
return value() == other; }
442 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 444 assert(
size() == other.size());
446 for (
int idx = 0; idx <
length_(); ++idx) {
447 if (data_[idx] != other.data_[idx]) {
454 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 455 {
return !operator==(other); }
457 template <
class RhsValueType>
458 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 459 {
return !operator==(other); }
461 template <
class RhsValueType>
462 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 463 {
return value() > other; }
465 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 467 assert(
size() == other.size());
469 return value() > other.value();
472 template <
class RhsValueType>
473 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 474 {
return value() < other; }
476 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 478 assert(
size() == other.size());
480 return value() < other.value();
483 template <
class RhsValueType>
484 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 485 {
return value() >= other; }
487 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 489 assert(
size() == other.size());
491 return value() >= other.value();
494 template <
class RhsValueType>
495 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 496 {
return value() <= other; }
498 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 500 assert(
size() == other.size());
502 return value() <= other.value();
510 template <
class RhsValueType>
511 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
515 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 517 assert(0 <= varIdx && varIdx <
size());
519 return data_[
dstart_() + varIdx];
523 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
525 assert(0 <= varIdx && varIdx <
size());
527 data_[
dstart_() + varIdx] = derVal;
530 template<
class Serializer>
531 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
537 std::array<ValueT, 3> data_;
543 #endif // OPM_DENSEAD_EVALUATION2_HPP OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:87
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: Evaluation2.hpp:92
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:82
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation.hpp:105
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:79
ValueT ValueType
field type
Definition: Evaluation2.hpp:58
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
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 dstart_() const
start index for derivatives
Definition: Evaluation2.hpp:74
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation2.hpp:66
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: Evaluation2.hpp:77
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation2.hpp:71
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation2.hpp:61
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:63