32#ifndef OPM_DENSEAD_EVALUATION_DYNAMIC_HPP
33#define OPM_DENSEAD_EVALUATION_DYNAMIC_HPP
44#include <opm/common/utility/gpuDecorators.hpp>
53template <
class ValueT,
unsigned staticSize>
65 OPM_HOST_DEVICE
int size()
const
66 {
return data_.size() - 1; }
71 {
return data_.size(); }
78 OPM_HOST_DEVICE
constexpr int dstart_()
const
81 OPM_HOST_DEVICE
int dend_()
const
90 Valgrind::CheckDefined(data_[i]);
105 : data_(std::move(other.data_))
111 data_ = std::move(other.data_);
116 OPM_HOST_DEVICE
explicit Evaluation(
int numDerivatives)
117 : data_(1 + numDerivatives)
124 template <
class RhsValueType>
125 OPM_HOST_DEVICE
Evaluation(
int numDerivatives,
const RhsValueType& c)
126 : data_(1 + numDerivatives, 0.0)
138 template <
class RhsValueType>
139 OPM_HOST_DEVICE
Evaluation(
int nVars,
const RhsValueType& c,
int varPos)
140 : data_(1 + nVars, 0.0)
143 assert(0 <= varPos && varPos <
size());
147 data_[varPos +
dstart_()] = 1.0;
153 OPM_HOST_DEVICE
void clearDerivatives()
179 template <
class RhsValueType>
180 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&,
int)
182 throw std::logic_error(
"Dynamically sized evaluations require that the number of "
183 "derivatives is specified when creating an evaluation");
186 template <
class RhsValueType>
187 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
194 template <
class RhsValueType>
195 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation& x,
const RhsValueType& value,
int varPos)
205 template <
class RhsValueType>
206 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
213 template <
class RhsValueType>
214 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&)
216 throw std::logic_error(
"Dynamically-sized evaluation objects require to specify the number of derivatives.");
221 template <
class RhsValueType>
222 OPM_HOST_DEVICE
static Evaluation createConstant(
const Evaluation& x,
const RhsValueType& value)
228 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
230 assert(
size() == other.size());
233 data_[i] = other.data_[i];
240 assert(
size() == other.size());
242 for (
int i = 0; i <
length_(); ++i)
243 data_[i] += other.data_[i];
249 template <
class RhsValueType>
250 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
261 assert(
size() == other.size());
263 for (
int i = 0; i <
length_(); ++i)
264 data_[i] -= other.data_[i];
270 template <
class RhsValueType>
271 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
282 assert(
size() == other.size());
294 data_[i] = data_[i] * v + other.data_[i] * u;
300 template <
class RhsValueType>
301 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
303 for (
int i = 0; i <
length_(); ++i)
312 assert(
size() == other.size());
320 const ValueType& vPrime = other.data_[idx];
322 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
330 template <
class RhsValueType>
331 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
335 for (
int i = 0; i <
length_(); ++i)
344 assert(
size() == other.size());
354 template <
class RhsValueType>
355 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
367 assert(
size() == other.size());
377 template <
class RhsValueType>
378 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
393 for (
int i = 0; i <
length_(); ++i)
394 result.data_[i] = - data_[i];
401 assert(
size() == other.size());
410 template <
class RhsValueType>
411 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
422 assert(
size() == other.size());
431 template <
class RhsValueType>
432 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
441 template <
class RhsValueType>
442 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
453 template <
class RhsValueType>
454 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
455 {
return value() == other; }
457 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
459 assert(
size() == other.size());
461 for (
int idx = 0; idx <
length_(); ++idx) {
462 if (data_[idx] != other.data_[idx]) {
469 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
470 {
return !operator==(other); }
472 template <
class RhsValueType>
473 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
474 {
return !operator==(other); }
476 template <
class RhsValueType>
477 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
478 {
return value() > other; }
480 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
482 assert(
size() == other.size());
484 return value() > other.value();
487 template <
class RhsValueType>
488 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
489 {
return value() < other; }
491 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
493 assert(
size() == other.size());
495 return value() < other.value();
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();
521 OPM_HOST_DEVICE
const ValueType& value()
const
525 template <
class RhsValueType>
526 OPM_HOST_DEVICE
void setValue(
const RhsValueType& val)
530 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
532 assert(0 <= varIdx && varIdx <
size());
534 return data_[
dstart_() + varIdx];
538 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
540 assert(0 <= varIdx && varIdx <
size());
542 data_[
dstart_() + varIdx] = derVal;
545 template<
class Serializer>
546 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
552 FastSmallVector<ValueT, staticSize> data_;
555template <
class Scalar,
unsigned staticSize = 0>
556using DynamicEvaluation = Evaluation<Scalar, DynamicSize, staticSize>;
560template <
class Scalar,
unsigned staticSize>
561OPM_HOST_DEVICE DenseAd::Evaluation<Scalar, -1, staticSize> constant(
int numDerivatives,
const Scalar& value)
562{
return DenseAd::Evaluation<Scalar, -1, staticSize>::createConstant(numDerivatives, value); }
564template <
class Scalar,
unsigned staticSize>
565OPM_HOST_DEVICE DenseAd::Evaluation<Scalar, -1, staticSize> variable(
int numDerivatives,
const Scalar& value,
unsigned idx)
566{
return DenseAd::Evaluation<Scalar, -1, staticSize>::createVariable(numDerivatives, value, idx); }
An implementation of vector/array based on small object optimization.
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE int dend_() const
end+1 index for derivatives
Definition DynamicEvaluation.hpp:81
Evaluation(const Evaluation &other)=default
copy other function evaluation
OPM_HOST_DEVICE Evaluation()
default constructor
Definition DynamicEvaluation.hpp:96
OPM_HOST_DEVICE void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition DynamicEvaluation.hpp:86
OPM_HOST_DEVICE Evaluation & operator=(Evaluation &&other)
move assignment
Definition DynamicEvaluation.hpp:109
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition DynamicEvaluation.hpp:75
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition DynamicEvaluation.hpp:78
OPM_HOST_DEVICE int size() const
number of derivatives
Definition DynamicEvaluation.hpp:65
OPM_HOST_DEVICE int length_() const
length of internal data vector
Definition DynamicEvaluation.hpp:70
ValueT ValueType
field type
Definition DynamicEvaluation.hpp:62
OPM_HOST_DEVICE Evaluation(Evaluation &&other)
move other function evaluation (this only makes sense for dynamically allocated Evaluations)
Definition DynamicEvaluation.hpp:104
Represents a function evaluation and its derivatives w.r.t.
Definition Evaluation.hpp:59
ValueT ValueType
field type
Definition Evaluation.hpp:66
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:82
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation.hpp:63
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:74
OPM_HOST_DEVICE void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation.hpp:90
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation.hpp:100
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:79
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation.hpp:69
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation.hpp:85
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30