petsc_preconditioner.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 // Local includes
28 #include "libmesh/preconditioner.h"
29 #include "libmesh/libmesh_common.h"
31 #include "libmesh/libmesh.h"
32 #include "libmesh/petsc_macro.h"
33 
34 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
35 namespace libMesh
36 {
37 enum PreconditionerType : int;
38 }
39 #else
41 #endif
42 
43 // Petsc includes
44 #include "petscpc.h"
45 
46 namespace libMesh
47 {
48 
49 // forward declarations
50 template <typename T> class SparseMatrix;
51 template <typename T> class NumericVector;
52 template <typename T> class ShellMatrix;
53 
62 template <typename T>
64 {
65 public:
66 
71 
75  virtual ~PetscPreconditioner ();
76 
77  virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) override;
78 
79  virtual void clear () override;
80 
81  virtual void init () override;
82 
87  PC pc() { return _pc; }
88 
92  static void set_petsc_preconditioner_type (const PreconditionerType & preconditioner_type, PC & pc);
93 
94 protected:
95 
99  PC _pc;
100 
104  Mat _mat;
105 
106 private:
114 #if PETSC_VERSION_LESS_THAN(3,0,0)
115  // In Petsc 2.3.3, PCType was #define'd as const char *
116  static void set_petsc_subpreconditioner_type(PCType type, PC & pc);
117 #else
118  // In later versions, PCType is #define'd as char *, so we need the const
119  static void set_petsc_subpreconditioner_type(const PCType type, PC & pc);
120 #endif
121 };
122 
123 
124 
125 
126 /*----------------------- inline functions ----------------------------------*/
127 template <typename T>
128 inline
130  Preconditioner<T>(comm_in),
131  _pc(PETSC_NULL)
132 {
133 }
134 
135 
136 
137 template <typename T>
138 inline
140 {
141  this->clear ();
142 }
143 
144 } // namespace libMesh
145 
146 #endif // #ifdef LIBMESH_HAVE_PETSC
147 #endif // LIBMESH_PETSC_PRECONDITIONER_H
virtual void init() override
PreconditionerType type() const
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
virtual void apply(const NumericVector< T > &x, NumericVector< T > &y) override
static void set_petsc_subpreconditioner_type(PCType type, PC &pc)
PetscPreconditioner(const libMesh::Parallel::Communicator &comm_in)
virtual void clear() override
static void set_petsc_preconditioner_type(const PreconditionerType &preconditioner_type, PC &pc)