libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
Public 类型 | Public 成员函数 | 静态 Public 成员函数 | Protected 类型 | Protected 成员函数 | Protected 属性 | 静态 Protected 属性 | Private 属性 | 友元 | 所有成员列表
libMesh::EigenSparseMatrix< T > 模板类 参考final

EigenSparseMatrix 类包装了来自 Eigen 库的稀疏矩阵对象。 更多...

#include <eigen_sparse_matrix.h>

类 libMesh::EigenSparseMatrix< T > 继承关系图:
[图例]

Public 类型

typedef EigenSM DataType
 便捷的类型定义。 更多...
 
typedef Eigen::Triplet< T,
eigen_idx_type
TripletType
 

Public 成员函数

 EigenSparseMatrix (const Parallel::Communicator &comm)
 构造函数;初始化矩阵为空,没有任何结构,即矩阵无法使用。 更多...
 
 EigenSparseMatrix (EigenSparseMatrix &&)=default
 五个特殊函数对于这个类可以默认,因为它本身不管理任何内存。 更多...
 
 EigenSparseMatrix (const EigenSparseMatrix &)=default
 
EigenSparseMatrixoperator= (const EigenSparseMatrix &)=default
 
EigenSparseMatrixoperator= (EigenSparseMatrix &&)=default
 
virtual ~EigenSparseMatrix ()=default
 
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 init (ParallelType=PARALLEL) override
 使用由 dof_map 计算的稀疏性结构初始化此矩阵。 更多...
 
virtual void clear () override
 恢复 SparseMatrix<T> 到原始状态。 更多...
 
virtual void zero () override
 将所有条目设置为 0。 更多...
 
virtual std::unique_ptr
< SparseMatrix< T > > 
zero_clone () const override
 
virtual std::unique_ptr
< SparseMatrix< T > > 
clone () const override
 
virtual void close () override
 调用 SparseMatrix 的内部装配例程,确保值在处理器之间保持一致。 更多...
 
virtual numeric_index_type m () const override
 
virtual numeric_index_type n () const override
 
virtual numeric_index_type row_start () const override
 
virtual numeric_index_type row_stop () const override
 
virtual void set (const numeric_index_type i, const numeric_index_type j, const T value) override
 设置元素 (i,j) 为 value . 更多...
 
virtual void add (const numeric_index_type i, const numeric_index_type j, const T value) override
 value 添加到元素 (i,j) . 更多...
 
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。这对于在装配时添加元素矩阵很有用。 更多...
 
virtual void add_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices) override
 add_matrix 相同,但假定行和列映射相同。因此矩阵 dm 必须是方阵。 更多...
 
virtual void add (const T a, const SparseMatrix< T > &X) override
 计算 $ A \leftarrow A + a*X $,其中 a 为标量,X 为矩阵。 更多...
 
virtual T operator() (const numeric_index_type i, const numeric_index_type j) const override
 
virtual Real l1_norm () const override
 获取矩阵的 $ \ell_1 $-范数,即最大列和: $ |M|_1 = \max_{j} \sum_{i} |M_{ij}| $ 更多...
 
virtual Real linfty_norm () const override
 获取矩阵的 $ \ell_{\infty} $-范数,即最大行和: 更多...
 
virtual bool closed () const override
 
virtual void print_personal (std::ostream &os=libMesh::out) const override
 以个性化的风格(如果可用)将矩阵的内容打印到屏幕上。 更多...
 
virtual void get_diagonal (NumericVector< T > &dest) const override
 复制矩阵的对角线部分到 dest。 更多...
 
virtual void get_transpose (SparseMatrix< T > &dest) const override
 将矩阵的转置复制到 dest 中,dest 可能是 *this。 更多...
 
virtual bool initialized () const
 
void attach_dof_map (const DofMap &dof_map)
 设置要使用的 DofMap 的指针。如果不使用单独的稀疏性模式, 则使用来自 DofMap 的模式。 更多...
 
void attach_sparsity_pattern (const SparsityPattern::Build &sp)
 设置要使用的稀疏性模式的指针。在矩阵需要比系统中的大(或更小以提高效率)的模式, 或者在 DofMap 未计算系统稀疏性模式的情况下使用。 更多...
 
virtual bool need_full_sparsity_pattern () const
 
virtual void update_sparsity_pattern (const SparsityPattern::Graph &)
 更新矩阵的稀疏性模式。当您的 SparseMatrix<T> 实现不需要此数据时, 只需不覆盖此方法。 更多...
 
virtual void zero_rows (std::vector< numeric_index_type > &rows, T diag_value=0.0)
 将所有行条目设置为 0,然后将 diag_value 放在对角线条目。 更多...
 
virtual void flush ()
 对于 PETSc 矩阵,此函数类似于 close,但不收缩内存。 当我们希望在 ADD_VALUES 和 INSERT_VALUES 之间切换时,这很有用。 在使用矩阵之前应该调用 close。 更多...
 
virtual numeric_index_type local_m () const
 获取此进程拥有的行数。 更多...
 
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 add_block_matrix (const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &dof_indices)
 add_block_matrix() 相同,但假定行和列映射相同。 因此矩阵 dm 必须是方阵。 更多...
 
virtual void matrix_matrix_mult (SparseMatrix< T > &, SparseMatrix< T > &, bool)
 计算 Y = A*X,其中 X 为矩阵。 更多...
 
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) 更多...
 
void print (std::ostream &os=libMesh::out, const bool sparse=false) const
 将矩阵的内容以统一的样式打印到屏幕上,而不考虑正在使用的矩阵/求解器包。 更多...
 
template<>
void print (std::ostream &os, const bool sparse) const
 
virtual void print_matlab (const std::string &="") const
 以 Matlab 的稀疏矩阵格式打印矩阵的内容。可选择将矩阵打印到名为 name 的文件中。 如果未指定 name ,则将其转储到屏幕上。 更多...
 
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 类型定义。 注意:rowscols 向量需要排序; 如果 rowscols 向量未排序,则使用下面的 nosort 版本; rowscols 仅包含由此处理器拥有的索引。 更多...
 
virtual void create_submatrix_nosort (SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &) const
 与上述函数类似,此函数创建由 rowscols 向量中的索引定义的 submatrix。 注意:rowscols 可以是无序的; 如果索引已排序,则对于效率更高的操作,请使用上面的函数; rowscols 可以包含由其他处理器拥有的索引。 更多...
 
virtual void reinit_submatrix (SparseMatrix< T > &submatrix, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols) const
 此函数与上述函数类似,但允许您重用 "submatrix" 的现有稀疏性模式,而不是再次分配它。 如果经常提取相同大小的子矩阵,这应该更有效。 更多...
 
