31 #ifndef OPM_DENSEAD_EVALUATION3_HPP 32 #define OPM_DENSEAD_EVALUATION3_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()
156 template <
class RhsValueType>
157 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&
value,
int varPos)
164 template <
class RhsValueType>
165 OPM_HOST_DEVICE
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 3 derivatives");
176 template <
class RhsValueType>
187 template <
class RhsValueType>
188 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType&
value)
191 throw std::logic_error(
"This statically-sized evaluation can only represent objects" 192 " with 3 derivatives");
198 template <
class RhsValueType>
199 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&
value)
206 template <
class RhsValueType>
213 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
215 assert(
size() == other.size());
217 data_[1] = other.data_[1];
218 data_[2] = other.data_[2];
219 data_[3] = other.data_[3];
226 assert(
size() == other.size());
228 data_[0] += other.data_[0];
229 data_[1] += other.data_[1];
230 data_[2] += other.data_[2];
231 data_[3] += other.data_[3];
237 template <
class RhsValueType>
238 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
249 assert(
size() == other.size());
251 data_[0] -= other.data_[0];
252 data_[1] -= other.data_[1];
253 data_[2] -= other.data_[2];
254 data_[3] -= other.data_[3];
260 template <
class RhsValueType>
261 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
272 assert(
size() == other.size());
283 data_[1] = data_[1] * v + other.data_[1] * u;
284 data_[2] = data_[2] * v + other.data_[2] * u;
285 data_[3] = data_[3] * v + other.data_[3] * u;
291 template <
class RhsValueType>
292 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
305 assert(
size() == other.size());
311 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
312 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
313 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
320 template <
class RhsValueType>
321 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
336 assert(
size() == other.size());
346 template <
class RhsValueType>
347 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const 359 assert(
size() == other.size());
369 template <
class RhsValueType>
370 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const 385 result.data_[0] = - data_[0];
386 result.data_[1] = - data_[1];
387 result.data_[2] = - data_[2];
388 result.data_[3] = - data_[3];
395 assert(
size() == other.size());
404 template <
class RhsValueType>
405 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const 416 assert(
size() == other.size());
425 template <
class RhsValueType>
426 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const 435 template <
class RhsValueType>
436 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
447 template <
class RhsValueType>
448 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const 449 {
return value() == other; }
451 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const 453 assert(
size() == other.size());
455 for (
int idx = 0; idx <
length_(); ++idx) {
456 if (data_[idx] != other.data_[idx]) {
463 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const 464 {
return !operator==(other); }
466 template <
class RhsValueType>
467 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const 468 {
return !operator==(other); }
470 template <
class RhsValueType>
471 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const 472 {
return value() > other; }
474 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const 476 assert(
size() == other.size());
478 return value() > other.value();
481 template <
class RhsValueType>
482 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const 483 {
return value() < other; }
485 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const 487 assert(
size() == other.size());
489 return value() < other.value();
492 template <
class RhsValueType>
493 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const 494 {
return value() >= other; }
496 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const 498 assert(
size() == other.size());
500 return value() >= other.value();
503 template <
class RhsValueType>
504 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const 505 {
return value() <= other; }
507 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const 509 assert(
size() == other.size());
511 return value() <= other.value();
519 template <
class RhsValueType>
520 OPM_HOST_DEVICE constexpr
void setValue(
const RhsValueType& val)
524 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const 526 assert(0 <= varIdx && varIdx <
size());
528 return data_[
dstart_() + varIdx];
532 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
534 assert(0 <= varIdx && varIdx <
size());
536 data_[
dstart_() + varIdx] = derVal;
539 template<
class Serializer>
540 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
546 std::array<ValueT, 4> data_;
552 #endif // OPM_DENSEAD_EVALUATION3_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 constexpr int length_() const
length of internal data vector
Definition: Evaluation3.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
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition: Evaluation3.hpp:74
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
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation3.hpp:77
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 valuepos_() const
position index for value
Definition: Evaluation3.hpp:71
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:82
ValueT ValueType
field type
Definition: Evaluation3.hpp:58
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition: Evaluation3.hpp:61
OPM_HOST_DEVICE Evaluation()
default constructor
Definition: Evaluation3.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