$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_PETSC_PRECONDITIONER_H 00021 #define LIBMESH_PETSC_PRECONDITIONER_H 00022 00023 #include "libmesh/libmesh_config.h" 00024 00025 #ifdef LIBMESH_HAVE_PETSC 00026 00027 // Local includes 00028 #include "libmesh/preconditioner.h" 00029 #include "libmesh/libmesh_common.h" 00030 #include "libmesh/enum_solver_package.h" 00031 #include "libmesh/enum_preconditioner_type.h" 00032 #include "libmesh/reference_counted_object.h" 00033 #include "libmesh/libmesh.h" 00034 #include "libmesh/petsc_macro.h" 00035 00036 // Petsc includes 00037 EXTERN_C_FOR_PETSC_BEGIN 00038 #include "petscpc.h" 00039 EXTERN_C_FOR_PETSC_END 00040 00041 // C++ includes 00042 00043 namespace libMesh 00044 { 00045 00046 // forward declarations 00047 template <typename T> class SparseMatrix; 00048 template <typename T> class NumericVector; 00049 template <typename T> class ShellMatrix; 00050 00058 template <typename T> 00059 class PetscPreconditioner : public Preconditioner<T> 00060 { 00061 public: 00062 00066 PetscPreconditioner (const libMesh::Parallel::Communicator &comm_in 00067 LIBMESH_CAN_DEFAULT_TO_COMMWORLD); 00068 00072 virtual ~PetscPreconditioner (); 00073 00078 virtual void apply(const NumericVector<T> & x, NumericVector<T> & y); 00079 00083 virtual void clear (); 00084 00088 virtual void init (); 00089 00094 PC pc() { return _pc; } 00095 00099 static void set_petsc_preconditioner_type (const PreconditionerType & preconditioner_type, PC & pc); 00100 00101 protected: 00102 00106 PC _pc; 00107 00112 Mat _mat; 00113 00114 private: 00122 #if PETSC_VERSION_LESS_THAN(3,0,0) 00123 // In Petsc 2.3.3, PCType was #define'd as const char* 00124 static void set_petsc_subpreconditioner_type(PCType type, PC& pc); 00125 #else 00126 // In later versions, PCType is #define'd as char*, so we need the const 00127 static void set_petsc_subpreconditioner_type(const PCType type, PC& pc); 00128 #endif 00129 }; 00130 00131 00132 00133 00134 /*----------------------- inline functions ----------------------------------*/ 00135 template <typename T> 00136 inline 00137 PetscPreconditioner<T>::PetscPreconditioner (const libMesh::Parallel::Communicator &comm_in) : 00138 Preconditioner<T>(comm_in), 00139 _pc(PETSC_NULL) 00140 { 00141 } 00142 00143 00144 00145 template <typename T> 00146 inline 00147 PetscPreconditioner<T>::~PetscPreconditioner () 00148 { 00149 this->clear (); 00150 } 00151 00152 } // namespace libMesh 00153 00154 #endif // #ifdef LIBMESH_HAVE_PETSC 00155 #endif // LIBMESH_PETSC_PRECONDITIONER_H