libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
preconditioner.C
浏览该文件的文档.
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 // Local Includes
21 #include "libmesh/preconditioner.h"
22 #include "libmesh/eigen_preconditioner.h"
23 #include "libmesh/petsc_preconditioner.h"
24 #include "libmesh/trilinos_preconditioner.h"
25 #include "libmesh/enum_solver_package.h"
26 #include "libmesh/enum_preconditioner_type.h"
27 
28 
29 // C++ Includes
30 #include <memory>
31 
32 
33 namespace libMesh
34 {
35 
36 template <typename T>
37 inline
38 Preconditioner<T>::Preconditioner (const libMesh::Parallel::Communicator & comm_in) :
39  ParallelObject(comm_in),
40  _matrix(nullptr),
41  _preconditioner_type (ILU_PRECOND),
42  _is_initialized (false)
43 {
44 }
45 
46 
47 
48 template <typename T>
49 std::unique_ptr<Preconditioner<T>>
50 Preconditioner<T>::build_preconditioner(const libMesh::Parallel::Communicator & comm,
51  const SolverPackage solver_package)
52 {
53  // Avoid unused parameter warnings when no solver packages are enabled.
54  libmesh_ignore(comm);
55 
56  // Build and return the appropriate Preconditioner object.
57  switch (solver_package)
58  {
59 
60 #ifdef LIBMESH_HAVE_PETSC
61  case PETSC_SOLVERS:
62  {
63  return std::make_unique<PetscPreconditioner<T>>(comm);
64  }
65 #endif
66 
67 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
68  case TRILINOS_SOLVERS:
69  return std::make_unique<TrilinosPreconditioner<T>>(comm);
70 #endif
71 
72 #ifdef LIBMESH_HAVE_EIGEN
73  case EIGEN_SOLVERS:
74  return std::make_unique<EigenPreconditioner<T>>(comm);
75 #endif
76 
77  default:
78  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
79  }
80 }
81 
82 
83 
84 //------------------------------------------------------------------
85 // Explicit instantiations
86 template class LIBMESH_EXPORT Preconditioner<Number>;
87 
88 } // namespace libMesh
EIGEN_SOLVERS
Definition: libmesh.C:249
TRILINOS_SOLVERS
Definition: libmesh.C:247
该类提供了一个统一的接口,用于预处理器。此基类可继承,以包装来自不同软件包(如 PETSc 或 Trilinos)的预处理器。
void libmesh_ignore(const Args &...)
Preconditioner(const libMesh::Parallel::Communicator &comm)
构造函数。初始化 Preconditioner 的数据结构。
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:242
static std::unique_ptr< Preconditioner< T > > build_preconditioner(const libMesh::Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
构建一个 Preconditioner,使用由 solver_package 指定的线性求解器软件包, 并以 std::unique_ptr 包装结果以确保安全性。 ...