void vector_mult (NumericVector< T > &dest, const NumericVector< T > &arg) const
 将矩阵乘以 NumericVector arg 并将结果存储在 NumericVector dest 中。 更多...
 
void vector_mult_add (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
 从矩阵获取一行。 更多...
 

静态 Public 成员函数

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>。 更多...
 
static std::string get_info ()
 Gets a string containing the reference information. 更多...
 
static void print_info (std::ostream &out_stream=libMesh::out)
 Prints the reference information, by default to libMesh::out. 更多...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. 更多...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() 更多...
 
static void disable_print_counter_info ()
 

Protected 类型

typedef std::map< std::string,
std::pair< unsigned int,
unsigned int > > 
Counts
 Data structure to log the information. 更多...
 

Protected 成员函数

virtual void _get_submatrix (SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
 创建子矩阵和 reinit_submatrix 例程的受保护实现。 更多...
 
void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter. 更多...
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter. 更多...
 

Protected 属性

DofMap const * _dof_map
 与此对象关联的 DofMap 对象。可以查询其在处理器上的自由度计数。 更多...
 
SparsityPattern::Build const * _sp
 与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。 更多...
 
bool _is_initialized
 标志,指示矩阵是否已初始化。 更多...
 

静态 Protected 属性

static Counts _counts
 Actually holds the data. 更多...
 
static Threads::atomic
< unsigned int > 
_n_objects
 The number of objects. 更多...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. 更多...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. 更多...
 

Private 属性

DataType _mat
 实际的 Eigen::SparseMatrix<> 对象。 更多...
 
bool _closed
 指示矩阵是否已关闭的标志。 更多...
 

友元

class EigenSparseVector< T >
 使其他 Eigen 数据类型成为友元类。 更多...
 
class EigenSparseLinearSolver< T >
 

详细描述

template<typename T>
class libMesh::EigenSparseMatrix< T >

EigenSparseMatrix 类包装了来自 Eigen 库的稀疏矩阵对象。

该类是一个模板类,处理不同数据类型 T 的情况。继承自 SparseMatrix<T>。

作者
Benjamin S. Kirk
日期
2013

在文件 eigen_sparse_matrix.h54 行定义.

成员类型定义说明

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

在文件 reference_counter.h119 行定义.

template<typename T>
typedef EigenSM libMesh::EigenSparseMatrix< T >::DataType

便捷的类型定义。

在文件 eigen_sparse_matrix.h82 行定义.

template<typename T>
typedef Eigen::Triplet<T,eigen_idx_type> libMesh::EigenSparseMatrix< T >::TripletType

在文件 eigen_sparse_matrix.h83 行定义.

构造及析构函数说明

template<typename T >
libMesh::EigenSparseMatrix< T >::EigenSparseMatrix ( const Parallel::Communicator &  comm)

构造函数;初始化矩阵为空,没有任何结构,即矩阵无法使用。

因此,该构造函数仅对作为类成员的矩阵有用。所有其他矩阵应在数据流的某个点创建, 在那里所有必要的信息都是可用的。

在使用之前,您必须使用 init(...) 初始化矩阵。

参数
comm通信器对象,指定通信环境。

在文件 eigen_sparse_matrix.C163 行定义.

163  :
164  SparseMatrix<T>(comm_in),
165  _closed (false)
166 {
167 }
bool _closed
指示矩阵是否已关闭的标志。
template<typename T>
libMesh::EigenSparseMatrix< T >::EigenSparseMatrix ( EigenSparseMatrix< T > &&  )
default

五个特殊函数对于这个类可以默认,因为它本身不管理任何内存。

template<typename T>
libMesh::EigenSparseMatrix< T >::EigenSparseMatrix ( const EigenSparseMatrix< T > &  )
default
template<typename T>
virtual libMesh::EigenSparseMatrix< T >::~EigenSparseMatrix ( )
virtualdefault

成员函数说明

template<typename T>
virtual void libMesh::SparseMatrix< T >::_get_submatrix ( SparseMatrix< T > &  ,
const std::vector< numeric_index_type > &  ,
const std::vector< numeric_index_type > &  ,
const bool   
) const
inlineprotectedvirtualinherited

创建子矩阵和 reinit_submatrix 例程的受保护实现。

注解
派生类必须在此函数中覆盖,以使其正常工作!

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h483 行定义.

参考自 libMesh::SparseMatrix< T >::create_submatrix() , 以及 libMesh::SparseMatrix< T >::reinit_submatrix().

487  {
488  libmesh_not_implemented();
489  }
template<typename T >
void libMesh::EigenSparseMatrix< T >::add ( const numeric_index_type  i,
const numeric_index_type  j,
const T  value 
)
overridevirtual

value 添加到元素 (i,j) .

如果条目不存在,则抛出错误。 可以将零值“添加”到不存在的条目中。

参数
i矩阵行索引
j矩阵列索引
value元素的值

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C272 行定义.

参考 libMesh::initialized().

275 {
276  libmesh_assert (this->initialized());
277  libmesh_assert_less (i, this->m());
278  libmesh_assert_less (j, this->n());
279 
280  _mat.coeffRef(i,j) += value;
281 }
virtual numeric_index_type m() const override
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual bool initialized() const
virtual numeric_index_type n() const override
template<typename T >
void libMesh::EigenSparseMatrix< T >::add ( const T  a,
const SparseMatrix< T > &  X 
)
overridevirtual

计算 $ A \leftarrow A + a*X $,其中 a 为标量,X 为矩阵。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C295 行定义.

参考 libMesh::EigenSparseMatrix< T >::_mat, libMesh::initialized(), libMesh::SparseMatrix< T >::m() , 以及 libMesh::SparseMatrix< T >::n().

296 {
297  libmesh_assert (this->initialized());
298  libmesh_assert_equal_to (this->m(), X_in.m());
299  libmesh_assert_equal_to (this->n(), X_in.n());
300 
301  const EigenSparseMatrix<T> & X =
302  cast_ref<const EigenSparseMatrix<T> &> (X_in);
303 
304  _mat += X._mat*a_in;
305 }
virtual numeric_index_type m() const override
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual bool initialized() const
virtual numeric_index_type n() const override
template<typename T >
void libMesh::SparseMatrix< T >::add_block_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  brows,
const std::vector< numeric_index_type > &  bcols 
)
virtualinherited

将完整矩阵 dm 添加到 SparseMatrix。这对于在装配时添加元素矩阵很有用。 矩阵被假定为块矩阵,brow、bcol 对应于*块*行和列索引。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.C77 行定义.

参考 libMesh::DenseMatrixBase< T >::m() , 以及 libMesh::DenseMatrixBase< T >::n().

参考自 libMesh::SparseMatrix< T >::add_block_matrix().

80 {
81  libmesh_assert_equal_to (dm.m() / brows.size(), dm.n() / bcols.size());
82 
83  const numeric_index_type blocksize = cast_int<numeric_index_type>
84  (dm.m() / brows.size());
85 
86  libmesh_assert_equal_to (dm.m()%blocksize, 0);
87  libmesh_assert_equal_to (dm.n()%blocksize, 0);
88 
89  std::vector<numeric_index_type> rows, cols;
90 
91  rows.reserve(blocksize*brows.size());
92  cols.reserve(blocksize*bcols.size());
93 
94  for (auto & row : brows)
95  {
96  numeric_index_type i = row * blocksize;
97 
98  for (unsigned int v=0; v<blocksize; v++)
99  rows.push_back(i++);
100  }
101 
102  for (auto & col : bcols)
103  {
104  numeric_index_type j = col * blocksize;
105 
106  for (unsigned int v=0; v<blocksize; v++)
107  cols.push_back(j++);
108  }
109 
110  this->add_matrix (dm, rows, cols);
111 }
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。这对于在装配时添加元素矩阵很有用。
dof_id_type numeric_index_type
Definition: id_types.h:99
template<typename T>
virtual void libMesh::SparseMatrix< T >::add_block_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  dof_indices 
)
inlinevirtualinherited

