1#ifndef _RHEO_AD_POINT_H
2#define _RHEO_AD_POINT_H
45#include "rheolef/point.h"
95typedef ad3_basic<Float>
ad3;
99std::ostream&
operator<< (std::ostream& os,
const ad3_basic<T>& a);
167operator<< (std::ostream& os,
const ad3_basic<T>& a)
215template <
class T,
class U>
219 details::is_rheolef_arithmetic<U>::value
229template <
class T,
class U>
233 details::is_rheolef_arithmetic<U>::value
243template <
class T,
class U>
247 details::is_rheolef_arithmetic<U>::value
257template <
class T,
class U>
261 details::is_rheolef_arithmetic<U>::value
279template <
class T,
class U>
283 details::is_rheolef_arithmetic<U>::value
299template <
class T,
class U>
303 details::is_rheolef_arithmetic<U>::value
321 c._g = _v*b._g + _g*b._v;
324template <
class T,
class U>
328 details::is_rheolef_arithmetic<U>::value
338template <
class T,
class U>
342 details::is_rheolef_arithmetic<U>::value
360template <
class T,
class U>
364 details::is_rheolef_arithmetic<U>::value
382 c._g = _g/b._v - _v*b._g/b._v;
385template <
class T,
class U>
389 details::is_rheolef_arithmetic<U>::value
396 c._g = - a*b._g/b._v;
399template <
class T,
class U>
403 details::is_rheolef_arithmetic<U>::value
421template <
class T,
class U>
425 details::is_rheolef_arithmetic<U>::value
436#define _RHEOLEF_ad3_comparator(OP) \
440operator OP (const ad3_basic<T> &a, const ad3_basic<T> &b) \
442 return a._v OP b._v; \
444template <class T, class U> \
448 details::is_rheolef_arithmetic<U>::value \
451operator OP (const ad3_basic<T> &a, const U &b) \
455template <class T, class U> \
459 details::is_rheolef_arithmetic<U>::value \
462operator 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
482sqr (
const ad3_basic<T>& a)
486 c._g = (2*a._v)*a._g;
492fabs (
const ad3_basic<T>& a)
496 c._g = (
a._v >= 0 ? 1 : -1)*
a._g;
504INLINE2 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;
513INLINE2 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;
522INLINE2 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;
532INLINE2 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;
542INLINE2 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;
552INLINE2 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;
562INLINE2 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;
572INLINE2 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;
582INLINE2 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;
594INLINE2 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];
604INLINE2 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];
613INLINE2 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];
626INLINE2 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;
see the point page for the full documentation
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.
csr< T, sequential > operator-(const csr< T, sequential > &a)
tensor_basic< T > exp(const tensor_basic< T > &a, size_t d)
std::ostream & operator<<(std::ostream &os, const catchmark &m)
dia< T, M > operator/(const T &lambda, const dia< T, M > &d)
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)
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-=(ad3_basic< T > &a, const U &b)
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 T &lambda, const csr< T, sequential > &a)
float_traits< T >::type type
helper for std::complex<T>: get basic T type