21 #ifndef OPM_AUTODIFF_HPP_HEADER
22 #define OPM_AUTODIFF_HPP_HEADER
35 template <
typename Scalar>
44 return function(x, Scalar(0));
52 return function(x, Scalar(1));
58 function(
const Scalar x,
const Scalar dx)
99 der_ = der_*rhs.val_ + val_*rhs.der_;
113 der_ = (der_*rhs.val_ - val_*rhs.der_) / (rhs.val_ * rhs.val_);
117 template <
class Ostream>
121 os <<
"(x,dx) = (" << val_ <<
',' << der_ <<
")";
126 const Scalar
val()
const {
return val_; }
127 const Scalar
der()
const {
return der_; }
130 AutoDiff(
const Scalar x,
const Scalar dx)
139 template <
class Ostream,
typename Scalar>
141 operator<<(Ostream& os, const AutoDiff<Scalar>& fw)
146 template <
typename Scalar>
157 template <
typename Scalar,
typename T>
168 template <
typename Scalar,
typename T>
179 template <
typename Scalar>
190 template <
typename Scalar,
typename T>
198 template <
typename Scalar,
typename T>
209 template <
typename Scalar>
220 template <
typename Scalar,
typename T>
231 template <
typename Scalar,
typename T>
242 template <
typename Scalar>
253 template <
typename Scalar,
typename T>
258 Scalar a = Scalar(lhs) / rhs.
val();
259 Scalar b = -Scalar(lhs) / (rhs.
val() * rhs.
val());
264 template <
typename Scalar,
typename T>
269 Scalar a = lhs.
val() / Scalar(rhs);
270 Scalar b = lhs.
der() / Scalar(rhs);
275 template <
typename Scalar>
280 Scalar b = -std::sin(x.
val()) * x.
der();
285 template <
typename Scalar>
290 Scalar b = (Scalar(1.0) / (Scalar(2.0) * a)) * x.
der();
AutoDiff< Scalar > operator+(const AutoDiff< Scalar > &lhs, const AutoDiff< Scalar > &rhs)
Definition: AutoDiff.hpp:148
AutoDiff< Scalar > operator*(const AutoDiff< Scalar > &lhs, const AutoDiff< Scalar > &rhs)
Definition: AutoDiff.hpp:211
static AutoDiff constant(const Scalar x)
Definition: AutoDiff.hpp:42
static AutoDiff variable(const Scalar x)
Definition: AutoDiff.hpp:50
void operator/=(const Scalar &rhs)
Definition: AutoDiff.hpp:104
Definition: AdditionalObjectDeleter.hpp:22
Definition: AutoDiff.hpp:36
void operator-=(const Scalar &rhs)
Definition: AutoDiff.hpp:77
AutoDiff< Scalar > operator/(const AutoDiff< Scalar > &lhs, const AutoDiff< Scalar > &rhs)
Definition: AutoDiff.hpp:244
AutoDiff< Scalar > operator-(const AutoDiff< Scalar > &lhs, const AutoDiff< Scalar > &rhs)
Definition: AutoDiff.hpp:181
AutoDiff< Scalar > cos(const AutoDiff< Scalar > &x)
Definition: AutoDiff.hpp:277
const Scalar der() const
Definition: AutoDiff.hpp:127
Ostream & print(Ostream &os) const
Definition: AutoDiff.hpp:119
static AutoDiff function(const Scalar x, const Scalar dx)
Definition: AutoDiff.hpp:58
void operator*=(const Scalar &rhs)
Definition: AutoDiff.hpp:90
AutoDiff< Scalar > sqrt(const AutoDiff< Scalar > &x)
Definition: AutoDiff.hpp:287
const Scalar val() const
Definition: AutoDiff.hpp:126
void operator+=(const Scalar &rhs)
Definition: AutoDiff.hpp:64