libMesh
preconditioner.h
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 #ifndef LIBMESH_PRECONDITIONER_H
21 #define LIBMESH_PRECONDITIONER_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/reference_counted_object.h"
27 #include "libmesh/libmesh.h"
28 #include "libmesh/parallel_object.h"
29 
30 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
31 namespace libMesh
32 {
33 enum SolverPackage : int;
34 enum PreconditionerType : int;
35 }
36 #else
37 #include "libmesh/enum_solver_package.h"
38 #include "libmesh/enum_preconditioner_type.h"
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 
74  Preconditioner (const libMesh::Parallel::Communicator & comm);
75 
79  virtual ~Preconditioner ();
80 
86  static std::unique_ptr<Preconditioner<T>>
87  build_preconditioner(const libMesh::Parallel::Communicator & comm,
88  const SolverPackage solver_package = libMesh::default_solver_package());
89 
96 #ifdef LIBMESH_ENABLE_DEPRECATED
97  static Preconditioner<T> *
98  build(const libMesh::Parallel::Communicator & comm,
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
libMesh::SolverPackage
SolverPackage
Defines an enum for various linear solver packages.
Definition: enum_solver_package.h:34
libMesh::Preconditioner::apply
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y)=0
Computes the preconditioned vector y based on input vector x.
libMesh::Preconditioner::_preconditioner_type
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.
Definition: preconditioner.h:160
libMesh::ReferenceCountedObject
This class implements reference counting.
Definition: reference_counted_object.h:65
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Preconditioner::initialized
bool initialized() const
Definition: preconditioner.h:106
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::default_solver_package
SolverPackage default_solver_package()
Definition: libmesh.C:993
libMesh::Preconditioner::setup
virtual void setup()
This is called every time the "operator might have changed".
Definition: preconditioner.h:132
libMesh::Preconditioner::init
virtual void init()
Initialize data structures if not done so already.
Definition: preconditioner.h:125
libMesh::Preconditioner::Preconditioner
Preconditioner(const libMesh::Parallel::Communicator &comm)
Constructor.
Definition: preconditioner.C:34
libMesh::SparseMatrix< Number >
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::Preconditioner::set_type
void set_type(const PreconditionerType pct)
Sets the type of preconditioner to use.
Definition: preconditioner.h:190
libMesh::Preconditioner::_matrix
SparseMatrix< T > * _matrix
The matrix P...
Definition: preconditioner.h:155
libMesh::Preconditioner
This class provides a uniform interface for preconditioners.
Definition: preconditioner.h:66
libMesh::Preconditioner::~Preconditioner
virtual ~Preconditioner()
Destructor.
Definition: preconditioner.h:174
libMesh::Preconditioner::build_preconditioner
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,...
Definition: preconditioner.C:46
libMesh::Preconditioner::build
static Preconditioner< T > * build(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.
Definition: preconditioner.C:84
libMesh::Preconditioner::clear
virtual void clear()
Release all memory and clear data structures.
Definition: preconditioner.h:118
libMesh::PreconditionerType
PreconditionerType
Defines an enum for preconditioner types.
Definition: enum_preconditioner_type.h:33
libMesh::Preconditioner::set_matrix
void set_matrix(SparseMatrix< Number > &mat)
Sets the matrix to be preconditioned.
Definition: preconditioner.h:181
libMesh::libMeshPrivateData::_is_initialized
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:246
libMesh::Preconditioner::_is_initialized
bool _is_initialized
Flag indicating if the data structures have been initialized.
Definition: preconditioner.h:165
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55
libMesh::Preconditioner::type
PreconditionerType type() const
Definition: preconditioner.h:142
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360