SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mthAD.h
Go to the documentation of this file.
1 #ifndef MTH_AD_H
2 #define MTH_AD_H
3 
4 #include <cmath>
5 #include <iostream>
6 #include "canArray.h"
7 
11 namespace mth {
12 
14 template <class T=double, unsigned int N=0>
15 class AD
16 {
17  public:
19  double x_;
21  T dx_[N];
23  enum { degree = N };
25  AD():x_(0.) {zero();}
27  AD(double x):x_(x) {zero();}
29  AD(AD<T, N> const& other) {copy(other);}
30  template <class B>
31  AD(AD<B, N> const& other) {copy(other);}
33  unsigned int size() const {return N;}
35  void diff(unsigned int i, unsigned int n=0)
36  {
37  (void)n;
38  zero();
39  dx_[i] = 1.;
40  }
42  double& val() {return x_;}
44  const double& val() const {return x_;}
46  T& dx(unsigned int i) {return dx_[i];}
48  const T& dx(unsigned int i) const {return dx_[i];}
50  inline void resize(unsigned int i) {(void)i;}
52  operator double() const {return double(x_);}
54  AD<T, N>& operator=(double other)
55  {
56  x_ = other;
57  zero();
58  return *this;
59  }
61  AD<T, N>& operator=(AD<T, N> const& other)
62  {
63  copy(other);
64  return *this;
65  }
66 
67  template <class B>
68  AD<T, N>& operator=(AD<B, N> const& other)
69  {
70  copy(other);
71  return *this;
72  }
74  AD<T, N>& operator+=(double other)
75  {
76  x_ += other;
77  return *this;
78  }
80  template< class B>
81  AD<T, N>& operator+=(AD<B, N> const& other)
82  {
83  x_ += other.x_;
84  for (unsigned int i=0; i < N; ++i)
85  dx_[i] += other.dx_[i];
86  return *this;
87  }
89  AD<T, N>& operator-=(double other)
90  {
91  x_ -= other;
92  return *this;
93  }
95  template< class B>
96  AD<T, N>& operator-=(AD<B, N> const& other)
97  {
98  x_ -= other.x_;
99  for (unsigned int i=0; i < N; ++i)
100  dx_[i] -= other.dx_[i];
101  return *this;
102  }
104  AD<T, N>& operator*=(double other)
105  {
106  x_ *= other;
107  for (unsigned int i=0; i < N; ++i)
108  dx_[i] *= other;
109  return *this;
110  }
112  template<class B>
113  AD<T, N>& operator*=(AD<B, N> const& other)
114  {
115  x_ *= other.x_;
116  for (unsigned int i=0; i < N; ++i)
117  dx_[i] = dx_[i]*other + x_*other.dx_[i];
118  }
120  AD<T, N>& operator/=(double other)
121  {
122  x_ /= other;
123  for (unsigned int i=0; i < N; ++i)
124  dx_[i] /= other;
125  return *this;
126  }
128  template<class B>
129  AD<T, N>& operator/=(AD<B, N> const& other)
130  {
131  x_ /= other.x_;
132  for (unsigned int i=0; i < N; ++i)
133  dx_[i] = (dx_[i]*other - other*other.dx_[i]) / (other*other);
134  }
135  private:
136  void zero()
137  {
138  for (unsigned int i=0; i < N; ++i)
139  dx_[i] = 0.;
140  }
141 
142  template <class B>
143  void copy(AD<B, N> const& other)
144  {
145  this->x_ = other.x_;
146  for (unsigned int i=0; i < N; ++i)
147  this->dx_[i] = (T)other.dx_[i];
148  }
149 };
150 
152 template <class T>
153 class AD<T,0>
154 {
155  public:
157  double x_;
160  const static double _zero_;
162  AD():x_(0), dx_() {zero();}
164  AD(double val):x_(val), dx_() {zero();}
166  template<class B>
167  AD(AD<B, 0> const& other) {zero(); copy(other);}
168  unsigned size() { return dx_.size();}
169  unsigned size() const { return dx_.size();}
170  void diff(unsigned int i, unsigned int n)
171  {
172  dx_.resize_copy(n);
173  zero();
174  dx_[i] = 1;
175  }
177  double& val() {return x_;}
179  const double& val() const {return x_;}
181  T& dx(unsigned int i)
182  {
183  if(i >= size())
184  {
185  unsigned int temp_size = size();
186  dx_.resize_copy(i + 1);
187  for(unsigned int x = temp_size; x <= i; x++)
188  dx_[x] = 0.;
189  }
190  return dx_[i];
191  }
193  const T dx(unsigned int i) const {
194  if(i >= size())
195  return T(_zero_);
196  return dx_[i];
197  }
199  operator double() const {return double(x_);}
201  AD<T, 0>& operator=(double other)
202  {
203  x_ = other;
204  zero();
205  return *this;
206  }
208  template<class B>
209  AD<T, 0>& operator=(AD<B, 0> const& other)
210  {
211  resize(other.size());
212  copy(other);
213  return *this;
214  }
216  AD<T, 0>& operator+=(double other)
217  {
218  x_ += other;
219  return *this;
220  }
222  AD<T, 0>& operator+=(AD<T, 0> const& other)
223  {
224  resize(other.size());
225  x_ += other.x_;
226  for (unsigned int i=0; i < size(); ++i)
227  dx_[i] += other.dx_[i];
228  return *this;
229  }
231  AD<T, 0>& operator-=(double other)
232  {
233  x_ -= other;
234  return *this;
235  }
237  AD<T, 0>& operator-=(AD<T, 0> const& other)
238  {
239  if (other.size() > size())
240  resize(other.size());
241  x_ -= other.x_;
242  for (unsigned int i=0; i < size(); ++i)
243  dx_[i] -= other.dx_[i];
244  return *this;
245  }
247  AD<T, 0>& operator*=(double other)
248  {
249  x_ *= other;
250  for (unsigned int i=0; i < size(); ++i)
251  dx_[i] *= other;
252  return *this;
253  }
255  AD<T, 0>& operator*=(AD<T, 0> const& other)
256  {
257  resize(other.size());
258  x_ *= other.x_;
259  for (unsigned int i=0; i < size(); ++i)
260  dx_[i] = dx_[i]*other.x_ + x_*other.dx_[i];
261  return *this;
262  }
264  AD<T, 0>& operator/=(double other)
265  {
266  x_ /= other;
267  for (unsigned int i=0; i < size(); ++i)
268  dx_[i] /= other;
269  return *this;
270  }
272  AD<T, 0>& operator/=(AD<T, 0> const& other)
273  {
274  resize(other.size());
275  x_ /= other.x_;
276  for (unsigned int i=0; i < size(); ++i)
277  dx_[i] = (dx_[i]*other.x_ - x_*other.dx_[i]) / (other.x_*other.x_);
278  return *this;
279  }
280  void resize(unsigned int n)
281  {
282  dx_.resize(n);
283  }
284  private:
285  void zero()
286  {
287  for (unsigned int i=0; i < size(); ++i)
288  dx_[i] = 0.;
289  }
290  template<class B> //templating allows for different derivative sizes
291  void copy(AD<B, 0> const& other)
292  {
293  if(size() != other.size())
294  dx_.resize(other.size());
295  x_ = other.x_;
296  for (unsigned int i=0; i < size(); ++i)
297  dx_[i] = (T)other.dx_[i];
298  }
299 };
300 
301 template<class T>
302 const double mth::AD<T, 0>::_zero_ = 0.;
303 
304 /**********************
305  * UNARY OPERATIONS *
306 ***********************/
307 
309 template <class T, unsigned int N>
311 {
312  AD<T, N> tmp;
313  tmp.resize(A.size());
314  tmp = AD<T, N>(-1.) * A;
315  return tmp;
316 }
317 
318 /***********************
319  * BINARY OPERATIONS *
320 ************************/
321 
323 template <class T, unsigned int N>
324 AD<T, N> operator+(double L, AD<T, N> const& R)
325 {
326  AD<T, N> tmp;
327  tmp.resize(R.size());
328  for (unsigned int i=0; i < tmp.size(); ++i)
329  tmp.dx(i) = T(R.dx(i));
330  tmp.val() = L + R.val();
331  return tmp;
332 }
333 
335 template <class T, unsigned int N>
336 AD<T, N> operator+(AD<T, N> const& L, double R)
337 {
338  AD<T, N> tmp;
339  tmp.resize(L.size());
340  for (unsigned int i=0; i < tmp.size(); ++i)
341  tmp.dx(i) = T(L.dx(i));
342  tmp.val() = L.val() + R;
343  return tmp;
344 }
346 template <class T, class B, unsigned int N>
347 AD<T, N> operator+(AD<T, N> const& L, AD<B, N> const& R)
348 {
349  AD<T, N> tmp;
350  unsigned int max = L.size() > R.size() ? L.size() : R.size();
351  tmp.resize(max);
352  for (unsigned int i=0; i < tmp.size(); ++i)
353  tmp.dx(i) = T(L.dx(i) + R.dx(i));
354  tmp.val() = L.val() + R.val();
355  return tmp;
356 }
357 
359 template <class T, unsigned int N>
360 AD<T, N> operator-(double L, AD<T, N> const& R)
361 {
362  AD<T, N> tmp;
363  tmp.resize(R.size());
364  for (unsigned int i=0; i < tmp.size(); ++i)
365  tmp.dx(i) = T(-R.dx(i));
366  tmp.val() = L - R.val();
367  return tmp;
368 }
369 
371 template <class T, unsigned int N>
372 AD<T, N> operator-(AD<T, N> const& L, double R)
373 {
374  AD<T, N> tmp;
375  tmp.resize(L.size());
376  for (unsigned int i=0; i < tmp.size(); ++i)
377  tmp.dx(i) = T(L.dx(i));
378  tmp.val() = L.val() - R;
379  return tmp;
380 }
381 
383 template <class T, class B, unsigned int N>
384 AD<T, N> operator-(AD<T, N> const& L, AD<B, N> const& R)
385 {
386  AD<T, N> tmp;
387  unsigned int max = L.size() > R.size() ? L.size() : R.size();
388  tmp.resize(max);
389  for (unsigned int i=0; i < tmp.size(); ++i)
390  tmp.dx(i) = T(L.dx(i) - R.dx(i));
391  tmp.val() = L.val() - R.val();
392  return tmp;
393 }
394 
396 template <class T, unsigned int N>
397 AD<T, N> operator*(double L, AD<T, N> const& R)
398 {
399  AD<T, N> tmp;
400  tmp.resize(R.size());
401  for (unsigned int i=0; i < tmp.size(); ++i)
402  tmp.dx(i) = T(L * R.dx(i));
403  tmp.val() = L * R.val();
404  return tmp;
405 }
406 
408 template <class T, unsigned int N>
409 AD<T, N> operator*(AD<T, N> const& L, double R)
410 {
411  AD<T, N> tmp;
412  tmp.resize(L.size());
413  for (unsigned int i=0; i < tmp.size(); ++i)
414  tmp.dx(i) = T(L.dx(i) * R);
415  tmp.val() = L.val() * R;
416  return tmp;
417 }
418 
420 template <class T, class B, unsigned int N>
421 AD<T, N> operator*(AD<T, N> const& L, AD<B, N> const& R)
422 {
423  AD<T, N> tmp;
424  unsigned int max = L.size() > R.size() ? L.size() : R.size();
425  tmp.resize(max);
426  for (unsigned int i=0; i < tmp.size(); ++i)
427  tmp.dx(i) = T(L.dx(i) * R + L * R.dx(i));
428  tmp.val() = L.val() * R.val();
429  return tmp;
430 }
431 
433 template <class T, unsigned int N>
434 AD<T, N> operator/(double L, AD<T, N> const& R)
435 {
436  AD<T, N> tmp;
437  tmp.resize(R.size());
438  T R_tmp = R; //Recursive R, used to prevent infinite recurrsion.
439  for (unsigned int i = 0; i < R.size(); i++)
440  tmp.dx(i) = T(-L * R.dx(i) * (1. / R_tmp) * (1. / R_tmp));
441  tmp.val() = L / R.val();
442  return tmp;
443 }
444 
446 template <class T, unsigned int N>
447 AD<T, N> operator/(AD<T, N> const& L, double R)
448 {
449  AD<T, N> tmp;
450  tmp.resize(L.size());
451  for (unsigned int i=0; i < L.size(); ++i)
452  tmp.dx(i) = T(L.dx(i) / R);
453  tmp.val() = L.val() / R;
454  return tmp;
455 }
456 
458 template <class T, class B, unsigned int N>
459 AD<T, N> operator/(AD<B, N> const& L, AD<T, N> const& R)
460 {
461  AD<T, N> tmp;
462  unsigned int max = L.size() > R.size() ? L.size() : R.size();
463  tmp.resize(max);
464  for (unsigned int i=0; i < tmp.size(); ++i)
465  tmp.dx(i) = T(((L.dx(i) * R) - (L * R.dx(i))) * (1. / R) * (1. / R));
466  tmp.val() = L.val() / R.val();
467  return tmp;
468 }
469 
470 /********************
471  * FANCY FUNCIONS *
472 *********************/
473 
475 double exp(double x)
476 {
477  return std::exp(x);
478 }
479 
481 template <class T, unsigned int N>
483 {
484  AD<T, N> tmp;
485  tmp.resize(A.size());
486  T A_tmp = A;
487  tmp.val() = std::exp(A.val());
488  for (unsigned int i=0; i < A.size(); ++i)
489  tmp.dx(i) = T(A.dx(i) * exp(A_tmp));
490  return tmp;
491 }
492 
494 double log(double A)
495 {
496  return std::log(A);
497 }
498 
500 template <class T, unsigned int N>
502 {
503  AD<T, N> tmp;
504  tmp.resize(A.size());
505  T A_tmp = A;
506  tmp.val() = std::log(A.val());
507  for (unsigned int i=0; i < A.size(); ++i)
508  tmp.dx(i) = T(A.dx(i) / A_tmp);
509  return tmp;
510 }
511 
513 double pow(double A, double e)
514 {
515  return std::pow(A, e);
516 }
517 
519 template <class T, unsigned int N>
520 AD<T, N> pow(AD<T, N> const& A, const int e)
521 {
522  AD<T, N> tmp;
523  tmp.resize(A.size());
524  T A_tmp = A;
525  tmp.val() = std::pow(A.val(), e);
526  for (unsigned int i=0; i < tmp.size(); ++i)
527  tmp.dx(i) = T(AD<T, N>(e)*A.dx(i)*pow(A_tmp, (double)e-1.));
528  return tmp;
529 }
530 
532 template <class T, unsigned int N>
533 AD<T, N> pow(AD<T, N> const& A, const double e)
534 {
535  AD<T, N> tmp;
536  tmp.resize(A.size());
537  T A_tmp = A;
538  tmp.val() = pow(A.val(), e);
539  for (unsigned int i=0; i < tmp.size(); ++i)
540  tmp.dx(i) = T(e*A.dx(i)*pow(A_tmp, e - 1.));
541  return tmp;
542 }
543 
545 template <class T, unsigned int N>
546 AD<T, N> pow(const int base, AD<T, N> const& A)
547 {
548  AD<T, N> tmp;
549  tmp.resize(A.size());
550  T A_tmp = A;
551  tmp.val() = std::pow((double)base, A.val());
552  for (unsigned int i=0; i < tmp.size(); ++i)
553  tmp.dx(i) = T(std::log((double)base) * pow((double)base, A_tmp) * A.dx(i));
554  return tmp;
555 }
556 
558 template <class T, unsigned int N>
559 AD<T, N> pow(const double base, AD<T, N> const& A)
560 {
561  AD<T, N> tmp;
562  tmp.resize(A.size());
563  T A_tmp = A;
564  tmp.val() = std::pow((double)base, A.val());
565  for (unsigned int i=0; i < tmp.size(); ++i)
566  tmp.dx(i) = T(std::log(base) * pow(base, A_tmp) * A.dx(i));
567  return tmp;
568 }
569 
570 
572 template <class T, unsigned int N>
573 AD<T, N> pow(AD<T, N> const& A, AD<T, N> const& e)
574 {
575  AD<T, N> tmp;
576  unsigned int max = A.size() > e.size() ? A.size() : e.size();
577  tmp.resize(max);
578  T A_tmp = A;
579  T e_tmp = e;
580  tmp.val() = std::pow(A.val(), e.val());
581  for (unsigned int i=0; i < tmp.size(); ++i)
582  tmp.dx(i) = T(e.dx(i) * log(A_tmp) * pow(A_tmp, e_tmp) +
583  e_tmp * A.dx(i) * pow(A_tmp, e_tmp - 1.));
584  return tmp;
585 }
586 
588 double sqrt(double A)
589 {
590  return std::sqrt(A);
591 }
592 
594 template <class T, unsigned int N>
596 {
597  AD<T, N> tmp;
598  tmp.resize(A.size());
599  tmp.val() = std::sqrt(A.val());
600  T A_tmp = A;
601  for (unsigned int i=0; i < tmp.size(); ++i)
602  tmp.dx(i) = T(.5 * A.dx(i) / sqrt(A_tmp));
603  return tmp;
604 }
605 
607 double sin(double A)
608 {
609  return std::sin(A);
610 }
611 
613 double cos(double A)
614 {
615  return std::cos(A);
616 }
617 
619 template <class T, unsigned int N>
621 {
622  AD<T, N> tmp;
623  tmp.resize(A.size());
624  tmp.val() = std::sin(A.val());
625  T A_tmp = A;
626  for(unsigned int i = 0; i < tmp.size(); i++)
627  tmp.dx(i) = T(cos(A_tmp) * A.dx(i));
628  return tmp;
629 }
630 
632 template <class T, unsigned int N>
634 {
635  AD<T, N> tmp;
636  tmp.val() = std::cos(A.val());
637  T A_tmp = A;
638  tmp.resize(A.size());
639  for(unsigned int i = 0; i < tmp.size(); i++)
640  tmp.dx(i) = T(-sin(A_tmp) * A.dx(i));
641  return tmp;
642 }
643 
645 template <class T, unsigned int N>
647 {
648  AD<T, N> tmp;
649  tmp.val() = std::tan(A.val());
650  T A_tmp = A;
651  tmp.resize(A.size());
652  for(unsigned int i = 0; i < tmp.size(); i++)
653  tmp.dx(i) = T(A.dx(i) * (1. / (cos(A_tmp) * cos(A_tmp))));
654  return tmp;
655 }
656 
658 template <class T, unsigned int N>
660 {
661  int sign = A.val() > 0 ? 1 : 0;
662  if (sign) return A;
663  else return (-A);
664 }
665 
666 /**************************
667  * COMPARISON OPERATORS *
668 ***************************/
669 
671 template <class T, unsigned int N>
672 bool operator<(double L, AD<T, N> const& R)
673 {
674  return L < R.val();
675 }
676 
678 template <class T, unsigned int N>
679 bool operator<(AD<T, N> const& R, double L)
680 {
681  return R.val() < L;
682 }
683 
685 template <class T, unsigned int N>
686 bool operator<(AD<T, N> const& R, AD<T, N> const& L)
687 {
688  return R.val() < L.val();
689 }
690 
692 template <class T, unsigned int N>
693 bool operator<=(double L, AD<T, N> const& R)
694 {
695  return L <= R.val();
696 }
697 
699 template <class T, unsigned int N>
700 bool operator<=(AD<T, N> const& R, double L)
701 {
702  return R.val() <= L;
703 }
704 
706 template <class T, unsigned int N>
707 bool operator<=(AD<T, N> const& R, AD<T, N> const& L)
708 {
709  return R.val() <= L.val();
710 }
711 
713 template <class T, unsigned int N>
714 bool operator>(double L, AD<T, N> const& R)
715 {
716  return L > R.val();
717 }
718 
720 template <class T, unsigned int N>
721 bool operator>(AD<T, N> const& R, double L)
722 {
723  return R.val() > L;
724 }
725 
727 template <class T, unsigned int N>
728 bool operator>(AD<T, N> const& R, AD<T, N> const& L)
729 {
730  return R.val() > L.val();
731 }
732 
734 template <class T, unsigned int N>
735 bool operator>=(double L, AD<T, N> const& R)
736 {
737  return L >= R.val();
738 }
739 
741 template <class T, unsigned int N>
742 bool operator>=(AD<T, N> const& R, double L)
743 {
744  return R.val() >= L;
745 }
746 
748 template <class T, unsigned int N>
749 bool operator>=(AD<T, N> const& R, AD<T, N> const& L)
750 {
751  return R.val() >= L.val();
752 }
753 }
754 #endif
AD< T, N > tan(AD< T, N > const &A)
tan of an AD variable
Definition: mthAD.h:646
const double & val() const
get the value of the variable (immutable)
Definition: mthAD.h:44
double pow(double A, double e)
wrapper to standard pow function
Definition: mthAD.h:513
double exp(double x)
wrapper to standard exp function
Definition: mthAD.h:475
bool operator>=(double L, AD< T, N > const &R)
double greater than or equal to an AD variable
Definition: mthAD.h:735
double x_
the variable value
Definition: mthAD.h:19
AD< T, N > operator+(double L, AD< T, N > const &R)
binary addition between a double and an AD variable
Definition: mthAD.h:324
bool operator>(double L, AD< T, N > const &R)
double greater than an AD variable
Definition: mthAD.h:714
AD< T, N > & operator-=(double other)
subtraction assignment with a double
Definition: mthAD.h:89
AD< T, 0 > & operator*=(double other)
multiplication assignment with a double
Definition: mthAD.h:247
AD< T, N > operator/(double L, AD< T, N > const &R)
binary division between a double and an AD variable
Definition: mthAD.h:434
forward automatic differentiation variable
Definition: mthAD.h:15
AD(double val)
constructs from a double
Definition: mthAD.h:164
AD< T, N > & operator+=(double other)
addition assignment with a double
Definition: mthAD.h:74
forward automatic differentiation variable with dynamic variable array
Definition: mthAD.h:153
double cos(double A)
wrapper for standard cos function
Definition: mthAD.h:613
void diff(unsigned int i, unsigned int n=0)
set as the ith variable of N
Definition: mthAD.h:35
AD(AD< T, N > const &other)
copy constructor
Definition: mthAD.h:29
T & dx(unsigned int i)
get the ith derivative value (mutable)
Definition: mthAD.h:46
AD< T, N > & operator-=(AD< B, N > const &other)
subtraction assignment with another AD variable
Definition: mthAD.h:96
AD< T, 0 > & operator/=(double other)
division assignment with a double
Definition: mthAD.h:264
AD< T, 0 > & operator+=(double other)
addition assignment with a double
Definition: mthAD.h:216
double & val()
get the value of the variable (mutable)
Definition: mthAD.h:42
compile-time size array
AD< T, 0 > & operator*=(AD< T, 0 > const &other)
multiplication assignment with another AD variable
Definition: mthAD.h:255
AD()
default constructor
Definition: mthAD.h:162
T & dx(unsigned int i)
get the ith derivative value (mutable)
Definition: mthAD.h:181
void resize(unsigned int i)
resize for static AD (no-op)
Definition: mthAD.h:50
AD< T, N > & operator*=(AD< B, N > const &other)
multiplication assignment with another AD variable
Definition: mthAD.h:113
AD< T, N > abs(AD< T, N > const &A)
absolute value of an AD variable
Definition: mthAD.h:659
const T dx(unsigned int i) const
get the ith deriative value (immutable)
Definition: mthAD.h:193
double & val()
get the value of the variable (mutable)
Definition: mthAD.h:177
AD< T, N > & operator*=(double other)
multiplication assignment with a double
Definition: mthAD.h:104
T dx_[N]
the derivative array
Definition: mthAD.h:21
AD< T, N > operator*(double L, AD< T, N > const &R)
binary multiplication between a double and an AD variable
Definition: mthAD.h:397
AD< T, N > operator-(AD< T, N > const &A)
unary subtraction
Definition: mthAD.h:310
AD< T, 0 > & operator/=(AD< T, 0 > const &other)
division assignment with another AD variable
Definition: mthAD.h:272
AD< T, 0 > & operator=(AD< B, 0 > const &other)
assignment to another AD variable
Definition: mthAD.h:209
double sin(double A)
wrapper for standard sin function
Definition: mthAD.h:607
AD< T, 0 > & operator-=(AD< T, 0 > const &other)
subtraction assignment with another AD variable
Definition: mthAD.h:237
AD()
default constructor
Definition: mthAD.h:25
AD< T, 0 > & operator-=(double other)
subtraction assignment with a double
Definition: mthAD.h:231
double x_
the variable value
Definition: mthAD.h:157
double sqrt(double A)
wrapper for standard sqrt function
Definition: mthAD.h:588
AD< T, N > & operator/=(AD< B, N > const &other)
division assignment with another AD variable
Definition: mthAD.h:129
AD< T, N > & operator=(AD< T, N > const &other)
assignment to another AD variable
Definition: mthAD.h:61
AD< T, N > & operator+=(AD< B, N > const &other)
addition assignment with another AD variable
Definition: mthAD.h:81
AD< T, N > & operator/=(double other)
division assignment with a double
Definition: mthAD.h:120
can::Array< T > dx_
the dynamic derivative array
Definition: mthAD.h:159
AD(AD< B, 0 > const &other)
constructs from other AD
Definition: mthAD.h:167
AD(double x)
default constructor from a double
Definition: mthAD.h:27
const T & dx(unsigned int i) const
get the ith derivative value (immutable)
Definition: mthAD.h:48
const double & val() const
get the value of the variable (immutable)
Definition: mthAD.h:179
unsigned int size() const
get the size of the derivative array
Definition: mthAD.h:33
double log(double A)
wrapper for stander log function
Definition: mthAD.h:494
AD< T, 0 > & operator=(double other)
assignment to a double
Definition: mthAD.h:201
AD< T, N > & operator=(double other)
assignment to a double
Definition: mthAD.h:54
AD< T, 0 > & operator+=(AD< T, 0 > const &other)
addition assignment with another AD variable
Definition: mthAD.h:222