31 #ifndef OPM_DENSEAD_EVALUATION5_HPP 32 #define OPM_DENSEAD_EVALUATION5_HPP 43 #include <opm/common/ErrorMacros.hpp> 44 #include <opm/common/utility/gpuDecorators.hpp> 49 template <
class ValueT>
61 OPM_HOST_DEVICE constexpr
int size()
const 66 OPM_HOST_DEVICE constexpr
int length_()
const 67 {
return size() + 1; }
74 OPM_HOST_DEVICE constexpr
int dstart_()
const 77 OPM_HOST_DEVICE constexpr
int dend_()
const 85 for (
const auto& v: data_)
86 Valgrind::CheckDefined(v);
103 template <
class RhsValueType>
104 OPM_HOST_DEVICE constexpr
Evaluation(
const RhsValueType& c): data_{}
114 template <
class RhsValueType>
115 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
118 assert(0 <= varPos && varPos <
size());
123 data_[varPos +
dstart_()] = 1.0;
129 OPM_HOST_DEVICE constexpr
void clearDerivatives()
158 template <
class RhsValueType>
159 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
166 template <
class RhsValueType>
167 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
170 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 171 " with 5 derivatives");
178 template <
class RhsValueType>
189 template <
class RhsValueType>
190 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
193 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 194 " with 5 derivatives");
200 template <
class RhsValueType>
201 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
208 template <
class RhsValueType>
215 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
217 assert(
size() == other.size());
219 data_[1] = other.data_[1];
220 data_[2] = other.data_[2];
221 data_[3] = other.data_[3];
222 data_[4] = other.data_[4];
223 data_[5] = other.data_[5];
230 assert(
size() == other.size());
232 data_[0] += other.data_[0];
233 data_[1] += other.data_[1];
234 data_[2] += other.data_[2];
235 data_[3] += other.data_[3];
236 data_[4] += other.data_[4];
237 data_[5] += other.data_[5];
243 template <
class RhsValueType>
244 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
255 assert(
size() == other.size());
257 data_[0] -= other.data_[0];
258 data_[1] -= other.data_[1];
259 data_[2] -= other.data_[2];
260 data_[3] -= other.data_[3];
261 data_[4] -= other.data_[4];
262 data_[5] -= other.data_[5];
268 template <
class RhsValueType>
269 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
280 assert(
size() == other.size());
291 data_[1] = data_[1] * v + other.data_[1] * u;
292 data_[2] = data_[2] * v + other.data_[2] * u;
293 data_[3] = data_[3] * v + other.data_[3] * u;
294 data_[4] = data_[4] * v + other.data_[4] * u;
295 data_[5] = data_[5] * v + other.data_[5] * u;
301 template <
class RhsValueType>
302 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
317 assert(
size() == other.size());
323 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
324 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
325 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
326 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
327 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
334 template <
class RhsValueType>
335 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
352 assert(
size() == other.size());
362 template <
class RhsValueType>
363 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 375 assert(
size() == other.size());
385 template <
class RhsValueType>
386 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 401 result.data_[0] = - data_[0];
402 result.data_[1] = - data_[1];
403 result.data_[2] = - data_[2];
404 result.data_[3] = - data_[3];
405 result.data_[4] = - data_[4];
406 result.data_[5] = - data_[5];
413 assert(
size() == other.size());
422 template <
class RhsValueType>
423 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 434 assert(
size() == other.size());
443 template <
class RhsValueType>
444 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 453 template <
class RhsValueType>
454 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
465 template <
class RhsValueType>
466 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 467 {
return value() == other; }
469 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 471 assert(
size() == other.size());
473 for (
int idx = 0; idx <
length_(); ++idx) {
474 if (data_[idx] != other.data_[idx]) {
481 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 482 {
return !operator==(other); }
484 template <
class RhsValueType>
485 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 486 {
return !operator==(other); }
488 template <
class RhsValueType>
489 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 490 {
return value() > other; }
492 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 494 assert(
size() == other.size());
496 return value() > other.value();
499 template <
class RhsValueType>
500 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 501 {
return value() < other; }
503 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 505 assert(
size() == other.size());
507 return value() < other.value();
510 template <
class RhsValueType>
511 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 512 {
return value() >= other; }
514 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 516 assert(
size() == other.size());
518 return value() >= other.value();
521 template <
class RhsValueType>
522 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 523 {
return value() <= other; }
525 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 527 assert(
size() == other.size());
529 return value() <= other.value();
537 template <
class RhsValueType>
538 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
542 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 544 assert(0 <= varIdx && varIdx <
size());
546 return data_[
dstart_() + varIdx];
550 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
552 assert(0 <= varIdx && varIdx <
size());
554 data_[
dstart_() + varIdx] = derVal;
557 template<
class Serializer>
558 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
564 std::array<ValueT, 6> data_;
570 #endif // OPM_DENSEAD_EVALUATION5_HPP OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:87
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:95
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation5.hpp:71
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation.hpp:84
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation5.hpp:77
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation5.hpp:92
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation.hpp:105
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:79
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
ValueT ValueType
field type
Definition: Evaluation.hpp:71
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation.hpp:74
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition: Evaluation.hpp:68
ValueT ValueType
field type
Definition: Evaluation5.hpp:58
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation5.hpp:74
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: Evaluation5.hpp:82
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation5.hpp:66
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation5.hpp:61
Some templates to wrap the valgrind client request macros.
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:63