Sacado Package Browser (Single Doxygen Collection)  Version of the Day
Sacado_MathFunctions.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef SACADO_MATHFUNCTIONS_HPP
31 #define SACADO_MATHFUNCTIONS_HPP
32 
33 #include <cmath>
34 
35 #include "Sacado_ConfigDefs.h"
36 #include "Sacado_Base.hpp"
38 #include "Sacado_SFINAE_Macros.hpp"
39 
40 #define UNARYFUNC_MACRO(OP,FADOP) \
41 namespace Sacado { \
42  \
43  namespace Fad { \
44  template <typename T> class FADOP; \
45  template <typename T> \
46  KOKKOS_INLINE_FUNCTION \
47  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
48  \
49  template <typename T> class SimpleFad; \
50  template <typename T> \
51  SimpleFad<T> OP (const SimpleFad<T>&); \
52  } \
53  \
54  namespace ELRFad { \
55  template <typename T> class FADOP; \
56  template <typename T> class Expr; \
57  template <typename T> \
58  KOKKOS_INLINE_FUNCTION \
59  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
60  } \
61  \
62  namespace CacheFad { \
63  template <typename T> class FADOP; \
64  template <typename T> class Expr; \
65  template <typename T> \
66  KOKKOS_INLINE_FUNCTION \
67  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
68  } \
69  \
70  namespace ELRCacheFad { \
71  template <typename T> class FADOP; \
72  template <typename T> class Expr; \
73  template <typename T> \
74  KOKKOS_INLINE_FUNCTION \
75  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
76  } \
77  \
78  namespace LFad { \
79  template <typename T> class FADOP; \
80  template <typename T> class Expr; \
81  template <typename T> \
82  Expr< FADOP< Expr<T> > > OP (const Expr<T>&); \
83  } \
84  \
85  namespace Tay { \
86  template <typename T> class Taylor; \
87  template <typename T> Taylor<T> OP (const Base< Taylor<T> >&); \
88  } \
89  \
90  namespace FlopCounterPack { \
91  template <typename T> class ScalarFlopCounter; \
92  template <typename T> \
93  ScalarFlopCounter<T> OP (const Base< ScalarFlopCounter<T> >&); \
94  } \
95  \
96  namespace Rad { \
97  template <typename T> class ADvari; \
98  template <typename T> class IndepADvar; \
99  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&); \
100  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&); \
101  } \
102 } \
103  \
104 namespace std { \
105  using Sacado::Fad::OP; \
106  using Sacado::ELRFad::OP; \
107  using Sacado::CacheFad::OP; \
108  using Sacado::ELRCacheFad::OP; \
109  using Sacado::LFad::OP; \
110  using Sacado::Tay::OP; \
111  using Sacado::FlopCounterPack::OP; \
112  using Sacado::Rad::OP; \
113 }
114 
133 #ifdef HAVE_SACADO_CXX11
135 #endif
136 
137 #undef UNARYFUNC_MACRO
138 
139 #define BINARYFUNC_MACRO(OP,FADOP) \
140 namespace Sacado { \
141  \
142  namespace Fad { \
143  template <typename T1, typename T2> class FADOP; \
144  template <typename T> class ConstExpr; \
145  template <typename T> struct IsFadExpr; \
146  template <typename T> struct ExprLevel; \
147  template <typename T1, typename T2> \
148  KOKKOS_INLINE_FUNCTION \
149  typename mpl::enable_if_c< \
150  ExprLevel< Expr<T1> >::value == ExprLevel< Expr<T2> >::value, \
151  Expr< FADOP< Expr<T1>, Expr<T2> > > \
152  >::type \
153  /*SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP)*/ \
154  OP (const Expr<T1>&, const Expr<T2>&); \
155  \
156  template <typename T> \
157  KOKKOS_INLINE_FUNCTION \
158  Expr< FADOP< Expr<T>, Expr<T> > > \
159  OP (const Expr<T>&, const Expr<T>&); \
160  \
161  template <typename T> \
162  KOKKOS_INLINE_FUNCTION \
163  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
164  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
165  \
166  template <typename T> \
167  KOKKOS_INLINE_FUNCTION \
168  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
169  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
170  \
171  template <typename T> \
172  KOKKOS_INLINE_FUNCTION \
173  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
174  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
175  \
176  template <typename T> \
177  KOKKOS_INLINE_FUNCTION \
178  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
179  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
180  \
181  template <typename T> class SimpleFad; \
182  template <typename T> \
183  SimpleFad<T> \
184  OP (const SimpleFad<T>&, const SimpleFad<T>&); \
185  \
186  template <typename T> \
187  SimpleFad<T> \
188  OP (const SimpleFad<T>&, \
189  const typename SimpleFad<T>::value_type&); \
190  \
191  template <typename T> \
192  SimpleFad<T> \
193  OP (const typename SimpleFad<T>::value_type&, \
194  const SimpleFad<T>&); \
195  } \
196  \
197  namespace ELRFad { \
198  template <typename T1, typename T2> class FADOP; \
199  template <typename T> class Expr; \
200  template <typename T> class ConstExpr; \
201  template <typename T> struct IsFadExpr; \
202  template <typename T> struct ExprLevel; \
203  template <typename T1, typename T2> \
204  KOKKOS_INLINE_FUNCTION \
205  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
206  OP (const T1&, const T2&); \
207  \
208  template <typename T> \
209  KOKKOS_INLINE_FUNCTION \
210  Expr< FADOP< Expr<T>, Expr<T> > > \
211  OP (const Expr<T>&, const Expr<T>&); \
212  \
213  template <typename T> \
214  KOKKOS_INLINE_FUNCTION \
215  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
216  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
217  \
218  template <typename T> \
219  KOKKOS_INLINE_FUNCTION \
220  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
221  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
222  \
223  template <typename T> \
224  KOKKOS_INLINE_FUNCTION \
225  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
226  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
227  \
228  template <typename T> \
229  KOKKOS_INLINE_FUNCTION \
230  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
231  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
232  } \
233  \
234  namespace CacheFad { \
235  template <typename T1, typename T2> class FADOP; \
236  template <typename T> class Expr; \
237  template <typename T> class ConstExpr; \
238  template <typename T> struct IsFadExpr; \
239  template <typename T> struct ExprLevel; \
240  template <typename T1, typename T2> \
241  KOKKOS_INLINE_FUNCTION \
242  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
243  OP (const T1&, const T2&); \
244  \
245  template <typename T> \
246  KOKKOS_INLINE_FUNCTION \
247  Expr< FADOP< Expr<T>, Expr<T> > > \
248  OP (const Expr<T>&, const Expr<T>&); \
249  \
250  template <typename T> \
251  KOKKOS_INLINE_FUNCTION \
252  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
253  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
254  \
255  template <typename T> \
256  KOKKOS_INLINE_FUNCTION \
257  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
258  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
259  \
260  template <typename T> \
261  KOKKOS_INLINE_FUNCTION \
262  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
263  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
264  \
265  template <typename T> \
266  KOKKOS_INLINE_FUNCTION \
267  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
268  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
269  } \
270  \
271  namespace ELRCacheFad { \
272  template <typename T1, typename T2> class FADOP; \
273  template <typename T> class Expr; \
274  template <typename T> class ConstExpr; \
275  template <typename T> struct IsFadExpr; \
276  template <typename T> struct ExprLevel; \
277  template <typename T1, typename T2> \
278  KOKKOS_INLINE_FUNCTION \
279  SACADO_FAD_OP_ENABLE_EXPR_EXPR(FADOP) \
280  OP (const T1&, const T2&); \
281  \
282  template <typename T> \
283  KOKKOS_INLINE_FUNCTION \
284  Expr< FADOP< Expr<T>, Expr<T> > > \
285  OP (const Expr<T>&, const Expr<T>&); \
286  \
287  template <typename T> \
288  KOKKOS_INLINE_FUNCTION \
289  Expr< FADOP< ConstExpr<typename Expr<T>::value_type>, Expr<T> > > \
290  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
291  \
292  template <typename T> \
293  KOKKOS_INLINE_FUNCTION \
294  Expr< FADOP< Expr<T>, ConstExpr<typename Expr<T>::value_type> > > \
295  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
296  \
297  template <typename T> \
298  KOKKOS_INLINE_FUNCTION \
299  SACADO_FAD_OP_ENABLE_SCALAR_EXPR(FADOP) \
300  OP (const typename Expr<T>::scalar_type&, const Expr<T>&); \
301  \
302  template <typename T> \
303  KOKKOS_INLINE_FUNCTION \
304  SACADO_FAD_OP_ENABLE_EXPR_SCALAR(FADOP) \
305  OP (const Expr<T>&, const typename Expr<T>::scalar_type&); \
306  } \
307  \
308  namespace LFad { \
309  template <typename T1, typename T2> class FADOP; \
310  template <typename T> class Expr; \
311  \
312  template <typename T1, typename T2> \
313  Expr< FADOP< Expr<T1>, Expr<T2> > > \
314  OP (const Expr<T1>&, const Expr<T2>&); \
315  \
316  template <typename T> \
317  Expr< FADOP< Expr<T>, Expr<T> > > \
318  OP (const Expr<T>&, const Expr<T>&); \
319  \
320  template <typename T> \
321  Expr< FADOP< typename Expr<T>::value_type, Expr<T> > > \
322  OP (const typename Expr<T>::value_type&, const Expr<T>&); \
323  \
324  template <typename T> \
325  Expr< FADOP< Expr<T>, typename Expr<T>::value_type > > \
326  OP (const Expr<T>&, const typename Expr<T>::value_type&); \
327  } \
328  \
329  namespace Tay { \
330  template <typename T> class Taylor; \
331  template <typename T> Taylor<T> OP ( \
332  const Base< Taylor<T> >&, \
333  const Base< Taylor<T> >&); \
334  template <typename T> Taylor<T> OP ( \
335  const typename Taylor<T>::value_type&, \
336  const Base< Taylor<T> >&); \
337  template <typename T> Taylor<T> OP ( \
338  const Base< Taylor<T> >&, \
339  const typename Taylor<T>::value_type&); \
340  } \
341  \
342  namespace FlopCounterPack { \
343  template <typename T> class ScalarFlopCounter; \
344  template <typename T> \
345  ScalarFlopCounter<T> OP ( \
346  const Base< ScalarFlopCounter<T> >&, \
347  const Base< ScalarFlopCounter<T> >&); \
348  template <typename T> \
349  ScalarFlopCounter<T> OP ( \
350  const typename ScalarFlopCounter<T>::value_type&, \
351  const Base< ScalarFlopCounter<T> >&); \
352  template <typename T> \
353  ScalarFlopCounter<T> OP ( \
354  const Base< ScalarFlopCounter<T> >&, \
355  const typename ScalarFlopCounter<T>::value_type&); \
356  template <typename T> \
357  ScalarFlopCounter<T> OP ( \
358  const int&, \
359  const Base< ScalarFlopCounter<T> >&); \
360  template <typename T> \
361  ScalarFlopCounter<T> OP ( \
362  const Base< ScalarFlopCounter<T> >&, \
363  const int&); \
364  } \
365  \
366  namespace Rad { \
367  template <typename T> class ADvari; \
368  template <typename T> class IndepADvar; \
369  template <typename T> class DoubleAvoid; \
370  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
371  const Base< ADvari<T> >&); \
372  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
373  const Base< ADvari<T> >&); \
374  template <typename T> ADvari<T>& OP (T, \
375  const Base< ADvari<T> >&); \
376  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::dtype,\
377  const Base< ADvari<T> >&); \
378  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::itype,\
379  const Base< ADvari<T> >&); \
380  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::ltype,\
381  const Base< ADvari<T> >&); \
382  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
383  const Base< IndepADvar<T> >&); \
384  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
385  T); \
386  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
387  typename DoubleAvoid<T>::dtype);\
388  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
389  typename DoubleAvoid<T>::itype);\
390  template <typename T> ADvari<T>& OP (const Base< ADvari<T> >&, \
391  typename DoubleAvoid<T>::ltype);\
392  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
393  const Base< IndepADvar<T> >&); \
394  template <typename T> ADvari<T>& OP (T, \
395  const Base< IndepADvar<T> >&); \
396  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::dtype,\
397  const Base< IndepADvar<T> >&); \
398  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::itype,\
399  const Base< IndepADvar<T> >&); \
400  template <typename T> ADvari<T>& OP (typename DoubleAvoid<T>::ltype,\
401  const Base< IndepADvar<T> >&); \
402  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
403  T); \
404  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
405  typename DoubleAvoid<T>::dtype);\
406  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
407  typename DoubleAvoid<T>::itype);\
408  template <typename T> ADvari<T>& OP (const Base< IndepADvar<T> >&, \
409  typename DoubleAvoid<T>::ltype);\
410  } \
411  \
412 } \
413  \
414 namespace std { \
415  using Sacado::Fad::OP; \
416  using Sacado::ELRFad::OP; \
417  using Sacado::CacheFad::OP; \
418  using Sacado::ELRCacheFad::OP; \
419  using Sacado::LFad::OP; \
420  using Sacado::Tay::OP; \
421  using Sacado::FlopCounterPack::OP; \
422  using Sacado::Rad::OP; \
423 }
424 
429 
430 #undef BINARYFUNC_MACRO
431 
432 #if defined(HAVE_SACADO_KOKKOSCORE)
433 
434 namespace Sacado {
435 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
436  namespace Fad {
437  template <typename ValT, unsigned sl, unsigned ss, typename U>
438  class ViewFadPtr;
439  template <typename T> class DFad;
440  template <typename T, int N> class SFad;
441  template <typename T, int N> class SLFad;
442  template <typename T>
444  void atomic_add(DFad<T>* dst, const DFad<T>& x);
445  template <typename T, int N>
447  void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
448  template <typename T, int N>
450  void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
451  template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
453  void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
454  }
455 #endif
456  namespace ELRFad {
457  template <typename ValT, unsigned sl, unsigned ss, typename U>
458  class ViewFadPtr;
459  template <typename T> class DFad;
460  template <typename T, int N> class SFad;
461  template <typename T, int N> class SLFad;
462  template <typename T>
464  void atomic_add(DFad<T>* dst, const DFad<T>& x);
465  template <typename T, int N>
467  void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
468  template <typename T, int N>
470  void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
471  template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
473  void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
474  }
475  namespace CacheFad {
476  template <typename ValT, unsigned sl, unsigned ss, typename U>
477  class ViewFadPtr;
478  template <typename T> class DFad;
479  template <typename T, int N> class SFad;
480  template <typename T, int N> class SLFad;
481  template <typename T>
483  void atomic_add(DFad<T>* dst, const DFad<T>& x);
484  template <typename T, int N>
486  void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
487  template <typename T, int N>
489  void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
490  template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
492  void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
493  }
494  namespace ELRCacheFad {
495  template <typename ValT, unsigned sl, unsigned ss, typename U>
496  class ViewFadPtr;
497  template <typename T> class DFad;
498  template <typename T, int N> class SFad;
499  template <typename T, int N> class SLFad;
500  template <typename T>
502  void atomic_add(DFad<T>* dst, const DFad<T>& x);
503  template <typename T, int N>
505  void atomic_add(SFad<T,N>* dst, const SFad<T,N>& x);
506  template <typename T, int N>
508  void atomic_add(SLFad<T,N>* dst, const SLFad<T,N>& x);
509  template <typename ValT, unsigned sl, unsigned ss, typename U, typename T>
511  void atomic_add(ViewFadPtr<ValT,sl,ss,U> dst, const Expr<T>& x);
512  }
513 }
514 
515 namespace Kokkos {
516 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
517  using Sacado::Fad::atomic_add;
518 #endif
519  using Sacado::ELRFad::atomic_add;
520  using Sacado::CacheFad::atomic_add;
521  using Sacado::ELRCacheFad::atomic_add;
522 }
523 
524 #endif
525 
526 #ifdef SACADO_ENABLE_NEW_DESIGN
528 #endif
529 
530 #endif // SACADO_MATHFUNCTIONS_HPP
cbrt(expr.val())
expr expr SinOp
asinh(expr.val())
asin(expr.val())
cosh(expr.val())
abs(expr.val())
atanh(expr.val())
expr expr expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 expr1 expr1 expr1 expr1 expr1 c *expr2 expr1 c *expr2 expr1 c *expr2 expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 expr2 expr1 expr2 expr1 Atan2Op
expr expr CoshOp
expr expr ATanhOp
GeneralFad< StaticStorage< T, Num > > SLFad
expr expr TanhOp
pow(expr1.val(), expr2.val())
expr expr SqrtOp
expr expr ASinhOp
atan(expr.val())
#define KOKKOS_INLINE_FUNCTION
tanh(expr.val())
expr expr CosOp
#define BINARYFUNC_MACRO(OP, FADOP)
expr expr ATanOp
GeneralFad< DynamicStorage< T > > DFad
SimpleFad< ValueT > min(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
expr expr ACosOp
sqrt(expr.val())
sinh(expr.val())
tan(expr.val())
atan2(expr1.val(), expr2.val())
sin(expr.val())
log(expr.val())
expr expr ACoshOp
expr expr Log10Op
expr expr SinhOp
acosh(expr.val())
acos(expr.val())
SimpleFad< ValueT > max(const SimpleFad< ValueT > &a, const SimpleFad< ValueT > &b)
expr expr ASinOp
exp(expr.val())
expr expr expr ExpOp
expr2 expr1 expr2 expr2 c *expr2 c *expr1 c *expr2 c *expr1 PowerOp
fabs(expr.val())
expr expr AbsOp
expr expr TanOp
GeneralFad< StaticFixedStorage< T, Num > > SFad
log10(expr.val())
cos(expr.val())
#define UNARYFUNC_MACRO(OP, FADOP)