31 #ifndef OPM_DENSEAD_EVALUATION11_HPP
32 #define OPM_DENSEAD_EVALUATION11_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()
166 template <
class RhsValueType>
167 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
174 template <
class RhsValueType>
175 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
178 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
179 " with 11 derivatives");
186 template <
class RhsValueType>
197 template <
class RhsValueType>
198 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
201 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
202 " with 11 derivatives");
208 template <
class RhsValueType>
209 static Evaluation createConstant(
const RhsValueType& value)
216 template <
class RhsValueType>
223 void print(std::ostream& os = std::cout)
const
226 os <<
"v: " << value() <<
" / d:";
229 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
230 os <<
" " << derivative(varIdx);
237 assert(
size() == other.size());
239 data_[1] = other.data_[1];
240 data_[2] = other.data_[2];
241 data_[3] = other.data_[3];
242 data_[4] = other.data_[4];
243 data_[5] = other.data_[5];
244 data_[6] = other.data_[6];
245 data_[7] = other.data_[7];
246 data_[8] = other.data_[8];
247 data_[9] = other.data_[9];
248 data_[10] = other.data_[10];
249 data_[11] = other.data_[11];
256 assert(
size() == other.size());
258 data_[0] += other.data_[0];
259 data_[1] += other.data_[1];
260 data_[2] += other.data_[2];
261 data_[3] += other.data_[3];
262 data_[4] += other.data_[4];
263 data_[5] += other.data_[5];
264 data_[6] += other.data_[6];
265 data_[7] += other.data_[7];
266 data_[8] += other.data_[8];
267 data_[9] += other.data_[9];
268 data_[10] += other.data_[10];
269 data_[11] += other.data_[11];
275 template <
class RhsValueType>
276 Evaluation& operator+=(
const RhsValueType& other)
287 assert(
size() == other.size());
289 data_[0] -= other.data_[0];
290 data_[1] -= other.data_[1];
291 data_[2] -= other.data_[2];
292 data_[3] -= other.data_[3];
293 data_[4] -= other.data_[4];
294 data_[5] -= other.data_[5];
295 data_[6] -= other.data_[6];
296 data_[7] -= other.data_[7];
297 data_[8] -= other.data_[8];
298 data_[9] -= other.data_[9];
299 data_[10] -= other.data_[10];
300 data_[11] -= other.data_[11];
306 template <
class RhsValueType>
307 Evaluation& operator-=(
const RhsValueType& other)
318 assert(
size() == other.size());
329 data_[1] = data_[1] * v + other.data_[1] * u;
330 data_[2] = data_[2] * v + other.data_[2] * u;
331 data_[3] = data_[3] * v + other.data_[3] * u;
332 data_[4] = data_[4] * v + other.data_[4] * u;
333 data_[5] = data_[5] * v + other.data_[5] * u;
334 data_[6] = data_[6] * v + other.data_[6] * u;
335 data_[7] = data_[7] * v + other.data_[7] * u;
336 data_[8] = data_[8] * v + other.data_[8] * u;
337 data_[9] = data_[9] * v + other.data_[9] * u;
338 data_[10] = data_[10] * v + other.data_[10] * u;
339 data_[11] = data_[11] * v + other.data_[11] * u;
345 template <
class RhsValueType>
346 Evaluation& operator*=(
const RhsValueType& other)
367 assert(
size() == other.size());
373 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
374 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
375 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
376 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
377 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
378 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
379 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
380 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
381 data_[9] = (v*data_[9] - u*other.data_[9])/(v*v);
382 data_[10] = (v*data_[10] - u*other.data_[10])/(v*v);
383 data_[11] = (v*data_[11] - u*other.data_[11])/(v*v);
390 template <
class RhsValueType>
391 Evaluation& operator/=(
const RhsValueType& other)
414 assert(
size() == other.size());
424 template <
class RhsValueType>
425 Evaluation operator+(
const RhsValueType& other)
const
437 assert(
size() == other.size());
447 template <
class RhsValueType>
448 Evaluation operator-(
const RhsValueType& other)
const
463 result.data_[0] = - data_[0];
464 result.data_[1] = - data_[1];
465 result.data_[2] = - data_[2];
466 result.data_[3] = - data_[3];
467 result.data_[4] = - data_[4];
468 result.data_[5] = - data_[5];
469 result.data_[6] = - data_[6];
470 result.data_[7] = - data_[7];
471 result.data_[8] = - data_[8];
472 result.data_[9] = - data_[9];
473 result.data_[10] = - data_[10];
474 result.data_[11] = - data_[11];
481 assert(
size() == other.size());
490 template <
class RhsValueType>
491 Evaluation operator*(
const RhsValueType& other)
const
502 assert(
size() == other.size());
511 template <
class RhsValueType>
512 Evaluation operator/(
const RhsValueType& other)
const
521 template <
class RhsValueType>
522 Evaluation& operator=(
const RhsValueType& other)
533 template <
class RhsValueType>
534 bool operator==(
const RhsValueType& other)
const
535 {
return value() == other; }
537 bool operator==(
const Evaluation& other)
const
539 assert(
size() == other.size());
541 for (
int idx = 0; idx <
length_(); ++idx) {
542 if (data_[idx] != other.data_[idx]) {
549 bool operator!=(
const Evaluation& other)
const
550 {
return !operator==(other); }
552 template <
class RhsValueType>
553 bool operator!=(
const RhsValueType& other)
const
554 {
return !operator==(other); }
556 template <
class RhsValueType>
557 bool operator>(RhsValueType other)
const
558 {
return value() > other; }
562 assert(
size() == other.size());
564 return value() > other.value();
567 template <
class RhsValueType>
568 bool operator<(RhsValueType other)
const
569 {
return value() < other; }
573 assert(
size() == other.size());
575 return value() < other.value();
578 template <
class RhsValueType>
579 bool operator>=(RhsValueType other)
const
580 {
return value() >= other; }
582 bool operator>=(
const Evaluation& other)
const
584 assert(
size() == other.size());
586 return value() >= other.value();
589 template <
class RhsValueType>
590 bool operator<=(RhsValueType other)
const
591 {
return value() <= other; }
593 bool operator<=(
const Evaluation& other)
const
595 assert(
size() == other.size());
597 return value() <= other.value();
605 template <
class RhsValueType>
606 void setValue(
const RhsValueType& val)
610 const ValueType& derivative(
int varIdx)
const
612 assert(0 <= varIdx && varIdx <
size());
614 return data_[
dstart_() + varIdx];
618 void setDerivative(
int varIdx,
const ValueType& derVal)
620 assert(0 <= varIdx && varIdx <
size());
622 data_[
dstart_() + varIdx] = derVal;
627 std::array<ValueT, 12> 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: Evaluation11.hpp:58
constexpr int size() const
number of derivatives
Definition: Evaluation11.hpp:61
constexpr int length_() const
length of internal data vector
Definition: Evaluation11.hpp:66
Evaluation(const Evaluation &other)=default
copy other function evaluation
Evaluation()
default constructor
Definition: Evaluation11.hpp:92
constexpr int valuepos_() const
position index for value
Definition: Evaluation11.hpp:71
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation11.hpp:77
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation11.hpp:74
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation11.hpp:82
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