31 #ifndef OPM_DENSEAD_EVALUATION3_HPP
32 #define OPM_DENSEAD_EVALUATION3_HPP
37 #include <opm/common/Valgrind.hpp>
39 #include <dune/common/version.hh>
51 template <
class ValueT>
59 static constexpr
int size = 3;
84 template <
class RhsValueType>
89 Valgrind::CheckDefined( data_ );
96 template <
class RhsValueType>
100 assert(0 <= varPos && varPos <
size);
106 Valgrind::CheckDefined(data_);
110 void clearDerivatives()
118 template <
class RhsValueType>
119 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
128 template <
class RhsValueType>
129 static Evaluation createConstant(
const RhsValueType& value)
135 void print(std::ostream& os = std::cout)
const
138 os <<
"v: " << value() <<
" / d:";
141 for (
int varIdx = 0; varIdx <
size; ++varIdx) {
142 os <<
" " << derivative(varIdx);
149 data_[1] = other.data_[1];
150 data_[2] = other.data_[2];
151 data_[3] = other.data_[3];
158 data_[0] += other.data_[0];
159 data_[1] += other.data_[1];
160 data_[2] += other.data_[2];
161 data_[3] += other.data_[3];
167 template <
class RhsValueType>
168 Evaluation& operator+=(
const RhsValueType& other)
179 data_[0] -= other.data_[0];
180 data_[1] -= other.data_[1];
181 data_[2] -= other.data_[2];
182 data_[3] -= other.data_[3];
188 template <
class RhsValueType>
189 Evaluation& operator-=(
const RhsValueType& other)
209 data_[1] = data_[1] * v + other.data_[1] * u;
210 data_[2] = data_[2] * v + other.data_[2] * u;
211 data_[3] = data_[3] * v + other.data_[3] * u;
217 template <
class RhsValueType>
218 Evaluation& operator*=(
const RhsValueType& other)
235 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
236 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
237 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
244 template <
class RhsValueType>
245 Evaluation& operator/=(
const RhsValueType& other)
268 template <
class RhsValueType>
269 Evaluation operator+(
const RhsValueType& other)
const
289 template <
class RhsValueType>
290 Evaluation operator-(
const RhsValueType& other)
const
305 result.data_[0] = - data_[0];
306 result.data_[1] = - data_[1];
307 result.data_[2] = - data_[2];
308 result.data_[3] = - data_[3];
322 template <
class RhsValueType>
323 Evaluation operator*(
const RhsValueType& other)
const
341 template <
class RhsValueType>
342 Evaluation operator/(
const RhsValueType& other)
const
351 template <
class RhsValueType>
352 Evaluation& operator=(
const RhsValueType& other)
363 template <
class RhsValueType>
364 bool operator==(
const RhsValueType& other)
const
365 {
return value() == other; }
367 bool operator==(
const Evaluation& other)
const
369 for (
int idx = 0; idx <
length_; ++idx) {
370 if (data_[idx] != other.data_[idx]) {
377 bool operator!=(
const Evaluation& other)
const
378 {
return !operator==(other); }
380 template <
class RhsValueType>
381 bool operator>(RhsValueType other)
const
382 {
return value() > other; }
385 {
return value() > other.value(); }
387 template <
class RhsValueType>
388 bool operator<(RhsValueType other)
const
389 {
return value() < other; }
392 {
return value() < other.value(); }
394 template <
class RhsValueType>
395 bool operator>=(RhsValueType other)
const
396 {
return value() >= other; }
398 bool operator>=(
const Evaluation& other)
const
399 {
return value() >= other.value(); }
401 template <
class RhsValueType>
402 bool operator<=(RhsValueType other)
const
403 {
return value() <= other; }
405 bool operator<=(
const Evaluation& other)
const
406 {
return value() <= other.value(); }
413 template <
class RhsValueType>
414 void setValue(
const RhsValueType& val)
418 const ValueType& derivative(
int varIdx)
const
420 assert(0 <= varIdx && varIdx <
size);
422 return data_[
dstart_ + varIdx];
426 void setDerivative(
int varIdx,
const ValueType& derVal)
428 assert(0 <= varIdx && varIdx <
size);
430 data_[
dstart_ + varIdx] = derVal;
434 std::array<ValueT, length_> data_;
439 #endif // OPM_DENSEAD_EVALUATION3_HPP
Evaluation()
default constructor
Definition: Evaluation.hpp:79
A number of commonly used algebraic functions for the localized OPM automatic differentiation (AD) fr...
ValueT ValueType
field type
Definition: Evaluation.hpp:61
static constexpr int valuepos_
position index for value
Definition: Evaluation.hpp:71
static constexpr int length_
length of internal data vector
Definition: Evaluation.hpp:68
static constexpr int dstart_
start index for derivatives
Definition: Evaluation.hpp:73
ValueT ValueType
field type
Definition: Evaluation3.hpp:56
Evaluation()
default constructor
Definition: Evaluation3.hpp:74
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:57
static constexpr int size
number of derivatives
Definition: Evaluation.hpp:64
static constexpr int dend_
end+1 index for derivatives
Definition: Evaluation.hpp:75
Representation of an evaluation of a function and its derivatives w.r.t.