31 #ifndef OPM_DENSEAD_EVALUATION8_HPP
32 #define OPM_DENSEAD_EVALUATION8_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()
163 template <
class RhsValueType>
164 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
171 template <
class RhsValueType>
172 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
175 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
176 " with 8 derivatives");
183 template <
class RhsValueType>
194 template <
class RhsValueType>
195 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
198 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
199 " with 8 derivatives");
205 template <
class RhsValueType>
206 static Evaluation createConstant(
const RhsValueType& value)
213 template <
class RhsValueType>
220 void print(std::ostream& os = std::cout)
const
223 os <<
"v: " << value() <<
" / d:";
226 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
227 os <<
" " << derivative(varIdx);
234 assert(
size() == other.size());
236 data_[1] = other.data_[1];
237 data_[2] = other.data_[2];
238 data_[3] = other.data_[3];
239 data_[4] = other.data_[4];
240 data_[5] = other.data_[5];
241 data_[6] = other.data_[6];
242 data_[7] = other.data_[7];
243 data_[8] = other.data_[8];
250 assert(
size() == other.size());
252 data_[0] += other.data_[0];
253 data_[1] += other.data_[1];
254 data_[2] += other.data_[2];
255 data_[3] += other.data_[3];
256 data_[4] += other.data_[4];
257 data_[5] += other.data_[5];
258 data_[6] += other.data_[6];
259 data_[7] += other.data_[7];
260 data_[8] += other.data_[8];
266 template <
class RhsValueType>
267 Evaluation& operator+=(
const RhsValueType& other)
278 assert(
size() == other.size());
280 data_[0] -= other.data_[0];
281 data_[1] -= other.data_[1];
282 data_[2] -= other.data_[2];
283 data_[3] -= other.data_[3];
284 data_[4] -= other.data_[4];
285 data_[5] -= other.data_[5];
286 data_[6] -= other.data_[6];
287 data_[7] -= other.data_[7];
288 data_[8] -= other.data_[8];
294 template <
class RhsValueType>
295 Evaluation& operator-=(
const RhsValueType& other)
306 assert(
size() == other.size());
317 data_[1] = data_[1] * v + other.data_[1] * u;
318 data_[2] = data_[2] * v + other.data_[2] * u;
319 data_[3] = data_[3] * v + other.data_[3] * u;
320 data_[4] = data_[4] * v + other.data_[4] * u;
321 data_[5] = data_[5] * v + other.data_[5] * u;
322 data_[6] = data_[6] * v + other.data_[6] * u;
323 data_[7] = data_[7] * v + other.data_[7] * u;
324 data_[8] = data_[8] * v + other.data_[8] * u;
330 template <
class RhsValueType>
331 Evaluation& operator*=(
const RhsValueType& other)
349 assert(
size() == other.size());
355 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
356 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
357 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
358 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
359 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
360 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
361 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
362 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
369 template <
class RhsValueType>
370 Evaluation& operator/=(
const RhsValueType& other)
390 assert(
size() == other.size());
400 template <
class RhsValueType>
401 Evaluation operator+(
const RhsValueType& other)
const
413 assert(
size() == other.size());
423 template <
class RhsValueType>
424 Evaluation operator-(
const RhsValueType& other)
const
439 result.data_[0] = - data_[0];
440 result.data_[1] = - data_[1];
441 result.data_[2] = - data_[2];
442 result.data_[3] = - data_[3];
443 result.data_[4] = - data_[4];
444 result.data_[5] = - data_[5];
445 result.data_[6] = - data_[6];
446 result.data_[7] = - data_[7];
447 result.data_[8] = - data_[8];
454 assert(
size() == other.size());
463 template <
class RhsValueType>
464 Evaluation operator*(
const RhsValueType& other)
const
475 assert(
size() == other.size());
484 template <
class RhsValueType>
485 Evaluation operator/(
const RhsValueType& other)
const
494 template <
class RhsValueType>
495 Evaluation& operator=(
const RhsValueType& other)
506 template <
class RhsValueType>
507 bool operator==(
const RhsValueType& other)
const
508 {
return value() == other; }
510 bool operator==(
const Evaluation& other)
const
512 assert(
size() == other.size());
514 for (
int idx = 0; idx <
length_(); ++idx) {
515 if (data_[idx] != other.data_[idx]) {
522 bool operator!=(
const Evaluation& other)
const
523 {
return !operator==(other); }
525 template <
class RhsValueType>
526 bool operator!=(
const RhsValueType& other)
const
527 {
return !operator==(other); }
529 template <
class RhsValueType>
530 bool operator>(RhsValueType other)
const
531 {
return value() > other; }
535 assert(
size() == other.size());
537 return value() > other.value();
540 template <
class RhsValueType>
541 bool operator<(RhsValueType other)
const
542 {
return value() < other; }
546 assert(
size() == other.size());
548 return value() < other.value();
551 template <
class RhsValueType>
552 bool operator>=(RhsValueType other)
const
553 {
return value() >= other; }
555 bool operator>=(
const Evaluation& other)
const
557 assert(
size() == other.size());
559 return value() >= other.value();
562 template <
class RhsValueType>
563 bool operator<=(RhsValueType other)
const
564 {
return value() <= other; }
566 bool operator<=(
const Evaluation& other)
const
568 assert(
size() == other.size());
570 return value() <= other.value();
578 template <
class RhsValueType>
579 void setValue(
const RhsValueType& val)
583 const ValueType& derivative(
int varIdx)
const
585 assert(0 <= varIdx && varIdx <
size());
587 return data_[
dstart_() + varIdx];
591 void setDerivative(
int varIdx,
const ValueType& derVal)
593 assert(0 <= varIdx && varIdx <
size());
595 data_[
dstart_() + varIdx] = derVal;
600 std::array<ValueT, 9> 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.
Evaluation()
default constructor
Definition: Evaluation8.hpp:92
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation8.hpp:77
constexpr int size() const
number of derivatives
Definition: Evaluation8.hpp:61
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation8.hpp:82
Evaluation(const Evaluation &other)=default
copy other function evaluation
ValueT ValueType
field type
Definition: Evaluation8.hpp:58
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation8.hpp:74
constexpr int valuepos_() const
position index for value
Definition: Evaluation8.hpp:71
constexpr int length_() const
length of internal data vector
Definition: Evaluation8.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