31 #ifndef OPM_DENSEAD_EVALUATION2_HPP
32 #define OPM_DENSEAD_EVALUATION2_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()
157 template <
class RhsValueType>
158 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
165 template <
class RhsValueType>
166 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
169 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
170 " with 2 derivatives");
177 template <
class RhsValueType>
188 template <
class RhsValueType>
189 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
192 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
193 " with 2 derivatives");
199 template <
class RhsValueType>
200 static Evaluation createConstant(
const RhsValueType& value)
207 template <
class RhsValueType>
214 void print(std::ostream& os = std::cout)
const
217 os <<
"v: " << value() <<
" / d:";
220 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
221 os <<
" " << derivative(varIdx);
228 assert(
size() == other.size());
230 data_[1] = other.data_[1];
231 data_[2] = other.data_[2];
238 assert(
size() == other.size());
240 data_[0] += other.data_[0];
241 data_[1] += other.data_[1];
242 data_[2] += other.data_[2];
248 template <
class RhsValueType>
249 Evaluation& operator+=(
const RhsValueType& other)
260 assert(
size() == other.size());
262 data_[0] -= other.data_[0];
263 data_[1] -= other.data_[1];
264 data_[2] -= other.data_[2];
270 template <
class RhsValueType>
271 Evaluation& operator-=(
const RhsValueType& other)
282 assert(
size() == other.size());
293 data_[1] = data_[1] * v + other.data_[1] * u;
294 data_[2] = data_[2] * v + other.data_[2] * u;
300 template <
class RhsValueType>
301 Evaluation& operator*=(
const RhsValueType& other)
313 assert(
size() == other.size());
319 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
320 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
327 template <
class RhsValueType>
328 Evaluation& operator/=(
const RhsValueType& other)
342 assert(
size() == other.size());
352 template <
class RhsValueType>
353 Evaluation operator+(
const RhsValueType& other)
const
365 assert(
size() == other.size());
375 template <
class RhsValueType>
376 Evaluation operator-(
const RhsValueType& other)
const
391 result.data_[0] = - data_[0];
392 result.data_[1] = - data_[1];
393 result.data_[2] = - data_[2];
400 assert(
size() == other.size());
409 template <
class RhsValueType>
410 Evaluation operator*(
const RhsValueType& other)
const
421 assert(
size() == other.size());
430 template <
class RhsValueType>
431 Evaluation operator/(
const RhsValueType& other)
const
440 template <
class RhsValueType>
441 Evaluation& operator=(
const RhsValueType& other)
452 template <
class RhsValueType>
453 bool operator==(
const RhsValueType& other)
const
454 {
return value() == other; }
456 bool operator==(
const Evaluation& other)
const
458 assert(
size() == other.size());
460 for (
int idx = 0; idx <
length_(); ++idx) {
461 if (data_[idx] != other.data_[idx]) {
468 bool operator!=(
const Evaluation& other)
const
469 {
return !operator==(other); }
471 template <
class RhsValueType>
472 bool operator!=(
const RhsValueType& other)
const
473 {
return !operator==(other); }
475 template <
class RhsValueType>
476 bool operator>(RhsValueType other)
const
477 {
return value() > other; }
481 assert(
size() == other.size());
483 return value() > other.value();
486 template <
class RhsValueType>
487 bool operator<(RhsValueType other)
const
488 {
return value() < other; }
492 assert(
size() == other.size());
494 return value() < other.value();
497 template <
class RhsValueType>
498 bool operator>=(RhsValueType other)
const
499 {
return value() >= other; }
501 bool operator>=(
const Evaluation& other)
const
503 assert(
size() == other.size());
505 return value() >= other.value();
508 template <
class RhsValueType>
509 bool operator<=(RhsValueType other)
const
510 {
return value() <= other; }
512 bool operator<=(
const Evaluation& other)
const
514 assert(
size() == other.size());
516 return value() <= other.value();
524 template <
class RhsValueType>
525 void setValue(
const RhsValueType& val)
529 const ValueType& derivative(
int varIdx)
const
531 assert(0 <= varIdx && varIdx <
size());
533 return data_[
dstart_() + varIdx];
537 void setDerivative(
int varIdx,
const ValueType& derVal)
539 assert(0 <= varIdx && varIdx <
size());
541 data_[
dstart_() + varIdx] = derVal;
546 std::array<ValueT, 3> 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 valuepos_() const
position index for value
Definition: Evaluation2.hpp:71
ValueT ValueType
field type
Definition: Evaluation2.hpp:58
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation2.hpp:74
constexpr int size() const
number of derivatives
Definition: Evaluation2.hpp:61
Evaluation()
default constructor
Definition: Evaluation2.hpp:92
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation2.hpp:82
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation2.hpp:77
constexpr int length_() const
length of internal data vector
Definition: Evaluation2.hpp:66
Evaluation(const Evaluation &other)=default
copy other function evaluation
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