31 #ifndef OPM_DENSEAD_EVALUATION3_HPP
32 #define OPM_DENSEAD_EVALUATION3_HPP
49 template <
class ValueT>
67 {
return size() + 1; }
85 for (
const auto& v: data_)
86 Valgrind::CheckDefined(v);
103 template <
class RhsValueType>
116 template <
class RhsValueType>
120 assert(0 <= varPos && varPos <
size());
125 data_[varPos +
dstart_()] = 1.0;
131 void clearDerivatives()
158 template <
class RhsValueType>
159 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
166 template <
class RhsValueType>
167 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
170 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
171 " with 3 derivatives");
178 template <
class RhsValueType>
189 template <
class RhsValueType>
190 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
193 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
194 " with 3 derivatives");
200 template <
class RhsValueType>
201 static Evaluation createConstant(
const RhsValueType& value)
208 template <
class RhsValueType>
215 void print(std::ostream& os = std::cout)
const
218 os <<
"v: " << value() <<
" / d:";
221 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
222 os <<
" " << derivative(varIdx);
229 assert(
size() == other.size());
231 data_[1] = other.data_[1];
232 data_[2] = other.data_[2];
233 data_[3] = other.data_[3];
240 assert(
size() == other.size());
242 data_[0] += other.data_[0];
243 data_[1] += other.data_[1];
244 data_[2] += other.data_[2];
245 data_[3] += other.data_[3];
251 template <
class RhsValueType>
252 Evaluation& operator+=(
const RhsValueType& other)
263 assert(
size() == other.size());
265 data_[0] -= other.data_[0];
266 data_[1] -= other.data_[1];
267 data_[2] -= other.data_[2];
268 data_[3] -= other.data_[3];
274 template <
class RhsValueType>
275 Evaluation& operator-=(
const RhsValueType& other)
286 assert(
size() == other.size());
297 data_[1] = data_[1] * v + other.data_[1] * u;
298 data_[2] = data_[2] * v + other.data_[2] * u;
299 data_[3] = data_[3] * v + other.data_[3] * u;
305 template <
class RhsValueType>
306 Evaluation& operator*=(
const RhsValueType& other)
319 assert(
size() == other.size());
325 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
326 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
327 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
334 template <
class RhsValueType>
335 Evaluation& operator/=(
const RhsValueType& other)
350 assert(
size() == other.size());
360 template <
class RhsValueType>
361 Evaluation operator+(
const RhsValueType& other)
const
373 assert(
size() == other.size());
383 template <
class RhsValueType>
384 Evaluation operator-(
const RhsValueType& other)
const
399 result.data_[0] = - data_[0];
400 result.data_[1] = - data_[1];
401 result.data_[2] = - data_[2];
402 result.data_[3] = - data_[3];
409 assert(
size() == other.size());
418 template <
class RhsValueType>
419 Evaluation operator*(
const RhsValueType& other)
const
430 assert(
size() == other.size());
439 template <
class RhsValueType>
440 Evaluation operator/(
const RhsValueType& other)
const
449 template <
class RhsValueType>
450 Evaluation& operator=(
const RhsValueType& other)
461 template <
class RhsValueType>
462 bool operator==(
const RhsValueType& other)
const
463 {
return value() == other; }
465 bool operator==(
const Evaluation& other)
const
467 assert(
size() == other.size());
469 for (
int idx = 0; idx <
length_(); ++idx) {
470 if (data_[idx] != other.data_[idx]) {
477 bool operator!=(
const Evaluation& other)
const
478 {
return !operator==(other); }
480 template <
class RhsValueType>
481 bool operator!=(
const RhsValueType& other)
const
482 {
return !operator==(other); }
484 template <
class RhsValueType>
485 bool operator>(RhsValueType other)
const
486 {
return value() > other; }
490 assert(
size() == other.size());
492 return value() > other.value();
495 template <
class RhsValueType>
496 bool operator<(RhsValueType other)
const
497 {
return value() < other; }
501 assert(
size() == other.size());
503 return value() < other.value();
506 template <
class RhsValueType>
507 bool operator>=(RhsValueType other)
const
508 {
return value() >= other; }
510 bool operator>=(
const Evaluation& other)
const
512 assert(
size() == other.size());
514 return value() >= other.value();
517 template <
class RhsValueType>
518 bool operator<=(RhsValueType other)
const
519 {
return value() <= other; }
521 bool operator<=(
const Evaluation& other)
const
523 assert(
size() == other.size());
525 return value() <= other.value();
533 template <
class RhsValueType>
534 void setValue(
const RhsValueType& val)
538 const ValueType& derivative(
int varIdx)
const
540 assert(0 <= varIdx && varIdx <
size());
542 return data_[
dstart_() + varIdx];
546 void setDerivative(
int varIdx,
const ValueType& derVal)
548 assert(0 <= varIdx && varIdx <
size());
550 data_[
dstart_() + varIdx] = derVal;
555 std::array<ValueT, 4> data_;
Representation of an evaluation of a function and its derivatives w.r.t.
A number of commonly used algebraic functions for the localized OPM automatic differentiation (AD) fr...
Some templates to wrap the valgrind client request macros.
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation3.hpp:77
constexpr int length_() const
length of internal data vector
Definition: Evaluation3.hpp:66
constexpr int size() const
number of derivatives
Definition: Evaluation3.hpp:61
Evaluation()
default constructor
Definition: Evaluation3.hpp:92
Evaluation(const Evaluation &other)=default
copy other function evaluation
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation3.hpp:82
ValueT ValueType
field type
Definition: Evaluation3.hpp:58
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation3.hpp:74
constexpr int valuepos_() const
position index for value
Definition: Evaluation3.hpp:71
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:59
Evaluation()
default constructor
Definition: Evaluation.hpp:100
ValueT ValueType
field type
Definition: Evaluation.hpp:66
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation.hpp:90
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition: Evaluation.hpp:63
constexpr int size() const
number of derivatives
Definition: Evaluation.hpp:69
constexpr int valuepos_() const
position index for value
Definition: Evaluation.hpp:79
constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:74
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:82