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()
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 6 derivatives");
180 template <
class RhsValueType>
181 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
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 6 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];
233 assert(
size() == other.size());
235 data_[0] += other.data_[0];
236 data_[1] += other.data_[1];
237 data_[2] += other.data_[2];
238 data_[3] += other.data_[3];
239 data_[4] += other.data_[4];
240 data_[5] += other.data_[5];
241 data_[6] += other.data_[6];
247 template <
class RhsValueType>
248 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
259 assert(
size() == other.size());
261 data_[0] -= other.data_[0];
262 data_[1] -= other.data_[1];
263 data_[2] -= other.data_[2];
264 data_[3] -= other.data_[3];
265 data_[4] -= other.data_[4];
266 data_[5] -= other.data_[5];
267 data_[6] -= other.data_[6];
273 template <
class RhsValueType>
274 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
285 assert(
size() == other.size());
296 data_[1] = data_[1] * v + other.data_[1] * u;
297 data_[2] = data_[2] * v + other.data_[2] * u;
298 data_[3] = data_[3] * v + other.data_[3] * u;
299 data_[4] = data_[4] * v + other.data_[4] * u;
300 data_[5] = data_[5] * v + other.data_[5] * u;
301 data_[6] = data_[6] * v + other.data_[6] * u;
307 template <
class RhsValueType>
308 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
324 assert(
size() == other.size());
330 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
331 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
332 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
333 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
334 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
335 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
342 template <
class RhsValueType>
343 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
361 assert(
size() == other.size());
371 template <
class RhsValueType>
372 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
384 assert(
size() == other.size());
394 template <
class RhsValueType>
395 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
410 result.data_[0] = - data_[0];
411 result.data_[1] = - data_[1];
412 result.data_[2] = - data_[2];
413 result.data_[3] = - data_[3];
414 result.data_[4] = - data_[4];
415 result.data_[5] = - data_[5];
416 result.data_[6] = - data_[6];
423 assert(
size() == other.size());
432 template <
class RhsValueType>
433 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
444 assert(
size() == other.size());
453 template <
class RhsValueType>
454 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
463 template <
class RhsValueType>
464 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
475 template <
class RhsValueType>
476 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
477 {
return value() == other; }
479 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
481 assert(
size() == other.size());
483 for (
int idx = 0; idx <
length_(); ++idx) {
484 if (data_[idx] != other.data_[idx]) {
491 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
492 {
return !operator==(other); }
494 template <
class RhsValueType>
495 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
496 {
return !operator==(other); }
498 template <
class RhsValueType>
499 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
500 {
return value() > other; }
502 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
504 assert(
size() == other.size());
506 return value() > other.value();
509 template <
class RhsValueType>
510 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
511 {
return value() < other; }
513 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
515 assert(
size() == other.size());
517 return value() < other.value();
520 template <
class RhsValueType>
521 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
522 {
return value() >= other; }
524 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
526 assert(
size() == other.size());
528 return value() >= other.value();
531 template <
class RhsValueType>
532 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
533 {
return value() <= other; }
535 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
537 assert(
size() == other.size());
539 return value() <= other.value();
543 OPM_HOST_DEVICE
const ValueType& value()
const
547 template <
class RhsValueType>
548 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
552 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
554 assert(0 <= varIdx && varIdx <
size());
556 return data_[
dstart_() + varIdx];
560 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
562 assert(0 <= varIdx && varIdx <
size());
564 data_[
dstart_() + varIdx] = derVal;
567 template<
class Serializer>
568 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
574 std::array<ValueT, 7> data_;