libMesh
preconditioner.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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/auto_ptr.h"
23 #include "libmesh/eigen_preconditioner.h"
24 #include "libmesh/petsc_preconditioner.h"
25 #include "libmesh/trilinos_preconditioner.h"
26 #include "libmesh/enum_solver_package.h"
27 #include "libmesh/enum_preconditioner_type.h"
28 
29 namespace libMesh
30 {
31 
32 template <typename T>
33 inline
34 Preconditioner<T>::Preconditioner (const libMesh::Parallel::Communicator & comm_in) :
35  ParallelObject(comm_in),
36  _matrix(nullptr),
37  _preconditioner_type (ILU_PRECOND),
38  _is_initialized (false)
39 {
40 }
41 
42 
43 
44 template <typename T>
45 std::unique_ptr<Preconditioner<T>>
46 Preconditioner<T>::build_preconditioner(const libMesh::Parallel::Communicator & comm,
47  const SolverPackage solver_package)
48 {
49  // Avoid unused parameter warnings when no solver packages are enabled.
50  libmesh_ignore(comm);
51 
52  // Build and return the appropriate Preconditioner object.
53  switch (solver_package)
54  {
55 
56 #ifdef LIBMESH_HAVE_PETSC
57  case PETSC_SOLVERS:
58  {
59  return libmesh_make_unique<PetscPreconditioner<T>>(comm);
60  }
61 #endif
62 
63 #ifdef LIBMESH_TRILINOS_HAVE_EPETRA
64  case TRILINOS_SOLVERS:
65  return libmesh_make_unique<TrilinosPreconditioner<T>>(comm);
66 #endif
67 
68 #ifdef LIBMESH_HAVE_EIGEN
69  case EIGEN_SOLVERS:
70  return libmesh_make_unique<EigenPreconditioner<T>>(comm);
71 #endif
72 
73  default:
74  libmesh_error_msg("ERROR: Unrecognized solver package: " << solver_package);
75  }
76 }
77 
78 
79 
80 #ifdef LIBMESH_ENABLE_DEPRECATED
81 
82 template <typename T>
84 Preconditioner<T>::build(const libMesh::Parallel::Communicator & comm,
85  const SolverPackage solver_package)
86 {
87  // You should be calling build_preconditioner() instead.
88  libmesh_deprecated();
89 
90  // Call the non-deprecated method
91  std::unique_ptr<Preconditioner<T>> ptr =
92  Preconditioner<T>::build_preconditioner(comm, solver_package);
93 
94  // Vaya con dios
95  return ptr.release();
96 }
97 
98 #endif
99 
100 
101 //------------------------------------------------------------------
102 // Explicit instantiations
103 template class Preconditioner<Number>;
104 
105 } // namespace libMesh
libMesh::SolverPackage
SolverPackage
Defines an enum for various linear solver packages.
Definition: enum_solver_package.h:34
libMesh::PETSC_SOLVERS
Definition: enum_solver_package.h:36
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Preconditioner::Preconditioner
Preconditioner(const libMesh::Parallel::Communicator &comm)
Constructor.
Definition: preconditioner.C:34
libMesh::libmesh_ignore
void libmesh_ignore(const Args &...)
Definition: libmesh_common.h:526
libMesh::Preconditioner
This class provides a uniform interface for preconditioners.
Definition: preconditioner.h:66
libMesh::TRILINOS_SOLVERS
Definition: enum_solver_package.h:37
libMesh::libMeshPrivateData::_is_initialized
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:246
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55
libMesh::EIGEN_SOLVERS
Definition: enum_solver_package.h:40
libMesh::ILU_PRECOND
Definition: enum_preconditioner_type.h:43