1 #ifndef _tinyfadthree_h_ 2 #define _tinyfadthree_h_ 9 template <
class T>
class TinyFad<3,T> {
24 void diff(
const size_t ith,
const size_t sz){
31 case 0 : dx0_ = T(1.);
break;
32 case 1 : dx1_ = T(1.);
break;
33 case 2 : dx2_ = T(1.);
break;
34 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
38 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
44 case 0 : dx0_ = T(1.);
break;
45 case 1 : dx1_ = T(1.);
break;
46 case 2 : dx2_ = T(1.);
break;
47 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
69 int N()
const {
return n-1;}
74 const T&
d0()
const {
return dx0_;}
75 T&
d0() {
return dx0_;}
77 const T&
d1()
const {
return dx1_;}
78 T&
d1() {
return dx1_;}
80 const T&
d2()
const {
return dx2_;}
81 T&
d2() {
return dx2_;}
88 default : cout <<
"i out of bounds" << endl;exit(1);
91 const T&
dx(
int i)
const {
96 default : cout <<
"i out of bounds" << endl;exit(1);
101 case 0 :
return dx0_;
102 case 1 :
return dx1_;
103 case 2 :
return dx2_;
104 default : cout <<
"i out of bounds" << endl;exit(1);
107 const T&
d(
int i)
const {
109 case 0 :
return dx0_;
110 case 1 :
return dx1_;
111 case 2 :
return dx2_;
112 default : cout <<
"i out of bounds" << endl;exit(1);
154 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
155 dx1_ = dx1_ * in.
val_ + val_ * in.
dx1_;
156 dx2_ = dx2_ * in.
val_ + val_ * in.
dx2_;
162 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
189 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
230 template <
class L,
class R>
inline 239 tmp.d0() = un.d0() + deux.d0();
241 tmp.d1() = un.d1() + deux.d1();
243 tmp.d2() = un.d2() + deux.d2();
250 template <
class L,
class R>
inline 265 tmp.
val() = un.
val() + deux;
270 template <
class L,
class R>
inline 276 template <
class L,
class R>
inline 285 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
287 tmp.d1() = un.d1()*deux.
val() + un.
val() * deux.d1();
289 tmp.d2() = un.d2()*deux.
val() + un.
val() * deux.d2();
296 template <
class L,
class R>
inline 305 tmp.d0() = un.d0()*deux;
307 tmp.d1() = un.d1()*deux;
309 tmp.d2() = un.d2()*deux;
311 tmp.
val() = un.
val() * deux;
316 template <
class L,
class R>
inline 324 template <
class L,
class R>
inline 333 tmp.d0() = un.d0() - deux.d0();
335 tmp.d1() = un.d1() - deux.d1();
337 tmp.d2() = un.d2() - deux.d2();
344 template <
class L,
class R>
inline 353 tmp.d0() -= deux.d0();
355 tmp.d1() -= deux.d1();
357 tmp.d2() -= deux.d2();
359 tmp.
val() = un - deux.
val();
364 template <
class L,
class R>
inline 378 tmp.
val() = un.
val() - deux;
383 template <
class L,
class R>
inline 389 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<3,L> & un, const TinyFad<3,R> & deux), dividing by 0");
393 value_type dval = deux.
val();
395 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
397 tmp.d1() = ( un.d1()* deux.
val() - un.
val() * deux.d1() ) / dval / dval ;
399 tmp.d2() = ( un.d2()* deux.
val() - un.
val() * deux.d2() ) / dval / dval ;
401 tmp.
val() = un.
val() / dval;
406 template <
class L,
class R>
inline 412 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<3,R> & deux), dividing by 0");
416 value_type dval = deux.
val();
418 tmp.d0() = - un * deux.d0() / dval / dval ;
420 tmp.d1() = - un * deux.d1() / dval / dval ;
422 tmp.d2() = - un * deux.d2() / dval / dval ;
424 tmp.
val() = un / dval;
429 template <
class L,
class R>
inline 435 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<3,L> & un, const R & deux), dividing by 0");
440 tmp.d0() = un.d0() / deux;
442 tmp.d1() = un.d1() / deux;
444 tmp.d2() = un.d2() / deux;
446 tmp.
val() = un.
val() / deux;
464 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
476 if ( in.
val() < 0. )
error(
"TinyFad<3,T> sqrt (const TinyFad& in) : negative value");
480 if ( in.
val() == T(0.) ){
481 if ( in.
d0() != T(0.) ) test =
false;
483 if ( in.
d1() != T(0.) ) test =
false;
485 if ( in.
d2() != T(0.) ) test =
false;
488 error(
"TinyFad<3,T> sqrt (const TinyFad& in) : null value");
523 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
526 T cosinus =
cos(in.
val());
527 tmp.
d0() = in.
d0() / cosinus / cosinus;
528 tmp.
d1() = in.
d1() / cosinus / cosinus;
529 tmp.
d2() = in.
d2() / cosinus / cosinus;
547 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
564 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
565 tmp.d1() = e*in.
d1()*
pow((
double)in.
val(), (double)e-1);
566 tmp.d2() = e*in.
d2()*
pow((
double)in.
val(), (double)e-1);
573 int sign = in.
val() > 0? 1:0;
579 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<3,T>& a)
581 os.setf(std::ios::fixed,std::ios::scientific);
583 os << a.
val() <<
" [";
TinyFad< 3, T > & operator--()
TinyFad< 3, T > log(const TinyFad< 3, T > &in)
TinyFad< 3, T > & operator++()
TinyFad(const T &ind, const int ini)
TinyFad< 3, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 3, L > &un, const TinyFad< 3, R > &deux)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 3, T > operator++(int)
TinyFad< 3, T > pow(const TinyFad< 3, T > &in, double e)
TinyFad(const TinyFad< 3, T > &in)
TinyFad< 3, T > abs(const TinyFad< 3, T > &in)
TinyFad(const No_Initialization &)
TinyFad< 3, T > cos(const TinyFad< 3, T > &in)
AutoPointerMutexArrayInit tmp
void diff(const size_t ith, const size_t sz)
TinyFad< 3, T > exp(const TinyFad< 3, T > &in)
TinyFad< 3, T > operator--(int)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 3, T > sqrt(const TinyFad< 3, T > &in)
TinyFad< 3, T > sin(const TinyFad< 3, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 3, T > operator+(const TinyFad< 3, T > &in)
TinyFad< 3, T > operator-(const TinyFad< 3, T > &in)
TinyFad< 3, T > tan(const TinyFad< 3, T > &in)
TinyFad< 3, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 3, L > &un, const TinyFad< 3, R > &deux)
const T & dx(int i) const