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
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)
136 template <
class RhsValueType>
137 OPM_HOST_DEVICE
Evaluation(
int nVars,
const RhsValueType& c,
int varPos)
138 : data_(1 + nVars, 0.0)
141 assert(0 <= varPos && varPos <
size());
145 data_[varPos +
dstart_()] = 1.0;
151 OPM_HOST_DEVICE
constexpr void clearDerivatives()
177 template <
class RhsValueType>
178 OPM_HOST_DEVICE
static Evaluation createVariable(
const RhsValueType&,
int)
180 throw std::logic_error(
"Dynamically sized evaluations require that the number of "
181 "derivatives is specified when creating an evaluation");
184 template <
class RhsValueType>
185 OPM_HOST_DEVICE
static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
192 template <
class RhsValueType>
193 OPM_HOST_DEVICE
static Evaluation createVariable(
const Evaluation& x,
const RhsValueType& value,
int varPos)
203 template <
class RhsValueType>
204 OPM_HOST_DEVICE
static Evaluation createConstant(
int nVars,
const RhsValueType& value)
211 template <
class RhsValueType>
212 OPM_HOST_DEVICE
static Evaluation createConstant(
const RhsValueType&)
214 throw std::logic_error(
"Dynamically-sized evaluation objects require to specify the number of derivatives.");
219 template <
class RhsValueType>
220 OPM_HOST_DEVICE
static Evaluation createConstant(
const Evaluation& x,
const RhsValueType& value)
226 OPM_HOST_DEVICE
void copyDerivatives(
const Evaluation& other)
228 assert(
size() == other.size());
231 data_[i] = other.data_[i];
238 assert(
size() == other.size());
240 for (
int i = 0; i <
length_(); ++i)
241 data_[i] += other.data_[i];
247 template <
class RhsValueType>
248 OPM_HOST_DEVICE
Evaluation& operator+=(
const RhsValueType& other)
259 assert(
size() == other.size());
261 for (
int i = 0; i <
length_(); ++i)
262 data_[i] -= other.data_[i];
268 template <
class RhsValueType>
269 OPM_HOST_DEVICE
Evaluation& operator-=(
const RhsValueType& other)
280 assert(
size() == other.size());
292 data_[i] = data_[i] * v + other.data_[i] * u;
298 template <
class RhsValueType>
299 OPM_HOST_DEVICE
Evaluation& operator*=(
const RhsValueType& other)
301 for (
int i = 0; i <
length_(); ++i)
310 assert(
size() == other.size());
318 const ValueType& vPrime = other.data_[idx];
320 data_[idx] = (v*uPrime - u*vPrime)/(v*v);
328 template <
class RhsValueType>
329 OPM_HOST_DEVICE
Evaluation& operator/=(
const RhsValueType& other)
333 for (
int i = 0; i <
length_(); ++i)
342 assert(
size() == other.size());
352 template <
class RhsValueType>
353 OPM_HOST_DEVICE
Evaluation operator+(
const RhsValueType& other)
const
365 assert(
size() == other.size());
375 template <
class RhsValueType>
376 OPM_HOST_DEVICE
Evaluation operator-(
const RhsValueType& other)
const
391 for (
int i = 0; i <
length_(); ++i)
392 result.data_[i] = - data_[i];
399 assert(
size() == other.size());
408 template <
class RhsValueType>
409 OPM_HOST_DEVICE
Evaluation operator*(
const RhsValueType& other)
const
420 assert(
size() == other.size());
429 template <
class RhsValueType>
430 OPM_HOST_DEVICE
Evaluation operator/(
const RhsValueType& other)
const
439 template <
class RhsValueType>
440 OPM_HOST_DEVICE
Evaluation& operator=(
const RhsValueType& other)
451 template <
class RhsValueType>
452 OPM_HOST_DEVICE
bool operator==(
const RhsValueType& other)
const
453 {
return value() == other; }
455 OPM_HOST_DEVICE
bool operator==(
const Evaluation& other)
const
457 assert(
size() == other.size());
459 for (
int idx = 0; idx <
length_(); ++idx) {
460 if (data_[idx] != other.data_[idx]) {
467 OPM_HOST_DEVICE
bool operator!=(
const Evaluation& other)
const
468 {
return !operator==(other); }
470 template <
class RhsValueType>
471 OPM_HOST_DEVICE
bool operator!=(
const RhsValueType& other)
const
472 {
return !operator==(other); }
474 template <
class RhsValueType>
475 OPM_HOST_DEVICE
bool operator>(RhsValueType other)
const
476 {
return value() > other; }
478 OPM_HOST_DEVICE
bool operator>(
const Evaluation& other)
const
480 assert(
size() == other.size());
482 return value() > other.value();
485 template <
class RhsValueType>
486 OPM_HOST_DEVICE
bool operator<(RhsValueType other)
const
487 {
return value() < other; }
489 OPM_HOST_DEVICE
bool operator<(
const Evaluation& other)
const
491 assert(
size() == other.size());
493 return value() < other.value();
496 template <
class RhsValueType>
497 OPM_HOST_DEVICE
bool operator>=(RhsValueType other)
const
498 {
return value() >= other; }
500 OPM_HOST_DEVICE
bool operator>=(
const Evaluation& other)
const
502 assert(
size() == other.size());
504 return value() >= other.value();
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();
519 OPM_HOST_DEVICE
const ValueType& value()
const
523 template <
class RhsValueType>
524 OPM_HOST_DEVICE
constexpr void setValue(
const RhsValueType& val)
528 OPM_HOST_DEVICE
const ValueType& derivative(
int varIdx)
const
530 assert(0 <= varIdx && varIdx <
size());
532 return data_[
dstart_() + varIdx];
536 OPM_HOST_DEVICE
void setDerivative(
int varIdx,
const ValueType& derVal)
538 assert(0 <= varIdx && varIdx <
size());
540 data_[
dstart_() + varIdx] = derVal;
543 template<
class Serializer>
544 OPM_HOST_DEVICE
void serializeOp(Serializer& serializer)
550 FastSmallVector<ValueT, staticSize> data_;
553template <
class Scalar,
unsigned staticSize = 0>
558template <
class Scalar,
unsigned staticSize>
559OPM_HOST_DEVICE
DenseAd::Evaluation<Scalar, -1, staticSize> constant(
int numDerivatives,
const Scalar& value)
560{
return DenseAd::Evaluation<Scalar, -1, staticSize>::createConstant(numDerivatives, value); }
562template <
class Scalar,
unsigned staticSize>
563OPM_HOST_DEVICE
DenseAd::Evaluation<Scalar, -1, staticSize> variable(
int numDerivatives,
const Scalar& value,
unsigned idx)
564{
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 bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition Valgrind.hpp:76
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 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
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition DynamicEvaluation.hpp:59
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
OPM_HOST_DEVICE constexpr void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition DynamicEvaluation.hpp:86
Represents a function evaluation and its derivatives w.r.t.
Definition Evaluation.hpp:63
ValueT ValueType
field type
Definition Evaluation.hpp:70
OPM_HOST_DEVICE constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:86
OPM_HOST_DEVICE constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:78
OPM_HOST_DEVICE Evaluation()
default constructor
Definition Evaluation.hpp:104
OPM_HOST_DEVICE constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:83
OPM_HOST_DEVICE constexpr void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation.hpp:94
OPM_HOST_DEVICE constexpr int size() const
number of derivatives
Definition Evaluation.hpp:73
OPM_HOST_DEVICE constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation.hpp:89
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30