add_block_matrix() 相同,但假定行和列映射相同。 因此矩阵 dm 必须是方阵。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h278 行定义.

参考 libMesh::SparseMatrix< T >::add_block_matrix().

280  { this->add_block_matrix (dm, dof_indices, dof_indices); }
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 对应于*块*行和列索引。
Definition: sparse_matrix.C:77
template<typename T >
void libMesh::EigenSparseMatrix< T >::add_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
)
overridevirtual

将完整矩阵 dm 添加到 SparseMatrix。这对于在装配时添加元素矩阵很有用。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C123 行定义.

参考 libMesh::initialized(), libMesh::DenseMatrixBase< T >::m() , 以及 libMesh::DenseMatrixBase< T >::n().

127 {
128  libmesh_assert (this->initialized());
129  unsigned int n_rows = cast_int<unsigned int>(rows.size());
130  unsigned int n_cols = cast_int<unsigned int>(cols.size());
131  libmesh_assert_equal_to (dm.m(), n_rows);
132  libmesh_assert_equal_to (dm.n(), n_cols);
133 
134 
135  for (unsigned int i=0; i<n_rows; i++)
136  for (unsigned int j=0; j<n_cols; j++)
137  this->add(rows[i],cols[j],dm(i,j));
138 }
virtual void add(const numeric_index_type i, const numeric_index_type j, const T value) override
将 value 添加到元素 (i,j) .
virtual bool initialized() const
template<typename T >
void libMesh::EigenSparseMatrix< T >::add_matrix ( const DenseMatrix< T > &  dm,
const std::vector< numeric_index_type > &  dof_indices 
)
overridevirtual

add_matrix 相同,但假定行和列映射相同。因此矩阵 dm 必须是方阵。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C286 行定义.

288 {
289  this->add_matrix (dm, dof_indices, dof_indices);
290 }
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。这对于在装配时添加元素矩阵很有用。
template<typename T>
virtual void libMesh::SparseMatrix< T >::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   
)
inlinevirtualinherited

scalar* spm 添加到此矩阵的行和列中: A(rows[i], cols[j]) += scalar * spm(i,j)

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h297 行定义.

301  { libmesh_not_implemented(); }
template<typename T >
void libMesh::SparseMatrix< T >::attach_dof_map ( const DofMap dof_map)
inherited

设置要使用的 DofMap 的指针。如果不使用单独的稀疏性模式, 则使用来自 DofMap 的模式。

dof_map 的生命周期必须超过 this 的生命周期。

在文件 sparse_matrix.C58 行定义.

参考 libMesh::DofMap::get_sparsity_pattern().

参考自 libMesh::DofMap::update_sparsity_pattern().

59 {
60  _dof_map = &dof_map;
61  if (!_sp)
62  _sp = dof_map.get_sparsity_pattern();
63 }
const SparsityPattern::Graph & get_sparsity_pattern() const
Rows of sparse matrix indices, indexed by the offset from the first DoF on this processor.
SparsityPattern::Build const * _sp
与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。
DofMap const * _dof_map
与此对象关联的 DofMap 对象。可以查询其在处理器上的自由度计数。
template<typename T >
void libMesh::SparseMatrix< T >::attach_sparsity_pattern ( const SparsityPattern::Build sp)
inherited

设置要使用的稀疏性模式的指针。在矩阵需要比系统中的大(或更小以提高效率)的模式, 或者在 DofMap 未计算系统稀疏性模式的情况下使用。

sp 的生命周期必须超过 this 的生命周期。

在文件 sparse_matrix.C68 行定义.

参考自 libMesh::DofMap::update_sparsity_pattern().

69 {
70  _sp = &sp;
71 }
SparsityPattern::Build const * _sp
与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。
template<typename T >
std::unique_ptr< SparseMatrix< T > > libMesh::SparseMatrix< T >::build ( const Parallel::Communicator &  comm,
const SolverPackage  solver_package = libMesh::default_solver_package(),
const MatrixBuildType  matrix_build_type = MatrixBuildType::AUTOMATIC 
)
staticinherited

使用由 solver_package 指定的线性求解器包构建一个 SparseMatrix<T>。

在文件 sparse_matrix.C151 行定义.

参考 libMesh::EIGEN_SOLVERS, libMesh::LASPACK_SOLVERS, libMesh::libmesh_ignore() , 以及 libMesh::TRILINOS_SOLVERS.

参考自 libMesh::DofMap::process_mesh_constraint_rows().

154 {
155  // Avoid unused parameter warnings when no solver packages are enabled.
156  libmesh_ignore(comm);
157 
158  if (matrix_build_type == MatrixBuildType::DIAGONAL)
159  return std::make_unique<DiagonalMatrix<T>>(comm);
160 
161  // Build the appropriate vector
162  switch (solver_package)
163  {
164 
165 #ifdef LIBMESH_HAVE_LASPACK
166  case LASPACK_SOLVERS:
167  return std::make_unique<LaspackMatrix<T>>(comm);
168 #endif
169 
170 
171 #ifdef LIBMESH_HAVE_PETSC
172  case PETSC_SOLVERS:
173  return std::make_unique<PetscMatrix<T>>(comm);
174 #endif
175 
176 
177 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
178  case TRILINOS_SOLVERS:
179  return std::make_unique<EpetraMatrix<T>>(comm);
180 #endif
181 
182 
183 #ifdef LIBMESH_HAVE_EIGEN
184  case EIGEN_SOLVERS:
185  return std::make_unique<EigenSparseMatrix<T>>(comm);
186 #endif
187 
188  default:
189  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
190  }
191 }
EIGEN_SOLVERS
Definition: libmesh.C:249
TRILINOS_SOLVERS
Definition: libmesh.C:247
void libmesh_ignore(const Args &...)
LASPACK_SOLVERS
Definition: libmesh.C:251
template<typename T >
void libMesh::EigenSparseMatrix< T >::clear ( )
overridevirtual

