31 #ifndef OPM_DENSEAD_EVALUATION7_HPP
32 #define OPM_DENSEAD_EVALUATION7_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()
162 template <
class RhsValueType>
163 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
170 template <
class RhsValueType>
171 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
174 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
175 " with 7 derivatives");
182 template <
class RhsValueType>
193 template <
class RhsValueType>
194 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
197 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
198 " with 7 derivatives");
204 template <
class RhsValueType>
205 static Evaluation createConstant(
const RhsValueType& value)
212 template <
class RhsValueType>
219 void print(std::ostream& os = std::cout)
const
222 os <<
"v: " << value() <<
" / d:";
225 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
226 os <<
" " << derivative(varIdx);
233 assert(
size() == other.size());
235 data_[1] = other.data_[1];
236 data_[2] = other.data_[2];
237 data_[3] = other.data_[3];
238 data_[4] = other.data_[4];
239 data_[5] = other.data_[5];
240 data_[6] = other.data_[6];
241 data_[7] = other.data_[7];
248 assert(
size() == other.size());
250 data_[0] += other.data_[0];
251 data_[1] += other.data_[1];
252 data_[2] += other.data_[2];
253 data_[3] += other.data_[3];
254 data_[4] += other.data_[4];
255 data_[5] += other.data_[5];
256 data_[6] += other.data_[6];
257 data_[7] += other.data_[7];
263 template <
class RhsValueType>
264 Evaluation& operator+=(
const RhsValueType& other)
275 assert(
size() == other.size());
277 data_[0] -= other.data_[0];
278 data_[1] -= other.data_[1];
279 data_[2] -= other.data_[2];
280 data_[3] -= other.data_[3];
281 data_[4] -= other.data_[4];
282 data_[5] -= other.data_[5];
283 data_[6] -= other.data_[6];
284 data_[7] -= other.data_[7];
290 template <
class RhsValueType>
291 Evaluation& operator-=(
const RhsValueType& other)
302 assert(
size() == other.size());
313 data_[1] = data_[1] * v + other.data_[1] * u;
314 data_[2] = data_[2] * v + other.data_[2] * u;
315 data_[3] = data_[3] * v + other.data_[3] * u;
316 data_[4] = data_[4] * v + other.data_[4] * u;
317 data_[5] = data_[5] * v + other.data_[5] * u;
318 data_[6] = data_[6] * v + other.data_[6] * u;
319 data_[7] = data_[7] * v + other.data_[7] * u;
325 template <
class RhsValueType>
326 Evaluation& operator*=(
const RhsValueType& other)
343 assert(
size() == other.size());
349 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
350 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
351 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
352 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
353 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
354 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
355 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
362 template <
class RhsValueType>
363 Evaluation& operator/=(
const RhsValueType& other)
382 assert(
size() == other.size());
392 template <
class RhsValueType>
393 Evaluation operator+(
const RhsValueType& other)
const
405 assert(
size() == other.size());
415 template <
class RhsValueType>
416 Evaluation operator-(
const RhsValueType& other)
const
431 result.data_[0] = - data_[0];
432 result.data_[1] = - data_[1];
433 result.data_[2] = - data_[2];
434 result.data_[3] = - data_[3];
435 result.data_[4] = - data_[4];
436 result.data_[5] = - data_[5];
437 result.data_[6] = - data_[6];
438 result.data_[7] = - data_[7];
445 assert(
size() == other.size());
454 template <
class RhsValueType>
455 Evaluation operator*(
const RhsValueType& other)
const
466 assert(
size() == other.size());
475 template <
class RhsValueType>
476 Evaluation operator/(
const RhsValueType& other)
const
485 template <
class RhsValueType>
486 Evaluation& operator=(
const RhsValueType& other)
497 template <
class RhsValueType>
498 bool operator==(
const RhsValueType& other)
const
499 {
return value() == other; }
501 bool operator==(
const Evaluation& other)
const
503 assert(
size() == other.size());
505 for (
int idx = 0; idx <
length_(); ++idx) {
506 if (data_[idx] != other.data_[idx]) {
513 bool operator!=(
const Evaluation& other)
const
514 {
return !operator==(other); }
516 template <
class RhsValueType>
517 bool operator!=(
const RhsValueType& other)
const
518 {
return !operator==(other); }
520 template <
class RhsValueType>
521 bool operator>(RhsValueType other)
const
522 {
return value() > other; }
526 assert(
size() == other.size());
528 return value() > other.value();
531 template <
class RhsValueType>
532 bool operator<(RhsValueType other)
const
533 {
return value() < other; }
537 assert(
size() == other.size());
539 return value() < other.value();
542 template <
class RhsValueType>
543 bool operator>=(RhsValueType other)
const
544 {
return value() >= other; }
546 bool operator>=(
const Evaluation& other)
const
548 assert(
size() == other.size());
550 return value() >= other.value();
553 template <
class RhsValueType>
554 bool operator<=(RhsValueType other)
const
555 {
return value() <= other; }
557 bool operator<=(
const Evaluation& other)
const
559 assert(
size() == other.size());
561 return value() <= other.value();
569 template <
class RhsValueType>
570 void setValue(
const RhsValueType& val)
574 const ValueType& derivative(
int varIdx)
const
576 assert(0 <= varIdx && varIdx <
size());
578 return data_[
dstart_() + varIdx];
582 void setDerivative(
int varIdx,
const ValueType& derVal)
584 assert(0 <= varIdx && varIdx <
size());
586 data_[
dstart_() + varIdx] = derVal;
591 std::array<ValueT, 8> 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: Evaluation7.hpp:61
Evaluation(const Evaluation &other)=default
copy other function evaluation
Evaluation()
default constructor
Definition: Evaluation7.hpp:92
constexpr int length_() const
length of internal data vector
Definition: Evaluation7.hpp:66
ValueT ValueType
field type
Definition: Evaluation7.hpp:58
constexpr int valuepos_() const
position index for value
Definition: Evaluation7.hpp:71
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation7.hpp:82
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation7.hpp:77
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation7.hpp:74
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