31 #ifndef OPM_DENSEAD_EVALUATION4_HPP
32 #define OPM_DENSEAD_EVALUATION4_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()
159 template <
class RhsValueType>
160 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
167 template <
class RhsValueType>
168 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
171 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
172 " with 4 derivatives");
179 template <
class RhsValueType>
190 template <
class RhsValueType>
191 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
194 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
195 " with 4 derivatives");
201 template <
class RhsValueType>
202 static Evaluation createConstant(
const RhsValueType& value)
209 template <
class RhsValueType>
216 void print(std::ostream& os = std::cout)
const
219 os <<
"v: " << value() <<
" / d:";
222 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
223 os <<
" " << derivative(varIdx);
230 assert(
size() == other.size());
232 data_[1] = other.data_[1];
233 data_[2] = other.data_[2];
234 data_[3] = other.data_[3];
235 data_[4] = other.data_[4];
242 assert(
size() == other.size());
244 data_[0] += other.data_[0];
245 data_[1] += other.data_[1];
246 data_[2] += other.data_[2];
247 data_[3] += other.data_[3];
248 data_[4] += other.data_[4];
254 template <
class RhsValueType>
255 Evaluation& operator+=(
const RhsValueType& other)
266 assert(
size() == other.size());
268 data_[0] -= other.data_[0];
269 data_[1] -= other.data_[1];
270 data_[2] -= other.data_[2];
271 data_[3] -= other.data_[3];
272 data_[4] -= other.data_[4];
278 template <
class RhsValueType>
279 Evaluation& operator-=(
const RhsValueType& other)
290 assert(
size() == other.size());
301 data_[1] = data_[1] * v + other.data_[1] * u;
302 data_[2] = data_[2] * v + other.data_[2] * u;
303 data_[3] = data_[3] * v + other.data_[3] * u;
304 data_[4] = data_[4] * v + other.data_[4] * u;
310 template <
class RhsValueType>
311 Evaluation& operator*=(
const RhsValueType& other)
325 assert(
size() == other.size());
331 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
332 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
333 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
334 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
341 template <
class RhsValueType>
342 Evaluation& operator/=(
const RhsValueType& other)
358 assert(
size() == other.size());
368 template <
class RhsValueType>
369 Evaluation operator+(
const RhsValueType& other)
const
381 assert(
size() == other.size());
391 template <
class RhsValueType>
392 Evaluation operator-(
const RhsValueType& other)
const
407 result.data_[0] = - data_[0];
408 result.data_[1] = - data_[1];
409 result.data_[2] = - data_[2];
410 result.data_[3] = - data_[3];
411 result.data_[4] = - data_[4];
418 assert(
size() == other.size());
427 template <
class RhsValueType>
428 Evaluation operator*(
const RhsValueType& other)
const
439 assert(
size() == other.size());
448 template <
class RhsValueType>
449 Evaluation operator/(
const RhsValueType& other)
const
458 template <
class RhsValueType>
459 Evaluation& operator=(
const RhsValueType& other)
470 template <
class RhsValueType>
471 bool operator==(
const RhsValueType& other)
const
472 {
return value() == other; }
474 bool operator==(
const Evaluation& other)
const
476 assert(
size() == other.size());
478 for (
int idx = 0; idx <
length_(); ++idx) {
479 if (data_[idx] != other.data_[idx]) {
486 bool operator!=(
const Evaluation& other)
const
487 {
return !operator==(other); }
489 template <
class RhsValueType>
490 bool operator!=(
const RhsValueType& other)
const
491 {
return !operator==(other); }
493 template <
class RhsValueType>
494 bool operator>(RhsValueType other)
const
495 {
return value() > other; }
499 assert(
size() == other.size());
501 return value() > other.value();
504 template <
class RhsValueType>
505 bool operator<(RhsValueType other)
const
506 {
return value() < other; }
510 assert(
size() == other.size());
512 return value() < other.value();
515 template <
class RhsValueType>
516 bool operator>=(RhsValueType other)
const
517 {
return value() >= other; }
519 bool operator>=(
const Evaluation& other)
const
521 assert(
size() == other.size());
523 return value() >= other.value();
526 template <
class RhsValueType>
527 bool operator<=(RhsValueType other)
const
528 {
return value() <= other; }
530 bool operator<=(
const Evaluation& other)
const
532 assert(
size() == other.size());
534 return value() <= other.value();
542 template <
class RhsValueType>
543 void setValue(
const RhsValueType& val)
547 const ValueType& derivative(
int varIdx)
const
549 assert(0 <= varIdx && varIdx <
size());
551 return data_[
dstart_() + varIdx];
555 void setDerivative(
int varIdx,
const ValueType& derVal)
557 assert(0 <= varIdx && varIdx <
size());
559 data_[
dstart_() + varIdx] = derVal;
564 std::array<ValueT, 5> 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 dstart_() const
start index for derivatives
Definition: Evaluation4.hpp:74
ValueT ValueType
field type
Definition: Evaluation4.hpp:58
Evaluation(const Evaluation &other)=default
copy other function evaluation
constexpr int valuepos_() const
position index for value
Definition: Evaluation4.hpp:71
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation4.hpp:77
constexpr int size() const
number of derivatives
Definition: Evaluation4.hpp:61
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation4.hpp:82
Evaluation()
default constructor
Definition: Evaluation4.hpp:92
constexpr int length_() const
length of internal data vector
Definition: Evaluation4.hpp:66
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