Reference documentation for deal.II version GIT relicensing-487-ge9eb5ab491 2024-04-25 07:20:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
sacado_product_types.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2015 - 2018 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_differentiation_ad_sacado_product_types_h
16#define dealii_differentiation_ad_sacado_product_types_h
17
18#include <deal.II/base/config.h>
19
21
22#ifdef DEAL_II_TRILINOS_WITH_SACADO
23
24# include <Sacado.hpp>
25// It appears that some versions of Trilinos do not directly or indirectly
26// include all the headers for all forward and reverse Sacado AD types.
27// So we directly include these both here as a precaution.
28// Standard forward AD classes (templated)
29# include <Sacado_Fad_DFad.hpp>
30// Reverse AD classes (templated)
31# include <Sacado_trad.hpp>
32
34
35
36/* -------------- Sacado::Fad::DFad
37 * (Differentiation::AD::NumberTypes::[sacado_fad/sacado_fad_fad])
38 * -------------- */
39
40
41namespace internal
42{
43 template <typename T>
44 struct ProductTypeImpl<Sacado::Fad::DFad<T>, float>
45 {
46 using type = Sacado::Fad::DFad<T>;
47 };
48
49 template <typename T>
50 struct ProductTypeImpl<float, Sacado::Fad::DFad<T>>
51 {
52 using type = Sacado::Fad::DFad<T>;
53 };
54
55 template <typename T>
56 struct ProductTypeImpl<Sacado::Fad::DFad<T>, double>
57 {
58 using type = Sacado::Fad::DFad<T>;
59 };
60
61 template <typename T>
62 struct ProductTypeImpl<double, Sacado::Fad::DFad<T>>
63 {
64 using type = Sacado::Fad::DFad<T>;
65 };
66
67 template <typename T>
68 struct ProductTypeImpl<Sacado::Fad::DFad<T>, int>
69 {
70 using type = Sacado::Fad::DFad<T>;
71 };
72
73 template <typename T>
74 struct ProductTypeImpl<int, Sacado::Fad::DFad<T>>
75 {
76 using type = Sacado::Fad::DFad<T>;
77 };
78
79 template <typename T, typename U>
80 struct ProductTypeImpl<Sacado::Fad::DFad<T>, Sacado::Fad::DFad<U>>
81 {
82 using type = Sacado::Fad::DFad<typename ProductType<T, U>::type>;
83 };
84
85
86 // Sacado::Fad::Dfad expression templates
87 // We demote the result of the expression template operations
88 // to a Sacado::Fad::Dfad itself. This is the only way to retain
89 // consistency between the number type going into a complex chain of
90 // (potentially branching) operations and that coming out of them.
91
92 template <typename T, typename U>
93 struct ProductTypeImpl<Sacado::Fad::Expr<T>, U>
94 {
95 using type =
97 };
98
99 template <typename T, typename U>
100 struct ProductTypeImpl<T, Sacado::Fad::Expr<U>>
101 {
102 using type =
104 };
105
106 template <typename T, typename U>
107 struct ProductTypeImpl<Sacado::Fad::Expr<T>, Sacado::Fad::Expr<U>>
108 {
109 using type =
111 typename Sacado::Fad::Expr<U>::value_type>::type;
112 };
113
114} // namespace internal
115
116
117template <typename T>
118struct EnableIfScalar<Sacado::Fad::DFad<T>>
119{
120 using type = Sacado::Fad::DFad<T>;
121};
122
123template <typename T>
124struct EnableIfScalar<Sacado::Fad::Expr<T>>
125{
126 using type = typename Sacado::Fad::Expr<T>::value_type;
127};
128
129
130/* -------------- Sacado::Rad::ADvar
131 * (Differentiation::AD::NumberTypes::[sacado_rad/sacado_rad_fad])
132 * -------------- */
133
134
135namespace internal
136{
137 template <typename T>
138 struct ProductTypeImpl<Sacado::Rad::ADvar<T>, float>
139 {
140 using type = Sacado::Rad::ADvar<T>;
141 };
142
143 template <typename T>
144 struct ProductTypeImpl<float, Sacado::Rad::ADvar<T>>
145 {
146 using type = Sacado::Rad::ADvar<T>;
147 };
148
149 template <typename T>
150 struct ProductTypeImpl<Sacado::Rad::ADvar<T>, double>
151 {
152 using type = Sacado::Rad::ADvar<T>;
153 };
154
155 template <typename T>
156 struct ProductTypeImpl<double, Sacado::Rad::ADvar<T>>
157 {
158 using type = Sacado::Rad::ADvar<T>;
159 };
160
161 template <typename T>
162 struct ProductTypeImpl<Sacado::Rad::ADvar<T>, int>
163 {
164 using type = Sacado::Rad::ADvar<T>;
165 };
166
167 template <typename T>
168 struct ProductTypeImpl<int, Sacado::Rad::ADvar<T>>
169 {
170 using type = Sacado::Rad::ADvar<T>;
171 };
172
173 template <typename T, typename U>
174 struct ProductTypeImpl<Sacado::Rad::ADvar<T>, Sacado::Rad::ADvar<U>>
175 {
176 using type = Sacado::Rad::ADvar<typename ProductType<T, U>::type>;
177 };
178
179 /* --- Sacado::Rad::ADvar: Temporary type --- */
180
181 template <typename T>
182 struct ProductTypeImpl<Sacado::Rad::ADvari<T>, float>
183 {
184 using type = Sacado::Rad::ADvari<T>;
185 };
186
187 template <typename T>
188 struct ProductTypeImpl<float, Sacado::Rad::ADvari<T>>
189 {
190 using type = Sacado::Rad::ADvari<T>;
191 };
192
193 template <typename T>
194 struct ProductTypeImpl<Sacado::Rad::ADvari<T>, double>
195 {
196 using type = Sacado::Rad::ADvari<T>;
197 };
198
199 template <typename T>
200 struct ProductTypeImpl<double, Sacado::Rad::ADvari<T>>
201 {
202 using type = Sacado::Rad::ADvari<T>;
203 };
204
205 template <typename T>
206 struct ProductTypeImpl<Sacado::Rad::ADvari<T>, int>
207 {
208 using type = Sacado::Rad::ADvari<T>;
209 };
210
211 template <typename T>
212 struct ProductTypeImpl<int, Sacado::Rad::ADvari<T>>
213 {
214 using type = Sacado::Rad::ADvari<T>;
215 };
216
217 template <typename T, typename U>
218 struct ProductTypeImpl<Sacado::Rad::ADvari<T>, Sacado::Rad::ADvari<U>>
219 {
220 using type = Sacado::Rad::ADvari<typename ProductType<T, U>::type>;
221 };
222
223 /* --- Sacado::Rad::ADvar: Main and temporary type --- */
224
225 template <typename T, typename U>
226 struct ProductTypeImpl<Sacado::Rad::ADvar<T>, Sacado::Rad::ADvari<U>>
227 {
228 using type = Sacado::Rad::ADvar<typename ProductType<T, U>::type>;
229 };
230
231 template <typename T, typename U>
232 struct ProductTypeImpl<Sacado::Rad::ADvari<T>, Sacado::Rad::ADvar<U>>
233 {
234 using type = Sacado::Rad::ADvar<typename ProductType<T, U>::type>;
235 };
236
237} // namespace internal
238
239
240template <typename T>
241struct EnableIfScalar<Sacado::Rad::ADvar<T>>
242{
243 using type = Sacado::Rad::ADvar<T>;
244};
245
246
247template <typename T>
248struct EnableIfScalar<Sacado::Rad::ADvari<T>>
249{
250 using type = Sacado::Rad::ADvari<T>;
251};
252
253
255
256#endif // DEAL_II_TRILINOS_WITH_SACADO
257
258#endif
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
typename Sacado::Fad::Expr< T >::value_type type
Sacado::Fad::DFad< typename ProductType< T, U >::type > type
typename ProductType< typename Sacado::Fad::Expr< T >::value_type, typename Sacado::Fad::Expr< U >::value_type >::type type
typename ProductType< typename Sacado::Fad::Expr< T >::value_type, U >::type type
typename ProductType< T, typename Sacado::Fad::Expr< U >::value_type >::type type
decltype(std::declval< T >() *std::declval< U >()) type