31 #ifndef OPM_DENSEAD_EVALUATION4_HPP
32 #define OPM_DENSEAD_EVALUATION4_HPP
37 #include <opm/common/Valgrind.hpp>
39 #include <dune/common/version.hh>
51 template <
class ValueT>
59 static constexpr
int size = 4;
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()
119 template <
class RhsValueType>
120 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
129 template <
class RhsValueType>
130 static Evaluation createConstant(
const RhsValueType& value)
136 void print(std::ostream& os = std::cout)
const
139 os <<
"v: " << value() <<
" / d:";
142 for (
int varIdx = 0; varIdx <
size; ++varIdx) {
143 os <<
" " << derivative(varIdx);
150 data_[1] = other.data_[1];
151 data_[2] = other.data_[2];
152 data_[3] = other.data_[3];
153 data_[4] = other.data_[4];
160 data_[0] += other.data_[0];
161 data_[1] += other.data_[1];
162 data_[2] += other.data_[2];
163 data_[3] += other.data_[3];
164 data_[4] += other.data_[4];
170 template <
class RhsValueType>
171 Evaluation& operator+=(
const RhsValueType& other)
182 data_[0] -= other.data_[0];
183 data_[1] -= other.data_[1];
184 data_[2] -= other.data_[2];
185 data_[3] -= other.data_[3];
186 data_[4] -= other.data_[4];
192 template <
class RhsValueType>
193 Evaluation& operator-=(
const RhsValueType& other)
213 data_[1] = data_[1] * v + other.data_[1] * u;
214 data_[2] = data_[2] * v + other.data_[2] * u;
215 data_[3] = data_[3] * v + other.data_[3] * u;
216 data_[4] = data_[4] * v + other.data_[4] * u;
222 template <
class RhsValueType>
223 Evaluation& operator*=(
const RhsValueType& other)
241 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
242 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
243 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
244 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
251 template <
class RhsValueType>
252 Evaluation& operator/=(
const RhsValueType& other)
276 template <
class RhsValueType>
277 Evaluation operator+(
const RhsValueType& other)
const
297 template <
class RhsValueType>
298 Evaluation operator-(
const RhsValueType& other)
const
313 result.data_[0] = - data_[0];
314 result.data_[1] = - data_[1];
315 result.data_[2] = - data_[2];
316 result.data_[3] = - data_[3];
317 result.data_[4] = - data_[4];
331 template <
class RhsValueType>
332 Evaluation operator*(
const RhsValueType& other)
const
350 template <
class RhsValueType>
351 Evaluation operator/(
const RhsValueType& other)
const
360 template <
class RhsValueType>
361 Evaluation& operator=(
const RhsValueType& other)
372 template <
class RhsValueType>
373 bool operator==(
const RhsValueType& other)
const
374 {
return value() == other; }
376 bool operator==(
const Evaluation& other)
const
378 for (
int idx = 0; idx <
length_; ++idx) {
379 if (data_[idx] != other.data_[idx]) {
386 bool operator!=(
const Evaluation& other)
const
387 {
return !operator==(other); }
389 template <
class RhsValueType>
390 bool operator>(RhsValueType other)
const
391 {
return value() > other; }
394 {
return value() > other.value(); }
396 template <
class RhsValueType>
397 bool operator<(RhsValueType other)
const
398 {
return value() < other; }
401 {
return value() < other.value(); }
403 template <
class RhsValueType>
404 bool operator>=(RhsValueType other)
const
405 {
return value() >= other; }
407 bool operator>=(
const Evaluation& other)
const
408 {
return value() >= other.value(); }
410 template <
class RhsValueType>
411 bool operator<=(RhsValueType other)
const
412 {
return value() <= other; }
414 bool operator<=(
const Evaluation& other)
const
415 {
return value() <= other.value(); }
422 template <
class RhsValueType>
423 void setValue(
const RhsValueType& val)
427 const ValueType& derivative(
int varIdx)
const
429 assert(0 <= varIdx && varIdx <
size);
431 return data_[
dstart_ + varIdx];
435 void setDerivative(
int varIdx,
const ValueType& derVal)
437 assert(0 <= varIdx && varIdx <
size);
439 data_[
dstart_ + varIdx] = derVal;
443 std::array<ValueT, length_> data_;
448 #endif // OPM_DENSEAD_EVALUATION4_HPP
Evaluation()
default constructor
Definition: Evaluation.hpp:79
ValueT ValueType
field type
Definition: Evaluation4.hpp:56
Evaluation()
default constructor
Definition: Evaluation4.hpp:74
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
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.