31 #ifndef OPM_DENSEAD_EVALUATION6_HPP
32 #define OPM_DENSEAD_EVALUATION6_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()
161 template <
class RhsValueType>
162 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
169 template <
class RhsValueType>
170 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
173 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
174 " with 6 derivatives");
181 template <
class RhsValueType>
192 template <
class RhsValueType>
193 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
196 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
197 " with 6 derivatives");
203 template <
class RhsValueType>
204 static Evaluation createConstant(
const RhsValueType& value)
211 template <
class RhsValueType>
218 void print(std::ostream& os = std::cout)
const
221 os <<
"v: " << value() <<
" / d:";
224 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
225 os <<
" " << derivative(varIdx);
232 assert(
size() == other.size());
234 data_[1] = other.data_[1];
235 data_[2] = other.data_[2];
236 data_[3] = other.data_[3];
237 data_[4] = other.data_[4];
238 data_[5] = other.data_[5];
239 data_[6] = other.data_[6];
246 assert(
size() == other.size());
248 data_[0] += other.data_[0];
249 data_[1] += other.data_[1];
250 data_[2] += other.data_[2];
251 data_[3] += other.data_[3];
252 data_[4] += other.data_[4];
253 data_[5] += other.data_[5];
254 data_[6] += other.data_[6];
260 template <
class RhsValueType>
261 Evaluation& operator+=(
const RhsValueType& other)
272 assert(
size() == other.size());
274 data_[0] -= other.data_[0];
275 data_[1] -= other.data_[1];
276 data_[2] -= other.data_[2];
277 data_[3] -= other.data_[3];
278 data_[4] -= other.data_[4];
279 data_[5] -= other.data_[5];
280 data_[6] -= other.data_[6];
286 template <
class RhsValueType>
287 Evaluation& operator-=(
const RhsValueType& other)
298 assert(
size() == other.size());
309 data_[1] = data_[1] * v + other.data_[1] * u;
310 data_[2] = data_[2] * v + other.data_[2] * u;
311 data_[3] = data_[3] * v + other.data_[3] * u;
312 data_[4] = data_[4] * v + other.data_[4] * u;
313 data_[5] = data_[5] * v + other.data_[5] * u;
314 data_[6] = data_[6] * v + other.data_[6] * u;
320 template <
class RhsValueType>
321 Evaluation& operator*=(
const RhsValueType& other)
337 assert(
size() == other.size());
343 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
344 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
345 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
346 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
347 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
348 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
355 template <
class RhsValueType>
356 Evaluation& operator/=(
const RhsValueType& other)
374 assert(
size() == other.size());
384 template <
class RhsValueType>
385 Evaluation operator+(
const RhsValueType& other)
const
397 assert(
size() == other.size());
407 template <
class RhsValueType>
408 Evaluation operator-(
const RhsValueType& other)
const
423 result.data_[0] = - data_[0];
424 result.data_[1] = - data_[1];
425 result.data_[2] = - data_[2];
426 result.data_[3] = - data_[3];
427 result.data_[4] = - data_[4];
428 result.data_[5] = - data_[5];
429 result.data_[6] = - data_[6];
436 assert(
size() == other.size());
445 template <
class RhsValueType>
446 Evaluation operator*(
const RhsValueType& other)
const
457 assert(
size() == other.size());
466 template <
class RhsValueType>
467 Evaluation operator/(
const RhsValueType& other)
const
476 template <
class RhsValueType>
477 Evaluation& operator=(
const RhsValueType& other)
488 template <
class RhsValueType>
489 bool operator==(
const RhsValueType& other)
const
490 {
return value() == other; }
492 bool operator==(
const Evaluation& other)
const
494 assert(
size() == other.size());
496 for (
int idx = 0; idx <
length_(); ++idx) {
497 if (data_[idx] != other.data_[idx]) {
504 bool operator!=(
const Evaluation& other)
const
505 {
return !operator==(other); }
507 template <
class RhsValueType>
508 bool operator!=(
const RhsValueType& other)
const
509 {
return !operator==(other); }
511 template <
class RhsValueType>
512 bool operator>(RhsValueType other)
const
513 {
return value() > other; }
517 assert(
size() == other.size());
519 return value() > other.value();
522 template <
class RhsValueType>
523 bool operator<(RhsValueType other)
const
524 {
return value() < other; }
528 assert(
size() == other.size());
530 return value() < other.value();
533 template <
class RhsValueType>
534 bool operator>=(RhsValueType other)
const
535 {
return value() >= other; }
537 bool operator>=(
const Evaluation& other)
const
539 assert(
size() == other.size());
541 return value() >= other.value();
544 template <
class RhsValueType>
545 bool operator<=(RhsValueType other)
const
546 {
return value() <= other; }
548 bool operator<=(
const Evaluation& other)
const
550 assert(
size() == other.size());
552 return value() <= other.value();
560 template <
class RhsValueType>
561 void setValue(
const RhsValueType& val)
565 const ValueType& derivative(
int varIdx)
const
567 assert(0 <= varIdx && varIdx <
size());
569 return data_[
dstart_() + varIdx];
573 void setDerivative(
int varIdx,
const ValueType& derVal)
575 assert(0 <= varIdx && varIdx <
size());
577 data_[
dstart_() + varIdx] = derVal;
582 std::array<ValueT, 7> 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.
Evaluation(const Evaluation &other)=default
copy other function evaluation
constexpr int size() const
number of derivatives
Definition: Evaluation6.hpp:61
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation6.hpp:77
Evaluation()
default constructor
Definition: Evaluation6.hpp:92
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation6.hpp:82
constexpr int valuepos_() const
position index for value
Definition: Evaluation6.hpp:71
constexpr int length_() const
length of internal data vector
Definition: Evaluation6.hpp:66
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation6.hpp:74
ValueT ValueType
field type
Definition: Evaluation6.hpp:58
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