32 #ifndef OPM_DENSEAD_EVALUATION_HPP 33 #define OPM_DENSEAD_EVALUATION_HPP 44 #include <opm/common/utility/gpuDecorators.hpp> 47 #include <dune/common/typetraits.hh> 55 static constexpr
int DynamicSize = -1;
61 template <
class ValueT,
int numDerivs,
unsigned staticSize = 0>
73 OPM_HOST_DEVICE constexpr
int size()
const 78 OPM_HOST_DEVICE constexpr
int length_()
const 79 {
return size() + 1; }
86 OPM_HOST_DEVICE constexpr
int dstart_()
const 89 OPM_HOST_DEVICE constexpr
int dend_()
const 97 for (
const auto& v: data_)
98 Valgrind::CheckDefined(v);
115 template <
class RhsValueType>
116 OPM_HOST_DEVICE constexpr
Evaluation(
const RhsValueType& c): data_{}
126 template <
class RhsValueType>
127 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
130 assert(0 <= varPos && varPos <
size());
135 data_[varPos +
dstart_()] = 1.0;
141 OPM_HOST_DEVICE constexpr
void clearDerivatives()
167 template <
class RhsValueType>
168 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
175 template <
class RhsValueType>
176 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
179 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 180 " with 0 derivatives");
187 template <
class RhsValueType>
198 template <
class RhsValueType>
199 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
202 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 203 " with 0 derivatives");
209 template <
class RhsValueType>
210 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
217 template <
class RhsValueType>
224 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
226 assert(
size() == other.size());
229 data_[i] = other.data_[i];
236 assert(
size() == other.size());
238 for (
int i = 0; i <
length_(); ++i)
239 data_[i] += other.data_[i];
245 template <
class RhsValueType>
246 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
257 assert(
size() == other.size());
259 for (
int i = 0; i <
length_(); ++i)
260 data_[i] -= other.data_[i];
266 template <
class RhsValueType>
267 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
278 assert(
size() == other.size());
290 data_[i] = data_[i] * v + other.data_[i] * u;
296 template <
class RhsValueType>
297 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
299 for (
int i = 0; i <
length_(); ++i)
308 assert(
size() == other.size());
316 const ValueType& vPrime = other.data_[idx];
318 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
326 template <
class RhsValueType>
327 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
331 for (
int i = 0; i <
length_(); ++i)
340 assert(
size() == other.size());
350 template <
class RhsValueType>
351 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 363 assert(
size() == other.size());
373 template <
class RhsValueType>
374 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 389 for (
int i = 0; i <
length_(); ++i)
390 result.data_[i] = - data_[i];
397 assert(
size() == other.size());
406 template <
class RhsValueType>
407 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 418 assert(
size() == other.size());
427 template <
class RhsValueType>
428 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 437 template <
class RhsValueType>
438 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
449 template <
class RhsValueType>
450 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 451 {
return value() == other; }
453 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 455 assert(
size() == other.size());
457 for (
int idx = 0; idx <
length_(); ++idx) {
458 if (data_[idx] != other.data_[idx]) {
465 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 466 {
return !operator==(other); }
468 template <
class RhsValueType>
469 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 470 {
return !operator==(other); }
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();
505 template <
class RhsValueType>
506 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 507 {
return value() <= other; }
509 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 511 assert(
size() == other.size());
513 return value() <= other.value();
521 template <
class RhsValueType>
522 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
526 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 528 assert(0 <= varIdx && varIdx <
size());
530 return data_[
dstart_() + varIdx];
534 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
536 assert(0 <= varIdx && varIdx <
size());
538 data_[
dstart_() + varIdx] = derVal;
541 template<
class Serializer>
542 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
548 std::array<ValueT, numDerivs + 1> data_;
552 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
553 OPM_HOST_DEVICE
bool operator<(const RhsValueType& a, const Evaluation<ValueType, numVars, staticSize>& b)
556 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
557 OPM_HOST_DEVICE
bool operator>(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
560 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
561 OPM_HOST_DEVICE
bool operator<=(const RhsValueType& a, const Evaluation<ValueType, numVars, staticSize>& b)
564 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
565 OPM_HOST_DEVICE
bool operator>=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
568 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
569 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
570 {
return a != b.value(); }
572 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
573 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator+(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
575 Evaluation<ValueType, numVars, staticSize> result(b);
580 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
581 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator-(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
586 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
587 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator/(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
589 Evaluation<ValueType, numVars, staticSize> tmp(a);
594 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
595 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator*(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
597 Evaluation<ValueType, numVars, staticSize> result(b);
605 static constexpr
bool value =
false;
608 template <
class ValueType,
int numVars,
unsigned staticSize>
611 static constexpr
bool value =
true;
614 template <
class ValueType,
int numVars,
unsigned staticSize>
615 OPM_HOST_DEVICE
void printEvaluation(std::ostream& os,
617 bool withDer =
false);
619 template <
class ValueType,
int numVars,
unsigned staticSize>
620 OPM_HOST_DEVICE std::ostream& operator<<(std::ostream& os, const Evaluation<ValueType, numVars, staticSize>& eval)
623 printEvaluation(os, eval.value(),
false);
625 printEvaluation(os, eval,
true);
638 template <
class ValueT,
int numDerivs,
unsigned staticSize>
639 struct IsNumber<
Opm::DenseAd::Evaluation<ValueT,numDerivs,staticSize>>
640 :
public std::integral_constant<bool, std::is_arithmetic<ValueT>::value> {
645 #endif // OPM_DENSEAD_EVALUATION_HPP OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:86
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 valuepos_() const
position index for value
Definition: Evaluation.hpp:83
Definition: SymmTensor.hpp:23
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation.hpp:104
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:78
bool operator>(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Greater-than comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:280
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:70
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation.hpp:73
bool operator>=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Greater-than-or-equal comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:292
This file includes all specializations for the dense-AD Evaluation class.
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition: Evaluation.hpp:67
Some templates to wrap the valgrind client request macros.
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:62
Definition: Evaluation.hpp:603
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation.hpp:89
bool operator!=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Inequality operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:256