libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
eigen_sparse_matrix.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_EIGEN_SPARSE_MATRIX_H
21 #define LIBMESH_EIGEN_SPARSE_MATRIX_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_HAVE_EIGEN
26 
27 // Local includes
28 #include "libmesh/sparse_matrix.h"
29 #include "libmesh/eigen_core_support.h"
30 
31 // Eigen includes
32 
33 // C++ includes
34 #include <algorithm>
35 #include <cstddef>
36 
37 namespace libMesh
38 {
39 
40 // Forward declarations
41 template <typename T> class DenseMatrix;
42 template <typename T> class EigenSparseVector;
43 template <typename T> class EigenSparseLinearSolver;
44 
53 template <typename T>
54 class EigenSparseMatrix final : public SparseMatrix<T>
55 {
56 
57 public:
68  EigenSparseMatrix (const Parallel::Communicator & comm);
69 
73  EigenSparseMatrix (EigenSparseMatrix &&) = default;
74  EigenSparseMatrix (const EigenSparseMatrix &) = default;
75  EigenSparseMatrix & operator= (const EigenSparseMatrix &) = default;
77  virtual ~EigenSparseMatrix () = default;
78 
82  typedef EigenSM DataType;
83  typedef Eigen::Triplet<T,eigen_idx_type> TripletType;
84 
85  virtual void init (const numeric_index_type m,
86  const numeric_index_type n,
87  const numeric_index_type m_l,
88  const numeric_index_type n_l,
89  const numeric_index_type nnz=30,
90  const numeric_index_type noz=10,
91  const numeric_index_type blocksize=1) override;
92 
93  virtual void init (ParallelType = PARALLEL) override;
94 
95  virtual void clear () override;
96 
97  virtual void zero () override;
98 
99  virtual std::unique_ptr<SparseMatrix<T>> zero_clone () const override;
100 
101  virtual std::unique_ptr<SparseMatrix<T>> clone () const override;
102 
103  virtual void close () override { this->_closed = true; }
104 
105  virtual numeric_index_type m () const override;
106 
107  virtual numeric_index_type n () const override;
108 
109  virtual numeric_index_type row_start () const override;
110 
111  virtual numeric_index_type row_stop () const override;
112 
113  virtual void set (const numeric_index_type i,
114  const numeric_index_type j,
115  const T value) override;
116 
117  virtual void add (const numeric_index_type i,
118  const numeric_index_type j,
119  const T value) override;
120 
121  virtual void add_matrix (const DenseMatrix<T> & dm,
122  const std::vector<numeric_index_type> & rows,
123  const std::vector<numeric_index_type> & cols) override;
124 
125  virtual void add_matrix (const DenseMatrix<T> & dm,
126  const std::vector<numeric_index_type> & dof_indices) override;
127 
128  virtual void add (const T a, const SparseMatrix<T> & X) override;
129 
130  virtual T operator () (const numeric_index_type i,
131  const numeric_index_type j) const override;
132 
133  virtual Real l1_norm () const override;
134 
135  virtual Real linfty_norm () const override;
136 
137  virtual bool closed() const override { return _closed; }
138 
139  virtual void print_personal(std::ostream & os=libMesh::out) const override { this->print(os); }
140 
141  virtual void get_diagonal (NumericVector<T> & dest) const override;
142 
143  virtual void get_transpose (SparseMatrix<T> & dest) const override;
144 
145 private:
146 
151 
155  bool _closed;
156 
160  friend class EigenSparseVector<T>;
161  friend class EigenSparseLinearSolver<T>;
162 };
163 
164 } // namespace libMesh
165 
166 #endif // #ifdef LIBMESH_HAVE_EIGEN
167 #endif // #ifdef LIBMESH_EIGEN_SPARSE_MATRIX_H
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value) override
设置元素 (i,j) 为 value .
EigenSparseMatrix 类包装了来自 Eigen 库的稀疏矩阵对象。
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1) override
使用指定的大小初始化 SparseMatrix。
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
将 value 添加到元素 (i,j) .
virtual numeric_index_type m() const override
virtual void close() override
调用 SparseMatrix 的内部装配例程,确保值在处理器之间保持一致。
Eigen::Triplet< T, eigen_idx_type > TripletType
virtual numeric_index_type row_stop() const override
bool _closed
指示矩阵是否已关闭的标志。
virtual std::unique_ptr< SparseMatrix< T > > clone() const override
提供了不同线性代数库的向量存储方案的统一接口。
Definition: dof_map.h:67
EigenSparseMatrix & operator=(const EigenSparseMatrix &)=default
virtual ~EigenSparseMatrix()=default
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual void get_transpose(SparseMatrix< T > &dest) const override
将矩阵的转置复制到 dest 中,dest 可能是 *this。
这是一个通用的稀疏矩阵类。该类包含了必须在派生类中覆盖的纯虚拟成员。 使用一个公共的基类允许从不同的求解器包中以不同的格式统一访问稀疏矩阵。
Definition: dof_map.h:66
virtual void zero() override
将所有条目设置为 0。
virtual numeric_index_type n() const override
virtual bool closed() const override
virtual void get_diagonal(NumericVector< T > &dest) const override
复制矩阵的对角线部分到 dest。
dof_id_type numeric_index_type
Definition: id_types.h:99
EigenSparseMatrix(const Parallel::Communicator &comm)
构造函数;初始化矩阵为空,没有任何结构,即矩阵无法使用。
Eigen::SparseMatrix< Number, Eigen::RowMajor, eigen_idx_type > EigenSM
OStreamProxy out
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const override
EigenSM DataType
便捷的类型定义。
virtual numeric_index_type row_start() const override
virtual void print_personal(std::ostream &os=libMesh::out) const override
以个性化的风格(如果可用)将矩阵的内容打印到屏幕上。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real linfty_norm() const override
获取矩阵的 -范数,即最大行和:
virtual void clear() override
恢复 SparseMatrix&lt;T&gt; 到原始状态。
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
将矩阵的内容以统一的样式打印到屏幕上,而不考虑正在使用的矩阵/求解器包。
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const override
virtual Real l1_norm() const override
获取矩阵的 -范数,即最大列和:
定义用于有限元类型计算的密集矩阵。 用于在求和成全局矩阵之前存储单元刚度矩阵。所有被覆盖的虚函数都记录在dense_matrix_base.h中。
Definition: dof_map.h:65
This class provides a nice interface to the Eigen C++-based data structures for serial vectors...
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) override
将完整矩阵 dm 添加到 SparseMatrix。这对于在装配时添加元素矩阵很有用。