恢复 SparseMatrix<T> 到原始状态。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C172 行定义.

参考 libMesh::libMeshPrivateData::_is_initialized.

173 {
174  _mat.resize(0,0);
175 
176  _closed = false;
177  this->_is_initialized = false;
178 }
bool _closed
指示矩阵是否已关闭的标志。
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
bool _is_initialized
标志,指示矩阵是否已初始化。
template<typename T >
std::unique_ptr< SparseMatrix< T > > libMesh::EigenSparseMatrix< T >::clone ( ) const
overridevirtual
返回
此矩阵的副本的智能指针。
注解
这必须在派生类中覆盖。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C214 行定义.

215 {
216  return std::make_unique<EigenSparseMatrix<T>>(*this);
217 }
template<typename T>
virtual void libMesh::EigenSparseMatrix< T >::close ( )
inlineoverridevirtual

调用 SparseMatrix 的内部装配例程,确保值在处理器之间保持一致。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.h103 行定义.

参考 libMesh::EigenSparseMatrix< T >::_closed.

103 { this->_closed = true; }
bool _closed
指示矩阵是否已关闭的标志。
template<typename T>
virtual bool libMesh::EigenSparseMatrix< T >::closed ( ) const
inlineoverridevirtual
返回
如果矩阵已经组装,则为 true。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.h137 行定义.

参考 libMesh::EigenSparseMatrix< T >::_closed.

137 { return _closed; }
bool _closed
指示矩阵是否已关闭的标志。
template<typename T>
virtual void libMesh::SparseMatrix< T >::create_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
) const
inlinevirtualinherited

此函数创建一个名为 "submatrix" 的矩阵,其定义由 "rows" 和 "cols" 条目中的行和列索引给定。 目前,此操作仅对 PetscMatrix 类型定义。 注意:rowscols 向量需要排序; 如果 rowscols 向量未排序,则使用下面的 nosort 版本; rowscols 仅包含由此处理器拥有的索引。

在文件 sparse_matrix.h388 行定义.

参考 libMesh::SparseMatrix< T >::_get_submatrix().

391  {
392  this->_get_submatrix(submatrix,
393  rows,
394  cols,
395  false); // false means DO NOT REUSE submatrix
396  }
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
创建子矩阵和 reinit_submatrix 例程的受保护实现。
template<typename T>
virtual void libMesh::SparseMatrix< T >::create_submatrix_nosort ( SparseMatrix< T > &  ,
const std::vector< numeric_index_type > &  ,
const std::vector< numeric_index_type > &   
) const
inlinevirtualinherited

与上述函数类似,此函数创建由 rowscols 向量中的索引定义的 submatrix。 注意:rowscols 可以是无序的; 如果索引已排序,则对于效率更高的操作,请使用上面的函数; rowscols 可以包含由其他处理器拥有的索引。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h404 行定义.

407  {
408  libmesh_not_implemented();
409  }
void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

在文件 reference_counter.C100 行定义.

参考 libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = false;
103  return;
104 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

在文件 reference_counter.C94 行定义.

参考 libMesh::ReferenceCounter::_enable_print_counter.

95 {
96  _enable_print_counter = true;
97  return;
98 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
template<typename T>
virtual void libMesh::SparseMatrix< T >::flush ( )
inlinevirtualinherited

对于 PETSc 矩阵,此函数类似于 close,但不收缩内存。 当我们希望在 ADD_VALUES 和 INSERT_VALUES 之间切换时,这很有用。 在使用矩阵之前应该调用 close。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h202 行定义.

参考 libMesh::SparseMatrix< T >::close().

202 { close(); }
virtual void close()=0
调用 SparseMatrix 的内部装配例程,确保值在处理器之间保持一致。
template<typename T >
void libMesh::EigenSparseMatrix< T >::get_diagonal ( NumericVector< T > &  dest) const
overridevirtual

复制矩阵的对角线部分到 dest。

参数
dest存储对角线的目标 NumericVector。
注解
此函数将矩阵的对角线部分复制到 NumericVector dest 中。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C143 行定义.

参考 libMesh::EigenSparseVector< T >::_vec.

144 {
145  EigenSparseVector<T> & dest = cast_ref<EigenSparseVector<T> &>(dest_in);
146 
147  dest._vec = _mat.diagonal();
148 }
friend class EigenSparseVector< T >
使其他 Eigen 数据类型成为友元类。
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

在文件 reference_counter.C47 行定义.

参考 libMesh::ReferenceCounter::_counts.

参考自 libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (const auto & [name, cd] : _counts)
59  oss << "| " << name << " reference count information:\n"
60  << "| Creations: " << cd.first << '\n'
61  << "| Destructions: " << cd.second << '\n';
62 
63  oss << " ---------------------------------------------------------------------------- \n";
64 
65  return oss.str();
66 
67 #else
68 
69  return "";
70 
71 #endif
72 }
static Counts _counts
Actually holds the data.
template<typename T>
virtual void libMesh::SparseMatrix< T >::get_row ( numeric_index_type  ,
std::vector< numeric_index_type > &  ,
std::vector< T > &   
) const
inlinevirtualinherited

从矩阵获取一行。

参数
i要获取的矩阵行
indices将填充为与(可能)非零值对应的列索引的容器
values包含列值的容器
注解
此函数检索矩阵的一行,并将提供的容器填充为列索引和值。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h469 行定义.

472  {
473  libmesh_not_implemented();
474  }
template<typename T >
void libMesh::EigenSparseMatrix< T >::get_transpose ( SparseMatrix< T > &  dest) const
overridevirtual

将矩阵的转置复制到 dest 中,dest 可能是 *this。

参数
dest存储转置的目标 SparseMatrix。
注解
此函数将矩阵的转置复制到 SparseMatrix dest 中。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C153 行定义.

参考 libMesh::EigenSparseMatrix< T >::_mat.

154 {
155  EigenSparseMatrix<T> & dest = cast_ref<EigenSparseMatrix<T> &>(dest_in);
156 
157  dest._mat = _mat.transpose();
158 }
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

