31 #ifndef OPM_DENSEAD_EVALUATION12_HPP
32 #define OPM_DENSEAD_EVALUATION12_HPP
49 template <
class ValueT>
67 {
return size() + 1; }
85 for (
const auto& v: data_)
86 Valgrind::CheckDefined(v);
103 template <
class RhsValueType>
116 template <
class RhsValueType>
120 assert(0 <= varPos && varPos <
size());
125 data_[varPos +
dstart_()] = 1.0;
131 void clearDerivatives()
167 template <
class RhsValueType>
168 static Evaluation createVariable(
const RhsValueType& value,
int varPos)
175 template <
class RhsValueType>
176 static Evaluation createVariable(
int nVars,
const RhsValueType& value,
int varPos)
179 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
180 " with 12 derivatives");
187 template <
class RhsValueType>
198 template <
class RhsValueType>
199 static Evaluation createConstant(
int nVars,
const RhsValueType& value)
202 throw std::logic_error(
"This statically-sized evaluation can only represent objects"
203 " with 12 derivatives");
209 template <
class RhsValueType>
210 static Evaluation createConstant(
const RhsValueType& value)
217 template <
class RhsValueType>
224 void print(std::ostream& os = std::cout)
const
227 os <<
"v: " << value() <<
" / d:";
230 for (
int varIdx = 0; varIdx <
size(); ++varIdx) {
231 os <<
" " << derivative(varIdx);
238 assert(
size() == other.size());
240 data_[1] = other.data_[1];
241 data_[2] = other.data_[2];
242 data_[3] = other.data_[3];
243 data_[4] = other.data_[4];
244 data_[5] = other.data_[5];
245 data_[6] = other.data_[6];
246 data_[7] = other.data_[7];
247 data_[8] = other.data_[8];
248 data_[9] = other.data_[9];
249 data_[10] = other.data_[10];
250 data_[11] = other.data_[11];
251 data_[12] = other.data_[12];
258 assert(
size() == other.size());
260 data_[0] += other.data_[0];
261 data_[1] += other.data_[1];
262 data_[2] += other.data_[2];
263 data_[3] += other.data_[3];
264 data_[4] += other.data_[4];
265 data_[5] += other.data_[5];
266 data_[6] += other.data_[6];
267 data_[7] += other.data_[7];
268 data_[8] += other.data_[8];
269 data_[9] += other.data_[9];
270 data_[10] += other.data_[10];
271 data_[11] += other.data_[11];
272 data_[12] += other.data_[12];
278 template <
class RhsValueType>
279 Evaluation& operator+=(
const RhsValueType& other)
290 assert(
size() == other.size());
292 data_[0] -= other.data_[0];
293 data_[1] -= other.data_[1];
294 data_[2] -= other.data_[2];
295 data_[3] -= other.data_[3];
296 data_[4] -= other.data_[4];
297 data_[5] -= other.data_[5];
298 data_[6] -= other.data_[6];
299 data_[7] -= other.data_[7];
300 data_[8] -= other.data_[8];
301 data_[9] -= other.data_[9];
302 data_[10] -= other.data_[10];
303 data_[11] -= other.data_[11];
304 data_[12] -= other.data_[12];
310 template <
class RhsValueType>
311 Evaluation& operator-=(
const RhsValueType& other)
322 assert(
size() == other.size());
333 data_[1] = data_[1] * v + other.data_[1] * u;
334 data_[2] = data_[2] * v + other.data_[2] * u;
335 data_[3] = data_[3] * v + other.data_[3] * u;
336 data_[4] = data_[4] * v + other.data_[4] * u;
337 data_[5] = data_[5] * v + other.data_[5] * u;
338 data_[6] = data_[6] * v + other.data_[6] * u;
339 data_[7] = data_[7] * v + other.data_[7] * u;
340 data_[8] = data_[8] * v + other.data_[8] * u;
341 data_[9] = data_[9] * v + other.data_[9] * u;
342 data_[10] = data_[10] * v + other.data_[10] * u;
343 data_[11] = data_[11] * v + other.data_[11] * u;
344 data_[12] = data_[12] * v + other.data_[12] * u;
350 template <
class RhsValueType>
351 Evaluation& operator*=(
const RhsValueType& other)
373 assert(
size() == other.size());
379 data_[1] = (v*data_[1] - u*other.data_[1])/(v*v);
380 data_[2] = (v*data_[2] - u*other.data_[2])/(v*v);
381 data_[3] = (v*data_[3] - u*other.data_[3])/(v*v);
382 data_[4] = (v*data_[4] - u*other.data_[4])/(v*v);
383 data_[5] = (v*data_[5] - u*other.data_[5])/(v*v);
384 data_[6] = (v*data_[6] - u*other.data_[6])/(v*v);
385 data_[7] = (v*data_[7] - u*other.data_[7])/(v*v);
386 data_[8] = (v*data_[8] - u*other.data_[8])/(v*v);
387 data_[9] = (v*data_[9] - u*other.data_[9])/(v*v);
388 data_[10] = (v*data_[10] - u*other.data_[10])/(v*v);
389 data_[11] = (v*data_[11] - u*other.data_[11])/(v*v);
390 data_[12] = (v*data_[12] - u*other.data_[12])/(v*v);
397 template <
class RhsValueType>
398 Evaluation& operator/=(
const RhsValueType& other)
422 assert(
size() == other.size());
432 template <
class RhsValueType>
433 Evaluation operator+(
const RhsValueType& other)
const
445 assert(
size() == other.size());
455 template <
class RhsValueType>
456 Evaluation operator-(
const RhsValueType& other)
const
471 result.data_[0] = - data_[0];
472 result.data_[1] = - data_[1];
473 result.data_[2] = - data_[2];
474 result.data_[3] = - data_[3];
475 result.data_[4] = - data_[4];
476 result.data_[5] = - data_[5];
477 result.data_[6] = - data_[6];
478 result.data_[7] = - data_[7];
479 result.data_[8] = - data_[8];
480 result.data_[9] = - data_[9];
481 result.data_[10] = - data_[10];
482 result.data_[11] = - data_[11];
483 result.data_[12] = - data_[12];
490 assert(
size() == other.size());
499 template <
class RhsValueType>
500 Evaluation operator*(
const RhsValueType& other)
const
511 assert(
size() == other.size());
520 template <
class RhsValueType>
521 Evaluation operator/(
const RhsValueType& other)
const
530 template <
class RhsValueType>
531 Evaluation& operator=(
const RhsValueType& other)
542 template <
class RhsValueType>
543 bool operator==(
const RhsValueType& other)
const
544 {
return value() == other; }
546 bool operator==(
const Evaluation& other)
const
548 assert(
size() == other.size());
550 for (
int idx = 0; idx <
length_(); ++idx) {
551 if (data_[idx] != other.data_[idx]) {
558 bool operator!=(
const Evaluation& other)
const
559 {
return !operator==(other); }
561 template <
class RhsValueType>
562 bool operator!=(
const RhsValueType& other)
const
563 {
return !operator==(other); }
565 template <
class RhsValueType>
566 bool operator>(RhsValueType other)
const
567 {
return value() > other; }
571 assert(
size() == other.size());
573 return value() > other.value();
576 template <
class RhsValueType>
577 bool operator<(RhsValueType other)
const
578 {
return value() < other; }
582 assert(
size() == other.size());
584 return value() < other.value();
587 template <
class RhsValueType>
588 bool operator>=(RhsValueType other)
const
589 {
return value() >= other; }
591 bool operator>=(
const Evaluation& other)
const
593 assert(
size() == other.size());
595 return value() >= other.value();
598 template <
class RhsValueType>
599 bool operator<=(RhsValueType other)
const
600 {
return value() <= other; }
602 bool operator<=(
const Evaluation& other)
const
604 assert(
size() == other.size());
606 return value() <= other.value();
614 template <
class RhsValueType>
615 void setValue(
const RhsValueType& val)
619 const ValueType& derivative(
int varIdx)
const
621 assert(0 <= varIdx && varIdx <
size());
623 return data_[
dstart_() + varIdx];
627 void setDerivative(
int varIdx,
const ValueType& derVal)
629 assert(0 <= varIdx && varIdx <
size());
631 data_[
dstart_() + varIdx] = derVal;
636 std::array<ValueT, 13> data_;
Representation of an evaluation of a function and its derivatives w.r.t.
A number of commonly used algebraic functions for the localized OPM automatic differentiation (AD) fr...
Some templates to wrap the valgrind client request macros.
ValueT ValueType
field type
Definition: Evaluation12.hpp:58
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation12.hpp:74
constexpr int dend_() const
end+1 index for derivatives
Definition: Evaluation12.hpp:77
constexpr int size() const
number of derivatives
Definition: Evaluation12.hpp:61
constexpr int length_() const
length of internal data vector
Definition: Evaluation12.hpp:66
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation12.hpp:82
Evaluation(const Evaluation &other)=default
copy other function evaluation
Evaluation()
default constructor
Definition: Evaluation12.hpp:92
constexpr int valuepos_() const
position index for value
Definition: Evaluation12.hpp:71
Represents a function evaluation and its derivatives w.r.t.
Definition: Evaluation.hpp:59
Evaluation()
default constructor
Definition: Evaluation.hpp:100
ValueT ValueType
field type
Definition: Evaluation.hpp:66
void checkDefined_() const
instruct valgrind to check that the value and all derivatives of the Evaluation object are well-defin...
Definition: Evaluation.hpp:90
static const int numVars
the template argument which specifies the number of derivatives (-1 == "DynamicSize" means runtime de...
Definition: Evaluation.hpp:63
constexpr int size() const
number of derivatives
Definition: Evaluation.hpp:69
constexpr int valuepos_() const
position index for value
Definition: Evaluation.hpp:79
constexpr int length_() const
length of internal data vector
Definition: Evaluation.hpp:74
constexpr int dstart_() const
start index for derivatives
Definition: Evaluation.hpp:82