31 #ifndef OPM_DENSEAD_EVALUATION6_HPP 32 #define OPM_DENSEAD_EVALUATION6_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()
159 template <
class RhsValueType>
160 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
167 template <
class RhsValueType>
168 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
171 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 172 " with 6 derivatives");
179 template <
class RhsValueType>
190 template <
class RhsValueType>
191 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
194 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 195 " with 6 derivatives");
201 template <
class RhsValueType>
202 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
209 template <
class RhsValueType>
216 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
218 assert(
size() == other.size());
220 data_[1] = other.data_[1];
221 data_[2] = other.data_[2];
222 data_[3] = other.data_[3];
223 data_[4] = other.data_[4];
224 data_[5] = other.data_[5];
225 data_[6] = other.data_[6];
232 assert(
size() == other.size());
234 data_[0] += other.data_[0];
235 data_[1] += other.data_[1];
236 data_[2] += other.data_[2];
237 data_[3] += other.data_[3];
238 data_[4] += other.data_[4];
239 data_[5] += other.data_[5];
240 data_[6] += other.data_[6];
246 template <
class RhsValueType>
247 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
258 assert(
size() == other.size());
260 data_[0] -= other.data_[0];
261 data_[1] -= other.data_[1];
262 data_[2] -= other.data_[2];
263 data_[3] -= other.data_[3];
264 data_[4] -= other.data_[4];
265 data_[5] -= other.data_[5];
266 data_[6] -= other.data_[6];
272 template <
class RhsValueType>
273 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
284 assert(
size() == other.size());
295 data_[1] = data_[1] * v + other.data_[1] * u;
296 data_[2] = data_[2] * v + other.data_[2] * u;
297 data_[3] = data_[3] * v + other.data_[3] * u;
298 data_[4] = data_[4] * v + other.data_[4] * u;
299 data_[5] = data_[5] * v + other.data_[5] * u;
300 data_[6] = data_[6] * v + other.data_[6] * u;
306 template <
class RhsValueType>
307 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
323 assert(
size() == other.size());
329 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
330 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
331 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
332 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
333 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
334 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
341 template <
class RhsValueType>
342 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
360 assert(
size() == other.size());
370 template <
class RhsValueType>
371 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 383 assert(
size() == other.size());
393 template <
class RhsValueType>
394 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 409 result.data_[0] = - data_[0];
410 result.data_[1] = - data_[1];
411 result.data_[2] = - data_[2];
412 result.data_[3] = - data_[3];
413 result.data_[4] = - data_[4];
414 result.data_[5] = - data_[5];
415 result.data_[6] = - data_[6];
422 assert(
size() == other.size());
431 template <
class RhsValueType>
432 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 443 assert(
size() == other.size());
452 template <
class RhsValueType>
453 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 462 template <
class RhsValueType>
463 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
474 template <
class RhsValueType>
475 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 476 {
return value() == other; }
478 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 480 assert(
size() == other.size());
482 for (
int idx = 0; idx <
length_(); ++idx) {
483 if (data_[idx] != other.data_[idx]) {
490 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 491 {
return !operator==(other); }
493 template <
class RhsValueType>
494 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 495 {
return !operator==(other); }
497 template <
class RhsValueType>
498 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 499 {
return value() > other; }
501 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 503 assert(
size() == other.size());
505 return value() > other.value();
508 template <
class RhsValueType>
509 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 510 {
return value() < other; }
512 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 514 assert(
size() == other.size());
516 return value() < other.value();
519 template <
class RhsValueType>
520 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 521 {
return value() >= other; }
523 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 525 assert(
size() == other.size());
527 return value() >= other.value();
530 template <
class RhsValueType>
531 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 532 {
return value() <= other; }
534 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 536 assert(
size() == other.size());
538 return value() <= other.value();
546 template <
class RhsValueType>
547 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
551 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 553 assert(0 <= varIdx && varIdx <
size());
555 return data_[
dstart_() + varIdx];
559 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
561 assert(0 <= varIdx && varIdx <
size());
563 data_[
dstart_() + varIdx] = derVal;
566 template<
class Serializer>
567 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
573 std::array<ValueT, 7> data_;
579 #endif // OPM_DENSEAD_EVALUATION6_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: Evaluation.hpp:84
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
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation6.hpp:71
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 dend_() const
end+1 index for derivatives
Definition: Evaluation6.hpp:77
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
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation6.hpp:74
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation6.hpp:66
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation6.hpp:92
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:63
ValueT ValueType
field type
Definition: Evaluation6.hpp:58
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation6.hpp:61
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: Evaluation6.hpp:82