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()
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 5 derivatives");
179 template <
class RhsValueType>
180 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation&,
const RhsValueType& value,
int varPos)
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 5 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];
231 assert(
size() == other.size());
233 data_[0] += other.data_[0];
234 data_[1] += other.data_[1];
235 data_[2] += other.data_[2];
236 data_[3] += other.data_[3];
237 data_[4] += other.data_[4];
238 data_[5] += other.data_[5];
244 template <
class RhsValueType>
245 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
256 assert(
size() == other.size());
258 data_[0] -= other.data_[0];
259 data_[1] -= other.data_[1];
260 data_[2] -= other.data_[2];
261 data_[3] -= other.data_[3];
262 data_[4] -= other.data_[4];
263 data_[5] -= other.data_[5];
269 template <
class RhsValueType>
270 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
281 assert(
size() == other.size());
292 data_[1] = data_[1] * v + other.data_[1] * u;
293 data_[2] = data_[2] * v + other.data_[2] * u;
294 data_[3] = data_[3] * v + other.data_[3] * u;
295 data_[4] = data_[4] * v + other.data_[4] * u;
296 data_[5] = data_[5] * v + other.data_[5] * u;
302 template <
class RhsValueType>
303 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
318 assert(
size() == other.size());
324 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
325 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
326 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
327 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
328 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
335 template <
class RhsValueType>
336 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
353 assert(
size() == other.size());
363 template <
class RhsValueType>
364 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
376 assert(
size() == other.size());
386 template <
class RhsValueType>
387 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
402 result.data_[0] = - data_[0];
403 result.data_[1] = - data_[1];
404 result.data_[2] = - data_[2];
405 result.data_[3] = - data_[3];
406 result.data_[4] = - data_[4];
407 result.data_[5] = - data_[5];
414 assert(
size() == other.size());
423 template <
class RhsValueType>
424 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
435 assert(
size() == other.size());
444 template <
class RhsValueType>
445 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
454 template <
class RhsValueType>
455 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
466 template <
class RhsValueType>
467 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
468 {
return value() == other; }
470 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
472 assert(
size() == other.size());
474 for (
int idx = 0; idx <
length_(); ++idx) {
475 if (data_[idx] != other.data_[idx]) {
482 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
483 {
return !operator==(other); }
485 template <
class RhsValueType>
486 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
487 {
return !operator==(other); }
489 template <
class RhsValueType>
490 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
491 {
return value() > other; }
493 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
495 assert(
size() == other.size());
497 return value() > other.value();
500 template <
class RhsValueType>
501 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
502 {
return value() < other; }
504 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
506 assert(
size() == other.size());
508 return value() < other.value();
511 template <
class RhsValueType>
512 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
513 {
return value() >= other; }
515 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
517 assert(
size() == other.size());
519 return value() >= other.value();
522 template <
class RhsValueType>
523 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
524 {
return value() <= other; }
526 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
528 assert(
size() == other.size());
530 return value() <= other.value();
534 OPM_HOST_DEVICE
const ValueType& value()
const
538 template <
class RhsValueType>
539 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
543 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
545 assert(0 <= varIdx && varIdx <
size());
547 return data_[
dstart_() + varIdx];
551 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
553 assert(0 <= varIdx && varIdx <
size());
555 data_[
dstart_() + varIdx] = derVal;
558 template<
class Serializer>
559 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
565 std::array<ValueT, 6> data_;