libMesh
petsc_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_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 #include "libmesh/system.h"
35 
36 // Petsc includes
37 #include "petscpc.h"
38 
39 namespace libMesh
40 {
41 
42 // forward declarations
43 template <typename T> class SparseMatrix;
44 template <typename T> class NumericVector;
45 template <typename T> class ShellMatrix;
46 enum PreconditionerType : int;
47 
56 template <typename T>
58 {
59 public:
60 
65 
66  virtual ~PetscPreconditioner () = default;
67 
68  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) override;
69 
70  virtual void clear () override;
71 
72  virtual void init () override;
73 
78  PC pc();
79 
83  static void set_petsc_preconditioner_type (const PreconditionerType & preconditioner_type, PC & pc);
84 
88 #ifdef LIBMESH_HAVE_PETSC_HYPRE
89  static void set_petsc_aux_data (PC & pc, System & sys, const unsigned v = 0);
90  static void set_hypre_ams_data (PC & pc, System & sys, const unsigned v);
91  static void set_hypre_ads_data (PC & pc, System & sys, const unsigned v);
92 #else
93  static void set_petsc_aux_data (PC &, System &, const unsigned = 0) {}
94 #endif
95 
96 protected:
97 
102 
107  Mat _mat;
108 };
109 
110 } // namespace libMesh
111 
112 #endif // #ifdef LIBMESH_HAVE_PETSC
113 #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.
static void set_hypre_ads_data(PC &pc, System &sys, const unsigned v)
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: vector_fe_ex5.C:44
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.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
WrappedPetsc< PC > _pc
Preconditioner context.
static void set_petsc_aux_data(PC &, System &, const unsigned=0)
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
static void set_petsc_aux_data(PC &pc, System &sys, const unsigned v=0)
Builds PETSc auxiliary data needed by preconditioners such as hypre ams/ads.
static void set_hypre_ams_data(PC &pc, System &sys, const unsigned v)
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360