libMesh
Loading...
Searching...
No Matches
preconditioner.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
33namespace libMesh
34{
35
36template <typename T>
37inline
39 ParallelObject(comm_in),
40 _matrix(nullptr),
41 _preconditioner_type (ILU_PRECOND),
42 _is_initialized (false)
43{
44}
45
46
47
48template <typename T>
49std::unique_ptr<Preconditioner<T>>
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
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
86template class LIBMESH_EXPORT Preconditioner<Number>;
87
88} // namespace libMesh
An object whose state is distributed along a set of processors.
This class provides a uniform interface for preconditioners.
Preconditioner(const libMesh::Parallel::Communicator &comm)
Constructor.
static std::unique_ptr< Preconditioner< T > > build_preconditioner(const libMesh::Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a Preconditioner using the linear solver package specified by solver_package,...
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
SolverPackage
Defines an enum for various linear solver packages.