libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
tensor_tools.h
浏览该文件的文档.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2023 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_TENSOR_TOOLS_H
21 #define LIBMESH_TENSOR_TOOLS_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/compare_types.h"
26 
27 #ifdef LIBMESH_HAVE_METAPHYSICL
28 #include "metaphysicl/dualnumber_decl.h"
29 #endif
30 
31 namespace libMesh
32 {
33 // Forward declarations
34 template <typename T> class TypeVector;
35 template <typename T> class VectorValue;
36 template <typename T> class TypeTensor;
37 template <typename T> class TensorValue;
38 template <unsigned int N, typename T> class TypeNTensor;
39 
40 namespace TensorTools
41 {
42 // 通用情况下的内积计算,适用于标量
43 template <typename T, typename T2>
44 inline
45 typename boostcopy::enable_if_c<ScalarTraits<T>::value && ScalarTraits<T2>::value,
46  typename CompareTypes<T, T2>::supertype>::type
47 inner_product(const T & a, const T2& b)
48 { return a * b; }
49 
50 // 向量的内积计算
51 template <typename T, typename T2>
52 inline
53 typename CompareTypes<T, T2>::supertype
55 { return a * b; }
56 
57 // 张量的内积计算
58 template <typename T, typename T2>
59 inline
60 typename CompareTypes<T, T2>::supertype
62 { return a.contract(b); }
63 
64 // 多维张量的内积计算
65 template <unsigned int N, typename T, typename T2>
66 inline
67 typename CompareTypes<T, T2>::supertype
69 { return a.contract(b); }
70 
71 // 计算复数的模的平方
72 template<typename T>
73 inline
74 T norm_sq(std::complex<T> a) { return std::norm(a); }
75 
76 // 计算实数或复数的模的平方
77 template<typename T>
78 inline
79 auto norm_sq(const T & a) -> decltype(std::norm(a))
80 { return std::norm(a); }
81 
82 // 向量的模的平方计算
83 template <typename T>
84 inline
85 auto norm_sq(const TypeVector<T> & a) -> decltype(std::norm(T()))
86 { return a.norm_sq(); }
87 
88 // VectorValue类型的模的平方计算
89 template <typename T>
90 inline
91 auto norm_sq(const VectorValue<T> & a) -> decltype(std::norm(T()))
92 { return a.norm_sq(); }
93 
94 // 判断数值是否为零
95 template<typename T>
96 inline
97 bool is_zero(const T & a){ return a.is_zero();}
98 
99 // 增加张量秩的结构
100 template <typename T>
102 {
104 };
105 
106 // VectorValue类型的张量秩增加
107 template <typename T>
109 {
111 };
112 
113 // TypeVector类型的张量秩增加
114 template <typename T>
116 {
118 };
119 
120 // TypeTensor类型的张量秩增加
121 template <typename T>
123 {
125 };
126 
127 
128 template <typename T>
130 {
132 };
133 
134 template <unsigned int N, typename T>
136 {
138 };
139 
140 
141 // Also need rank-decreasing case
142 template <typename T>
144 {
145  // The default case is typically an error, but for simpler
146  // templated code we need it to be compatible with Number
147  // operations...
148  typedef T type;
149 };
150 
151 template <typename T>
153 {
154  typedef T type;
155 };
156 
157 template <typename T>
159 {
160  typedef T type;
161 };
162 
163 template <typename T>
165 {
167 };
168 
169 template <typename T>
171 {
173 };
174 
175 template <unsigned int N, typename T>
177 {
178  typedef TypeNTensor<N-1,T> type;
179 };
180 
181 // Handle the complex-valued case
182 template <typename T>
184 {
185 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
186  typedef std::complex<T> type;
187 #else
188  typedef T type;
189 #endif
190 };
191 
192 template <typename T>
193 struct MakeNumber<std::complex<T>>
194 {
195  // Should this be a compile-time error? we shouldn't need to make numbers out of
196  // numbers, but then again having the typedef below enables more generic
197  // programming
198  typedef std::complex<T> type;
199 };
200 
201 
202 template <typename T>
204 {
206 };
207 
208 template <typename T>
210 {
212 };
213 
214 template <typename T>
216 {
218 };
219 
220 template <typename T>
222 {
224 };
225 
226 template <unsigned int N, typename T>
228 {
229 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
231 #else
233 #endif
234 };
235 
236 // A utility for determining real-valued (e.g. shape function)
237 // types from corresponding complex-valued types
238 template <typename T>
239 struct MakeReal
240 {
241  typedef T type;
242 };
243 
244 template <typename T>
245 struct MakeReal<std::complex<T>>
246 {
247  typedef T type;
248 };
249 
250 template <typename T>
252 {
254 };
255 
256 template <typename T>
258 {
260 };
261 
262 template <typename T>
264 {
266 };
267 
268 template <typename T>
270 {
272 };
273 
274 template <unsigned int N, typename T>
275 struct MakeReal<TypeNTensor<N,T>>
276 {
278 };
279 
280 // 用于使ExactSolution编译通过
282 
285 
288 
291 
294 
297 
302 template <typename T>
304 {
305  static constexpr bool value = false;
306 };
307 
311 template <typename T>
313 {
314  static constexpr bool value = true;
315 };
316 
320 template <typename T>
322 {
323  static constexpr bool value = true;
324 };
325 
329 template <typename T>
331 {
332  static constexpr bool value = true;
333 };
334 
338 template <typename T>
340 {
341  static constexpr bool value = true;
342 };
343 
347 template <unsigned int N, typename T>
349 {
350  static constexpr bool value = true;
351 };
352 
357 template <typename T, typename enable = void>
358 struct MakeBaseNumber {};
359 
363 template <typename T>
364 struct MakeBaseNumber<T, typename std::enable_if<ScalarTraits<T>::value>::type> {
365  typedef typename MakeNumber<T>::type type;
366 };
367 
372 template <template <typename> class Wrapper, typename T>
374  Wrapper<T>,
375  typename std::enable_if<MathWrapperTraits<Wrapper<T>>::value>::type> {
376  typedef typename MakeBaseNumber<T>::type type;
377 };
378 
383 template <typename T, typename Enable = void>
385 {
386  static_assert(always_false<T>,
387  "Instantiating the generic template of TensorTraits. You must specialize "
388  "TensorTraits for your type.");
389  static constexpr unsigned char rank = 0;
390 };
391 
395 template <typename T>
396 struct TensorTraits<T, typename std::enable_if<ScalarTraits<T>::value>::type>
397 {
398  static constexpr unsigned char rank = 0;
399 };
400 
404 template <typename T>
406 {
407  static constexpr unsigned char rank = 1;
408 };
409 
413 template <typename T>
415 {
416  static constexpr unsigned char rank = 1;
417 };
418 
422 template <typename T>
424 {
425  static constexpr unsigned char rank = 2;
426 };
427 
431 template <typename T>
433 {
434  static constexpr unsigned char rank = 2;
435 };
436 
440 template <typename T, unsigned int N>
442 {
443  static constexpr unsigned char rank = static_cast<unsigned char>(N);
444 };
445 
446 }//namespace TensorTools
447 
448 }//namespace libMesh
449 
450 #endif // LIBMESH_TENSOR_TOOLS_H
Number div_from_grad(const VectorValue< Number > &)
虚拟函数。标量的散度未定义,但需要使ExactSolution编译通过
Definition: tensor_tools.C:54
TypeTensor< typename MakeNumber< T >::type > type
Definition: tensor_tools.h:223
bool is_zero(const T &a)
Definition: tensor_tools.h:97
此类定义了LIBMESH_DIM维的实数或复数空间中的向量。
Definition: tensor_tools.h:35
CompareTypes< T, T2 >::supertype contract(const TypeNTensor< N, T2 > &) const
将两个张量相乘,返回一个标量,即 张量可能包含不同的数值类型。 也被称为张量的“双内积”或“双点积”。
TypeVector< typename MakeNumber< T >::type > type
Definition: tensor_tools.h:205
TypeTensor< typename MakeReal< T >::type > type
Definition: tensor_tools.h:271
This class defines a tensor in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:36
T norm_sq(std::complex< T > a)
Definition: tensor_tools.h:74
TypeVector< typename MakeReal< T >::type > type
Definition: tensor_tools.h:253
TypeTensor< typename MakeReal< T >::type > type
Definition: tensor_tools.h:265
VectorValue< typename MakeReal< T >::type > type
Definition: tensor_tools.h:259
该类定义了一个在 LIBMESH_DIM 维度空间中类型为 T 的向量。
Definition: tensor_tools.h:34
TypeNTensor< N, typename MakeReal< T >::type > type
Definition: tensor_tools.h:277
该类最终将定义一个在类型为T的LIBMESH_DIM维空间中的N阶张量。
Definition: tensor_tools.h:38
此模板结构用于创建基础数值类型,支持标量类型。 如果模板类型不是标量类型,则不会创建基础数值类型。
Definition: tensor_tools.h:358
CompareTypes< T, T2 >::supertype contract(const TypeTensor< T2 > &) const
将两个 Tensor 相乘,返回一个标量,即 。 这些 Tensor 可能包含不同的数值类型。
Definition: type_tensor.h:1358
TypeTensor< typename MakeNumber< T >::type > type
Definition: tensor_tools.h:217
VectorValue< typename MakeNumber< T >::type > type
Definition: tensor_tools.h:211
static constexpr unsigned char rank
Definition: tensor_tools.h:389
此辅助结构用于确定模板类是否是我们的数学结构之一, 例如TypeVector、TypeTensor及其后代
Definition: tensor_tools.h:303
ADRealEigenVector< T, D, asd > norm(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的范数。
Definition: type_vector.h:64
boostcopy::enable_if_c< ScalarTraits< T >::value &&ScalarTraits< T2 >::value, typename CompareTypes< T, T2 >::supertype >::type inner_product(const T &a, const T2 &b)
Definition: tensor_tools.h:47
此模板结构用于获取张量的特性,包括张量的秩。 默认情况下,它被断言为false,需要为特定类型进行特化。
Definition: tensor_tools.h:384
Number curl_from_grad(const VectorValue< Number > &)
Definition: tensor_tools.C:28
此类定义了LIBMESH_DIM维度的实数或复数空间中的张量。typedef RealTensorValue总是定义为实数值的张量, 而NumberTensorValue则根据库的配置定义为实数或复数值...
Definition: tensor_tools.h:37