32 #ifndef OPM_DENSEAD_EVALUATION_HPP
33 #define OPM_DENSEAD_EVALUATION_HPP
38 #include <opm/common/Valgrind.hpp>
40 #include <dune/common/version.hh>
56 template <
class ValueT,
int numDerivs>
64 static constexpr
int size = numDerivs;
89 template <
class RhsValueType>
94 Valgrind::CheckDefined( data_ );
101 template <
class RhsValueType>
105 assert(0 <= varPos && varPos <
size);
111 Valgrind::CheckDefined(data_);
115 void clearDerivatives()
123 template <
class RhsValueType>
124 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
133 template <
class RhsValueType>
134 static Evaluation createConstant(
const RhsValueType& value)
140 void print(std::ostream& os = std::cout)
const
143 os <<
"v: " << value() <<
" / d:";
146 for (
int varIdx = 0; varIdx <
size; ++varIdx) {
147 os <<
" " << derivative(varIdx);
155 data_[i] = other.data_[i];
163 for (
int i = 0; i <
length_; ++i) {
164 data_[i] += other.data_[i];
171 template <
class RhsValueType>
172 Evaluation& operator+=(
const RhsValueType& other)
183 for (
int i = 0; i <
length_; ++i) {
184 data_[i] -= other.data_[i];
191 template <
class RhsValueType>
192 Evaluation& operator-=(
const RhsValueType& other)
213 data_[i] = data_[i] * v + other.data_[i] * u;
220 template <
class RhsValueType>
221 Evaluation& operator*=(
const RhsValueType& other)
223 for (
int i = 0; i <
length_; ++i) {
239 const ValueType& vPrime = other.data_[idx];
241 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
249 template <
class RhsValueType>
250 Evaluation& operator/=(
const RhsValueType& other)
254 for (
int i = 0; i <
length_; ++i) {
272 template <
class RhsValueType>
273 Evaluation operator+(
const RhsValueType& other)
const
293 template <
class RhsValueType>
294 Evaluation operator-(
const RhsValueType& other)
const
309 for (
int i = 0; i <
length_; ++i) {
310 result.data_[i] = - data_[i];
325 template <
class RhsValueType>
326 Evaluation operator*(
const RhsValueType& other)
const
344 template <
class RhsValueType>
345 Evaluation operator/(
const RhsValueType& other)
const
354 template <
class RhsValueType>
355 Evaluation& operator=(
const RhsValueType& other)
366 template <
class RhsValueType>
367 bool operator==(
const RhsValueType& other)
const
368 {
return value() == other; }
370 bool operator==(
const Evaluation& other)
const
372 for (
int idx = 0; idx <
length_; ++idx) {
373 if (data_[idx] != other.data_[idx]) {
380 bool operator!=(
const Evaluation& other)
const
381 {
return !operator==(other); }
383 template <
class RhsValueType>
384 bool operator>(RhsValueType other)
const
385 {
return value() > other; }
388 {
return value() > other.value(); }
390 template <
class RhsValueType>
391 bool operator<(RhsValueType other)
const
392 {
return value() < other; }
395 {
return value() < other.value(); }
397 template <
class RhsValueType>
398 bool operator>=(RhsValueType other)
const
399 {
return value() >= other; }
401 bool operator>=(
const Evaluation& other)
const
402 {
return value() >= other.value(); }
404 template <
class RhsValueType>
405 bool operator<=(RhsValueType other)
const
406 {
return value() <= other; }
408 bool operator<=(
const Evaluation& other)
const
409 {
return value() <= other.value(); }
416 template <
class RhsValueType>
417 void setValue(
const RhsValueType& val)
421 const ValueType& derivative(
int varIdx)
const
423 assert(0 <= varIdx && varIdx <
size);
425 return data_[
dstart_ + varIdx];
429 void setDerivative(
int varIdx,
const ValueType& derVal)
431 assert(0 <= varIdx && varIdx <
size);
433 data_[
dstart_ + varIdx] = derVal;
437 std::array<ValueT, length_> data_;
441 template <
class RhsValueType,
class ValueType,
int numVars>
442 bool operator<(const RhsValueType& a, const Evaluation<ValueType, numVars>& b)
445 template <
class RhsValueType,
class ValueType,
int numVars>
446 bool operator>(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
449 template <
class RhsValueType,
class ValueType,
int numVars>
450 bool operator<=(const RhsValueType& a, const Evaluation<ValueType, numVars>& b)
453 template <
class RhsValueType,
class ValueType,
int numVars>
454 bool operator>=(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
457 template <
class RhsValueType,
class ValueType,
int numVars>
458 bool operator!=(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
459 {
return a != b.value(); }
461 template <
class RhsValueType,
class ValueType,
int numVars>
462 Evaluation<ValueType, numVars> operator+(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
464 Evaluation<ValueType, numVars> result(b);
469 template <
class RhsValueType,
class ValueType,
int numVars>
470 Evaluation<ValueType, numVars> operator-(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
472 Evaluation<ValueType, numVars> result(a);
477 template <
class RhsValueType,
class ValueType,
int numVars>
478 Evaluation<ValueType, numVars> operator/(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
480 Evaluation<ValueType, numVars> tmp(a);
485 template <
class RhsValueType,
class ValueType,
int numVars>
486 Evaluation<ValueType, numVars> operator*(
const RhsValueType& a,
const Evaluation<ValueType, numVars>& b)
488 Evaluation<ValueType, numVars> result(b);
493 template <
class ValueType,
int numVars>
494 std::ostream& operator<<(std::ostream& os, const Evaluation<ValueType, numVars>& eval)
523 #if !(DUNE_VERSION_NEWER(DUNE_COMMON, 2,4))
527 template <
class ValueType,
int numVars>
528 Evaluation<ValueType, numVars> abs(
const Evaluation<ValueType, numVars>&);
532 template <
class ValueType,
int numVars>
534 {
return Opm::DenseAd::abs(x); }
538 #if defined DUNE_DENSEMATRIX_HH
540 "Due to some C++ peculiarity regarding function overloads, the 'Evaluation.hpp'" \
541 "header file must be included before Dune's 'densematrix.hh' for Dune < 2.4. " \
542 "(If Evaluations are to be used in conjunction with a dense matrix.)"
548 #include <dune/common/ftraits.hh>
551 template <
class ValueType,
int numVars>
552 struct FieldTraits<Opm::DenseAd::Evaluation<ValueType, numVars> >
565 #endif // OPM_DENSEAD_EVALUATION_HPP
Evaluation()
default constructor
Definition: Evaluation.hpp:79
A number of commonly used algebraic functions for the localized OPM automatic differentiation (AD) fr...
This file includes all specializations for the dense-AD Evaluation class.
ValueT ValueType
field type
Definition: Evaluation.hpp:61
static constexpr int valuepos_
position index for value
Definition: Evaluation.hpp:71
static constexpr int length_
length of internal data vector
Definition: Evaluation.hpp:68
static constexpr int dstart_
start index for derivatives
Definition: Evaluation.hpp:73
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:57
static constexpr int size
number of derivatives
Definition: Evaluation.hpp:64
static constexpr int dend_
end+1 index for derivatives
Definition: Evaluation.hpp:75
Representation of an evaluation of a function and its derivatives w.r.t.