32 #ifndef OPM_DENSEAD_EVALUATION_HPP 33 #define OPM_DENSEAD_EVALUATION_HPP 44 #include <opm/common/ErrorMacros.hpp> 45 #include <opm/common/utility/gpuDecorators.hpp> 48 #include <dune/common/typetraits.hh> 56 static constexpr
int DynamicSize = -1;
62 template <
class ValueT,
int numDerivs,
unsigned staticSize = 0>
74 OPM_HOST_DEVICE constexpr
int size()
const 79 OPM_HOST_DEVICE constexpr
int length_()
const 80 {
return size() + 1; }
87 OPM_HOST_DEVICE constexpr
int dstart_()
const 90 OPM_HOST_DEVICE constexpr
int dend_()
const 98 for (
const auto& v: data_)
99 Valgrind::CheckDefined(v);
116 template <
class RhsValueType>
117 OPM_HOST_DEVICE constexpr
Evaluation(
const RhsValueType& c): data_{}
127 template <
class RhsValueType>
128 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
131 assert(0 <= varPos && varPos <
size());
136 data_[varPos +
dstart_()] = 1.0;
142 OPM_HOST_DEVICE constexpr
void clearDerivatives()
168 template <
class RhsValueType>
169 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
176 template <
class RhsValueType>
177 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
180 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 181 " with 0 derivatives");
188 template <
class RhsValueType>
199 template <
class RhsValueType>
200 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
203 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 204 " with 0 derivatives");
210 template <
class RhsValueType>
211 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
218 template <
class RhsValueType>
225 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
227 assert(
size() == other.size());
230 data_[i] = other.data_[i];
237 assert(
size() == other.size());
239 for (
int i = 0; i <
length_(); ++i)
240 data_[i] += other.data_[i];
246 template <
class RhsValueType>
247 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
258 assert(
size() == other.size());
260 for (
int i = 0; i <
length_(); ++i)
261 data_[i] -= other.data_[i];
267 template <
class RhsValueType>
268 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
279 assert(
size() == other.size());
291 data_[i] = data_[i] * v + other.data_[i] * u;
297 template <
class RhsValueType>
298 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
300 for (
int i = 0; i <
length_(); ++i)
309 assert(
size() == other.size());
317 const ValueType& vPrime = other.data_[idx];
319 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
327 template <
class RhsValueType>
328 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
332 for (
int i = 0; i <
length_(); ++i)
341 assert(
size() == other.size());
351 template <
class RhsValueType>
352 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 364 assert(
size() == other.size());
374 template <
class RhsValueType>
375 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 390 for (
int i = 0; i <
length_(); ++i)
391 result.data_[i] = - data_[i];
398 assert(
size() == other.size());
407 template <
class RhsValueType>
408 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 419 assert(
size() == other.size());
428 template <
class RhsValueType>
429 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 438 template <
class RhsValueType>
439 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
450 template <
class RhsValueType>
451 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 452 {
return value() == other; }
454 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 456 assert(
size() == other.size());
458 for (
int idx = 0; idx <
length_(); ++idx) {
459 if (data_[idx] != other.data_[idx]) {
466 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 467 {
return !operator==(other); }
469 template <
class RhsValueType>
470 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 471 {
return !operator==(other); }
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();
506 template <
class RhsValueType>
507 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 508 {
return value() <= other; }
510 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 512 assert(
size() == other.size());
514 return value() <= other.value();
522 template <
class RhsValueType>
523 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
527 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 529 assert(0 <= varIdx && varIdx <
size());
531 return data_[
dstart_() + varIdx];
535 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
537 assert(0 <= varIdx && varIdx <
size());
539 data_[
dstart_() + varIdx] = derVal;
542 template<
class Serializer>
543 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
549 std::array<ValueT, numDerivs + 1> data_;
553 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
554 OPM_HOST_DEVICE
bool operator<(const RhsValueType& a, const Evaluation<ValueType, numVars, staticSize>& b)
557 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
558 OPM_HOST_DEVICE
bool operator>(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
561 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
562 OPM_HOST_DEVICE
bool operator<=(const RhsValueType& a, const Evaluation<ValueType, numVars, staticSize>& b)
565 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
566 OPM_HOST_DEVICE
bool operator>=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
569 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
570 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
571 {
return a != b.value(); }
573 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
574 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator+(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
576 Evaluation<ValueType, numVars, staticSize> result(b);
581 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
582 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator-(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
587 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
588 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator/(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
590 Evaluation<ValueType, numVars, staticSize> tmp(a);
595 template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
596 OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator*(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
598 Evaluation<ValueType, numVars, staticSize> result(b);
606 static constexpr
bool value =
false;
609 template <
class ValueType,
int numVars,
unsigned staticSize>
612 static constexpr
bool value =
true;
615 template <
class ValueType,
int numVars,
unsigned staticSize>
616 OPM_HOST_DEVICE
void printEvaluation(std::ostream& os,
618 bool withDer =
false);
620 template <
class ValueType,
int numVars,
unsigned staticSize>
621 OPM_HOST_DEVICE std::ostream& operator<<(std::ostream& os, const Evaluation<ValueType, numVars, staticSize>& eval)
624 printEvaluation(os, eval.value(),
false);
626 printEvaluation(os, eval,
true);
639 template <
class ValueT,
int numDerivs,
unsigned staticSize>
640 struct IsNumber<
Opm::DenseAd::Evaluation<ValueT,numDerivs,staticSize>>
641 :
public std::integral_constant<bool, std::is_arithmetic<ValueT>::value> {
646 #endif // OPM_DENSEAD_EVALUATION_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
Definition: SymmTensor.hpp:23
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
bool operator>(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Greater-than comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:302
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
bool operator>=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Greater-than-or-equal comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:314
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:68
Some templates to wrap the valgrind client request macros.
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:63
Definition: Evaluation.hpp:604
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation.hpp:90
bool operator!=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Inequality operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:278