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

这个类允许使用 PETSc shell 矩阵。 所有覆盖的虚拟函数都在 shell_matrix.h 中有文档说明。 更多...

#include <petsc_shell_matrix.h>

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

Public 成员函数

 PetscShellMatrix (const Parallel::Communicator &comm_in)
 构造函数。 更多...
 
virtual ~PetscShellMatrix ()=default
 默认虚拟析构函数。 更多...
 
virtual numeric_index_type m () const override
 获取矩阵的行数。 更多...
 
virtual numeric_index_type n () const override
 获取矩阵的列数。 更多...
 
virtual numeric_index_type local_m () const
 获取本地处理的矩阵行数。 更多...
 
virtual numeric_index_type local_n () const
 获取本地处理的矩阵列数。 更多...
 
virtual void vector_mult (NumericVector< T > &dest, const NumericVector< T > &arg) const override
 执行矩阵与向量的乘法。 更多...
 
virtual void vector_mult_add (NumericVector< T > &dest, const NumericVector< T > &arg) const override
 执行矩阵与向量的乘法,并将结果添加到目标向量。 更多...
 
virtual void get_diagonal (NumericVector< T > &dest) const override
 获取矩阵的对角线。 更多...
 
virtual void clear () override
 清除矩阵的内部数据结构。 更多...
 
virtual void init () override
 初始化矩阵。 更多...
 
virtual bool initialized () const
 检查矩阵是否已初始化。 更多...
 
Mat mat ()
 返回指向底层 PETSc Mat 对象的指针。调用此函数前必须调用 init()更多...
 
void attach_dof_map (const DofMap &dof_map)
 附加要使用的 DofMap 指针。 更多...
 

静态 Public 成员函数

