31 #ifndef OPM_DENSEAD_EVALUATION10_HPP
32 #define OPM_DENSEAD_EVALUATION10_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()
165 template <
class RhsValueType>
166 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
173 template <
class RhsValueType>
174 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
177 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
178 " with 10 derivatives");
185 template <
class RhsValueType>
196 template <
class RhsValueType>
197 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
200 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
201 " with 10 derivatives");
207 template <
class RhsValueType>
208 static Evaluation createConstant(
const RhsValueType& value)
215 template <
class RhsValueType>
222 void print(std::ostream& os = std::cout)
const
225 os <<
"v: " << value() <<
" / d:";
228 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
229 os <<
" " << derivative(varIdx);
236 assert(
size() == other.size());
238 data_[1] = other.data_[1];
239 data_[2] = other.data_[2];
240 data_[3] = other.data_[3];
241 data_[4] = other.data_[4];
242 data_[5] = other.data_[5];
243 data_[6] = other.data_[6];
244 data_[7] = other.data_[7];
245 data_[8] = other.data_[8];
246 data_[9] = other.data_[9];
247 data_[10] = other.data_[10];
254 assert(
size() == other.size());
256 data_[0] += other.data_[0];
257 data_[1] += other.data_[1];
258 data_[2] += other.data_[2];
259 data_[3] += other.data_[3];
260 data_[4] += other.data_[4];
261 data_[5] += other.data_[5];
262 data_[6] += other.data_[6];
263 data_[7] += other.data_[7];
264 data_[8] += other.data_[8];
265 data_[9] += other.data_[9];
266 data_[10] += other.data_[10];
272 template <
class RhsValueType>
273 Evaluation& operator+=(
const RhsValueType& other)
284 assert(
size() == other.size());
286 data_[0] -= other.data_[0];
287 data_[1] -= other.data_[1];
288 data_[2] -= other.data_[2];
289 data_[3] -= other.data_[3];
290 data_[4] -= other.data_[4];
291 data_[5] -= other.data_[5];
292 data_[6] -= other.data_[6];
293 data_[7] -= other.data_[7];
294 data_[8] -= other.data_[8];
295 data_[9] -= other.data_[9];
296 data_[10] -= other.data_[10];
302 template <
class RhsValueType>
303 Evaluation& operator-=(
const RhsValueType& other)
314 assert(
size() == other.size());
325 data_[1] = data_[1] * v + other.data_[1] * u;
326 data_[2] = data_[2] * v + other.data_[2] * u;
327 data_[3] = data_[3] * v + other.data_[3] * u;
328 data_[4] = data_[4] * v + other.data_[4] * u;
329 data_[5] = data_[5] * v + other.data_[5] * u;
330 data_[6] = data_[6] * v + other.data_[6] * u;
331 data_[7] = data_[7] * v + other.data_[7] * u;
332 data_[8] = data_[8] * v + other.data_[8] * u;
333 data_[9] = data_[9] * v + other.data_[9] * u;
334 data_[10] = data_[10] * v + other.data_[10] * u;
340 template <
class RhsValueType>
341 Evaluation& operator*=(
const RhsValueType& other)
361 assert(
size() == other.size());
367 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
368 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
369 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
370 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
371 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
372 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
373 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
374 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
375 data_[9] = (v*data_[9] - u*other.data_[9])/(v*v);
376 data_[10] = (v*data_[10] - u*other.data_[10])/(v*v);
383 template <
class RhsValueType>
384 Evaluation& operator/=(
const RhsValueType& other)
406 assert(
size() == other.size());
416 template <
class RhsValueType>
417 Evaluation operator+(
const RhsValueType& other)
const
429 assert(
size() == other.size());
439 template <
class RhsValueType>
440 Evaluation operator-(
const RhsValueType& other)
const
455 result.data_[0] = - data_[0];
456 result.data_[1] = - data_[1];
457 result.data_[2] = - data_[2];
458 result.data_[3] = - data_[3];
459 result.data_[4] = - data_[4];
460 result.data_[5] = - data_[5];
461 result.data_[6] = - data_[6];
462 result.data_[7] = - data_[7];
463 result.data_[8] = - data_[8];
464 result.data_[9] = - data_[9];
465 result.data_[10] = - data_[10];
472 assert(
size() == other.size());
481 template <
class RhsValueType>
482 Evaluation operator*(
const RhsValueType& other)
const
493 assert(
size() == other.size());
502 template <
class RhsValueType>
503 Evaluation operator/(
const RhsValueType& other)
const
512 template <
class RhsValueType>
513 Evaluation& operator=(
const RhsValueType& other)
524 template <
class RhsValueType>
525 bool operator==(
const RhsValueType& other)
const
526 {
return value() == other; }
528 bool operator==(
const Evaluation& other)
const
530 assert(
size() == other.size());
532 for (
int idx = 0; idx <
length_(); ++idx) {
533 if (data_[idx] != other.data_[idx]) {
540 bool operator!=(
const Evaluation& other)
const
541 {
return !operator==(other); }
543 template <
class RhsValueType>
544 bool operator!=(
const RhsValueType& other)
const
545 {
return !operator==(other); }
547 template <
class RhsValueType>
548 bool operator>(RhsValueType other)
const
549 {
return value() > other; }
553 assert(
size() == other.size());
555 return value() > other.value();
558 template <
class RhsValueType>
559 bool operator<(RhsValueType other)
const
560 {
return value() < other; }
564 assert(
size() == other.size());
566 return value() < other.value();
569 template <
class RhsValueType>
570 bool operator>=(RhsValueType other)
const
571 {
return value() >= other; }
573 bool operator>=(
const Evaluation& other)
const
575 assert(
size() == other.size());
577 return value() >= other.value();
580 template <
class RhsValueType>
581 bool operator<=(RhsValueType other)
const
582 {
return value() <= other; }
584 bool operator<=(
const Evaluation& other)
const
586 assert(
size() == other.size());
588 return value() <= other.value();
596 template <
class RhsValueType>
597 void setValue(
const RhsValueType& val)
601 const ValueType& derivative(
int varIdx)
const
603 assert(0 <= varIdx && varIdx <
size());
605 return data_[
dstart_() + varIdx];
609 void setDerivative(
int varIdx,
const ValueType& derVal)
611 assert(0 <= varIdx && varIdx <
size());
613 data_[
dstart_() + varIdx] = derVal;
618 std::array<ValueT, 11> 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 dend_() const
end+1 index for derivatives
Definition: Evaluation10.hpp:77
ValueT ValueType
field type
Definition: Evaluation10.hpp:58
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation10.hpp:82
Evaluation()
default constructor
Definition: Evaluation10.hpp:92
Evaluation(const Evaluation &other)=default
copy other function evaluation
constexpr int valuepos_() const
position index for value
Definition: Evaluation10.hpp:71
constexpr int length_() const
length of internal data vector
Definition: Evaluation10.hpp:66
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation10.hpp:74
constexpr int size() const
number of derivatives
Definition: Evaluation10.hpp:61
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