32#ifndef OPM_DENSEAD_EVALUATION_DYNAMIC_HPP
33#define OPM_DENSEAD_EVALUATION_DYNAMIC_HPP
51template <
class ValueT,
unsigned staticSize>
64 {
return data_.size() - 1; }
69 {
return data_.size(); }
88 Valgrind::CheckDefined(data_[i]);
103 : data_(std::move(other.data_))
109 data_ = std::move(other.data_);
115 : data_(1 + numDerivatives)
122 template <
class RhsValueType>
123 Evaluation(
int numDerivatives,
const RhsValueType& c)
124 : data_(1 + numDerivatives, 0.0)
136 template <
class RhsValueType>
137 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 void clearDerivatives()
177 template <
class RhsValueType>
178 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 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
192 template <
class RhsValueType>
203 template <
class RhsValueType>
204 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
211 template <
class RhsValueType>
212 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>
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 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 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 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 Evaluation& operator/=(
const RhsValueType& other)
333 for (
int i = 0; i <
length_(); ++i)
342 assert(
size() == other.size());
352 template <
class RhsValueType>
353 Evaluation operator+(
const RhsValueType& other)
const
365 assert(
size() == other.size());
375 template <
class RhsValueType>
376 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 Evaluation operator*(
const RhsValueType& other)
const
420 assert(
size() == other.size());
429 template <
class RhsValueType>
430 Evaluation operator/(
const RhsValueType& other)
const
439 template <
class RhsValueType>
440 Evaluation& operator=(
const RhsValueType& other)
451 template <
class RhsValueType>
452 bool operator==(
const RhsValueType& other)
const
453 {
return value() == other; }
455 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 bool operator!=(
const Evaluation& other)
const
468 {
return !operator==(other); }
470 template <
class RhsValueType>
471 bool operator!=(
const RhsValueType& other)
const
472 {
return !operator==(other); }
474 template <
class RhsValueType>
475 bool operator>(RhsValueType other)
const
476 {
return value() > other; }
480 assert(
size() == other.size());
482 return value() > other.value();
485 template <
class RhsValueType>
486 bool operator<(RhsValueType other)
const
487 {
return value() < other; }
491 assert(
size() == other.size());
493 return value() < other.value();
496 template <
class RhsValueType>
497 bool operator>=(RhsValueType other)
const
498 {
return value() >= other; }
500 bool operator>=(
const Evaluation& other)
const
502 assert(
size() == other.size());
504 return value() >= other.value();
507 template <
class RhsValueType>
508 bool operator<=(RhsValueType other)
const
509 {
return value() <= other; }
511 bool operator<=(
const Evaluation& other)
const
513 assert(
size() == other.size());
515 return value() <= other.value();
523 template <
class RhsValueType>
524 void setValue(
const RhsValueType& val)
528 const ValueType& derivative(
int varIdx)
const
530 assert(0 <= varIdx && varIdx <
size());
532 return data_[
dstart_() + varIdx];
536 void setDerivative(
int varIdx,
const ValueType& derVal)
538 assert(0 <= varIdx && varIdx <
size());
540 data_[
dstart_() + varIdx] = derVal;
543 template<
class Serializer>
544 void serializeOp(Serializer& serializer)
550 FastSmallVector<ValueT, staticSize> data_;
553template <
class Scalar,
unsigned staticSize = 0>
554using DynamicEvaluation = Evaluation<Scalar, DynamicSize, staticSize>;
558template <
class Scalar,
unsigned staticSize>
559DenseAd::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>
563DenseAd::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.
constexpr int dstart_() const
start index for derivatives
Definition DynamicEvaluation.hpp:76
Evaluation(const Evaluation &other)=default
copy other function evaluation
int length_() const
length of internal data vector
Definition DynamicEvaluation.hpp:68
Evaluation(Evaluation &&other)
move other function evaluation (this only makes sense for dynamically allocated Evaluations)
Definition DynamicEvaluation.hpp:102
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition DynamicEvaluation.hpp:84
int size() const
number of derivatives
Definition DynamicEvaluation.hpp:63
int dend_() const
end+1 index for derivatives
Definition DynamicEvaluation.hpp:79
Evaluation & operator=(Evaluation &&other)
move assignment
Definition DynamicEvaluation.hpp:107
ValueT ValueType
field type
Definition DynamicEvaluation.hpp:60
Evaluation()
default constructor
Definition DynamicEvaluation.hpp:94
constexpr int valuepos_() const
position index for value
Definition DynamicEvaluation.hpp:73
Represents a function evaluation and its derivatives w.r.t.
Definition Evaluation.hpp:57
Evaluation()
default constructor
Definition Evaluation.hpp:98
ValueT ValueType
field type
Definition Evaluation.hpp:64
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition Evaluation.hpp:88
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition Evaluation.hpp:61
constexpr int size() const
number of derivatives
Definition Evaluation.hpp:67
constexpr int valuepos_() const
position index for value
Definition Evaluation.hpp:77
constexpr int dend_() const
end+1 index for derivatives
Definition Evaluation.hpp:83
constexpr int length_() const
length of internal data vector
Definition Evaluation.hpp:72
constexpr int dstart_() const
start index for derivatives
Definition Evaluation.hpp:80
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30