Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
adolcnamespaceinjections.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_UTILITIES_ADOLC_NAMESPACE_INJECTIONS_HH
5#define DUNE_FUFEM_UTILITIES_ADOLC_NAMESPACE_INJECTIONS_HH
6
7#include <limits>
8#include <type_traits>
9
12
13#if __has_include(<adolc/adolc.h>)
14#include <adolc/adolc.h>
15#endif
16
17/* The following code contains hacks around deficiencies in ADOL-C 2.7.2 and earlier.
18 */
19#if __has_include(<adolc/adouble.h>)
20adouble sqrt_hack(adouble a) {
21 return sqrt(a);
22}
23
24adouble abs_hack(adouble a) {
25 return fabs(a);
26}
27
28adouble log_hack(adouble a) {
29 return log(a);
30}
31
32adouble pow_hack(const adouble& a, const adouble& b) {
33 return pow(a,b);
34}
35
36adouble pow_hack(const adouble& a, double b) {
37 return pow(a,b);
38}
39
40adouble sin_hack(adouble a) {
41 return sin(a);
42}
43
44adouble cos_hack(adouble a) {
45 return cos(a);
46}
47
48adouble acos_hack(adouble a) {
49 return acos(a);
50}
51
52namespace std
53{
55 // Do not use 'min', because ADOL-C lacks support for that in vector-mode
56 return (a + b - abs_hack(a - b))*0.5;
57 }
58
60 // Do not use 'max', because ADOL-C lacks support for that in vector-mode
61 return - min(-a,-b);
62 }
63
65 return sqrt_hack(a);
66 }
67
69 return abs_hack(a);
70 }
71
73 return abs_hack(a);
74 }
75
77 return log_hack(a);
78 }
79
80 adouble pow(const adouble& a, const adouble& b) {
81 return pow_hack(a,b);
82 }
83
84 adouble pow(const adouble& a, double b) {
85 return pow_hack(a,b);
86 }
87
89 return sin_hack(a);
90 }
91
93 return cos_hack(a);
94 }
95
97 return acos_hack(a);
98 }
99
100 bool isnan(adouble a) {
101 return std::isnan(a.value());
102 }
103
104 bool isinf(adouble a) {
105 return std::isinf(a.value());
106 }
107
108 bool isfinite(adouble a) {
109 return std::isfinite(a.value());
110 }
111
112 bool isnormal(adouble a) {
113 return std::isnormal(a.value());
114 }
115
117 template <>
118 struct numeric_limits<adouble> {
119
120 static adouble max() {
122 }
123
124 static adouble epsilon() {
126 }
127 static adouble quiet_NaN() {
129 }
130
131 static constexpr bool is_integer = false;
132
133 };
134}
135#endif
136
137#if __has_include(<adolc/adolc.h>)
138namespace Dune
139{
140 // Declare to Dune that `adouble` is a number
141 template<>
142 struct IsNumber<adouble>
144 {};
145
146 /* The following code is only necessary for ADOL-C 2.7.2 and earlier.
147 * Later versions have dropped the `adub` class, and the standard C++
148 * return type deduction mechanism can be used with them.
149 */
150#if __has_include(<adolc/adouble.h>)
151 /* Specializations of the PromotionTraits class from dune-common for the adouble type.
152 * This is needed, e.g., to be able to use the FieldVector implementation of dot products
153 * between a FieldVector<double> and a FieldVector<adouble>. The standard C++ return type
154 * deduction mechanism doesn't help here, because the product of a double and an adouble
155 * is actually a proxy class called 'adub', which is not to be used outside of the ADOL-C
156 * library.
157 */
158 template <>
159 struct PromotionTraits<double,adouble>
160 {
161 typedef adouble PromotedType;
162 };
163
164 template <>
165 struct PromotionTraits<adouble,double>
166 {
167 typedef adouble PromotedType;
168 };
169#endif
170}
171#endif
172
173#endif
constexpr T abs(T t)
STL namespace.
decltype(std::declval< T1 >()+std::declval< T2 >()) PromotedType
T acos(T... args)
T cos(T... args)
T epsilon(T... args)
T fabs(T... args)
T forward(T... args)
T isfinite(T... args)
T isinf(T... args)
T isnan(T... args)
T isnormal(T... args)
T log(T... args)
T max(T... args)
T min(T... args)
T pow(T... args)
T quiet_NaN(T... args)
T sin(T... args)
T sqrt(T... args)