preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_PRECONDITIONER_H
21 #define LIBMESH_PRECONDITIONER_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
27 #include "libmesh/libmesh.h"
29 
30 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
31 namespace libMesh
32 {
33 enum SolverPackage : int;
34 enum PreconditionerType : int;
35 }
36 #else
39 #endif
40 
41 
42 // C++ includes
43 #include <cstddef>
44 
45 namespace libMesh
46 {
47 
48 // forward declarations
49 template <typename T> class SparseMatrix;
50 template <typename T> class NumericVector;
51 template <typename T> class ShellMatrix;
52 
65 template <typename T>
66 class Preconditioner : public ReferenceCountedObject<Preconditioner<T>>,
67  public ParallelObject
68 {
69 public:
70 
75 
79  virtual ~Preconditioner ();
80 
86  static std::unique_ptr<Preconditioner<T>>
88  const SolverPackage solver_package = libMesh::default_solver_package());
89 
96 #ifdef LIBMESH_ENABLE_DEPRECATED
97  static Preconditioner<T> *
99  const SolverPackage solver_package = libMesh::default_solver_package());
100 #endif
101 
106  bool initialized () const { return _is_initialized; }
107 
113  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) = 0;
114 
118  virtual void clear () {}
119 
125  virtual void init () {}
126 
132  virtual void setup () {}
133 
137  void set_matrix(SparseMatrix<Number> & mat);
138 
143 
147  void set_type (const PreconditionerType pct);
148 
149 protected:
150 
156 
161 
166 };
167 
168 
169 
170 
171 /*----------------------- inline functions ----------------------------------*/
172 template <typename T>
173 inline
175 {
176  this->clear ();
177 }
178 
179 template <typename T>
180 void
182 {
183  //If the matrix is changing then we (probably) need to reinitialize.
184  _is_initialized = false;
185  _matrix = &mat;
186 }
187 
188 template <typename T>
189 void
191 {
192  //If the preconditioner type changes we (probably) need to reinitialize.
193  _is_initialized = false;
194  _preconditioner_type = pct;
195 }
196 
197 } // namespace libMesh
198 
199 
200 #endif // LIBMESH_PRECONDITIONER_H
PreconditionerType type() const
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y)=0
PreconditionerType _preconditioner_type
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
const Parallel::Communicator & comm() const
void set_matrix(SparseMatrix< Number > &mat)
static Preconditioner< T > * build(const libMesh::Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
SolverPackage default_solver_package()
Definition: libmesh.C:971
Preconditioner(const libMesh::Parallel::Communicator &comm)
void set_type(const PreconditionerType pct)
static std::unique_ptr< Preconditioner< T > > build_preconditioner(const libMesh::Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
SparseMatrix< T > * _matrix