31 #ifndef OPM_DENSEAD_EVALUATION8_HPP
32 #define OPM_DENSEAD_EVALUATION8_HPP
37 #include <opm/common/Valgrind.hpp>
39 #include <dune/common/version.hh>
51 template <
class ValueT>
59 static constexpr
int size = 8;
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()
123 template <
class RhsValueType>
124 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
133 template <
class RhsValueType>
134 static Evaluation createConstant(
const RhsValueType& value)
140 void print(std::ostream& os = std::cout)
const
143 os <<
"v: " << value() <<
" / d:";
146 for (
int varIdx = 0; varIdx <
size; ++varIdx) {
147 os <<
" " << derivative(varIdx);
154 data_[1] = other.data_[1];
155 data_[2] = other.data_[2];
156 data_[3] = other.data_[3];
157 data_[4] = other.data_[4];
158 data_[5] = other.data_[5];
159 data_[6] = other.data_[6];
160 data_[7] = other.data_[7];
161 data_[8] = other.data_[8];
168 data_[0] += other.data_[0];
169 data_[1] += other.data_[1];
170 data_[2] += other.data_[2];
171 data_[3] += other.data_[3];
172 data_[4] += other.data_[4];
173 data_[5] += other.data_[5];
174 data_[6] += other.data_[6];
175 data_[7] += other.data_[7];
176 data_[8] += other.data_[8];
182 template <
class RhsValueType>
183 Evaluation& operator+=(
const RhsValueType& other)
194 data_[0] -= other.data_[0];
195 data_[1] -= other.data_[1];
196 data_[2] -= other.data_[2];
197 data_[3] -= other.data_[3];
198 data_[4] -= other.data_[4];
199 data_[5] -= other.data_[5];
200 data_[6] -= other.data_[6];
201 data_[7] -= other.data_[7];
202 data_[8] -= other.data_[8];
208 template <
class RhsValueType>
209 Evaluation& operator-=(
const RhsValueType& other)
229 data_[1] = data_[1] * v + other.data_[1] * u;
230 data_[2] = data_[2] * v + other.data_[2] * u;
231 data_[3] = data_[3] * v + other.data_[3] * u;
232 data_[4] = data_[4] * v + other.data_[4] * u;
233 data_[5] = data_[5] * v + other.data_[5] * u;
234 data_[6] = data_[6] * v + other.data_[6] * u;
235 data_[7] = data_[7] * v + other.data_[7] * u;
236 data_[8] = data_[8] * v + other.data_[8] * u;
242 template <
class RhsValueType>
243 Evaluation& operator*=(
const RhsValueType& other)
265 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
266 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
267 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
268 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
269 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
270 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
271 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
272 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
279 template <
class RhsValueType>
280 Evaluation& operator/=(
const RhsValueType& other)
308 template <
class RhsValueType>
309 Evaluation operator+(
const RhsValueType& other)
const
329 template <
class RhsValueType>
330 Evaluation operator-(
const RhsValueType& other)
const
345 result.data_[0] = - data_[0];
346 result.data_[1] = - data_[1];
347 result.data_[2] = - data_[2];
348 result.data_[3] = - data_[3];
349 result.data_[4] = - data_[4];
350 result.data_[5] = - data_[5];
351 result.data_[6] = - data_[6];
352 result.data_[7] = - data_[7];
353 result.data_[8] = - data_[8];
367 template <
class RhsValueType>
368 Evaluation operator*(
const RhsValueType& other)
const
386 template <
class RhsValueType>
387 Evaluation operator/(
const RhsValueType& other)
const
396 template <
class RhsValueType>
397 Evaluation& operator=(
const RhsValueType& other)
408 template <
class RhsValueType>
409 bool operator==(
const RhsValueType& other)
const
410 {
return value() == other; }
412 bool operator==(
const Evaluation& other)
const
414 for (
int idx = 0; idx <
length_; ++idx) {
415 if (data_[idx] != other.data_[idx]) {
422 bool operator!=(
const Evaluation& other)
const
423 {
return !operator==(other); }
425 template <
class RhsValueType>
426 bool operator>(RhsValueType other)
const
427 {
return value() > other; }
430 {
return value() > other.value(); }
432 template <
class RhsValueType>
433 bool operator<(RhsValueType other)
const
434 {
return value() < other; }
437 {
return value() < other.value(); }
439 template <
class RhsValueType>
440 bool operator>=(RhsValueType other)
const
441 {
return value() >= other; }
443 bool operator>=(
const Evaluation& other)
const
444 {
return value() >= other.value(); }
446 template <
class RhsValueType>
447 bool operator<=(RhsValueType other)
const
448 {
return value() <= other; }
450 bool operator<=(
const Evaluation& other)
const
451 {
return value() <= other.value(); }
458 template <
class RhsValueType>
459 void setValue(
const RhsValueType& val)
463 const ValueType& derivative(
int varIdx)
const
465 assert(0 <= varIdx && varIdx <
size);
467 return data_[
dstart_ + varIdx];
471 void setDerivative(
int varIdx,
const ValueType& derVal)
473 assert(0 <= varIdx && varIdx <
size);
475 data_[
dstart_ + varIdx] = derVal;
479 std::array<ValueT, length_> data_;
484 #endif // OPM_DENSEAD_EVALUATION8_HPP
Evaluation()
default constructor
Definition: Evaluation.hpp:79
ValueT ValueType
field type
Definition: Evaluation8.hpp:56
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
Evaluation()
default constructor
Definition: Evaluation8.hpp:74
Representation of an evaluation of a function and its derivatives w.r.t.