static std::unique_ptr
< ShellMatrix< T > > 
build (const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
 使用指定的线性求解器包构建一个 ShellMatrix<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 成员函数

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 属性

WrappedPetsc< Mat > _mat
 PETSc Shell 矩阵。 更多...
 
bool _is_initialized
 表示矩阵是否已初始化的标志。 更多...
 
DofMap const * _dof_map
 与此对象关联的 DofMap 对象。 更多...
 

静态 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. 更多...
 

详细描述

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

这个类允许使用 PETSc shell 矩阵。 所有覆盖的虚拟函数都在 shell_matrix.h 中有文档说明。

作者
Fande Kong (fdkong.jd.com)
日期
2019

在文件 petsc_shell_matrix.h57 行定义.

成员类型定义说明

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 >
libMesh::PetscShellMatrix< T >::PetscShellMatrix ( const Parallel::Communicator &  comm_in)
inline

构造函数。

参数
comm_in用于初始化的并行通信器。

在文件 petsc_shell_matrix.h168 行定义.

168  :
169  ShellMatrix<T>(comm_in),
170  _is_initialized(false)
171 {}
bool _is_initialized
表示矩阵是否已初始化的标志。
template<typename T >
virtual libMesh::PetscShellMatrix< T >::~PetscShellMatrix ( )
virtualdefault

默认虚拟析构函数。

成员函数说明

template<typename T>
void libMesh::ShellMatrix< T >::attach_dof_map ( const DofMap dof_map)
inlineinherited

附加要使用的 DofMap 指针。

参数
dof_map要附加的 DofMap 对象

在文件 shell_matrix.h120 行定义.

参考 libMesh::ShellMatrix< T >::_dof_map.

121  { _dof_map = &dof_map; }
DofMap const * _dof_map
与此对象关联的 DofMap 对象。
Definition: shell_matrix.h:141
template<typename T >
std::unique_ptr< ShellMatrix< T > > libMesh::ShellMatrix< T >::build ( const Parallel::Communicator &  comm,
const SolverPackage  solver_package = libMesh::default_solver_package() 
)
staticinherited

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

参数
comm通信器对象
solver_package线性求解器包
返回
返回一个包含 ShellMatrix<T> 的 std::unique_ptr

在文件 shell_matrix.C32 行定义.

参考 libMesh::libmesh_ignore().

34  {
35  // Avoid unused parameter warnings when no solver packages are enabled.
36  libmesh_ignore(comm);
37 
38  // Build the appropriate vector
39  switch (solver_package)
40  {
41  #ifdef LIBMESH_HAVE_PETSC
42  case PETSC_SOLVERS:
43  return std::make_unique<PetscShellMatrix<T>>(comm);
44  #endif
45 
46  default:
47  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
48  }
49  }
void libmesh_ignore(const Args &...)
template<typename T >
void libMesh::PetscShellMatrix< T >::clear ( )
overridevirtual

清除矩阵的内部数据结构。

重载 libMesh::ShellMatrix< T > .

在文件 petsc_shell_matrix.C53 行定义.

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

54 {
55  if (this->initialized())
56  {
57  _mat.destroy();
58  this->_is_initialized = false;
59  }
60 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
virtual bool initialized() const
检查矩阵是否已初始化。
bool _is_initialized
表示矩阵是否已初始化的标志。
void destroy()
必须特例化以调用适当的XXXDestroy()例程,以便实例化WrappedPetsc&lt;T&gt;对象。
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 >
void libMesh::PetscShellMatrix< T >::get_diagonal ( NumericVector< T > &  dest) const
inlineoverridevirtual

获取矩阵的对角线。

参数
dest存储对角线的向量。

实现了 libMesh::ShellMatrix< T >.

在文件 petsc_shell_matrix.h235 行定义.

参考 libMesh::PetscVector< T >::vec().

236 {
237  // 确保传入的NumericVector确实是PetscVector
238  PetscVector<T> & petsc_dest = cast_ref<PetscVector<T> &>(dest);
239 
240  PetscErrorCode ierr = MatGetDiagonal(_mat, petsc_dest.vec());
241  LIBMESH_CHKERR(ierr);
242 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
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.
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 >
void libMesh::PetscShellMatrix< T >::init ( )
overridevirtual

初始化矩阵。

重载 libMesh::ShellMatrix< T > .

在文件 petsc_shell_matrix.C64 行定义.

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

65 {
66  libmesh_assert(this->_dof_map);
67 
68  // Clear initialized matrices
69  if (this->initialized())
70  this->clear();
71 
72  this->_is_initialized = true;
73 
74 
75  const numeric_index_type my_m = this->_dof_map->n_dofs();
76  const numeric_index_type my_n = my_m;
77  const numeric_index_type n_l = this->_dof_map->n_dofs_on_processor(this->processor_id());
78  const numeric_index_type m_l = n_l;
79 
80 
81  PetscErrorCode ierr = 0;
82  PetscInt m_global = static_cast<PetscInt>(my_m);
83  PetscInt n_global = static_cast<PetscInt>(my_n);
84  PetscInt m_local = static_cast<PetscInt>(m_l);
85  PetscInt n_local = static_cast<PetscInt>(n_l);
86 
87  ierr = MatCreate(this->comm().get(), _mat.get());
88  LIBMESH_CHKERR(ierr);
89  ierr = MatSetSizes(_mat, m_local, n_local, m_global, n_global);
90  LIBMESH_CHKERR(ierr);
91  PetscInt blocksize = static_cast<PetscInt>(this->_dof_map->block_size());
92  ierr = MatSetBlockSize(_mat, blocksize);
93  LIBMESH_CHKERR(ierr);
94 
95  ierr = MatSetType(_mat, MATSHELL);
96  LIBMESH_CHKERR(ierr);
97 
98  // Is prefix information available somewhere? Perhaps pass in the system name?
99  ierr = MatSetOptionsPrefix(_mat, "");
100  LIBMESH_CHKERR(ierr);
101  ierr = MatSetFromOptions(_mat);
102  LIBMESH_CHKERR(ierr);
103  ierr = MatSetUp(_mat);
104  LIBMESH_CHKERR(ierr);
105 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
virtual bool initialized() const
检查矩阵是否已初始化。
virtual void clear() override
清除矩阵的内部数据结构。
unsigned int block_size() const
Definition: dof_map.h:651
dof_id_type n_dofs() const
Definition: dof_map.h:659
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:675
dof_id_type numeric_index_type
Definition: id_types.h:99
bool _is_initialized
表示矩阵是否已初始化的标志。
DofMap const * _dof_map
与此对象关联的 DofMap 对象。
Definition: shell_matrix.h:141
T * get()
获取托管对象的指针。 这用于模拟以下代码: KSP ksp; KSPCreate(comm, &amp;ksp); 因为在这种上下文中,取包装对象的地址是没有意义的。
template<typename T >
bool libMesh::PetscShellMatrix< T >::initialized ( ) const
virtual

检查矩阵是否已初始化。

返回
如果矩阵已初始化,则返回 true;否则返回 false。

在文件 petsc_shell_matrix.C108 行定义.

参考 libMesh::libMeshPrivateData::_is_initialized.

109 {
110  return _is_initialized;
111 }
bool _is_initialized
表示矩阵是否已初始化的标志。
template<typename T >
numeric_index_type libMesh::PetscShellMatrix< T >::local_m ( ) const
inlinevirtual

获取本地处理的矩阵行数。

返回
返回本地处理的矩阵行数。

在文件 petsc_shell_matrix.h206 行定义.

207 {
208  PetscErrorCode ierr;
209  PetscInt m;
210 
211  ierr = MatGetLocalSize(_mat, &m, nullptr);
212  LIBMESH_CHKERR(ierr);
213 
214  return m;
215 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
virtual numeric_index_type m() const override
获取矩阵的行数。
template<typename T >
numeric_index_type libMesh::PetscShellMatrix< T >::local_n ( ) const
inlinevirtual

获取本地处理的矩阵列数。

返回
返回本地处理的矩阵列数。

在文件 petsc_shell_matrix.h221 行定义.

222 {
223  PetscErrorCode ierr;
224  PetscInt n;
225 
226  ierr = MatGetLocalSize(_mat, nullptr, &n);
227  LIBMESH_CHKERR(ierr);
228 
229  return n;
230 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
virtual numeric_index_type n() const override
获取矩阵的列数。
template<typename T >
numeric_index_type libMesh::PetscShellMatrix< T >::m ( ) const
inlineoverridevirtual

获取矩阵的行数。

返回
返回矩阵的行数。

实现了 libMesh::ShellMatrix< T >.

在文件 petsc_shell_matrix.h177 行定义.

178 {
179  PetscErrorCode ierr;
180  PetscInt m;
181 
182  ierr = MatGetSize(_mat, &m, nullptr);
183  LIBMESH_CHKERR(ierr);
184 
185  return m;
186 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
virtual numeric_index_type m() const override
获取矩阵的行数。
template<typename T >
Mat libMesh::PetscShellMatrix< T >::mat ( )

返回指向底层 PETSc Mat 对象的指针。调用此函数前必须调用 init()

返回
返回 PETSc Mat 对象的指针。

在文件 petsc_shell_matrix.C114 行定义.

115 {
116  libmesh_error_msg_if(!_mat, "A petsc shell matrix is not created yet. Please call init() first.");
117  return _mat;
118 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
template<typename T >
numeric_index_type libMesh::PetscShellMatrix< T >::n ( ) const
inlineoverridevirtual

获取矩阵的列数。

返回
返回矩阵的列数。

实现了 libMesh::ShellMatrix< T >.

在文件 petsc_shell_matrix.h192 行定义.

193 {
194  PetscErrorCode ierr;
195  PetscInt n;
196 
197  ierr = MatGetSize(_mat, nullptr, &n);
198  LIBMESH_CHKERR(ierr);
199 
200  return n;
201 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
virtual numeric_index_type n() const override
获取矩阵的列数。
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.
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 >
void libMesh::PetscShellMatrix< T >::vector_mult ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
overridevirtual

执行矩阵与向量的乘法。

参数
dest结果向量。
arg输入向量。

实现了 libMesh::ShellMatrix< T >.

在文件 petsc_shell_matrix.C28 行定义.

参考 libMesh::PetscVector< T >::vec().

30 {
31  PetscVector<T> & petsc_dest = cast_ref<PetscVector<T> &>(dest);
32  const PetscVector<T> & petsc_arg = cast_ref<const PetscVector<T> &>(arg);
33 
34  PetscErrorCode ierr = MatMult(_mat, petsc_arg.vec(), petsc_dest.vec());
35  LIBMESH_CHKERR(ierr);
36 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。
template<typename T >
void libMesh::PetscShellMatrix< T >::vector_mult_add ( NumericVector< T > &  dest,
const NumericVector< T > &  arg 
) const
overridevirtual

执行矩阵与向量的乘法,并将结果添加到目标向量。

参数
dest结果向量。
arg输入向量。

实现了 libMesh::ShellMatrix< T >.

在文件 petsc_shell_matrix.C41 行定义.

参考 libMesh::PetscVector< T >::vec().

43 {
44  PetscVector<T> & petsc_dest = cast_ref<PetscVector<T> &>(dest);
45  const PetscVector<T> & petsc_arg = cast_ref<const PetscVector<T> &>(arg);
46 
47  PetscErrorCode ierr = MatMultAdd(_mat, petsc_arg.vec(), petsc_dest.vec(), petsc_dest.vec());
48  LIBMESH_CHKERR(ierr);
49 }
WrappedPetsc< Mat > _mat
PETSc Shell 矩阵。

类成员变量说明

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

Actually holds the data.

在文件 reference_counter.h124 行定义.

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

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

与此对象关联的 DofMap 对象。

在文件 shell_matrix.h141 行定义.

参考自 libMesh::ShellMatrix< T >::attach_dof_map().

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::PetscShellMatrix< T >::_is_initialized
protected

表示矩阵是否已初始化的标志。

在文件 petsc_shell_matrix.h160 行定义.

template<typename T >
WrappedPetsc<Mat> libMesh::PetscShellMatrix< T >::_mat
protected

PETSc Shell 矩阵。

在文件 petsc_shell_matrix.h155 行定义.

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().


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