20 #ifndef LIBMESH_SPARSE_MATRIX_H
21 #define LIBMESH_SPARSE_MATRIX_H
25 #include "libmesh/libmesh.h"
26 #include "libmesh/libmesh_common.h"
27 #include "libmesh/reference_counted_object.h"
28 #include "libmesh/id_types.h"
29 #include "libmesh/parallel_object.h"
30 #include "libmesh/enum_parallel_type.h"
31 #include "libmesh/enum_matrix_build_type.h"
43 template <
typename T>
class SparseMatrix;
44 template <
typename T>
class DenseMatrix;
46 namespace SparsityPattern {
50 template <
typename T>
class NumericVector;
54 std::ostream & operator << (std::ostream & os, const SparseMatrix<T> & m);
65 class SparseMatrix :
public ReferenceCountedObject<SparseMatrix<T>>,
94 static std::unique_ptr<SparseMatrix<T>>
95 build(
const Parallel::Communicator & comm,
97 const MatrixBuildType matrix_build_type = MatrixBuildType::AUTOMATIC);
161 virtual void init (ParallelType type = PARALLEL) = 0;
166 virtual void clear () = 0;
171 virtual void zero () = 0;
178 virtual std::unique_ptr<SparseMatrix<T>>
zero_clone ()
const = 0;
185 virtual std::unique_ptr<SparseMatrix<T>>
clone ()
const = 0;
190 virtual void zero_rows (std::vector<numeric_index_type> & rows, T diag_value = 0.0);
195 virtual void close () = 0;
257 const std::vector<numeric_index_type> & rows,
258 const std::vector<numeric_index_type> & cols) = 0;
264 const std::vector<numeric_index_type> & dof_indices) = 0;
271 const std::vector<numeric_index_type> & brows,
272 const std::vector<numeric_index_type> & bcols);
279 const std::vector<numeric_index_type> & dof_indices)
291 { libmesh_not_implemented(); }
298 const std::map<numeric_index_type, numeric_index_type> & ,
299 const std::map<numeric_index_type, numeric_index_type> & ,
301 { libmesh_not_implemented(); }
340 virtual bool closed()
const = 0;
365 friend std::ostream & operator << <>(std::ostream & os,
const SparseMatrix<T> &
m);
378 libmesh_not_implemented();
389 const std::vector<numeric_index_type> & rows,
390 const std::vector<numeric_index_type> & cols)
const
405 const std::vector<numeric_index_type> & ,
406 const std::vector<numeric_index_type> & )
const
408 libmesh_not_implemented();
416 const std::vector<numeric_index_type> & rows,
417 const std::vector<numeric_index_type> & cols)
const
470 std::vector<numeric_index_type> & ,
471 std::vector<T> & )
const
473 libmesh_not_implemented();
484 const std::vector<numeric_index_type> & ,
485 const std::vector<numeric_index_type> & ,
488 libmesh_not_implemented();
516 template <
typename T>
517 std::ostream & operator << (std::ostream & os, const SparseMatrix<T> & m)
527 #endif // LIBMESH_SPARSE_MATRIX_H
virtual void add_block_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &brows, const std::vector< numeric_index_type > &bcols)
将完整矩阵 dm 添加到 SparseMatrix。这对于在装配时添加元素矩阵很有用。 矩阵被假定为块矩阵,brow、bcol 对应于*块*行和列索引。
virtual void print_personal(std::ostream &os=libMesh::out) const =0
以个性化的风格(如果可用)将矩阵的内容打印到屏幕上。
virtual void create_submatrix_nosort(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &) const
与上述函数类似,此函数创建由 rows 和 cols 向量中的索引定义的 submatrix。 注意:rows 和 cols 可以是无序的; 如果索引已排序,则对于效率更高的操作,请使用上面的函数; r...
SparseMatrix(const Parallel::Communicator &comm)
构造函数;初始化矩阵为空,没有任何结构,即矩阵无法使用。
This helper class can be called on multiple threads to compute the sparsity pattern (or graph) of the...
virtual ~SparseMatrix()=default
virtual void print_matlab(const std::string &="") const
以 Matlab 的稀疏矩阵格式打印矩阵的内容。可选择将矩阵打印到名为 name 的文件中。 如果未指定 name ,则将其转储到屏幕上。
void vector_mult(NumericVector< T > &dest, const NumericVector< T > &arg) const
将矩阵乘以 NumericVector arg 并将结果存储在 NumericVector dest 中。
virtual void get_row(numeric_index_type, std::vector< numeric_index_type > &, std::vector< T > &) const
从矩阵获取一行。
SparsityPattern::Build const * _sp
与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。
void attach_sparsity_pattern(const SparsityPattern::Build &sp)
设置要使用的稀疏性模式的指针。在矩阵需要比系统中的大(或更小以提高效率)的模式, 或者在 DofMap 未计算系统稀疏性模式的情况下使用。
void vector_mult_add(NumericVector< T > &dest, const NumericVector< T > &arg) const
将矩阵乘以 NumericVector arg ,并将结果添加到 NumericVector dest 中。
virtual void matrix_matrix_mult(SparseMatrix< T > &, SparseMatrix< T > &, bool)
计算 Y = A*X,其中 X 为矩阵。
virtual numeric_index_type local_m() const
获取此进程拥有的行数。
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
使用由 solver_package 指定的线性求解器包构建一个 SparseMatrix<T>。
virtual numeric_index_type row_stop() const =0
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
设置元素 (i,j) 为 value .
virtual void clear()=0
恢复 SparseMatrix<T> 到原始状态。
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value)=0
将 value 添加到元素 (i,j) .
virtual void add_sparse_matrix(const SparseMatrix< T > &, const std::map< numeric_index_type, numeric_index_type > &, const std::map< numeric_index_type, numeric_index_type > &, const T)
将 scalar* spm 添加到此矩阵的行和列中: A(rows[i], cols[j]) += scalar * spm(i,j)
virtual bool initialized() const
这是一个通用的稀疏矩阵类。该类包含了必须在派生类中覆盖的纯虚拟成员。 使用一个公共的基类允许从不同的求解器包中以不同的格式统一访问稀疏矩阵。
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
virtual void flush()
对于 PETSc 矩阵,此函数类似于 close,但不收缩内存。 当我们希望在 ADD_VALUES 和 INSERT_VALUES 之间切换时,这很有用。 在使用矩阵之前应该调用 close。 ...
virtual void create_submatrix(SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
此函数创建一个名为 "submatrix" 的矩阵,其定义由 "rows" 和 "cols" 条目中的行和列索引给定。 目前,此操作仅对 PetscMatrix 类型定义。 注意:rows 和 cols...
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
将完整矩阵 dm 添加到 SparseMatrix。这对于在装配时添加元素矩阵很有用。
virtual void zero()=0
将所有条目设置为 0。
dof_id_type numeric_index_type
bool _is_initialized
标志,指示矩阵是否已初始化。
virtual std::unique_ptr< SparseMatrix< T > > zero_clone() const =0
virtual numeric_index_type m() const =0
virtual bool need_full_sparsity_pattern() const
virtual void zero_rows(std::vector< numeric_index_type > &rows, T diag_value=0.0)
将所有行条目设置为 0,然后将 diag_value 放在对角线条目。
virtual void reinit_submatrix(SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
此函数与上述函数类似,但允许您重用 "submatrix" 的现有稀疏性模式,而不是再次分配它。 如果经常提取相同大小的子矩阵,这应该更有效。
virtual void get_diagonal(NumericVector< T > &dest) const =0
复制矩阵的对角线部分到 dest。
virtual bool closed() const =0
void attach_dof_map(const DofMap &dof_map)
设置要使用的 DofMap 的指针。如果不使用单独的稀疏性模式, 则使用来自 DofMap 的模式。
DofMap const * _dof_map
与此对象关联的 DofMap 对象。可以查询其在处理器上的自由度计数。
virtual void close()=0
调用 SparseMatrix 的内部装配例程,确保值在处理器之间保持一致。
virtual void update_sparsity_pattern(const SparsityPattern::Graph &)
更新矩阵的稀疏性模式。当您的 SparseMatrix<T> 实现不需要此数据时, 只需不覆盖此方法。
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type row_start() const =0
virtual void get_transpose(SparseMatrix< T > &dest) const =0
将矩阵的转置复制到 dest 中,dest 可能是 *this。
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
将矩阵的内容以统一的样式打印到屏幕上,而不考虑正在使用的矩阵/求解器包。
virtual Real linfty_norm() const =0
获取矩阵的 -范数,即最大行和:
SparseMatrix & operator=(const SparseMatrix &)=default
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
创建子矩阵和 reinit_submatrix 例程的受保护实现。
virtual Real l1_norm() const =0
获取矩阵的 -范数,即最大列和:
virtual std::unique_ptr< SparseMatrix< T > > clone() const =0
定义用于有限元类型计算的密集矩阵。 用于在求和成全局矩阵之前存储单元刚度矩阵。所有被覆盖的虚函数都记录在dense_matrix_base.h中。
virtual T operator()(const numeric_index_type i, const numeric_index_type j) const =0
virtual numeric_index_type n() const =0
virtual void add_block_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices)
与 add_block_matrix() 相同,但假定行和列映射相同。 因此矩阵 dm 必须是方阵。
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)=0
使用指定的大小初始化 SparseMatrix。