libMesh
Loading...
Searching...
No Matches
preconditioner.h
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#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// C++ includes
31#include <cstddef>
32
33namespace libMesh
34{
35
36// forward declarations
37template <typename T> class SparseMatrix;
38template <typename T> class NumericVector;
39template <typename T> class ShellMatrix;
40enum SolverPackage : int;
42
55template <typename T>
56class Preconditioner : public ReferenceCountedObject<Preconditioner<T>>,
57 public ParallelObject
58{
59public:
60
65
69 virtual ~Preconditioner ();
70
76 static std::unique_ptr<Preconditioner<T>>
78 const SolverPackage solver_package = libMesh::default_solver_package());
79
84 virtual 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 virtual void zero() {}
116
121
126
130 void set_type (const PreconditionerType pct);
131
132protected:
133
139
144
149};
150
151
152
153
154/*----------------------- inline functions ----------------------------------*/
155template <typename T>
156inline
158{
159 this->clear ();
160}
161
162template <typename T>
163void
165{
166 //If the matrix is changing then we (probably) need to reinitialize.
167 _is_initialized = false;
168 _matrix = &mat;
169}
170
171template <typename T>
172void
174{
175 //If the preconditioner type changes we (probably) need to reinitialize.
176 _is_initialized = false;
177 _preconditioner_type = pct;
178}
179
180} // namespace libMesh
181
182
183#endif // LIBMESH_PRECONDITIONER_H
void ErrorVector unsigned int
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
An object whose state is distributed along a set of processors.
const Parallel::Communicator & comm() const
This class provides a uniform interface for preconditioners.
void set_type(const PreconditionerType pct)
Sets the type of preconditioner to use.
bool _is_initialized
Flag indicating if the data structures have been initialized.
void set_matrix(SparseMatrix< Number > &mat)
Sets the matrix to be preconditioned.
PreconditionerType _preconditioner_type
Enum stating with type of preconditioner to use.
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y)=0
Computes the preconditioned vector y based on input vector x.
virtual void init()
Initialize data structures if not done so already.
PreconditionerType type() const
virtual ~Preconditioner()
Destructor.
virtual bool initialized() const
virtual void setup()
This is called every time the "operator might have changed".
virtual void zero()
Can be used to zero items relevant to the preconditioner.
SparseMatrix< T > * _matrix
The matrix P... ie the matrix to be preconditioned.
virtual void clear()
Release all memory and clear data structures.
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,...
This class implements reference counting.
Generic sparse matrix.
The libMesh namespace provides an interface to certain functionality in the library.
SolverPackage default_solver_package()
Definition libmesh.C:1064
SolverPackage
Defines an enum for various linear solver packages.
PreconditionerType
Defines an enum for preconditioner types.