Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 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 : 47 : /** 48 : * This class provides an interface to the suite of preconditioners 49 : * available from PETSc. All overridden virtual functions are 50 : * documented in preconditioner.h. 51 : * 52 : * \author Derek Gaston 53 : * \date 2009 54 : */ 55 : template <typename T> 56 : class PetscPreconditioner : public Preconditioner<T> 57 : { 58 : public: 59 : 60 : /** 61 : * Constructor. Initializes PetscPreconditioner data structures 62 : */ 63 : PetscPreconditioner (const libMesh::Parallel::Communicator & comm_in); 64 : 65 0 : 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 : 73 : /** 74 : * \returns The PETSc PC object. Can be useful for implementing 75 : * more advanced algorithms. 76 : */ 77 : PC pc(); 78 : 79 : /** 80 : * Tells PETSc to use the user-specified preconditioner. 81 : */ 82 : static void set_petsc_preconditioner_type (const PreconditionerType & preconditioner_type, PC & pc); 83 : 84 : protected: 85 : 86 : /** 87 : * Preconditioner context 88 : */ 89 : WrappedPetsc<PC> _pc; 90 : 91 : /** 92 : * PETSc Mat pulled out of the _matrix object during init(). We 93 : * aren't responsible for cleaning up this one. 94 : */ 95 : Mat _mat; 96 : }; 97 : 98 : } // namespace libMesh 99 : 100 : #endif // #ifdef LIBMESH_HAVE_PETSC 101 : #endif // LIBMESH_PETSC_PRECONDITIONER_H