在文件 reference_counter.h183 行定义.

参考 libMesh::err.

参考自 libMesh::ReferenceCountedObject< SparseMatrix< T > >::ReferenceCountedObject().

184 {
185  libmesh_try
186  {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189  p.first++;
190  }
191  libmesh_catch (...)
192  {
193  auto stream = libMesh::err.get();
194  stream->exceptions(stream->goodbit); // stream must not throw
195  libMesh::err << "Encountered unrecoverable error while calling "
196  << "ReferenceCounter::increment_constructor_count() "
197  << "for a(n) " << name << " object." << std::endl;
198  std::terminate();
199  }
200 }
OStreamProxy err
static Counts _counts
Actually holds the data.
void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

在文件 reference_counter.h207 行定义.

参考 libMesh::err.

参考自 libMesh::ReferenceCountedObject< SparseMatrix< T > >::~ReferenceCountedObject().

208 {
209  libmesh_try
210  {
211  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212  std::pair<unsigned int, unsigned int> & p = _counts[name];
213  p.second++;
214  }
215  libmesh_catch (...)
216  {
217  auto stream = libMesh::err.get();
218  stream->exceptions(stream->goodbit); // stream must not throw
219  libMesh::err << "Encountered unrecoverable error while calling "
220  << "ReferenceCounter::increment_destructor_count() "
221  << "for a(n) " << name << " object." << std::endl;
222  std::terminate();
223  }
224 }
OStreamProxy err
static Counts _counts
Actually holds the data.
template<typename T>
virtual void libMesh::EigenSparseMatrix< T >::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 
)
overridevirtual

使用指定的大小初始化 SparseMatrix。

参数
m全局行数。
n全局列数。
m_l本地行数。
n_l本地列数。
nnz每行的对角线非零元素数(默认为 30)。
noz每行的非对角线非零元素数(默认为 10)。
blocksize用于具有多个相同类型变量的系统的稠密耦合块的可选值。

实现了 libMesh::SparseMatrix< T >.

template<typename T >
void libMesh::EigenSparseMatrix< T >::init ( ParallelType  type = PARALLEL)
overridevirtual

使用由 dof_map 计算的稀疏性结构初始化此矩阵。

参数
type矩阵的串行/并行/幽灵类型
注解
此函数使用由 dof_map 计算的稀疏性结构初始化矩阵。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C65 行定义.

参考 libMesh::libMeshPrivateData::_is_initialized , 以及 libMesh::initialized().

66 {
67  // Ignore calls on initialized objects
68  if (this->initialized())
69  return;
70 
71  // We need the DofMap for this!
72  libmesh_assert(this->_dof_map);
73 
74  // Clear initialized matrices
75  if (this->initialized())
76  this->clear();
77 
78  const numeric_index_type n_rows = this->_dof_map->n_dofs();
79  const numeric_index_type n_cols = n_rows;
80 
81 #ifndef NDEBUG
82  // The following variables are only used for assertions,
83  // so avoid declaring them when asserts are inactive.
84  const numeric_index_type n_l = this->_dof_map->n_dofs_on_processor(0);
85  const numeric_index_type m_l = n_l;
86 #endif
87 
88  // Laspack Matrices only work for uniprocessor cases
89  libmesh_assert_equal_to (n_rows, n_cols);
90  libmesh_assert_equal_to (m_l, n_rows);
91  libmesh_assert_equal_to (n_l, n_cols);
92 
93  const std::vector<numeric_index_type> & n_nz = this->_sp->get_n_nz();
94 
95 #ifndef NDEBUG
96  // The following variables are only used for assertions,
97  // so avoid declaring them when asserts are inactive.
98  const std::vector<numeric_index_type> & n_oz = this->_sp->get_n_oz();
99 #endif
100 
101  // Make sure the sparsity pattern isn't empty
102  libmesh_assert_equal_to (n_nz.size(), n_l);
103  libmesh_assert_equal_to (n_oz.size(), n_l);
104 
105  if (n_rows==0)
106  {
107  _mat.resize(0,0);
108  return;
109  }
110 
111  _mat.resize(n_rows,n_cols);
112  _mat.reserve(n_nz);
113 
114  this->_is_initialized = true;
115 
116  libmesh_assert_equal_to (n_rows, this->m());
117  libmesh_assert_equal_to (n_cols, this->n());
118 }
virtual numeric_index_type m() const override
SparsityPattern::Build const * _sp
与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。
dof_id_type n_dofs() const
Definition: dof_map.h:659
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:675
const std::vector< dof_id_type > & get_n_oz() const
The number of off-processor nonzeros in my portion of the global matrix.
virtual bool initialized() const
virtual numeric_index_type n() const override
dof_id_type numeric_index_type
Definition: id_types.h:99
bool _is_initialized
标志,指示矩阵是否已初始化。
const std::vector< dof_id_type > & get_n_nz() const
The number of on-processor nonzeros in my portion of the global matrix.
DofMap const * _dof_map
与此对象关联的 DofMap 对象。可以查询其在处理器上的自由度计数。
virtual void clear() override
恢复 SparseMatrix&lt;T&gt; 到原始状态。
template<typename T>
virtual bool libMesh::SparseMatrix< T >::initialized ( ) const
inlinevirtualinherited
返回
如果矩阵已初始化,则为 true,否则为 false。

在文件 sparse_matrix.h102 行定义.

参考 libMesh::SparseMatrix< T >::_is_initialized.

参考自 libMesh::PetscMatrix< T >::_get_submatrix().

102 { return _is_initialized; }
bool _is_initialized
标志,指示矩阵是否已初始化。
template<typename T >
Real libMesh::EigenSparseMatrix< T >::l1_norm ( ) const
overridevirtual

获取矩阵的 $ \ell_1 $-范数,即最大列和: $ |M|_1 = \max_{j} \sum_{i} |M_{ij}| $

这是与向量的 $ \ell_1 $-范数兼容的自然矩阵范数,即 $ |Mv|_1 \leq |M|_1 |v|_1 $。 (参见 Haemmerlin-Hoffmann:Numerische Mathematik)

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C324 行定义.

参考 std::abs().

325 {
326  // There does not seem to be a straightforward way to iterate over
327  // the columns of an EigenSparseMatrix. So we use some extra
328  // storage and keep track of the column sums while going over the
329  // row entries...
330  std::vector<Real> abs_col_sums(this->n());
331 
332  // For a row-major Eigen SparseMatrix like we're using, the
333  // InnerIterator iterates over the non-zero entries of rows.
334  for (auto row : make_range(this->m()))
335  {
336  EigenSM::InnerIterator it(_mat, row);
337  for (; it; ++it)
338  abs_col_sums[it.col()] += std::abs(it.value());
339  }
340 
341  return *(std::max_element(abs_col_sums.begin(), abs_col_sums.end()));
342 }
virtual numeric_index_type m() const override
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
virtual numeric_index_type n() const override
template<typename T >
Real libMesh::EigenSparseMatrix< T >::linfty_norm ( ) const
overridevirtual

