32#ifndef OPM_DENSEAD_EVALUATION_HPP
33#define OPM_DENSEAD_EVALUATION_HPP
44#include <opm/common/utility/gpuDecorators.hpp>
51static constexpr int DynamicSize = -1;
57template <
class ValueT,
int numDerivs,
unsigned staticSize = 0>
69 OPM_HOST_DEVICE
constexpr int size()
const
74 OPM_HOST_DEVICE
constexpr int length_()
const
75 {
return size() + 1; }
82 OPM_HOST_DEVICE
constexpr int dstart_()
const
85 OPM_HOST_DEVICE
constexpr int dend_()
const
93 for (
const auto& v: data_)
94 Valgrind::CheckDefined(v);
111 template <
class RhsValueType>
112 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c)
124 template <
class RhsValueType>
125 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
128 assert(0 <= varPos && varPos <
size());
133 data_[varPos +
dstart_()] = 1.0;
139 OPM_HOST_DEVICE
void clearDerivatives()
165 template <
class RhsValueType>
166 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType& value,
int varPos)
173 template <
class RhsValueType>
174 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
177 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
178 " with 0 derivatives");
185 template <
class RhsValueType>
186 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
196 template <
class RhsValueType>
197 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
200 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
201 " with 0 derivatives");
207 template <
class RhsValueType>
208 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType& value)
215 template <
class RhsValueType>
222 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
224 assert(
size() == other.size());
227 data_[i] = other.data_[i];
234 assert(
size() == other.size());
236 for (
int i = 0; i <
length_(); ++i)
237 data_[i] += other.data_[i];
243 template <
class RhsValueType>
244 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
255 assert(
size() == other.size());
257 for (
int i = 0; i <
length_(); ++i)
258 data_[i] -= other.data_[i];
264 template <
class RhsValueType>
265 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
276 assert(
size() == other.size());
288 data_[i] = data_[i] * v + other.data_[i] * u;
294 template <
class RhsValueType>
295 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
297 for (
int i = 0; i <
length_(); ++i)
306 assert(
size() == other.size());
314 const ValueType& vPrime = other.data_[idx];
316 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
324 template <
class RhsValueType>
325 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
329 for (
int i = 0; i <
length_(); ++i)
338 assert(
size() == other.size());
348 template <
class RhsValueType>
349 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
361 assert(
size() == other.size());
371 template <
class RhsValueType>
372 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
387 for (
int i = 0; i <
length_(); ++i)
388 result.data_[i] = - data_[i];
395 assert(
size() == other.size());
404 template <
class RhsValueType>
405 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
416 assert(
size() == other.size());
425 template <
class RhsValueType>
426 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
435 template <
class RhsValueType>
436 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
447 template <
class RhsValueType>
448 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
449 {
return value() == other; }
451 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
453 assert(
size() == other.size());
455 for (
int idx = 0; idx <
length_(); ++idx) {
456 if (data_[idx] != other.data_[idx]) {
463 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
464 {
return !operator==(other); }
466 template <
class RhsValueType>
467 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
468 {
return !operator==(other); }
470 template <
class RhsValueType>
471 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
472 {
return value() > other; }
474 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
476 assert(
size() == other.size());
478 return value() > other.value();
481 template <
class RhsValueType>
482 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
483 {
return value() < other; }
485 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
487 assert(
size() == other.size());
489 return value() < other.value();
492 template <
class RhsValueType>
493 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
494 {
return value() >= other; }
496 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
498 assert(
size() == other.size());
500 return value() >= other.value();
503 template <
class RhsValueType>
504 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
505 {
return value() <= other; }
507 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
509 assert(
size() == other.size());
511 return value() <= other.value();
515 OPM_HOST_DEVICE
const ValueType& value()
const
519 template <
class RhsValueType>
520 OPM_HOST_DEVICE
void setValue(
const RhsValueType& val)
524 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
526 assert(0 <= varIdx && varIdx <
size());
528 return data_[
dstart_() + varIdx];
532 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
534 assert(0 <= varIdx && varIdx <
size());
536 data_[
dstart_() + varIdx] = derVal;
539 template<
class Serializer>
540 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
546 std::array<ValueT, numDerivs + 1> data_;
550template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
551OPM_HOST_DEVICE
bool operator<(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
554template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
555OPM_HOST_DEVICE
bool operator>(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
558template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
559OPM_HOST_DEVICE
bool operator<=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
562template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
563OPM_HOST_DEVICE
bool operator>=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
566template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
567OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
568{
return a != b.value(); }
570template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
571OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator+(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
573 Evaluation<ValueType, numVars, staticSize> result(b);
578template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
579OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator-(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
584template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
585OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator/(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
587 Evaluation<ValueType, numVars, staticSize> tmp(a);
592template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
593OPM_HOST_DEVICE Evaluation<ValueType, numVars, staticSize> operator*(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
595 Evaluation<ValueType, numVars, staticSize> result(b);
603 static constexpr bool value =
false;
606template <
class ValueType,
int numVars,
unsigned staticSize>
609 static constexpr bool value =
true;
612template <
class ValueType,
int numVars,
unsigned staticSize>
613OPM_HOST_DEVICE
void printEvaluation(std::ostream& os,
615 bool withDer =
false);
617template <
class ValueType,
int numVars,
unsigned staticSize>
621 printEvaluation(os, eval.value(),
false);
623 printEvaluation(os, eval,
true);
This file includes all specializations for the dense-AD Evaluation class.
Some templates to wrap the valgrind client request macros.
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 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 Evaluation()
default constructor
Definition Evaluation.hpp:100
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:79
Evaluation(const Evaluation &other)=default
copy other function evaluation
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation.hpp:69
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation.hpp:85
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Evaluation.hpp:602