31#ifndef OPM_DENSEAD_EVALUATION3_HPP
32#define OPM_DENSEAD_EVALUATION3_HPP
43#include <opm/common/utility/gpuDecorators.hpp>
48template <
class ValueT>
60 OPM_HOST_DEVICE
constexpr int size()
const
65 OPM_HOST_DEVICE
constexpr int length_()
const
66 {
return size() + 1; }
73 OPM_HOST_DEVICE
constexpr int dstart_()
const
76 OPM_HOST_DEVICE
constexpr int dend_()
const
84 for (
const auto& v: data_)
85 Valgrind::CheckDefined(v);
102 template <
class RhsValueType>
103 OPM_HOST_DEVICE
constexpr Evaluation(
const RhsValueType& c): data_{}
115 template <
class RhsValueType>
116 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
119 assert(0 <= varPos && varPos <
size());
124 data_[varPos +
dstart_()] = 1.0;
130 OPM_HOST_DEVICE
constexpr void clearDerivatives()
157 template <
class RhsValueType>
158 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType& value,
int varPos)
165 template <
class RhsValueType>
166 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
169 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
170 " with 3 derivatives");
177 template <
class RhsValueType>
178 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
188 template <
class RhsValueType>
189 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
192 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
193 " with 3 derivatives");
199 template <
class RhsValueType>
200 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType& value)
207 template <
class RhsValueType>
214 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
216 assert(
size() == other.size());
218 data_[1] = other.data_[1];
219 data_[2] = other.data_[2];
220 data_[3] = other.data_[3];
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];
238 template <
class RhsValueType>
239 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
250 assert(
size() == other.size());
252 data_[0] -= other.data_[0];
253 data_[1] -= other.data_[1];
254 data_[2] -= other.data_[2];
255 data_[3] -= other.data_[3];
261 template <
class RhsValueType>
262 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
273 assert(
size() == other.size());
284 data_[1] = data_[1] * v + other.data_[1] * u;
285 data_[2] = data_[2] * v + other.data_[2] * u;
286 data_[3] = data_[3] * v + other.data_[3] * u;
292 template <
class RhsValueType>
293 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
306 assert(
size() == other.size());
312 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
313 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
314 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
321 template <
class RhsValueType>
322 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
337 assert(
size() == other.size());
347 template <
class RhsValueType>
348 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
360 assert(
size() == other.size());
370 template <
class RhsValueType>
371 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
386 result.data_[0] = - data_[0];
387 result.data_[1] = - data_[1];
388 result.data_[2] = - data_[2];
389 result.data_[3] = - data_[3];
396 assert(
size() == other.size());
405 template <
class RhsValueType>
406 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
417 assert(
size() == other.size());
426 template <
class RhsValueType>
427 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
436 template <
class RhsValueType>
437 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
448 template <
class RhsValueType>
449 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
450 {
return value() == other; }
452 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
454 assert(
size() == other.size());
456 for (
int idx = 0; idx <
length_(); ++idx) {
457 if (data_[idx] != other.data_[idx]) {
464 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
465 {
return !operator==(other); }
467 template <
class RhsValueType>
468 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
469 {
return !operator==(other); }
471 template <
class RhsValueType>
472 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
473 {
return value() > other; }
475 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
477 assert(
size() == other.size());
479 return value() > other.value();
482 template <
class RhsValueType>
483 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
484 {
return value() < other; }
486 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
488 assert(
size() == other.size());
490 return value() < other.value();
493 template <
class RhsValueType>
494 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
495 {
return value() >= other; }
497 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
499 assert(
size() == other.size());
501 return value() >= other.value();
504 template <
class RhsValueType>
505 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
506 {
return value() <= other; }
508 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
510 assert(
size() == other.size());
512 return value() <= other.value();
516 OPM_HOST_DEVICE
const ValueType& value()
const
520 template <
class RhsValueType>
521 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
525 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
527 assert(0 <= varIdx && varIdx <
size());
529 return data_[
dstart_() + varIdx];
533 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
535 assert(0 <= varIdx && varIdx <
size());
537 data_[
dstart_() + varIdx] = derVal;
540 template<
class Serializer>
541 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
547 std::array<ValueT, 4> data_;
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation3.hpp:91
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation3.hpp:76
Evaluation(const Evaluation &other)=default
copy other function evaluation
OPM_HOST_DEVICE constexpr void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation3.hpp:81
ValueT ValueType
field type
Definition Evaluation3.hpp:57
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation3.hpp:60
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation3.hpp:73
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation3.hpp:70
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation3.hpp:65
Represents a function evaluation and its derivatives w.r.t.
Definition Evaluation.hpp:59
ValueT ValueType
field type
Definition Evaluation.hpp:66
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:82
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation.hpp:63
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:74
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation.hpp:100
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:79
OPM_HOST_DEVICE constexpr void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation.hpp:90
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation.hpp:69
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30