libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
dense_matrix_base.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_DENSE_MATRIX_BASE_H
21 #define LIBMESH_DENSE_MATRIX_BASE_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/compare_types.h"
26 #include "libmesh/int_range.h"
27 
28 // C++ includes
29 
30 namespace libMesh
31 {
32 
33 // Forward declarations
34 template <typename T> class DenseVectorBase;
35 template <typename T> class DenseVector;
36 
44 template<typename T>
46 {
47 
48 protected:
56  DenseMatrixBase(const unsigned int new_m=0,
57  const unsigned int new_n=0) : _m(new_m), _n(new_n) {}
58 
59 public:
63  DenseMatrixBase (DenseMatrixBase &&) = default;
64  DenseMatrixBase (const DenseMatrixBase &) = default;
65  DenseMatrixBase & operator= (const DenseMatrixBase &) = default;
67  virtual ~DenseMatrixBase() = default;
68 
72  virtual void zero() = 0;
73 
82  virtual T el(const unsigned int i,
83  const unsigned int j) const = 0;
84 
93  virtual T & el(const unsigned int i,
94  const unsigned int j) = 0;
95 
101  virtual void left_multiply (const DenseMatrixBase<T> & M2) = 0;
102 
108  virtual void right_multiply (const DenseMatrixBase<T> & M3) = 0;
109 
115  unsigned int m() const { return _m; }
116 
122  unsigned int n() const { return _n; }
123 
129  void print(std::ostream & os = libMesh::out) const;
130 
136  friend std::ostream & operator << (std::ostream & os, const DenseMatrixBase<T> & m)
137  {
138  m.print(os);
139  return os;
140  }
141 
148  void print_scientific(std::ostream & os, unsigned precision=8) const;
149 
157  template <typename T2, typename T3>
158  typename boostcopy::enable_if_c<
159  ScalarTraits<T2>::value, void >::type
160  add (const T2 factor,
161  const DenseMatrixBase<T3> & mat);
162 
168  DenseVector<T> diagonal() const;
169 
170 protected:
171 
183  static void multiply (DenseMatrixBase<T> & M1,
184  const DenseMatrixBase<T> & M2,
185  const DenseMatrixBase<T> & M3);
186 
196  void condense(const unsigned int i,
197  const unsigned int j,
198  const T val,
199  DenseVectorBase<T> & rhs);
200 
204  unsigned int _m;
205 
209  unsigned int _n;
210 };
211 
212 template<typename T>
213 template<typename T2, typename T3>
214 inline
215 typename boostcopy::enable_if_c<
216  ScalarTraits<T2>::value, void >::type
217 DenseMatrixBase<T>::add (const T2 factor,
218  const DenseMatrixBase<T3> & mat)
219 {
220  libmesh_assert_equal_to (this->m(), mat.m());
221  libmesh_assert_equal_to (this->n(), mat.n());
222 
223  for (auto j : make_range(this->n()))
224  for (auto i : make_range(this->m()))
225  this->el(i,j) += factor*mat.el(i,j);
226 }
227 
228 
229 } // namespace libMesh
230 
231 #endif // LIBMESH_DENSE_MATRIX_BASE_H
void print_scientific(std::ostream &os, unsigned precision=8) const
以科学计数法格式打印矩阵。
unsigned int n() const
返回矩阵的列维度。
virtual T el(const unsigned int i, const unsigned int j) const =0
返回矩阵的 (i,j) 元素。 由于内部数据表示可能不同,必须重新定义此函数。
virtual void left_multiply(const DenseMatrixBase< T > &M2)=0
执行操作: (*this) &lt;- M2 * (*this)。
unsigned int m() const
返回矩阵的行维度。
DenseMatrixBase(const unsigned int new_m=0, const unsigned int new_n=0)
构造函数。创建一个维度为 m 乘 n 的稠密矩阵。 Protected,以便用户无法创建一个实例。
OStreamProxy out
DenseMatrixBase & operator=(const DenseMatrixBase &)=default
unsigned int _n
列维度。
virtual void right_multiply(const DenseMatrixBase< T > &M3)=0
执行操作: (*this) &lt;- (*this) * M3。
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseMatrixBase< T3 > &mat)
将 factor 添加到矩阵的每个元素。 这应该仅在 T += T2 * T3 是有效的 C++,且 T2 是标量的情况下工作。返回类型是 void。
virtual void zero()=0
将矩阵的每个元素设置为 0。必须重新定义零矩阵的含义,因为它取决于值的存储方式。
DenseVector< T > diagonal() const
返回矩阵的对角线。
定义用于有限元计算的抽象稠密向量基类。 可以从这个类派生出特定的稠密向量,例如 DenseSubVectors。
Definition: dof_map.h:63
static void multiply(DenseMatrixBase< T > &M1, const DenseMatrixBase< T > &M2, const DenseMatrixBase< T > &M3)
辅助函数 - 执行计算 M1 = M2 * M3 其中: M1 = (m x n) M2 = (m x p) M3 = (p x n)
定义用于有限元计算的稠密向量类。该类基本上是为了补充 DenseMatrix 类而设计的。 它相对于 std::vector 具有额外的功能,使其在有限元中特别有用,特别是对于方程组。 所有重写的虚拟函...
Definition: dof_map.h:64
为有限元类型的计算定义了一个抽象的稠密矩阵基类。例如 DenseSubMatrices 可以从这个类派生出来。
void print(std::ostream &os=libMesh::out) const
漂亮地打印矩阵,默认为 libMesh::out。
virtual ~DenseMatrixBase()=default
void condense(const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)
将矩阵的 (i,j) 条目压缩出来,强制它取值为 val。这对于在数值模拟中应用边界条件很有用。 保留矩阵的对称性。
unsigned int _m
行维度。