$extrastylesheet
preconditioner.h
Go to the documentation of this file.
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_PRECONDITIONER_H
00021 #define LIBMESH_PRECONDITIONER_H
00022 
00023 
00024 // Local includes
00025 #include "libmesh/libmesh_common.h"
00026 #include "libmesh/enum_solver_package.h"
00027 #include "libmesh/enum_solver_type.h"
00028 #include "libmesh/enum_preconditioner_type.h"
00029 #include "libmesh/reference_counted_object.h"
00030 #include "libmesh/libmesh.h"
00031 #include "libmesh/parallel_object.h"
00032 
00033 // C++ includes
00034 #include <cstddef>
00035 
00036 namespace libMesh
00037 {
00038 
00039 // forward declarations
00040 template <typename T> class SparseMatrix;
00041 template <typename T> class NumericVector;
00042 template <typename T> class ShellMatrix;
00043 
00044 
00045 
00046 
00047 
00060 template <typename T>
00061 class Preconditioner : public ReferenceCountedObject<Preconditioner<T> >,
00062                        public ParallelObject
00063 {
00064 public:
00065 
00069   Preconditioner (const libMesh::Parallel::Communicator &comm);
00070 
00074   virtual ~Preconditioner ();
00075 
00080   static Preconditioner<T> * build(const libMesh::Parallel::Communicator &comm
00081                                    LIBMESH_CAN_DEFAULT_TO_COMMWORLD,
00082                                    const SolverPackage solver_package = libMesh::default_solver_package());
00083 
00088   bool initialized () const { return _is_initialized; }
00089 
00094   virtual void apply(const NumericVector<T> & x, NumericVector<T> & y) = 0;
00095 
00099   virtual void clear () {}
00100 
00106   virtual void init () {}
00107 
00113   virtual void setup () {}
00114 
00118   void set_matrix(SparseMatrix<Number> & mat);
00119 
00123   PreconditionerType type () const
00124   { return _preconditioner_type; }
00125 
00129   void set_type (const PreconditionerType pct);
00130 
00131 protected:
00132 
00137   SparseMatrix<T> * _matrix;
00138 
00142   PreconditionerType _preconditioner_type;
00143 
00147   bool _is_initialized;
00148 };
00149 
00150 
00151 
00152 
00153 /*----------------------- inline functions ----------------------------------*/
00154 template <typename T>
00155 inline
00156 Preconditioner<T>::Preconditioner (const libMesh::Parallel::Communicator &comm_in) :
00157   ParallelObject(comm_in),
00158   _matrix(NULL),
00159   _preconditioner_type (ILU_PRECOND),
00160   _is_initialized      (false)
00161 {
00162 }
00163 
00164 
00165 
00166 template <typename T>
00167 inline
00168 Preconditioner<T>::~Preconditioner ()
00169 {
00170   this->clear ();
00171 }
00172 
00173 template <typename T>
00174 void
00175 Preconditioner<T>::set_matrix(SparseMatrix<Number> & mat)
00176 {
00177   //If the matrix is changing then we (probably) need to reinitialize.
00178   _is_initialized = false;
00179   _matrix = &mat;
00180 }
00181 
00182 template <typename T>
00183 void
00184 Preconditioner<T>::set_type (const PreconditionerType pct)
00185 {
00186   //If the preconditioner type changes we (probably) need to reinitialize.
00187   _is_initialized = false;
00188   _preconditioner_type = pct;
00189 }
00190 
00191 } // namespace libMesh
00192 
00193 
00194 #endif // LIBMESH_PRECONDITIONER_H