获取矩阵的 $ \ell_{\infty} $-范数,即最大行和:

$ |M|_{\infty} = \max_{i} \sum_{j} |M_{ij}| $

这是与向量的 $ \ell_{\infty} $-范数兼容的自然矩阵范数,即 $ |Mv|_{\infty} \leq |M|_{\infty} |v|_{\infty} $。 (参见 Haemmerlin-Hoffmann:Numerische Mathematik)

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C347 行定义.

参考 std::abs() , 以及 libMesh::Real.

348 {
349  Real max_abs_row_sum = 0.;
350 
351  // For a row-major Eigen SparseMatrix like we're using, the
352  // InnerIterator iterates over the non-zero entries of rows.
353  for (auto row : make_range(this->m()))
354  {
355  Real current_abs_row_sum = 0.;
356  EigenSM::InnerIterator it(_mat, row);
357  for (; it; ++it)
358  current_abs_row_sum += std::abs(it.value());
359 
360  max_abs_row_sum = std::max(max_abs_row_sum, current_abs_row_sum);
361  }
362 
363  return max_abs_row_sum;
364 }
virtual numeric_index_type m() const override
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
Definition: type_vector.h:112
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template<typename T>
virtual numeric_index_type libMesh::SparseMatrix< T >::local_m ( ) const
inlinevirtualinherited

获取此进程拥有的行数。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h212 行定义.

参考 libMesh::SparseMatrix< T >::row_start() , 以及 libMesh::SparseMatrix< T >::row_stop().

212 { return row_stop() - row_start(); }
virtual numeric_index_type row_stop() const =0
virtual numeric_index_type row_start() const =0
template<typename T >
numeric_index_type libMesh::EigenSparseMatrix< T >::m ( ) const
overridevirtual
返回
矩阵的行维度。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C222 行定义.

参考 libMesh::initialized().

223 {
224  libmesh_assert (this->initialized());
225 
226  return cast_int<numeric_index_type>(_mat.rows());
227 }
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual bool initialized() const
template<typename T>
virtual void libMesh::SparseMatrix< T >::matrix_matrix_mult ( SparseMatrix< T > &  ,
SparseMatrix< T > &  ,
bool   
)
inlinevirtualinherited

计算 Y = A*X,其中 X 为矩阵。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h290 行定义.

291  { libmesh_not_implemented(); }
template<typename T >
numeric_index_type libMesh::EigenSparseMatrix< T >::n ( ) const
overridevirtual
返回
矩阵的列维度。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C232 行定义.

参考 libMesh::initialized().

233 {
234  libmesh_assert (this->initialized());
235 
236  return cast_int<numeric_index_type>(_mat.cols());
237 }
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual bool initialized() const
static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

在文件 reference_counter.h85 行定义.

参考 libMesh::ReferenceCounter::_n_objects.

参考自 libMesh::LibMeshInit::~LibMeshInit().

86  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.
template<typename T>
virtual bool libMesh::SparseMatrix< T >::need_full_sparsity_pattern ( ) const
inlinevirtualinherited
返回
如果此稀疏矩阵格式需要提供稀疏矩阵的图形,则为 true。

这对于 LaspackMatrix 是 true,但对于 PetscMatrix 是 false。 在不需要完整图形的情况下,我们可以有效地近似它以提供对稀疏矩阵所需大小的良好估计。

libMesh::EpetraMatrix< T > , 以及 libMesh::LaspackMatrix< T > 重载.

在文件 sparse_matrix.h126 行定义.

参考自 libMesh::DofMap::attach_matrix() , 以及 libMesh::DofMap::update_sparsity_pattern().

127  { return false; }
template<typename T >
T libMesh::EigenSparseMatrix< T >::operator() ( const numeric_index_type  i,
const numeric_index_type  j 
) const
overridevirtual
返回
矩阵条目 (i,j) 的副本。
注解
这可能是一个昂贵的操作,您应该谨慎调用此函数。
参数
i行索引。
j列索引。
返回
位于位置 (i,j) 的矩阵条目的副本。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C311 行定义.

参考 libMesh::initialized().

313 {
314  libmesh_assert (this->initialized());
315  libmesh_assert_less (i, this->m());
316  libmesh_assert_less (j, this->n());
317 
318  return _mat.coeff(i,j);
319 }
virtual numeric_index_type m() const override
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual bool initialized() const
virtual numeric_index_type n() const override
template<typename T>
EigenSparseMatrix& libMesh::EigenSparseMatrix< T >::operator= ( const EigenSparseMatrix< T > &  )
default
template<typename T>
EigenSparseMatrix& libMesh::EigenSparseMatrix< T >::operator= ( EigenSparseMatrix< T > &&  )
default
template<>
void libMesh::SparseMatrix< Complex >::print ( std::ostream &  os,
const bool  sparse 
) const
inherited

在文件 sparse_matrix.C117 行定义.

参考 std::imag() , 以及 std::real().

118 {
119  // std::complex<>::operator<<() is defined, but use this form
120 
121  if (sparse)
122  {
123  libmesh_not_implemented();
124  }
125 
126  os << "Real part:" << std::endl;
127  for (auto i : make_range(this->m()))
128  {
129  for (auto j : make_range(this->n()))
130  os << std::setw(8) << (*this)(i,j).real() << " ";
131  os << std::endl;
132  }
133 
134  os << std::endl << "Imaginary part:" << std::endl;
135  for (auto i : make_range(this->m()))
136  {
137  for (auto j : make_range(this->n()))
138  os << std::setw(8) << (*this)(i,j).imag() << " ";
139  os << std::endl;
140  }
141 }
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
virtual numeric_index_type m() const =0
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
virtual numeric_index_type n() const =0
template<typename T >
void libMesh::SparseMatrix< T >::print ( std::ostream &  os = libMesh::out,
const bool  sparse = false 
) const
inherited

将矩阵的内容以统一的样式打印到屏幕上,而不考虑正在使用的矩阵/求解器包。

在文件 sparse_matrix.C225 行定义.

参考 libMesh::initialized().

参考自 libMesh::EigenSparseMatrix< T >::print_personal() , 以及 libMesh::LaspackMatrix< T >::print_personal().

