31 #ifndef OPM_DENSEAD_EVALUATION7_HPP 32 #define OPM_DENSEAD_EVALUATION7_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()
160 template <
class RhsValueType>
161 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
168 template <
class RhsValueType>
169 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType&
value,
int varPos)
172 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 173 " with 7 derivatives");
180 template <
class RhsValueType>
191 template <
class RhsValueType>
192 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
195 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 196 " with 7 derivatives");
202 template <
class RhsValueType>
203 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
210 template <
class RhsValueType>
217 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
219 assert(
size() == other.size());
221 data_[1] = other.data_[1];
222 data_[2] = other.data_[2];
223 data_[3] = other.data_[3];
224 data_[4] = other.data_[4];
225 data_[5] = other.data_[5];
226 data_[6] = other.data_[6];
227 data_[7] = other.data_[7];
234 assert(
size() == other.size());
236 data_[0] += other.data_[0];
237 data_[1] += other.data_[1];
238 data_[2] += other.data_[2];
239 data_[3] += other.data_[3];
240 data_[4] += other.data_[4];
241 data_[5] += other.data_[5];
242 data_[6] += other.data_[6];
243 data_[7] += other.data_[7];
249 template <
class RhsValueType>
250 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
261 assert(
size() == other.size());
263 data_[0] -= other.data_[0];
264 data_[1] -= other.data_[1];
265 data_[2] -= other.data_[2];
266 data_[3] -= other.data_[3];
267 data_[4] -= other.data_[4];
268 data_[5] -= other.data_[5];
269 data_[6] -= other.data_[6];
270 data_[7] -= other.data_[7];
276 template <
class RhsValueType>
277 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
288 assert(
size() == other.size());
299 data_[1] = data_[1] * v + other.data_[1] * u;
300 data_[2] = data_[2] * v + other.data_[2] * u;
301 data_[3] = data_[3] * v + other.data_[3] * u;
302 data_[4] = data_[4] * v + other.data_[4] * u;
303 data_[5] = data_[5] * v + other.data_[5] * u;
304 data_[6] = data_[6] * v + other.data_[6] * u;
305 data_[7] = data_[7] * v + other.data_[7] * u;
311 template <
class RhsValueType>
312 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
329 assert(
size() == other.size());
335 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
336 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
337 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
338 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
339 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
340 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
341 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
348 template <
class RhsValueType>
349 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
368 assert(
size() == other.size());
378 template <
class RhsValueType>
379 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 391 assert(
size() == other.size());
401 template <
class RhsValueType>
402 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 417 result.data_[0] = - data_[0];
418 result.data_[1] = - data_[1];
419 result.data_[2] = - data_[2];
420 result.data_[3] = - data_[3];
421 result.data_[4] = - data_[4];
422 result.data_[5] = - data_[5];
423 result.data_[6] = - data_[6];
424 result.data_[7] = - data_[7];
431 assert(
size() == other.size());
440 template <
class RhsValueType>
441 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 452 assert(
size() == other.size());
461 template <
class RhsValueType>
462 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 471 template <
class RhsValueType>
472 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
483 template <
class RhsValueType>
484 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 485 {
return value() == other; }
487 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 489 assert(
size() == other.size());
491 for (
int idx = 0; idx <
length_(); ++idx) {
492 if (data_[idx] != other.data_[idx]) {
499 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 500 {
return !operator==(other); }
502 template <
class RhsValueType>
503 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 504 {
return !operator==(other); }
506 template <
class RhsValueType>
507 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 508 {
return value() > other; }
510 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 512 assert(
size() == other.size());
514 return value() > other.value();
517 template <
class RhsValueType>
518 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 519 {
return value() < other; }
521 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 523 assert(
size() == other.size());
525 return value() < other.value();
528 template <
class RhsValueType>
529 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 530 {
return value() >= other; }
532 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 534 assert(
size() == other.size());
536 return value() >= other.value();
539 template <
class RhsValueType>
540 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 541 {
return value() <= other; }
543 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 545 assert(
size() == other.size());
547 return value() <= other.value();
555 template <
class RhsValueType>
556 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
560 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 562 assert(0 <= varIdx && varIdx <
size());
564 return data_[
dstart_() + varIdx];
568 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
570 assert(0 <= varIdx && varIdx <
size());
572 data_[
dstart_() + varIdx] = derVal;
575 template<
class Serializer>
576 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
582 std::array<ValueT, 8> data_;
588 #endif // OPM_DENSEAD_EVALUATION7_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: Evaluation7.hpp:82
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 constexpr int dstart_() const
start index for derivatives
Definition: Evaluation7.hpp:74
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition: Evaluation7.hpp:66
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
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation7.hpp:61
ValueT ValueType
field type
Definition: Evaluation.hpp:71
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition: Evaluation7.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
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation7.hpp:92
Some templates to wrap the valgrind client request macros.
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:63
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation7.hpp:77
ValueT ValueType
field type
Definition: Evaluation7.hpp:58