32#ifndef OPM_DENSEAD_EVALUATION_HPP
33#define OPM_DENSEAD_EVALUATION_HPP
49static constexpr int DynamicSize = -1;
55template <
class ValueT,
int numDerivs,
unsigned staticSize = 0>
73 {
return size() + 1; }
91 for (
const auto& v: data_)
92 Valgrind::CheckDefined(v);
109 template <
class RhsValueType>
122 template <
class RhsValueType>
126 assert(0 <= varPos && varPos <
size());
131 data_[varPos +
dstart_()] = 1.0;
137 void clearDerivatives()
163 template <
class RhsValueType>
164 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
171 template <
class RhsValueType>
172 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
175 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
176 " with 0 derivatives");
183 template <
class RhsValueType>
194 template <
class RhsValueType>
195 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
198 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
199 " with 0 derivatives");
205 template <
class RhsValueType>
206 static Evaluation createConstant(
const RhsValueType& value)
213 template <
class RhsValueType>
222 assert(
size() == other.size());
225 data_[i] = other.data_[i];
232 assert(
size() == other.size());
234 for (
int i = 0; i <
length_(); ++i)
235 data_[i] += other.data_[i];
241 template <
class RhsValueType>
242 Evaluation& operator+=(
const RhsValueType& other)
253 assert(
size() == other.size());
255 for (
int i = 0; i <
length_(); ++i)
256 data_[i] -= other.data_[i];
262 template <
class RhsValueType>
263 Evaluation& operator-=(
const RhsValueType& other)
274 assert(
size() == other.size());
286 data_[i] = data_[i] * v + other.data_[i] * u;
292 template <
class RhsValueType>
293 Evaluation& operator*=(
const RhsValueType& other)
295 for (
int i = 0; i <
length_(); ++i)
304 assert(
size() == other.size());
312 const ValueType& vPrime = other.data_[idx];
314 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
322 template <
class RhsValueType>
323 Evaluation& operator/=(
const RhsValueType& other)
327 for (
int i = 0; i <
length_(); ++i)
336 assert(
size() == other.size());
346 template <
class RhsValueType>
347 Evaluation operator+(
const RhsValueType& other)
const
359 assert(
size() == other.size());
369 template <
class RhsValueType>
370 Evaluation operator-(
const RhsValueType& other)
const
385 for (
int i = 0; i <
length_(); ++i)
386 result.data_[i] = - data_[i];
393 assert(
size() == other.size());
402 template <
class RhsValueType>
403 Evaluation operator*(
const RhsValueType& other)
const
414 assert(
size() == other.size());
423 template <
class RhsValueType>
424 Evaluation operator/(
const RhsValueType& other)
const
433 template <
class RhsValueType>
434 Evaluation& operator=(
const RhsValueType& other)
445 template <
class RhsValueType>
446 bool operator==(
const RhsValueType& other)
const
447 {
return value() == other; }
449 bool operator==(
const Evaluation& other)
const
451 assert(
size() == other.size());
453 for (
int idx = 0; idx <
length_(); ++idx) {
454 if (data_[idx] != other.data_[idx]) {
461 bool operator!=(
const Evaluation& other)
const
462 {
return !operator==(other); }
464 template <
class RhsValueType>
465 bool operator!=(
const RhsValueType& other)
const
466 {
return !operator==(other); }
468 template <
class RhsValueType>
469 bool operator>(RhsValueType other)
const
470 {
return value() > other; }
474 assert(
size() == other.size());
476 return value() > other.value();
479 template <
class RhsValueType>
480 bool operator<(RhsValueType other)
const
481 {
return value() < other; }
485 assert(
size() == other.size());
487 return value() < other.value();
490 template <
class RhsValueType>
491 bool operator>=(RhsValueType other)
const
492 {
return value() >= other; }
494 bool operator>=(
const Evaluation& other)
const
496 assert(
size() == other.size());
498 return value() >= other.value();
501 template <
class RhsValueType>
502 bool operator<=(RhsValueType other)
const
503 {
return value() <= other; }
505 bool operator<=(
const Evaluation& other)
const
507 assert(
size() == other.size());
509 return value() <= other.value();
517 template <
class RhsValueType>
518 void setValue(
const RhsValueType& val)
522 const ValueType& derivative(
int varIdx)
const
524 assert(0 <= varIdx && varIdx <
size());
526 return data_[
dstart_() + varIdx];
530 void setDerivative(
int varIdx,
const ValueType& derVal)
532 assert(0 <= varIdx && varIdx <
size());
534 data_[
dstart_() + varIdx] = derVal;
537 template<
class Serializer>
538 void serializeOp(Serializer& serializer)
544 std::array<ValueT, numDerivs + 1> data_;
548template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
549bool operator<(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
552template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
553bool operator>(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
556template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
557bool operator<=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
560template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
561bool operator>=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
564template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
565bool operator!=(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
566{
return a != b.value(); }
568template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
569Evaluation<ValueType, numVars, staticSize> operator+(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
571 Evaluation<ValueType, numVars, staticSize> result(b);
576template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
577Evaluation<ValueType, numVars, staticSize> operator-(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
582template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
583Evaluation<ValueType, numVars, staticSize> operator/(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
585 Evaluation<ValueType, numVars, staticSize> tmp(a);
590template <
class RhsValueType,
class ValueType,
int numVars,
unsigned staticSize>
591Evaluation<ValueType, numVars, staticSize> operator*(
const RhsValueType& a,
const Evaluation<ValueType, numVars, staticSize>& b)
593 Evaluation<ValueType, numVars, staticSize> result(b);
601 static constexpr bool value =
false;
604template <
class ValueType,
int numVars,
unsigned staticSize>
607 static constexpr bool value =
true;
610template <
class ValueType,
int numVars,
unsigned staticSize>
611void printEvaluation(std::ostream& os,
613 bool withDer =
false);
615template <
class ValueType,
int numVars,
unsigned staticSize>
619 printEvaluation(os, eval.value(),
false);
621 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:57
Evaluation()
default constructor
Definition Evaluation.hpp:98
ValueT ValueType
field type
Definition Evaluation.hpp:64
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation.hpp:88
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation.hpp:61
constexpr int size() const
number of derivatives
Definition Evaluation.hpp:67
constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:77
Evaluation(const Evaluation &other)=default
copy other function evaluation
constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation.hpp:83
constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:72
constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:80
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Evaluation.hpp:600