libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
tensor_value.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_VALUE_H
21 #define LIBMESH_TENSOR_VALUE_H
22 
23 // Local includes
24 #include "libmesh/type_tensor.h"
25 #include "libmesh/libmesh.h" // for pi
26 
27 #ifdef LIBMESH_HAVE_METAPHYSICL
28 #include "metaphysicl/raw_type.h"
29 #endif
30 
31 namespace libMesh
32 {
33 
41 template <typename T>
42 class TensorValue : public TypeTensor<T>
43 {
44 public:
45  typedef T value_type;
46 
47  template <typename T2>
48  struct rebind
49  {
51  };
52 
57  TensorValue ();
58 
71  explicit TensorValue (const T & xx,
72  const T & xy=0,
73  const T & xz=0,
74  const T & yx=0,
75  const T & yy=0,
76  const T & yz=0,
77  const T & zx=0,
78  const T & zy=0,
79  const T & zz=0);
80 
93  template <typename Scalar>
94  explicit TensorValue (const Scalar & xx,
95  const Scalar & xy=0,
96  const Scalar & xz=0,
97  const Scalar & yx=0,
98  const Scalar & yy=0,
99  const Scalar & yz=0,
100  const Scalar & zx=0,
101  const Scalar & zy=0,
102  typename
103  boostcopy::enable_if_c<ScalarTraits<Scalar>::value,
104  const Scalar>::type & zz=0);
105 
110  template <typename T2>
111  TensorValue (const TypeVector<T2> & vx);
112 
118  template <typename T2>
119  TensorValue (const TypeVector<T2> & vx,
120  const TypeVector<T2> & vy);
121 
128  template <typename T2>
129  TensorValue (const TypeVector<T2> & vx,
130  const TypeVector<T2> & vy,
131  const TypeVector<T2> & vz);
132 
137  template <typename T2>
138  TensorValue (const TensorValue<T2> & p);
139 
144  template <typename T2>
145  TensorValue (const TypeTensor<T2> & p);
146 
147 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
148 
153  TensorValue (const TypeTensor<Real> & p_re,
154  const TypeTensor<Real> & p_im);
155 #endif
156 
162  template <typename Scalar>
163  typename boostcopy::enable_if_c<
164  ScalarTraits<Scalar>::value,
165  TensorValue &>::type
166  operator = (const Scalar & libmesh_dbg_var(p) )
167  { libmesh_assert_equal_to (p, Scalar(0)); this->zero(); return *this; }
168 
181  static TensorValue<Real> intrinsic_rotation_matrix(Real phi, Real theta, Real psi);
182 
192 
203  static TensorValue<Real>
204  extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg);
205 
213  static TensorValue<Real>
214  inverse_extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg);
215 };
216 
224 
225 
226 
227 //------------------------------------------------------
228 // Inline functions
229 template <typename T>
230 inline
232  TypeTensor<T> ()
233 {
234 }
235 
236 
237 
238 template <typename T>
239 inline
241  const T & xy,
242  const T & xz,
243  const T & yx,
244  const T & yy,
245  const T & yz,
246  const T & zx,
247  const T & zy,
248  const T & zz) :
249  TypeTensor<T> (xx,xy,xz,yx,yy,yz,zx,zy,zz)
250 {
251 }
252 
253 
254 template <typename T>
255 template <typename Scalar>
256 inline
257 TensorValue<T>::TensorValue (const Scalar & xx,
258  const Scalar & xy,
259  const Scalar & xz,
260  const Scalar & yx,
261  const Scalar & yy,
262  const Scalar & yz,
263  const Scalar & zx,
264  const Scalar & zy,
265  typename
266  boostcopy::enable_if_c<ScalarTraits<Scalar>::value,
267  const Scalar>::type & zz) :
268  TypeTensor<T> (xx,xy,xz,yx,yy,yz,zx,zy,zz)
269 {
270 }
271 
272 
273 
274 template <typename T>
275 template <typename T2>
276 inline
278  TypeTensor<T> (p)
279 {
280 }
281 
282 
283 
284 template <typename T>
285 template <typename T2>
286 inline
288  TypeTensor<T> (vx)
289 {
290 }
291 
292 
293 
294 template <typename T>
295 template <typename T2>
296 inline
298  const TypeVector<T2> & vy) :
299  TypeTensor<T> (vx, vy)
300 {
301 }
302 
303 
304 
305 template <typename T>
306 template <typename T2>
307 inline
309  const TypeVector<T2> & vy,
310  const TypeVector<T2> & vz) :
311  TypeTensor<T> (vx, vy, vz)
312 {
313 }
314 
315 
316 
317 template <typename T>
318 template <typename T2>
319 inline
321  TypeTensor<T> (p)
322 {
323 }
324 
325 
326 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
327 template <typename T>
328 inline
330  const TypeTensor<Real> & p_im) :
331  TypeTensor<T> (Complex (p_re(0,0), p_im(0,0)),
332  Complex (p_re(0,1), p_im(0,1)),
333  Complex (p_re(0,2), p_im(0,2)),
334  Complex (p_re(1,0), p_im(1,0)),
335  Complex (p_re(1,1), p_im(1,1)),
336  Complex (p_re(1,2), p_im(1,2)),
337  Complex (p_re(2,0), p_im(2,0)),
338  Complex (p_re(2,1), p_im(2,1)),
339  Complex (p_re(2,2), p_im(2,2)))
340 {
341 }
342 #endif
343 
344 template <typename T>
346 TensorValue<T>::intrinsic_rotation_matrix(const Real phi, const Real theta, const Real psi)
347 {
348 #if LIBMESH_DIM == 3
349  // We apply a negative sign here or else we don't get the appearance of
350  // counter-clockwise/right-hand-rule rotation of the bodies with respect to the coordinate axes
351  // (but as explained in the method doxygen we are *actually* rotating the coordinate axes while
352  // leaving the bodies fixed)
353  const Real p = -phi / 180. * pi;
354  const Real t = -theta / 180. * pi;
355  const Real s = -psi / 180. * pi;
356  const Real sp = std::sin(p), cp = std::cos(p);
357  const Real st = std::sin(t), ct = std::cos(t);
358  const Real ss = std::sin(s), cs = std::cos(s);
359 
360  return TensorValue<Real>(cp * cs - sp * ct * ss,
361  sp * cs + cp * ct * ss,
362  st * ss,
363  -cp * ss - sp * ct * cs,
364  -sp * ss + cp * ct * cs,
365  st * cs,
366  sp * st,
367  -cp * st,
368  ct);
369 #else
370  libmesh_ignore(phi, theta, psi);
371  libmesh_error_msg("TensorValue<T>::intrinsic_rotation_matrix() requires libMesh to be compiled "
372  "with LIBMESH_DIM==3");
373  // We'll never get here
374  return TensorValue<Real>();
375 #endif
376 }
377 
378 template <typename T>
381 {
382  // The inverse of a rotation matrix is just the transpose
383  return TensorValue<T>::intrinsic_rotation_matrix(phi, theta, psi).transpose();
384 }
385 
386 template <typename T>
389  const Real angle2_deg,
390  const Real angle3_deg)
391 {
392 #if LIBMESH_DIM == 3
393  const auto angle1 = angle1_deg / 180. * pi;
394  const auto angle2 = angle2_deg / 180. * pi;
395  const auto angle3 = angle3_deg / 180. * pi;
396  const auto s1 = std::sin(angle1), c1 = std::cos(angle1);
397  const auto s2 = std::sin(angle2), c2 = std::cos(angle2);
398  const auto s3 = std::sin(angle3), c3 = std::cos(angle3);
399 
400  return TensorValue<Real>(c1 * c3 - c2 * s1 * s3,
401  -c1 * s3 - c2 * c3 * s1,
402  s1 * s2,
403  c3 * s1 + c1 * c2 * s3,
404  c1 * c2 * c3 - s1 * s3,
405  -c1 * s2,
406  s2 * s3,
407  c3 * s2,
408  c2);
409 #else
410  libmesh_ignore(angle1_deg, angle2_deg, angle3_deg);
411  libmesh_error_msg("TensorValue<T>::extrinsic_rotation_matrix() requires libMesh to be compiled "
412  "with LIBMESH_DIM==3");
413  // We'll never get here
414  return TensorValue<Real>();
415 #endif
416 }
417 
418 template <typename T>
421  const Real angle2_deg,
422  const Real angle3_deg)
423 {
424  // The inverse of a rotation matrix is just the transpose
425  return TensorValue<T>::extrinsic_rotation_matrix(angle1_deg, angle2_deg, angle3_deg).transpose();
426 }
427 
428 } // namespace libMesh
429 
430 #ifdef LIBMESH_HAVE_METAPHYSICL
431 namespace MetaPhysicL
432 {
433 template <typename T>
434 struct RawType<libMesh::TensorValue<T>>
435 {
437 
439  {
440  value_type ret;
441  for (unsigned int i = 0; i < LIBMESH_DIM; ++i)
442  for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
443  ret(i,j) = raw_value(in(i,j));
444 
445  return ret;
446  }
447 };
448 
449 template <typename T, typename U>
450 struct ReplaceAlgebraicType<libMesh::TensorValue<T>, U>
451 {
452  typedef U type;
453 };
454 }
455 #endif
456 
457 #endif // LIBMESH_TENSOR_VALUE_H
static TensorValue< Real > extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg)
生成与提供的欧拉角关联的外禀旋转矩阵。外禀旋转旋转域中的物体,并保持坐标轴不变。 我们遵循https://en.wikipedia.org/wiki/Euler_angles#Rotation_matr...
Definition: tensor_value.h:388
static TensorValue< Real > inverse_extrinsic_rotation_matrix(Real angle1_deg, Real angle2_deg, Real angle3_deg)
反转与提供给extrinsic_rotation_matrix的相同角度的旋转,即返回到原始起始点。
Definition: tensor_value.h:420
void zero()
将 Tensor 的所有元素设置为零。
Definition: type_tensor.h:1428
static value_type value(const libMesh::TensorValue< T > &in)
Definition: tensor_value.h:438
static TensorValue< Real > inverse_intrinsic_rotation_matrix(Real phi, Real theta, Real psi)
反转与提供给intrinsic_rotation_matrix的相同角度的旋转,即返回到原始起始点。 所有角度应以度为单位提供。
Definition: tensor_value.h:380
RealTensorValue RealTensor
Definition: tensor_value.h:222
boostcopy::enable_if_c< ScalarTraits< Scalar >::value, TensorValue & >::type operator=(const Scalar &libmesh_dbg_var(p))
赋值给标量的运算符。仅用于将张量清零。
Definition: tensor_value.h:166
libMesh::TensorValue< typename RawType< T >::value_type > value_type
Definition: tensor_value.h:436
This class defines a tensor in LIBMESH_DIM dimensional space of type T.
Definition: tensor_tools.h:36
TensorValue()
无参构造函数。 在LIBMESH_DIM维度的T空间中创建零张量。
Definition: tensor_value.h:231
void libmesh_ignore(const Args &...)
static TensorValue< Real > intrinsic_rotation_matrix(Real phi, Real theta, Real psi)
生成与提供的欧拉角关联的内禀旋转矩阵。内禀旋转会保持域中的物体不动,同时旋转坐标轴。 我们遵循http://mathworld.wolfram.com/EulerAngles.html中描述的约定 (方程6-14给出了复合变换矩阵的条目)。旋转在z、x&#39;和z&#39;&#39;轴上按顺序执行。旋 转序列的每个步骤中的正角度给出了在旋转轴周围以逆时针方向旋转实体的外观,尽管事实上 旋转的是坐标轴本身。为了给出物体逆时针旋转的外观,我们实际上将角度传递到方法中的负角度。 所有角度应以度为单位提供。
Definition: tensor_value.h:346
该类定义了一个在 LIBMESH_DIM 维度空间中类型为 T 的向量。
Definition: tensor_tools.h:34
std::complex< Real > Complex
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
NumberTensorValue Tensor
Definition: tensor_value.h:223
TensorValue< T2 > other
Definition: tensor_value.h:50
TensorValue< Number > NumberTensorValue
Definition: tensor_value.h:221
TensorValue< Real > RealTensorValue
用于允许在实数和复数数据类型之间无缝切换的有用typedef。
Definition: tensor_value.h:220
此类定义了LIBMESH_DIM维度的实数或复数空间中的张量。typedef RealTensorValue总是定义为实数值的张量, 而NumberTensorValue则根据库的配置定义为实数或复数值...
Definition: tensor_tools.h:37
const Real pi
.
Definition: libmesh.h:242