Reference documentation for deal.II version 9.0.0
adolc_math.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2016 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_differentiation_ad_adolc_math_h
17 #define dealii_differentiation_ad_adolc_math_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_ADOLC
22 
23 #include <adolc/internal/adolc_settings.h>
24 #include <adolc/internal/adubfunc.h> // Taped double math functions
25 
26 #include <adolc/adouble.h> // Taped double
27 #include <adolc/adtl.h> // Tapeless double
28 
29 
30 #ifndef DOXYGEN
31 
40 namespace std
41 {
42 
46 #define DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION_COPY(func_to, func_from) \
47  inline adouble func_to(const adouble &x) {return func_from(static_cast<const badouble &>(x));} \
48  inline adtl::adouble func_to(const adtl::adouble &x) {return adtl::func_from(x);}
49 
53 #define DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(func) \
54  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION_COPY(func,func)
55 
59 #define DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_COPY(func_to,func_from) \
60  inline adouble func_to(const adouble &x, const adouble &y) {return func_from(static_cast<const badouble &>(x),static_cast<const badouble &>(y));} \
61  inline adouble func_to(const double &x, const adouble &y) {return func_from(x,static_cast<const badouble &>(y));} \
62  inline adouble func_to(const adouble &x, const double &y) {return func_from(static_cast<const badouble &>(x),y);} \
63  inline adtl::adouble func_to(const adtl::adouble &x, const adtl::adouble &y) {return adtl::func_from(x,y);} \
64  inline adtl::adouble func_to(const double &x, const adtl::adouble &y) {return adtl::func_from(x,y);} \
65  inline adtl::adouble func_to(const adtl::adouble &x, const double &y) {return adtl::func_from(x,y);}
66 
70 #define DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION(func) \
71  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_COPY(func,func)
72 
76 #define DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_2(func) \
77  inline adouble func(const adouble &x, const adouble &y) {return func(static_cast<const badouble &>(x),static_cast<const badouble &>(y));} \
78  inline adtl::adouble func(const adtl::adouble &x, const adtl::adouble &y) {return adtl::func(x,y);}
79 
80  // See
81  // https://gitlab.com/adol-c/adol-c/blob/master/ADOL-C/include/adolc/adouble.h
82  // https://gitlab.com/adol-c/adol-c/blob/master/ADOL-C/include/adolc/internal/paramfunc.h
83 
84  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION(pow)
85  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION(fmax)
86  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_COPY(max,fmax)
87  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION(fmin)
88  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_COPY(min,fmin)
89 
90  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(exp)
91  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(log)
92  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(log10)
93  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(sqrt)
94 #if defined(DEAL_II_ADOLC_WITH_ATRIG_ERF)
95  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(erf)
96  inline adouble erfc(const adouble &x)
97  {
98  return 1.0 - std::erf(x);
99  } \
100  inline adtl::adouble erfc(const adtl::adouble &x)
101  {
102  return 1.0 - std::erf(x);
103  }
104 #endif
105 
106  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(fabs)
107  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION_COPY(abs,fabs)
108  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(ceil)
109  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(floor)
110 
111  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(sin)
112  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(cos)
113  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(tan)
114  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(asin)
115  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(acos)
116  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(atan)
117  DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_2(atan2)
118 
119  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(sinh)
120  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(cosh)
121  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(tanh)
122 #if defined(DEAL_II_ADOLC_WITH_ATRIG_ERF)
123  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(asinh)
124  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(acosh)
125  DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION(atanh)
126 #endif
127 
128 #undef DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_2
129 #undef DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION
130 #undef DEAL_II_EXPOSE_ADOLC_BINARY_MATH_FUNCTION_COPY
131 #undef DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION
132 #undef DEAL_II_EXPOSE_ADOLC_UNARY_MATH_FUNCTION_COPY
133 
134 } // namespace std
135 
136 #endif // DOXYGEN
137 
138 #endif // DEAL_II_WITH_ADOLC
139 
140 #endif
STL namespace.