libMesh
preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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"
26 #include "libmesh/enum_solver_package.h"
27 #include "libmesh/enum_solver_type.h"
28 #include "libmesh/enum_preconditioner_type.h"
29 #include "libmesh/reference_counted_object.h"
30 #include "libmesh/libmesh.h"
31 #include "libmesh/parallel_object.h"
32 
33 // C++ includes
34 #include <cstddef>
35 
36 namespace libMesh
37 {
38 
39 // forward declarations
40 template <typename T> class SparseMatrix;
41 template <typename T> class NumericVector;
42 template <typename T> class ShellMatrix;
43 
56 template <typename T>
57 class Preconditioner : public ReferenceCountedObject<Preconditioner<T>>,
58  public ParallelObject
59 {
60 public:
61 
66 
70  virtual ~Preconditioner ();
71 
77  LIBMESH_CAN_DEFAULT_TO_COMMWORLD,
78  const SolverPackage solver_package = libMesh::default_solver_package());
79 
84  bool initialized () const { return _is_initialized; }
85 
91  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) = 0;
92 
96  virtual void clear () {}
97 
103  virtual void init () {}
104 
110  virtual void setup () {}
111 
115  void set_matrix(SparseMatrix<Number> & mat);
116 
121 
125  void set_type (const PreconditionerType pct);
126 
127 protected:
128 
134 
139 
144 };
145 
146 
147 
148 
149 /*----------------------- inline functions ----------------------------------*/
150 template <typename T>
151 inline
153  ParallelObject(comm_in),
156  _is_initialized (false)
157 {
158 }
159 
160 
161 
162 template <typename T>
163 inline
165 {
166  this->clear ();
167 }
168 
169 template <typename T>
170 void
172 {
173  //If the matrix is changing then we (probably) need to reinitialize.
174  _is_initialized = false;
175  _matrix = &mat;
176 }
177 
178 template <typename T>
179 void
181 {
182  //If the preconditioner type changes we (probably) need to reinitialize.
183  _is_initialized = false;
184  _preconditioner_type = pct;
185 }
186 
187 } // namespace libMesh
188 
189 
190 #endif // LIBMESH_PRECONDITIONER_H
Encapsulates the MPI_Comm object.
Definition: parallel.h:657
virtual void clear()
Release all memory and clear data structures.
PreconditionerType type() const
SolverPackage
Defines an enum for various linear solver packages.
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y)=0
Computes the preconditioned vector y based on input vector x.
const class libmesh_nullptr_t libmesh_nullptr
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.
Numeric vector.
Definition: dof_map.h:66
void set_matrix(SparseMatrix< Number > &mat)
Sets the matrix to be preconditioned.
The libMesh namespace provides an interface to certain functionality in the library.
SolverPackage default_solver_package()
Definition: libmesh.C:995
PreconditionerType
Defines an enum for preconditioner types.
This class provides a uniform interface for preconditioners.
Preconditioner(const libMesh::Parallel::Communicator &comm)
Constructor.
PetscErrorCode Vec x
This class implements reference counting.
This class forms the base class for all other classes that are expected to be implemented in parallel...
bool _is_initialized
Flag indicating if the data structures have been initialized.
const Parallel::Communicator & comm() const
void set_type(const PreconditionerType pct)
Sets the type of preconditioner to use.
virtual void init()
Initialize data structures if not done so already.
bool initialized() const
virtual void setup()
This is called every time the "operator might have changed".
static Preconditioner< T > * build(const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a Preconditioner using the linear solver package specified by solver_package.
virtual ~Preconditioner()
Destructor.
SparseMatrix< T > * _matrix
The matrix P...