31 #ifndef OPM_DENSEAD_EVALUATION6_HPP
32 #define OPM_DENSEAD_EVALUATION6_HPP
37 #include <opm/common/Valgrind.hpp>
39 #include <dune/common/version.hh>
51 template <
class ValueT>
59 static constexpr
int size = 6;
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()
121 template <
class RhsValueType>
122 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
131 template <
class RhsValueType>
132 static Evaluation createConstant(
const RhsValueType& value)
138 void print(std::ostream& os = std::cout)
const
141 os <<
"v: " << value() <<
" / d:";
144 for (
int varIdx = 0; varIdx <
size; ++varIdx) {
145 os <<
" " << derivative(varIdx);
152 data_[1] = other.data_[1];
153 data_[2] = other.data_[2];
154 data_[3] = other.data_[3];
155 data_[4] = other.data_[4];
156 data_[5] = other.data_[5];
157 data_[6] = other.data_[6];
164 data_[0] += other.data_[0];
165 data_[1] += other.data_[1];
166 data_[2] += other.data_[2];
167 data_[3] += other.data_[3];
168 data_[4] += other.data_[4];
169 data_[5] += other.data_[5];
170 data_[6] += other.data_[6];
176 template <
class RhsValueType>
177 Evaluation& operator+=(
const RhsValueType& other)
188 data_[0] -= other.data_[0];
189 data_[1] -= other.data_[1];
190 data_[2] -= other.data_[2];
191 data_[3] -= other.data_[3];
192 data_[4] -= other.data_[4];
193 data_[5] -= other.data_[5];
194 data_[6] -= other.data_[6];
200 template <
class RhsValueType>
201 Evaluation& operator-=(
const RhsValueType& other)
221 data_[1] = data_[1] * v + other.data_[1] * u;
222 data_[2] = data_[2] * v + other.data_[2] * u;
223 data_[3] = data_[3] * v + other.data_[3] * u;
224 data_[4] = data_[4] * v + other.data_[4] * u;
225 data_[5] = data_[5] * v + other.data_[5] * u;
226 data_[6] = data_[6] * v + other.data_[6] * u;
232 template <
class RhsValueType>
233 Evaluation& operator*=(
const RhsValueType& other)
253 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
254 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
255 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
256 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
257 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
258 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
265 template <
class RhsValueType>
266 Evaluation& operator/=(
const RhsValueType& other)
292 template <
class RhsValueType>
293 Evaluation operator+(
const RhsValueType& other)
const
313 template <
class RhsValueType>
314 Evaluation operator-(
const RhsValueType& other)
const
329 result.data_[0] = - data_[0];
330 result.data_[1] = - data_[1];
331 result.data_[2] = - data_[2];
332 result.data_[3] = - data_[3];
333 result.data_[4] = - data_[4];
334 result.data_[5] = - data_[5];
335 result.data_[6] = - data_[6];
349 template <
class RhsValueType>
350 Evaluation operator*(
const RhsValueType& other)
const
368 template <
class RhsValueType>
369 Evaluation operator/(
const RhsValueType& other)
const
378 template <
class RhsValueType>
379 Evaluation& operator=(
const RhsValueType& other)
390 template <
class RhsValueType>
391 bool operator==(
const RhsValueType& other)
const
392 {
return value() == other; }
394 bool operator==(
const Evaluation& other)
const
396 for (
int idx = 0; idx <
length_; ++idx) {
397 if (data_[idx] != other.data_[idx]) {
404 bool operator!=(
const Evaluation& other)
const
405 {
return !operator==(other); }
407 template <
class RhsValueType>
408 bool operator>(RhsValueType other)
const
409 {
return value() > other; }
412 {
return value() > other.value(); }
414 template <
class RhsValueType>
415 bool operator<(RhsValueType other)
const
416 {
return value() < other; }
419 {
return value() < other.value(); }
421 template <
class RhsValueType>
422 bool operator>=(RhsValueType other)
const
423 {
return value() >= other; }
425 bool operator>=(
const Evaluation& other)
const
426 {
return value() >= other.value(); }
428 template <
class RhsValueType>
429 bool operator<=(RhsValueType other)
const
430 {
return value() <= other; }
432 bool operator<=(
const Evaluation& other)
const
433 {
return value() <= other.value(); }
440 template <
class RhsValueType>
441 void setValue(
const RhsValueType& val)
445 const ValueType& derivative(
int varIdx)
const
447 assert(0 <= varIdx && varIdx <
size);
449 return data_[
dstart_ + varIdx];
453 void setDerivative(
int varIdx,
const ValueType& derVal)
455 assert(0 <= varIdx && varIdx <
size);
457 data_[
dstart_ + varIdx] = derVal;
461 std::array<ValueT, length_> data_;
466 #endif // OPM_DENSEAD_EVALUATION6_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
Evaluation()
default constructor
Definition: Evaluation6.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
ValueT ValueType
field type
Definition: Evaluation6.hpp:56
Representation of an evaluation of a function and its derivatives w.r.t.