libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
type_n_tensor.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_TYPE_N_TENSOR_H
21 #define LIBMESH_TYPE_N_TENSOR_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/type_vector.h"
26 #include "libmesh/tuple_of.h"
27 
28 // C++ includes
29 #include <cstdlib> // *must* precede <cmath> for proper std:abs() on PGI, Sun Studio CC
30 #include <cmath>
31 #include <vector>
32 
33 namespace libMesh
34 {
35 
45 template <unsigned int N, typename T>
46 class TypeNTensor
47 {
48 public:
53 
54  // 默认构造函数
55  TypeNTensor () : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
56 
57  // 复制构造函数
58  TypeNTensor (const T &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
59 
60  // 复制构造函数
61  TypeNTensor (const TypeVector<T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
62 
63  // 复制构造函数
64  TypeNTensor (const TypeTensor<T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
65 
66  // 复制构造函数
67  TypeNTensor (const TypeNTensor<N,T> &) : _coords(std::vector<T>(int_pow(LIBMESH_DIM, N))) {}
68 
69  // 赋值运算符,目前抛出未实现的异常
70  TypeNTensor & operator = (const TypeNTensor<N,T> &) { libmesh_not_implemented(); return *this; }
71 
72  // 类型转换运算符,目前抛出未实现的异常
73  operator TypeVector<T> () const { libmesh_not_implemented(); return 0; }
74  operator VectorValue<T> () const { libmesh_not_implemented(); return 0; }
75 
76  // 类型转换运算符,目前抛出未实现的异常
77  operator TypeTensor<T> () const { libmesh_not_implemented(); return 0; }
78  operator TensorValue<T> () const { libmesh_not_implemented(); return 0; }
79 
80  // 析构函数
81  ~TypeNTensor() = default;
82 
86  const TypeNTensor<N-1,T> slice (const unsigned int /*i*/) const
87  {
88  libmesh_not_implemented();
89  return TypeNTensor<N-1,T>();
90  }
91 
95  TypeNTensor<N-1,T> slice (const unsigned int /*i*/)
96  {
97  libmesh_not_implemented();
98  return TypeNTensor<N-1,T>();
99  }
100 
101  // 赋值运算符,目前抛出未实现的异常
102  template <typename Scalar>
103  typename boostcopy::enable_if_c<
104  ScalarTraits<Scalar>::value,
105  TypeNTensor &>::type
106  operator = (const Scalar & libmesh_dbg_var(p))
107  { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
108 
109  // 加法运算符,目前抛出未实现的异常
110  template<typename T2>
113  {
114  libmesh_not_implemented();
116  }
117 
118  // 复合赋值加法运算符,目前抛出未实现的异常
119  template<typename T2>
121  {
122  libmesh_not_implemented();
123  return *this;
124  }
125 
126  // 减法运算符,目前抛出未实现的异常
127  template<typename T2>
130  {
131  libmesh_not_implemented();
133  }
134 
135  // 复合赋值减法运算符,目前抛出未实现的异常
136  template<typename T2>
138  {
139  libmesh_not_implemented();
140  return *this;
141  }
142 
143  // 取负运算符,目前抛出未实现的异常
145  {
146  libmesh_not_implemented();
147  return *this;
148  }
149 
150  // 乘法运算符,目前抛出未实现的异常
151  template <typename Scalar>
152  typename boostcopy::enable_if_c<
153  ScalarTraits<Scalar>::value,
155  operator * (const Scalar) const
156  {
157  libmesh_not_implemented();
159  }
160 
161  // 复合赋值乘法运算符,目前抛出未实现的异常
162  template <typename Scalar>
163  const TypeNTensor<N,T> & operator *= (const Scalar)
164  {
165  libmesh_not_implemented();
166  return *this;
167  }
168 
169  // 除法运算符,目前抛出未实现的异常
170  template <typename Scalar>
171  typename boostcopy::enable_if_c<
172  ScalarTraits<Scalar>::value,
174  operator / (const Scalar) const
175  {
176  libmesh_not_implemented();
177  return *this;
178  }
179 
180  // 复合赋值除法运算符,目前抛出未实现的异常
182  {
183  libmesh_not_implemented();
184  return *this;
185  }
186 
195  template <typename T2>
196  typename CompareTypes<T,T2>::supertype
197  contract (const TypeNTensor<N,T2> &) const
198  {
199  libmesh_not_implemented();
200  return 0;
201  }
202 
206  auto norm_sq() const -> decltype(std::norm(T()))
207  {
208  libmesh_not_implemented();
209  return 0.;
210  }
211 
215  void zero() { libmesh_not_implemented(); }
216 
220  bool operator == (const TypeNTensor<N,T> & /*rhs*/) const
221  {
222  libmesh_not_implemented();
223  return true;
224  }
225 
231  bool operator < (const TypeNTensor<N,T> & /*rhs*/) const
232  {
233  libmesh_not_implemented();
234  return false;
235  }
236 
240  bool operator > (const TypeNTensor<N,T> & /*rhs*/) const
241  {
242  libmesh_not_implemented();
243  return false;
244  }
245 
249  void print(std::ostream & /*os = libMesh::out*/) const {}
250 
257  friend std::ostream & operator << (std::ostream & os,
258  const TypeNTensor<N,T> & t)
259  {
260  t.print(os);
261  return os;
262  }
263 
267  template<typename T2>
268  void add_scaled (const TypeNTensor<N, T2> &, const T &);
269 
273  std::vector<T> _coords;
274 
275 private:
276  static constexpr int int_pow(int b, int e)
277  {
278  return (e == 0) ? 1 : b * int_pow(b, e - 1);
279  }
280 };
281 
282 
283 template<unsigned int N, typename T>
284 template<typename T2>
285 inline
286 void TypeNTensor<N, T>::add_scaled (const TypeNTensor<N, T2> & p, const T & factor)
287 {
288  unsigned int size = int_pow(LIBMESH_DIM, N);
289  for (unsigned int i = 0; i < size ; i++)
290  _coords[i] += factor*p._coords[i];
291 }
292 
293 template <unsigned int N, typename T, typename Scalar>
294 typename boostcopy::enable_if_c<
295  ScalarTraits<Scalar>::value,
297 operator * (const Scalar &, const TypeNTensor<N, T> &)
298 {
299  libmesh_not_implemented();
301 }
302 
303 template <unsigned int N, typename T, typename Scalar>
304 typename boostcopy::enable_if_c<
305  ScalarTraits<Scalar>::value,
306  TypeNTensor<N,typename CompareTypes<Scalar, T>::supertype>>::type
307 operator / (const Scalar &, const TypeNTensor<N, T> &)
308 {
309  libmesh_not_implemented();
311 }
312 
313 
314 } // namespace libMesh
315 
316 
317 #endif // LIBMESH_TYPE_N_TENSOR_H
TypeNTensor(const T &)
Definition: type_n_tensor.h:58
static constexpr int int_pow(int b, int e)
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< Scalar, T >::supertype > >::type operator/(const Scalar &, const TypeNTensor< N, T > &)
TypeNTensor & operator=(const TypeNTensor< N, T > &)
Definition: type_n_tensor.h:70
void add_scaled(const TypeNTensor< N, T2 > &, const T &)
将一个经过缩放的类型N张量添加到该类型N张量中,而不创建临时张量。
TypeNTensor(const TypeNTensor< N, T > &)
Definition: type_n_tensor.h:67
此类定义了LIBMESH_DIM维的实数或复数空间中的向量。
Definition: tensor_tools.h:35
const TypeNTensor< N, T > & operator+=(const TypeNTensor< N, T2 > &)
CompareTypes< T, T2 >::supertype contract(const TypeNTensor< N, T2 > &) const
将两个张量相乘,返回一个标量,即 张量可能包含不同的数值类型。 也被称为张量的“双内积”或“双点积”。
const TypeNTensor< N, T > & operator-=(const TypeNTensor< N, T2 > &)
This class defines a tensor in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:36
bool operator==(const TypeNTensor< N, T > &) const
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator*(const Scalar) const
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< T, Scalar >::supertype > >::type operator/(const Scalar) const
TypeNTensor(const TypeTensor< T > &)
Definition: type_n_tensor.h:64
TypeNTensor< N, T > operator-() const
auto norm_sq() const -> decltype(std::norm(T()))
typename tuple_n< Index, T >::template type<> tuple_of
Definition: tuple_of.h:22
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TypeNTensor< N, typename CompareTypes< Scalar, T >::supertype > >::type operator*(const Scalar &, const TypeNTensor< N, T > &)
const TypeNTensor< N, T > & operator/=(const T)
该类定义了一个在 LIBMESH_DIM 维度空间中类型为 T 的向量。
Definition: tensor_tools.h:34
tuple_of< N, unsigned int > index_type
用于通用索引编程的辅助typedef
Definition: type_n_tensor.h:52
const TypeNTensor< N, T > & operator*=(const Scalar)
std::vector< T > _coords
TypeNTensor的坐标
bool operator>(const TypeNTensor< N, T > &) const
void print(std::ostream &) const
将该张量格式化打印到流中,默认为libMesh::out。
该类最终将定义一个在类型为T的LIBMESH_DIM维空间中的N阶张量。
Definition: tensor_tools.h:38
friend std::ostream & operator<<(std::ostream &os, const TypeNTensor< N, T > &t)
执行格式化打印(如上所述),但支持以下语法:
TypeNTensor< N-1, T > slice(const unsigned int)
Definition: type_n_tensor.h:95
void zero()
将张量的所有分量设置为0。
ADRealEigenVector< T, D, asd > norm(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的范数。
Definition: type_vector.h:64
TypeNTensor(const TypeVector< T > &)
Definition: type_n_tensor.h:61
TypeNTensor< N, typename CompareTypes< T, T2 >::supertype > operator+(const TypeNTensor< N, T2 > &) const
const TypeNTensor< N-1, T > slice(const unsigned int) const
Definition: type_n_tensor.h:86
此类定义了LIBMESH_DIM维度的实数或复数空间中的张量。typedef RealTensorValue总是定义为实数值的张量, 而NumberTensorValue则根据库的配置定义为实数或复数值...
Definition: tensor_tools.h:37