libMesh
petsc_preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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_PETSC_PRECONDITIONER_H
21 #define LIBMESH_PETSC_PRECONDITIONER_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #ifdef LIBMESH_HAVE_PETSC
26 
27 // libMesh includes
28 #include "libmesh/preconditioner.h"
29 #include "libmesh/libmesh_common.h"
30 #include "libmesh/reference_counted_object.h"
31 #include "libmesh/libmesh.h"
32 #include "libmesh/petsc_macro.h"
33 #include "libmesh/wrapped_petsc.h"
34 
35 // Petsc includes
36 #include "petscpc.h"
37 
38 namespace libMesh
39 {
40 
41 // forward declarations
42 template <typename T> class SparseMatrix;
43 template <typename T> class NumericVector;
44 template <typename T> class ShellMatrix;
45 enum PreconditionerType : int;
46 
55 template <typename T>
57 {
58 public:
59 
64 
65  virtual ~PetscPreconditioner () = default;
66 
67  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) override;
68 
69  virtual void clear () override;
70 
71  virtual void init () override;
72 
77  PC pc();
78 
82  static void set_petsc_preconditioner_type (const PreconditionerType & preconditioner_type, PC & pc);
83 
84 protected:
85 
90 
95  Mat _mat;
96 
97 private:
105  static void set_petsc_subpreconditioner_type(const PCType type, PC & pc);
106 };
107 
108 } // namespace libMesh
109 
110 #endif // #ifdef LIBMESH_HAVE_PETSC
111 #endif // LIBMESH_PETSC_PRECONDITIONER_H
This class provides an interface to the suite of preconditioners available from PETSc.
Mat _mat
PETSc Mat pulled out of the _matrix object during init().
virtual void init() override
Initialize data structures if not done so already.
PreconditionerType type() const
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:43
static void set_petsc_subpreconditioner_type(const PCType type, PC &pc)
Some PETSc preconditioners (ILU, LU) don&#39;t work in parallel.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
Computes the preconditioned vector y based on input vector x.
This class provides a uniform interface for preconditioners.
WrappedPetsc< PC > _pc
Preconditioner context.
PetscPreconditioner(const libMesh::Parallel::Communicator &comm_in)
Constructor.
virtual void clear() override
Release all memory and clear data structures.
static void set_petsc_preconditioner_type(const PreconditionerType &preconditioner_type, PC &pc)
Tells PETSc to use the user-specified preconditioner.
PreconditionerType
Defines an enum for preconditioner types.
virtual ~PetscPreconditioner()=default
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360