31 #ifndef OPM_DENSEAD_EVALUATION1_HPP
32 #define OPM_DENSEAD_EVALUATION1_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()
156 template <
class RhsValueType>
157 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
164 template <
class RhsValueType>
165 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
168 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
169 " with 1 derivatives");
176 template <
class RhsValueType>
187 template <
class RhsValueType>
188 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
191 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
192 " with 1 derivatives");
198 template <
class RhsValueType>
199 static Evaluation createConstant(
const RhsValueType& value)
206 template <
class RhsValueType>
213 void print(std::ostream& os = std::cout)
const
216 os <<
"v: " << value() <<
" / d:";
219 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
220 os <<
" " << derivative(varIdx);
227 assert(
size() == other.size());
229 data_[1] = other.data_[1];
236 assert(
size() == other.size());
238 data_[0] += other.data_[0];
239 data_[1] += other.data_[1];
245 template <
class RhsValueType>
246 Evaluation& operator+=(
const RhsValueType& other)
257 assert(
size() == other.size());
259 data_[0] -= other.data_[0];
260 data_[1] -= other.data_[1];
266 template <
class RhsValueType>
267 Evaluation& operator-=(
const RhsValueType& other)
278 assert(
size() == other.size());
289 data_[1] = data_[1] * v + other.data_[1] * u;
295 template <
class RhsValueType>
296 Evaluation& operator*=(
const RhsValueType& other)
307 assert(
size() == other.size());
313 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
320 template <
class RhsValueType>
321 Evaluation& operator/=(
const RhsValueType& other)
334 assert(
size() == other.size());
344 template <
class RhsValueType>
345 Evaluation operator+(
const RhsValueType& other)
const
357 assert(
size() == other.size());
367 template <
class RhsValueType>
368 Evaluation operator-(
const RhsValueType& other)
const
383 result.data_[0] = - data_[0];
384 result.data_[1] = - data_[1];
391 assert(
size() == other.size());
400 template <
class RhsValueType>
401 Evaluation operator*(
const RhsValueType& other)
const
412 assert(
size() == other.size());
421 template <
class RhsValueType>
422 Evaluation operator/(
const RhsValueType& other)
const
431 template <
class RhsValueType>
432 Evaluation& operator=(
const RhsValueType& other)
443 template <
class RhsValueType>
444 bool operator==(
const RhsValueType& other)
const
445 {
return value() == other; }
447 bool operator==(
const Evaluation& other)
const
449 assert(
size() == other.size());
451 for (
int idx = 0; idx <
length_(); ++idx) {
452 if (data_[idx] != other.data_[idx]) {
459 bool operator!=(
const Evaluation& other)
const
460 {
return !operator==(other); }
462 template <
class RhsValueType>
463 bool operator!=(
const RhsValueType& other)
const
464 {
return !operator==(other); }
466 template <
class RhsValueType>
467 bool operator>(RhsValueType other)
const
468 {
return value() > other; }
472 assert(
size() == other.size());
474 return value() > other.value();
477 template <
class RhsValueType>
478 bool operator<(RhsValueType other)
const
479 {
return value() < other; }
483 assert(
size() == other.size());
485 return value() < other.value();
488 template <
class RhsValueType>
489 bool operator>=(RhsValueType other)
const
490 {
return value() >= other; }
492 bool operator>=(
const Evaluation& other)
const
494 assert(
size() == other.size());
496 return value() >= other.value();
499 template <
class RhsValueType>
500 bool operator<=(RhsValueType other)
const
501 {
return value() <= other; }
503 bool operator<=(
const Evaluation& other)
const
505 assert(
size() == other.size());
507 return value() <= other.value();
515 template <
class RhsValueType>
516 void setValue(
const RhsValueType& val)
520 const ValueType& derivative(
int varIdx)
const
522 assert(0 <= varIdx && varIdx <
size());
524 return data_[
dstart_() + varIdx];
528 void setDerivative(
int varIdx,
const ValueType& derVal)
530 assert(0 <= varIdx && varIdx <
size());
532 data_[
dstart_() + varIdx] = derVal;
537 std::array<ValueT, 2> 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 length_() const
length of internal data vector
Definition: Evaluation1.hpp:66
Evaluation()
default constructor
Definition: Evaluation1.hpp:92
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation1.hpp:82
Evaluation(const Evaluation &other)=default
copy other function evaluation
ValueT ValueType
field type
Definition: Evaluation1.hpp:58
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation1.hpp:74
constexpr int size() const
number of derivatives
Definition: Evaluation1.hpp:61
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation1.hpp:77
constexpr int valuepos_() const
position index for value
Definition: Evaluation1.hpp:71
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