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_)
102 template <
class RhsValueType>
103 OPM_HOST_DEVICE
constexpr Evaluation(
const RhsValueType& c): data_{}
113 template <
class RhsValueType>
114 OPM_HOST_DEVICE
Evaluation(
const RhsValueType& c,
int varPos)
117 assert(0 <= varPos && varPos <
size());
122 data_[varPos +
dstart_()] = 1.0;
128 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 7 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 7 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];
225 data_[6] = other.data_[6];
226 data_[7] = other.data_[7];
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];
242 data_[7] += other.data_[7];
248 template <
class RhsValueType>
249 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
260 assert(
size() == other.size());
262 data_[0] -= other.data_[0];
263 data_[1] -= other.data_[1];
264 data_[2] -= other.data_[2];
265 data_[3] -= other.data_[3];
266 data_[4] -= other.data_[4];
267 data_[5] -= other.data_[5];
268 data_[6] -= other.data_[6];
269 data_[7] -= other.data_[7];
275 template <
class RhsValueType>
276 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
287 assert(
size() == other.size());
298 data_[1] = data_[1] * v + other.data_[1] * u;
299 data_[2] = data_[2] * v + other.data_[2] * u;
300 data_[3] = data_[3] * v + other.data_[3] * u;
301 data_[4] = data_[4] * v + other.data_[4] * u;
302 data_[5] = data_[5] * v + other.data_[5] * u;
303 data_[6] = data_[6] * v + other.data_[6] * u;
304 data_[7] = data_[7] * v + other.data_[7] * u;
310 template <
class RhsValueType>
311 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
328 assert(
size() == other.size());
334 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
335 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
336 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
337 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
338 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
339 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
340 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
347 template <
class RhsValueType>
348 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
367 assert(
size() == other.size());
377 template <
class RhsValueType>
378 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
390 assert(
size() == other.size());
400 template <
class RhsValueType>
401 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
416 result.data_[0] = - data_[0];
417 result.data_[1] = - data_[1];
418 result.data_[2] = - data_[2];
419 result.data_[3] = - data_[3];
420 result.data_[4] = - data_[4];
421 result.data_[5] = - data_[5];
422 result.data_[6] = - data_[6];
423 result.data_[7] = - data_[7];
430 assert(
size() == other.size());
439 template <
class RhsValueType>
440 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
451 assert(
size() == other.size());
460 template <
class RhsValueType>
461 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
470 template <
class RhsValueType>
471 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
482 template <
class RhsValueType>
483 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
484 {
return value() == other; }
486 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
488 assert(
size() == other.size());
490 for (
int idx = 0; idx <
length_(); ++idx) {
491 if (data_[idx] != other.data_[idx]) {
498 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
499 {
return !operator==(other); }
501 template <
class RhsValueType>
502 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
503 {
return !operator==(other); }
505 template <
class RhsValueType>
506 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
507 {
return value() > other; }
509 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
511 assert(
size() == other.size());
513 return value() > other.value();
516 template <
class RhsValueType>
517 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
518 {
return value() < other; }
520 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
522 assert(
size() == other.size());
524 return value() < other.value();
527 template <
class RhsValueType>
528 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
529 {
return value() >= other; }
531 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
533 assert(
size() == other.size());
535 return value() >= other.value();
538 template <
class RhsValueType>
539 OPM_HOST_DEVICE
bool operator<=(RhsValueType other)
const
540 {
return value() <= other; }
542 OPM_HOST_DEVICE
bool operator<=(
const Evaluation& other)
const
544 assert(
size() == other.size());
546 return value() <= other.value();
550 OPM_HOST_DEVICE
const ValueType& value()
const
554 template <
class RhsValueType>
555 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
559 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
561 assert(0 <= varIdx && varIdx <
size());
563 return data_[
dstart_() + varIdx];
567 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
569 assert(0 <= varIdx && varIdx <
size());
571 data_[
dstart_() + varIdx] = derVal;
574 template<
class Serializer>
575 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
581 std::array<ValueT, 8> data_;