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()
161 template <
class RhsValueType>
162 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType& value,
int varPos)
169 template <
class RhsValueType>
170 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
173 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
174 " with 7 derivatives");
181 template <
class RhsValueType>
182 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
192 template <
class RhsValueType>
193 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
196 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
197 " with 7 derivatives");
203 template <
class RhsValueType>
204 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType& value)
211 template <
class RhsValueType>
218 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
220 assert(
size() == other.size());
222 data_[1] = other.data_[1];
223 data_[2] = other.data_[2];
224 data_[3] = other.data_[3];
225 data_[4] = other.data_[4];
226 data_[5] = other.data_[5];
227 data_[6] = other.data_[6];
228 data_[7] = other.data_[7];
235 assert(
size() == other.size());
237 data_[0] += other.data_[0];
238 data_[1] += other.data_[1];
239 data_[2] += other.data_[2];
240 data_[3] += other.data_[3];
241 data_[4] += other.data_[4];
242 data_[5] += other.data_[5];
243 data_[6] += other.data_[6];
244 data_[7] += other.data_[7];
250 template <
class RhsValueType>
251 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
262 assert(
size() == other.size());
264 data_[0] -= other.data_[0];
265 data_[1] -= other.data_[1];
266 data_[2] -= other.data_[2];
267 data_[3] -= other.data_[3];
268 data_[4] -= other.data_[4];
269 data_[5] -= other.data_[5];
270 data_[6] -= other.data_[6];
271 data_[7] -= other.data_[7];
277 template <
class RhsValueType>
278 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
289 assert(
size() == other.size());
300 data_[1] = data_[1] * v + other.data_[1] * u;
301 data_[2] = data_[2] * v + other.data_[2] * u;
302 data_[3] = data_[3] * v + other.data_[3] * u;
303 data_[4] = data_[4] * v + other.data_[4] * u;
304 data_[5] = data_[5] * v + other.data_[5] * u;
305 data_[6] = data_[6] * v + other.data_[6] * u;
306 data_[7] = data_[7] * v + other.data_[7] * u;
312 template <
class RhsValueType>
313 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
330 assert(
size() == other.size());
336 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
337 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
338 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
339 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
340 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
341 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
342 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
349 template <
class RhsValueType>
350 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
369 assert(
size() == other.size());
379 template <
class RhsValueType>
380 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
392 assert(
size() == other.size());
402 template <
class RhsValueType>
403 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
418 result.data_[0] = - data_[0];
419 result.data_[1] = - data_[1];
420 result.data_[2] = - data_[2];
421 result.data_[3] = - data_[3];
422 result.data_[4] = - data_[4];
423 result.data_[5] = - data_[5];
424 result.data_[6] = - data_[6];
425 result.data_[7] = - data_[7];
432 assert(
size() == other.size());
441 template <
class RhsValueType>
442 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
453 assert(
size() == other.size());
462 template <
class RhsValueType>
463 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
472 template <
class RhsValueType>
473 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
484 template <
class RhsValueType>
485 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
486 {
return value() == other; }
488 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
490 assert(
size() == other.size());
492 for (
int idx = 0; idx <
length_(); ++idx) {
493 if (data_[idx] != other.data_[idx]) {
500 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
501 {
return !operator==(other); }
503 template <
class RhsValueType>
504 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
505 {
return !operator==(other); }
507 template <
class RhsValueType>
508 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
509 {
return value() > other; }
511 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
513 assert(
size() == other.size());
515 return value() > other.value();
518 template <
class RhsValueType>
519 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
520 {
return value() < other; }
522 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
524 assert(
size() == other.size());
526 return value() < other.value();
529 template <
class RhsValueType>
530 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
531 {
return value() >= other; }
533 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
535 assert(
size() == other.size());
537 return value() >= other.value();
540 template <
class RhsValueType>
541 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
542 {
return value() <= other; }
544 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
546 assert(
size() == other.size());
548 return value() <= other.value();
552 OPM_HOST_DEVICE
const ValueType& value()
const
556 template <
class RhsValueType>
557 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
561 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
563 assert(0 <= varIdx && varIdx <
size());
565 return data_[
dstart_() + varIdx];
569 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
571 assert(0 <= varIdx && varIdx <
size());
573 data_[
dstart_() + varIdx] = derVal;
576 template<
class Serializer>
577 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
583 std::array<ValueT, 8> data_;