libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
trilinos_preconditioner.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_TRILINOS_PRECONDITIONER_H
21 #define LIBMESH_TRILINOS_PRECONDITIONER_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
26 
27 // Local includes
28 #include "libmesh/preconditioner.h"
29 #include "libmesh/libmesh_common.h"
30 #include "libmesh/reference_counted_object.h"
31 #include "libmesh/libmesh.h"
32 
33 // Trilinos includes. Ignore many unused parameter warnings coming
34 // from these headers.
35 #include "libmesh/ignore_warnings.h"
36 #include "Epetra_Operator.h"
37 #include "Epetra_FECrsMatrix.h"
38 #include "Teuchos_ParameterList.hpp"
39 #include "libmesh/restore_warnings.h"
40 
41 // C++ includes
42 #include <cstddef>
43 
44 namespace libMesh
45 {
46 
47 // forward declarations
48 template <typename T> class SparseMatrix;
49 template <typename T> class NumericVector;
50 template <typename T> class ShellMatrix;
51 enum PreconditionerType : int;
52 
60 template <typename T>
62  public Preconditioner<T>,
63  public Epetra_Operator
64 {
65 public:
66 
72  TrilinosPreconditioner (const libMesh::Parallel::Communicator & comm);
73 
77  virtual ~TrilinosPreconditioner ();
78 
85  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) override;
86 
90  virtual void clear () override {}
91 
95  virtual void init () override;
96 
102  void set_params(Teuchos::ParameterList & list);
103 
109  Epetra_FECrsMatrix * mat() { return _mat; }
110 
118  void set_preconditioner_type (const PreconditionerType & preconditioner_type);
119 
123  void compute();
124 
125 protected:
126 
130  Epetra_Operator * _prec;
131 
135  Epetra_FECrsMatrix * _mat;
136 
140  Teuchos::ParameterList _param_list;
141 
142  // Epetra_Operator 接口
143 
144  // 设置是否使用转置操作
145  virtual int SetUseTranspose(bool UseTranspose) override;
146 
147  // 应用操作将输入向量 X 映射到输出向量 Y
148  virtual int Apply(const Epetra_MultiVector & X, Epetra_MultiVector & Y) const override;
149 
150  // 应用操作的逆操作,将输入向量 r 映射到输出向量 z
151  virtual int ApplyInverse(const Epetra_MultiVector & r, Epetra_MultiVector & z) const override;
152 
153  // 计算操作的无穷范数
154  virtual double NormInf() const override;
155 
156  // 返回操作的标签
157  virtual const char * Label() const override;
158 
159  // 返回是否使用了转置操作
160  virtual bool UseTranspose() const override;
161 
162  // 返回操作的无穷范数是否可用
163  virtual bool HasNormInf() const override;
164 
165  // 返回操作的通信器
166  virtual const Epetra_Comm & Comm() const override;
167 
168  // 返回操作的定义域映射
169  virtual const Epetra_Map & OperatorDomainMap() const override;
170 
171  // 返回操作的值域映射
172  virtual const Epetra_Map & OperatorRangeMap() const override;
173 };
174 
175 
176 
177 
178 /*----------------------- inline functions ----------------------------------*/
179 template <typename T>
180 inline
181 TrilinosPreconditioner<T>::TrilinosPreconditioner (const libMesh::Parallel::Communicator & comm) :
182  Preconditioner<T>(comm),
183  _prec(nullptr),
184  _mat(nullptr)
185 {
186 }
187 
188 
189 
190 template <typename T>
191 inline
193 {
194  this->clear ();
195 }
196 
197 } // namespace libMesh
198 
199 #endif // LIBMESH_TRILINOS_HAVE_EPETRA
200 #endif // LIBMESH_TRILINOS_PRECONDITIONER_H
void set_params(Teuchos::ParameterList &list)
存储 ParameterList list 的副本。
virtual void init() override
初始化预条件器。
virtual ~TrilinosPreconditioner()
析构函数。
TrilinosPreconditioner(const libMesh::Parallel::Communicator &comm)
构造函数。初始化 PetscPreconditioner 数据结构
Teuchos::ParameterList _param_list
用于构建预条件器的参数列表。
virtual bool HasNormInf() const override
Epetra_FECrsMatrix * mat()
返回实际的 Trilinos 预条件器对象。
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
应用预条件器。
提供了不同线性代数库的向量存储方案的统一接口。
Definition: dof_map.h:67
void set_preconditioner_type(const PreconditionerType &preconditioner_type)
根据 libMesh PreconditionerType 设置 Trilinos 预条件器。
virtual void clear() override
清除预条件器。
这个类提供了一个接口,用于使用Trilinos提供的预条件器套件。 所有重写的虚拟函数在preconditioner.h中有文档说明。
该类提供了一个统一的接口,用于预处理器。此基类可继承,以包装来自不同软件包(如 PETSc 或 Trilinos)的预处理器。
Epetra_FECrsMatrix * _mat
从 _matrix 对象中提取出来的 Trilinos 矩阵。
void compute()
计算预条件器。在 Trilinos 中,我们需要显式调用此函数。
virtual const Epetra_Map & OperatorDomainMap() const override
virtual bool UseTranspose() const override
virtual double NormInf() const override
virtual int SetUseTranspose(bool UseTranspose) override
virtual const char * Label() const override
virtual const Epetra_Map & OperatorRangeMap() const override
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const override
Epetra_Operator * _prec
Trilinos 预条件器。
virtual const Epetra_Comm & Comm() const override
virtual int ApplyInverse(const Epetra_MultiVector &r, Epetra_MultiVector &z) const override