31#ifndef OPM_DENSEAD_EVALUATION4_HPP
32#define OPM_DENSEAD_EVALUATION4_HPP
46template <
class ValueT>
64 {
return size() + 1; }
82 for (
const auto& v: data_)
83 Valgrind::CheckDefined(v);
100 template <
class RhsValueType>
113 template <
class RhsValueType>
117 assert(0 <= varPos && varPos <
size());
122 data_[varPos +
dstart_()] = 1.0;
128 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 4 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 4 derivatives");
198 template <
class RhsValueType>
199 static Evaluation createConstant(
const RhsValueType& value)
206 template <
class RhsValueType>
215 assert(
size() == other.size());
217 data_[1] = other.data_[1];
218 data_[2] = other.data_[2];
219 data_[3] = other.data_[3];
220 data_[4] = other.data_[4];
227 assert(
size() == other.size());
229 data_[0] += other.data_[0];
230 data_[1] += other.data_[1];
231 data_[2] += other.data_[2];
232 data_[3] += other.data_[3];
233 data_[4] += other.data_[4];
239 template <
class RhsValueType>
240 Evaluation& operator+=(
const RhsValueType& other)
251 assert(
size() == other.size());
253 data_[0] -= other.data_[0];
254 data_[1] -= other.data_[1];
255 data_[2] -= other.data_[2];
256 data_[3] -= other.data_[3];
257 data_[4] -= other.data_[4];
263 template <
class RhsValueType>
264 Evaluation& operator-=(
const RhsValueType& other)
275 assert(
size() == other.size());
286 data_[1] = data_[1] * v + other.data_[1] * u;
287 data_[2] = data_[2] * v + other.data_[2] * u;
288 data_[3] = data_[3] * v + other.data_[3] * u;
289 data_[4] = data_[4] * v + other.data_[4] * u;
295 template <
class RhsValueType>
296 Evaluation& operator*=(
const RhsValueType& other)
310 assert(
size() == other.size());
316 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
317 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
318 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
319 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
326 template <
class RhsValueType>
327 Evaluation& operator/=(
const RhsValueType& other)
343 assert(
size() == other.size());
353 template <
class RhsValueType>
354 Evaluation operator+(
const RhsValueType& other)
const
366 assert(
size() == other.size());
376 template <
class RhsValueType>
377 Evaluation operator-(
const RhsValueType& other)
const
392 result.data_[0] = - data_[0];
393 result.data_[1] = - data_[1];
394 result.data_[2] = - data_[2];
395 result.data_[3] = - data_[3];
396 result.data_[4] = - data_[4];
403 assert(
size() == other.size());
412 template <
class RhsValueType>
413 Evaluation operator*(
const RhsValueType& other)
const
424 assert(
size() == other.size());
433 template <
class RhsValueType>
434 Evaluation operator/(
const RhsValueType& other)
const
443 template <
class RhsValueType>
444 Evaluation& operator=(
const RhsValueType& other)
455 template <
class RhsValueType>
456 bool operator==(
const RhsValueType& other)
const
457 {
return value() == other; }
459 bool operator==(
const Evaluation& other)
const
461 assert(
size() == other.size());
463 for (
int idx = 0; idx <
length_(); ++idx) {
464 if (data_[idx] != other.data_[idx]) {
471 bool operator!=(
const Evaluation& other)
const
472 {
return !operator==(other); }
474 template <
class RhsValueType>
475 bool operator!=(
const RhsValueType& other)
const
476 {
return !operator==(other); }
478 template <
class RhsValueType>
479 bool operator>(RhsValueType other)
const
480 {
return value() > other; }
484 assert(
size() == other.size());
486 return value() > other.value();
489 template <
class RhsValueType>
490 bool operator<(RhsValueType other)
const
491 {
return value() < other; }
495 assert(
size() == other.size());
497 return value() < other.value();
500 template <
class RhsValueType>
501 bool operator>=(RhsValueType other)
const
502 {
return value() >= other; }
504 bool operator>=(
const Evaluation& other)
const
506 assert(
size() == other.size());
508 return value() >= other.value();
511 template <
class RhsValueType>
512 bool operator<=(RhsValueType other)
const
513 {
return value() <= other; }
515 bool operator<=(
const Evaluation& other)
const
517 assert(
size() == other.size());
519 return value() <= other.value();
527 template <
class RhsValueType>
528 void setValue(
const RhsValueType& val)
532 const ValueType& derivative(
int varIdx)
const
534 assert(0 <= varIdx && varIdx <
size());
536 return data_[
dstart_() + varIdx];
540 void setDerivative(
int varIdx,
const ValueType& derVal)
542 assert(0 <= varIdx && varIdx <
size());
544 data_[
dstart_() + varIdx] = derVal;
547 template<
class Serializer>
548 void serializeOp(Serializer& serializer)
554 std::array<ValueT, 5> data_;
Some templates to wrap the valgrind client request macros.
constexpr int dstart_() const
start index for derivatives
Definition Evaluation4.hpp:71
ValueT ValueType
field type
Definition Evaluation4.hpp:55
Evaluation(const Evaluation &other)=default
copy other function evaluation
constexpr int valuepos_() const
position index for value
Definition Evaluation4.hpp:68
constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation4.hpp:74
constexpr int size() const
number of derivatives
Definition Evaluation4.hpp:58
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation4.hpp:79
Evaluation()
default constructor
Definition Evaluation4.hpp:89
constexpr int length_() const
length of internal data vector
Definition Evaluation4.hpp:63
Represents a function evaluation and its derivatives w.r.t.
Definition Evaluation.hpp:57
Evaluation()
default constructor
Definition Evaluation.hpp:98
ValueT ValueType
field type
Definition Evaluation.hpp:64
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation.hpp:88
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation.hpp:61
constexpr int size() const
number of derivatives
Definition Evaluation.hpp:67
constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:77
constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:72
constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:80
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30