31 #ifndef OPM_DENSEAD_EVALUATION5_HPP
32 #define OPM_DENSEAD_EVALUATION5_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()
160 template <
class RhsValueType>
161 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
168 template <
class RhsValueType>
169 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
172 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
173 " with 5 derivatives");
180 template <
class RhsValueType>
191 template <
class RhsValueType>
192 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
195 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
196 " with 5 derivatives");
202 template <
class RhsValueType>
203 static Evaluation createConstant(
const RhsValueType& value)
210 template <
class RhsValueType>
217 void print(std::ostream& os = std::cout)
const
220 os <<
"v: " << value() <<
" / d:";
223 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
224 os <<
" " << derivative(varIdx);
231 assert(
size() == other.size());
233 data_[1] = other.data_[1];
234 data_[2] = other.data_[2];
235 data_[3] = other.data_[3];
236 data_[4] = other.data_[4];
237 data_[5] = other.data_[5];
244 assert(
size() == other.size());
246 data_[0] += other.data_[0];
247 data_[1] += other.data_[1];
248 data_[2] += other.data_[2];
249 data_[3] += other.data_[3];
250 data_[4] += other.data_[4];
251 data_[5] += other.data_[5];
257 template <
class RhsValueType>
258 Evaluation& operator+=(
const RhsValueType& other)
269 assert(
size() == other.size());
271 data_[0] -= other.data_[0];
272 data_[1] -= other.data_[1];
273 data_[2] -= other.data_[2];
274 data_[3] -= other.data_[3];
275 data_[4] -= other.data_[4];
276 data_[5] -= other.data_[5];
282 template <
class RhsValueType>
283 Evaluation& operator-=(
const RhsValueType& other)
294 assert(
size() == other.size());
305 data_[1] = data_[1] * v + other.data_[1] * u;
306 data_[2] = data_[2] * v + other.data_[2] * u;
307 data_[3] = data_[3] * v + other.data_[3] * u;
308 data_[4] = data_[4] * v + other.data_[4] * u;
309 data_[5] = data_[5] * v + other.data_[5] * u;
315 template <
class RhsValueType>
316 Evaluation& operator*=(
const RhsValueType& other)
331 assert(
size() == other.size());
337 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
338 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
339 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
340 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
341 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
348 template <
class RhsValueType>
349 Evaluation& operator/=(
const RhsValueType& other)
366 assert(
size() == other.size());
376 template <
class RhsValueType>
377 Evaluation operator+(
const RhsValueType& other)
const
389 assert(
size() == other.size());
399 template <
class RhsValueType>
400 Evaluation operator-(
const RhsValueType& other)
const
415 result.data_[0] = - data_[0];
416 result.data_[1] = - data_[1];
417 result.data_[2] = - data_[2];
418 result.data_[3] = - data_[3];
419 result.data_[4] = - data_[4];
420 result.data_[5] = - data_[5];
427 assert(
size() == other.size());
436 template <
class RhsValueType>
437 Evaluation operator*(
const RhsValueType& other)
const
448 assert(
size() == other.size());
457 template <
class RhsValueType>
458 Evaluation operator/(
const RhsValueType& other)
const
467 template <
class RhsValueType>
468 Evaluation& operator=(
const RhsValueType& other)
479 template <
class RhsValueType>
480 bool operator==(
const RhsValueType& other)
const
481 {
return value() == other; }
483 bool operator==(
const Evaluation& other)
const
485 assert(
size() == other.size());
487 for (
int idx = 0; idx <
length_(); ++idx) {
488 if (data_[idx] != other.data_[idx]) {
495 bool operator!=(
const Evaluation& other)
const
496 {
return !operator==(other); }
498 template <
class RhsValueType>
499 bool operator!=(
const RhsValueType& other)
const
500 {
return !operator==(other); }
502 template <
class RhsValueType>
503 bool operator>(RhsValueType other)
const
504 {
return value() > other; }
508 assert(
size() == other.size());
510 return value() > other.value();
513 template <
class RhsValueType>
514 bool operator<(RhsValueType other)
const
515 {
return value() < other; }
519 assert(
size() == other.size());
521 return value() < other.value();
524 template <
class RhsValueType>
525 bool operator>=(RhsValueType other)
const
526 {
return value() >= other; }
528 bool operator>=(
const Evaluation& other)
const
530 assert(
size() == other.size());
532 return value() >= other.value();
535 template <
class RhsValueType>
536 bool operator<=(RhsValueType other)
const
537 {
return value() <= other; }
539 bool operator<=(
const Evaluation& other)
const
541 assert(
size() == other.size());
543 return value() <= other.value();
551 template <
class RhsValueType>
552 void setValue(
const RhsValueType& val)
556 const ValueType& derivative(
int varIdx)
const
558 assert(0 <= varIdx && varIdx <
size());
560 return data_[
dstart_() + varIdx];
564 void setDerivative(
int varIdx,
const ValueType& derVal)
566 assert(0 <= varIdx && varIdx <
size());
568 data_[
dstart_() + varIdx] = derVal;
573 std::array<ValueT, 6> 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.
ValueT ValueType
field type
Definition: Evaluation5.hpp:58
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation5.hpp:74
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation5.hpp:82
Evaluation()
default constructor
Definition: Evaluation5.hpp:92
Evaluation(const Evaluation &other)=default
copy other function evaluation
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation5.hpp:77
constexpr int valuepos_() const
position index for value
Definition: Evaluation5.hpp:71
constexpr int size() const
number of derivatives
Definition: Evaluation5.hpp:61
constexpr int length_() const
length of internal data vector
Definition: Evaluation5.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