31 #ifndef OPM_DENSEAD_EVALUATION9_HPP
32 #define OPM_DENSEAD_EVALUATION9_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()
164 template <
class RhsValueType>
165 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
172 template <
class RhsValueType>
173 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
176 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
177 " with 9 derivatives");
184 template <
class RhsValueType>
195 template <
class RhsValueType>
196 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
199 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
200 " with 9 derivatives");
206 template <
class RhsValueType>
207 static Evaluation createConstant(
const RhsValueType& value)
214 template <
class RhsValueType>
221 void print(std::ostream& os = std::cout)
const
224 os <<
"v: " << value() <<
" / d:";
227 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
228 os <<
" " << derivative(varIdx);
235 assert(
size() == other.size());
237 data_[1] = other.data_[1];
238 data_[2] = other.data_[2];
239 data_[3] = other.data_[3];
240 data_[4] = other.data_[4];
241 data_[5] = other.data_[5];
242 data_[6] = other.data_[6];
243 data_[7] = other.data_[7];
244 data_[8] = other.data_[8];
245 data_[9] = other.data_[9];
252 assert(
size() == other.size());
254 data_[0] += other.data_[0];
255 data_[1] += other.data_[1];
256 data_[2] += other.data_[2];
257 data_[3] += other.data_[3];
258 data_[4] += other.data_[4];
259 data_[5] += other.data_[5];
260 data_[6] += other.data_[6];
261 data_[7] += other.data_[7];
262 data_[8] += other.data_[8];
263 data_[9] += other.data_[9];
269 template <
class RhsValueType>
270 Evaluation& operator+=(
const RhsValueType& other)
281 assert(
size() == other.size());
283 data_[0] -= other.data_[0];
284 data_[1] -= other.data_[1];
285 data_[2] -= other.data_[2];
286 data_[3] -= other.data_[3];
287 data_[4] -= other.data_[4];
288 data_[5] -= other.data_[5];
289 data_[6] -= other.data_[6];
290 data_[7] -= other.data_[7];
291 data_[8] -= other.data_[8];
292 data_[9] -= other.data_[9];
298 template <
class RhsValueType>
299 Evaluation& operator-=(
const RhsValueType& other)
310 assert(
size() == other.size());
321 data_[1] = data_[1] * v + other.data_[1] * u;
322 data_[2] = data_[2] * v + other.data_[2] * u;
323 data_[3] = data_[3] * v + other.data_[3] * u;
324 data_[4] = data_[4] * v + other.data_[4] * u;
325 data_[5] = data_[5] * v + other.data_[5] * u;
326 data_[6] = data_[6] * v + other.data_[6] * u;
327 data_[7] = data_[7] * v + other.data_[7] * u;
328 data_[8] = data_[8] * v + other.data_[8] * u;
329 data_[9] = data_[9] * v + other.data_[9] * u;
335 template <
class RhsValueType>
336 Evaluation& operator*=(
const RhsValueType& other)
355 assert(
size() == other.size());
361 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
362 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
363 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
364 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
365 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
366 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
367 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
368 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
369 data_[9] = (v*data_[9] - u*other.data_[9])/(v*v);
376 template <
class RhsValueType>
377 Evaluation& operator/=(
const RhsValueType& other)
398 assert(
size() == other.size());
408 template <
class RhsValueType>
409 Evaluation operator+(
const RhsValueType& other)
const
421 assert(
size() == other.size());
431 template <
class RhsValueType>
432 Evaluation operator-(
const RhsValueType& other)
const
447 result.data_[0] = - data_[0];
448 result.data_[1] = - data_[1];
449 result.data_[2] = - data_[2];
450 result.data_[3] = - data_[3];
451 result.data_[4] = - data_[4];
452 result.data_[5] = - data_[5];
453 result.data_[6] = - data_[6];
454 result.data_[7] = - data_[7];
455 result.data_[8] = - data_[8];
456 result.data_[9] = - data_[9];
463 assert(
size() == other.size());
472 template <
class RhsValueType>
473 Evaluation operator*(
const RhsValueType& other)
const
484 assert(
size() == other.size());
493 template <
class RhsValueType>
494 Evaluation operator/(
const RhsValueType& other)
const
503 template <
class RhsValueType>
504 Evaluation& operator=(
const RhsValueType& other)
515 template <
class RhsValueType>
516 bool operator==(
const RhsValueType& other)
const
517 {
return value() == other; }
519 bool operator==(
const Evaluation& other)
const
521 assert(
size() == other.size());
523 for (
int idx = 0; idx <
length_(); ++idx) {
524 if (data_[idx] != other.data_[idx]) {
531 bool operator!=(
const Evaluation& other)
const
532 {
return !operator==(other); }
534 template <
class RhsValueType>
535 bool operator!=(
const RhsValueType& other)
const
536 {
return !operator==(other); }
538 template <
class RhsValueType>
539 bool operator>(RhsValueType other)
const
540 {
return value() > other; }
544 assert(
size() == other.size());
546 return value() > other.value();
549 template <
class RhsValueType>
550 bool operator<(RhsValueType other)
const
551 {
return value() < other; }
555 assert(
size() == other.size());
557 return value() < other.value();
560 template <
class RhsValueType>
561 bool operator>=(RhsValueType other)
const
562 {
return value() >= other; }
564 bool operator>=(
const Evaluation& other)
const
566 assert(
size() == other.size());
568 return value() >= other.value();
571 template <
class RhsValueType>
572 bool operator<=(RhsValueType other)
const
573 {
return value() <= other; }
575 bool operator<=(
const Evaluation& other)
const
577 assert(
size() == other.size());
579 return value() <= other.value();
587 template <
class RhsValueType>
588 void setValue(
const RhsValueType& val)
592 const ValueType& derivative(
int varIdx)
const
594 assert(0 <= varIdx && varIdx <
size());
596 return data_[
dstart_() + varIdx];
600 void setDerivative(
int varIdx,
const ValueType& derVal)
602 assert(0 <= varIdx && varIdx <
size());
604 data_[
dstart_() + varIdx] = derVal;
609 std::array<ValueT, 10> 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 size() const
number of derivatives
Definition: Evaluation9.hpp:61
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation9.hpp:74
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation9.hpp:77
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation9.hpp:82
ValueT ValueType
field type
Definition: Evaluation9.hpp:58
constexpr int valuepos_() const
position index for value
Definition: Evaluation9.hpp:71
Evaluation(const Evaluation &other)=default
copy other function evaluation
Evaluation()
default constructor
Definition: Evaluation9.hpp:92
constexpr int length_() const
length of internal data vector
Definition: Evaluation9.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