226 {
227  parallel_object_only();
228 
229  libmesh_assert (this->initialized());
230 
231  libmesh_error_msg_if(!this->_dof_map, "Error! Trying to print a matrix with no dof_map set!");
232 
233  // We'll print the matrix from processor 0 to make sure
234  // it's serialized properly
235  if (this->processor_id() == 0)
236  {
237  libmesh_assert_equal_to (this->_dof_map->first_dof(), 0);
238  for (numeric_index_type i=this->_dof_map->first_dof();
239  i!=this->_dof_map->end_dof(); ++i)
240  {
241  if (sparse)
242  {
243  for (auto j : make_range(this->n()))
244  {
245  T c = (*this)(i,j);
246  if (c != static_cast<T>(0.0))
247  {
248  os << i << " " << j << " " << c << std::endl;
249  }
250  }
251  }
252  else
253  {
254  for (auto j : make_range(this->n()))
255  os << (*this)(i,j) << " ";
256  os << std::endl;
257  }
258  }
259 
260  std::vector<numeric_index_type> ibuf, jbuf;
261  std::vector<T> cbuf;
262  numeric_index_type currenti = this->_dof_map->end_dof();
263  for (auto p : IntRange<processor_id_type>(1, this->n_processors()))
264  {
265  this->comm().receive(p, ibuf);
266  this->comm().receive(p, jbuf);
267  this->comm().receive(p, cbuf);
268  libmesh_assert_equal_to (ibuf.size(), jbuf.size());
269  libmesh_assert_equal_to (ibuf.size(), cbuf.size());
270 
271  if (ibuf.empty())
272  continue;
273  libmesh_assert_greater_equal (ibuf.front(), currenti);
274  libmesh_assert_greater_equal (ibuf.back(), ibuf.front());
275 
276  std::size_t currentb = 0;
277  for (;currenti <= ibuf.back(); ++currenti)
278  {
279  if (sparse)
280  {
281  for (numeric_index_type j=0; j<this->n(); j++)
282  {
283  if (currentb < ibuf.size() &&
284  ibuf[currentb] == currenti &&
285  jbuf[currentb] == j)
286  {
287  os << currenti << " " << j << " " << cbuf[currentb] << std::endl;
288  currentb++;
289  }
290  }
291  }
292  else
293  {
294  for (auto j : make_range(this->n()))
295  {
296  if (currentb < ibuf.size() &&
297  ibuf[currentb] == currenti &&
298  jbuf[currentb] == j)
299  {
300  os << cbuf[currentb] << " ";
301  currentb++;
302  }
303  else
304  os << static_cast<T>(0.0) << " ";
305  }
306  os << std::endl;
307  }
308  }
309  }
310  if (!sparse)
311  {
312  for (; currenti != this->m(); ++currenti)
313  {
314  for (numeric_index_type j=0; j<this->n(); j++)
315  os << static_cast<T>(0.0) << " ";
316  os << std::endl;
317  }
318  }
319  }
320  else
321  {
322  std::vector<numeric_index_type> ibuf, jbuf;
323  std::vector<T> cbuf;
324 
325  // We'll assume each processor has access to entire
326  // matrix rows, so (*this)(i,j) is valid if i is a local index.
327  for (numeric_index_type i=this->_dof_map->first_dof();
328  i!=this->_dof_map->end_dof(); ++i)
329  {
330  for (auto j : make_range(this->n()))
331  {
332  T c = (*this)(i,j);
333  if (c != static_cast<T>(0.0))
334  {
335  ibuf.push_back(i);
336  jbuf.push_back(j);
337  cbuf.push_back(c);
338  }
339  }
340  }
341  this->comm().send(0,ibuf);
342  this->comm().send(0,jbuf);
343  this->comm().send(0,cbuf);
344  }
345 }
virtual bool initialized() const
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:684
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:708
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual numeric_index_type m() const =0
DofMap const * _dof_map
与此对象关联的 DofMap 对象。可以查询其在处理器上的自由度计数。
virtual numeric_index_type n() const =0
void libMesh::ReferenceCounter::print_info ( std::ostream &  out_stream = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

在文件 reference_counter.C81 行定义.

参考 libMesh::ReferenceCounter::_enable_print_counter , 以及 libMesh::ReferenceCounter::get_info().

参考自 libMesh::LibMeshInit::~LibMeshInit().

82 {
84  out_stream << ReferenceCounter::get_info();
85 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...
template<typename T>
virtual void libMesh::SparseMatrix< T >::print_matlab ( const std::string &  = "") const
inlinevirtualinherited

以 Matlab 的稀疏矩阵格式打印矩阵的内容。可选择将矩阵打印到名为 name 的文件中。 如果未指定 name ,则将其转储到屏幕上。

libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.h376 行定义.

377  {
378  libmesh_not_implemented();
379  }
template<typename T>
virtual void libMesh::EigenSparseMatrix< T >::print_personal ( std::ostream &  os = libMesh::out) const
inlineoverridevirtual

以个性化的风格(如果可用)将矩阵的内容打印到屏幕上。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.h139 行定义.

参考 libMesh::SparseMatrix< T >::print().

139 { this->print(os); }
void print(std::ostream &os=libMesh::out, const bool sparse=false) const
将矩阵的内容以统一的样式打印到屏幕上,而不考虑正在使用的矩阵/求解器包。
template<typename T>
virtual void libMesh::SparseMatrix< T >::reinit_submatrix ( SparseMatrix< T > &  submatrix,
const std::vector< numeric_index_type > &  rows,
const std::vector< numeric_index_type > &  cols 
) const
inlinevirtualinherited

此函数与上述函数类似,但允许您重用 "submatrix" 的现有稀疏性模式,而不是再次分配它。 如果经常提取相同大小的子矩阵,这应该更有效。

在文件 sparse_matrix.h415 行定义.

参考 libMesh::SparseMatrix< T >::_get_submatrix().

418  {
419  this->_get_submatrix(submatrix,
420  rows,
421  cols,
422  true); // true 表示重用 submatrix
423  }
virtual void _get_submatrix(SparseMatrix< T > &, const std::vector< numeric_index_type > &, const std::vector< numeric_index_type > &, const bool) const
创建子矩阵和 reinit_submatrix 例程的受保护实现。
template<typename T >
numeric_index_type libMesh::EigenSparseMatrix< T >::row_start ( ) const
overridevirtual
返回
存储在此处理器上的第一个矩阵行的索引。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C242 行定义.

243 {
244  return 0;
245 }
template<typename T >
numeric_index_type libMesh::EigenSparseMatrix< T >::row_stop ( ) const
overridevirtual
返回
存储在此处理器上的最后一个矩阵行(+1)的索引。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C250 行定义.

251 {
252  return this->m();
253 }
virtual numeric_index_type m() const override
template<typename T >
void libMesh::EigenSparseMatrix< T >::set ( const numeric_index_type  i,
const numeric_index_type  j,
const T  value 
)
overridevirtual

设置元素 (i,j) 为 value .

如果条目不存在,则抛出错误。 可以将零值“存储”在不存在的字段中。

参数
i矩阵行索引
j矩阵列索引
value元素的值

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C258 行定义.

参考 libMesh::initialized().

261 {
262  libmesh_assert (this->initialized());
263  libmesh_assert_less (i, this->m());
264  libmesh_assert_less (j, this->n());
265 
266  _mat.coeffRef(i,j) = value;
267 }
virtual numeric_index_type m() const override
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
virtual bool initialized() const
virtual numeric_index_type n() const override
template<typename T>
virtual void libMesh::SparseMatrix< T >::update_sparsity_pattern ( const SparsityPattern::Graph )
inlinevirtualinherited

更新矩阵的稀疏性模式。当您的 SparseMatrix<T> 实现不需要此数据时, 只需不覆盖此方法。

libMesh::EpetraMatrix< T > , 以及 libMesh::LaspackMatrix< T > 重载.

在文件 sparse_matrix.h133 行定义.

参考自 libMesh::DofMap::update_sparsity_pattern().

133 {}
template<typename T >
void libMesh::SparseMatrix< T >::vector_mult ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
inherited

将矩阵乘以 NumericVector arg 并将结果存储在 NumericVector dest 中。

参数
dest存储结果的目标 NumericVector。
arg乘法的源 NumericVector。
注解
此函数将矩阵乘以 NumericVector arg 并将结果存储在 dest 中。

在文件 sparse_matrix.C195 行定义.

参考 libMesh::NumericVector< T >::zero().

197 {
198  dest.zero();
199  this->vector_mult_add(dest,arg);
200 }
void vector_mult_add(NumericVector< T > &dest, const NumericVector< T > &arg) const
将矩阵乘以 NumericVector arg ,并将结果添加到 NumericVector dest 中。
template<typename T >
void libMesh::SparseMatrix< T >::vector_mult_add ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
inherited

将矩阵乘以 NumericVector arg ,并将结果添加到 NumericVector dest 中。

在文件 sparse_matrix.C205 行定义.

参考 libMesh::NumericVector< T >::add_vector().

207 {
208  /* This functionality is actually implemented in the \p
209  NumericVector class. */
210  dest.add_vector(arg,*this);
211 }
template<typename T >
void libMesh::EigenSparseMatrix< T >::zero ( )
overridevirtual

将所有条目设置为 0。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C183 行定义.

184 {
185  // This doesn't just zero, it clears the entire non-zero structure!
186  _mat.setZero();
187 
188  if (this->_sp)
189  {
190  // Re-reserve our non-zero structure
191  const std::vector<numeric_index_type> & n_nz = this->_sp->get_n_nz();
192  _mat.reserve(n_nz);
193  }
194 }
SparsityPattern::Build const * _sp
与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。
DataType _mat
实际的 Eigen::SparseMatrix&lt;&gt; 对象。
const std::vector< dof_id_type > & get_n_nz() const
The number of on-processor nonzeros in my portion of the global matrix.
template<typename T >
std::unique_ptr< SparseMatrix< T > > libMesh::EigenSparseMatrix< T >::zero_clone ( ) const
overridevirtual
返回
具有相同类型、大小和分区的此矩阵的零条目的副本的智能指针。
注解
这必须在派生类中覆盖。

实现了 libMesh::SparseMatrix< T >.

在文件 eigen_sparse_matrix.C199 行定义.

200 {
201  // TODO: If there is a more efficient way to make a zeroed-out copy
202  // of an EigenSM, we should call that instead.
203  auto ret = std::make_unique<EigenSparseMatrix<T>>(*this);
204  ret->zero();
205 
206  // Work around an issue on older compilers. We are able to simply
207  // "return ret;" on newer compilers
208  return std::unique_ptr<SparseMatrix<T>>(ret.release());
209 }
template<typename T >
void libMesh::SparseMatrix< T >::zero_rows ( std::vector< numeric_index_type > &  rows,
diag_value = 0.0 
)
virtualinherited

将所有行条目设置为 0,然后将 diag_value 放在对角线条目。

libMesh::DiagonalMatrix< T > , 以及 libMesh::PetscMatrix< T > 重载.

在文件 sparse_matrix.C216 行定义.

217 {
218  /* This functionality isn't implemented or stubbed in every subclass yet */
219  libmesh_not_implemented();
220 }

友元及相关函数文档

template<typename T>
friend class EigenSparseLinearSolver< T >
friend

在文件 eigen_sparse_matrix.h161 行定义.

template<typename T>
friend class EigenSparseVector< T >
friend

使其他 Eigen 数据类型成为友元类。

在文件 eigen_sparse_matrix.h160 行定义.

类成员变量说明

template<typename T>
bool libMesh::EigenSparseMatrix< T >::_closed
private

指示矩阵是否已关闭的标志。

在文件 eigen_sparse_matrix.h155 行定义.

参考自 libMesh::EigenSparseMatrix< T >::close() , 以及 libMesh::EigenSparseMatrix< T >::closed().

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

Actually holds the data.

在文件 reference_counter.h124 行定义.

参考自 libMesh::ReferenceCounter::get_info().

template<typename T>
DofMap const* libMesh::SparseMatrix< T >::_dof_map
protectedinherited

与此对象关联的 DofMap 对象。可以查询其在处理器上的自由度计数。

在文件 sparse_matrix.h494 行定义.

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

在文件 reference_counter.h143 行定义.

参考自 libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info() , 以及 libMesh::ReferenceCounter::print_info().

template<typename T>
bool libMesh::SparseMatrix< T >::_is_initialized
protectedinherited
template<typename T>
DataType libMesh::EigenSparseMatrix< T >::_mat
private

实际的 Eigen::SparseMatrix<> 对象。

在文件 eigen_sparse_matrix.h150 行定义.

参考自 libMesh::EigenSparseMatrix< T >::add() , 以及 libMesh::EigenSparseMatrix< T >::get_transpose().

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

在文件 reference_counter.h137 行定义.

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

在文件 reference_counter.h132 行定义.

参考自 libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter() , 以及 libMesh::ReferenceCounter::~ReferenceCounter().

template<typename T>
SparsityPattern::Build const* libMesh::SparseMatrix< T >::_sp
protectedinherited

与此对象关联的 sparsity pattern。在需要时, 应查询其入口计数(或使用 need_full_sparsity_pattern,模式)。

在文件 sparse_matrix.h500 行定义.


该类的文档由以下文件生成: