1 #ifndef _RHEO_AD_POINT_H
2 #define _RHEO_AD_POINT_H
45 #include "rheolef/point.h"
215 template <
class T,
class U>
219 details::is_rheolef_arithmetic<U>::value
229 template <
class T,
class U>
233 details::is_rheolef_arithmetic<U>::value
243 template <
class T,
class U>
247 details::is_rheolef_arithmetic<U>::value
257 template <
class T,
class U>
261 details::is_rheolef_arithmetic<U>::value
279 template <
class T,
class U>
283 details::is_rheolef_arithmetic<U>::value
299 template <
class T,
class U>
303 details::is_rheolef_arithmetic<U>::value
321 c._g = _v*
b._g + _g*
b._v;
324 template <
class T,
class U>
328 details::is_rheolef_arithmetic<U>::value
338 template <
class T,
class U>
342 details::is_rheolef_arithmetic<U>::value
360 template <
class T,
class U>
364 details::is_rheolef_arithmetic<U>::value
382 c._g = _g/
b._v - _v*
b._g/
b._v;
385 template <
class T,
class U>
389 details::is_rheolef_arithmetic<U>::value
396 c._g = -
a*
b._g/
b._v;
399 template <
class T,
class U>
403 details::is_rheolef_arithmetic<U>::value
421 template <
class T,
class U>
425 details::is_rheolef_arithmetic<U>::value
436 #define _RHEOLEF_ad3_comparator(OP) \
440 operator OP (const ad3_basic<T> &a, const ad3_basic<T> &b) \
442 return a._v OP b._v; \
444 template <class T, class U> \
448 details::is_rheolef_arithmetic<U>::value \
451 operator OP (const ad3_basic<T> &a, const U &b) \
455 template <class T, class U> \
459 details::is_rheolef_arithmetic<U>::value \
462 operator OP (const U &a, const ad3_basic<T> &b) \
467 _RHEOLEF_ad3_comparator(==)
468 _RHEOLEF_ad3_comparator(!=)
469 _RHEOLEF_ad3_comparator(>)
470 _RHEOLEF_ad3_comparator(>=)
471 _RHEOLEF_ad3_comparator(<)
472 _RHEOLEF_ad3_comparator(<=)
473 #undef _RHEOLEF_ad3_comparator
482 sqr (
const ad3_basic<T>&
a)
486 c._g = (2*
a._v)*
a._g;
492 fabs (
const ad3_basic<T>&
a)
496 c._g = (
a._v >= 0 ? 1 : -1)*
a._g;
504 INLINE2 ad3_basic<T>
exp (
const ad3_basic<T>&
a)
506 ad3_basic<T>
c(
exp(
a.v));
508 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
c.v;
513 INLINE2 ad3_basic<T> log (
const ad3_basic<T>&
a)
515 ad3_basic<T>
c(log(
a.v));
517 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]/
a.v;
522 INLINE2 ad3_basic<T> sqrt (
const ad3_basic<T>&
a)
524 ad3_basic<T>
c(sqrt(
a.v));
525 T tmp(
c.v*FADBAD_TWO);
527 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]/
tmp;
532 INLINE2 ad3_basic<T> sin (
const ad3_basic<T>&
a)
534 ad3_basic<T>
c(sin(
a.v));
537 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
542 INLINE2 ad3_basic<T> cos (
const ad3_basic<T>&
a)
544 ad3_basic<T>
c(cos(
a.v));
547 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
552 INLINE2 ad3_basic<T> tan (
const ad3_basic<T>&
a)
554 ad3_basic<T>
c(tan(
a.v));
556 T tmp(FADBAD_ONE+_sqr(
c.v));
557 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
562 INLINE2 ad3_basic<T> asin (
const ad3_basic<T>&
a)
564 ad3_basic<T>
c(asin(
a.v));
566 T tmp(FADBAD_ONE/sqrt(FADBAD_ONE-_sqr(
a.v)));
567 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
572 INLINE2 ad3_basic<T> acos (
const ad3_basic<T>&
a)
574 ad3_basic<T>
c(acos(
a.v));
576 T tmp(-FADBAD_ONE/sqrt(FADBAD_ONE-_sqr(
a.v)));
577 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
582 INLINE2 ad3_basic<T> atan (
const ad3_basic<T>&
a)
584 ad3_basic<T>
c(atan(
a.v));
586 T tmp(FADBAD_ONE/(FADBAD_ONE+_sqr(
a.v)));
587 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
594 INLINE2 ad3_basic<T>
pow (
const BaseType&
a,
const ad3_basic<T>&
b)
596 ad3_basic<T>
c(
pow(
a,
b.v));
599 for (
int i=0;i<
b.gsize;i++)
c.g[i]=
tmp*
b.g[i];
604 INLINE2 ad3_basic<T>
pow (
const ad3_basic<T>&
a,
const BaseType&
b)
606 ad3_basic<T>
c(
pow(
a.v,
b));
609 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
tmp*
a.g[i];
613 INLINE2 ad3_basic<T>
pow (
const ad3_basic<T>&
a,
const ad3_basic<T>&
b)
615 if (
a.gsize==0)
return pow1(
a.v,
b);
616 if (
b.gsize==0)
return pow2(
a,
b.v);
617 ad3_basic<T>
c(
pow(
a.v,
b.v));
618 USER_ASSERT(
a.gsize==
b.gsize,
"derivative vectors not of same size in pow");
621 for (
int i=0;i<
a.gsize;i++)
622 c.g[i]=
tmp*
a.g[i]+tmp1*
b.g[i];
626 INLINE2 ad3_basic<T>
pow (
const ad3_basic<T>&
a,
int b)
628 ad3_basic<T>
c(
pow(
a.v,
b));
631 for (
int i=0;i<
a.gsize;i++)
c.g[i]=
a.g[i]*
tmp;
ad3_basic< T > & operator*=(const ad3_basic< T > &b)
ad3_basic< T > & operator-=(const ad3_basic< T > &b)
ad3_basic< T > operator/(const ad3_basic< T > &b) const
ad3_basic< T > operator*(const ad3_basic< T > &b) const
ad3_basic< T > operator-() const
const point_basic< T > & grad() const
static point_basic< ad3_basic< T > > point(const point_basic< T > &x0)
ad3_basic< T > & operator/=(const ad3_basic< T > &b)
point_basic< T >::size_type size_type
ad3_basic< T > & operator+=(const ad3_basic< T > &b)
ad3_basic(const ad3_basic &)
ad3_basic< T > operator+() const
ad3_basic< T > & operator=(const ad3_basic< T > &)
This file is part of Rheolef.
std::enable_if< details::is_rheolef_arithmetic< U >::value,ad3_basic< T > & >::type operator*=(ad3_basic< T > &a, const U &b)
dia< T, M > operator/(const T &lambda, const dia< T, M > &d)
std::enable_if< details::is_rheolef_arithmetic< U >::value,ad3_basic< T > & >::type operator-=(ad3_basic< T > &a, const U &b)
std::enable_if< details::is_rheolef_arithmetic< U >::value,ad3_basic< T >>::type operator+(const U &a, const ad3_basic< T > &b)
csr< T, sequential > operator-(const csr< T, sequential > &a)
csr< T, sequential > operator*(const T &lambda, const csr< T, sequential > &a)
std::enable_if< details::is_rheolef_arithmetic< U >::value,ad3_basic< T > & >::type operator/=(ad3_basic< T > &a, const U &b)
std::ostream & operator<<(std::ostream &os, const catchmark &m)
space_mult_list< T, M > pow(const space_basic< T, M > &X, size_t n)
std::enable_if< details::is_rheolef_arithmetic< U >::value,ad3_basic< T > & >::type operator+=(ad3_basic< T > &a, const U &b)
tensor_basic< T > exp(const tensor_basic< T > &a, size_t d)
float_traits< T >::type type
helper for std::complex<T>: get basic T type