include/deal.II/lac/precondition_selector.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: precondition_selector.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__precondition_selector_h
00013 #define __deal2__precondition_selector_h
00014 
00015 
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/smartpointer.h>
00018 #include <string>
00019 
00020 DEAL_II_NAMESPACE_OPEN
00021 
00022 template <class number> class Vector;
00023 template <class number> class SparseMatrix;
00024 
00025 
00091 template <class MATRIX = SparseMatrix<double>,
00092           class VECTOR = ::Vector<double> >
00093 class PreconditionSelector : public Subscriptor
00094 {
00095   public:
00096 
00102     PreconditionSelector(const std::string                 &preconditioning,
00103                          const typename VECTOR::value_type &omega=1.);
00104 
00108     virtual ~PreconditionSelector();
00109 
00116     void use_matrix(const MATRIX &M);
00117 
00123     virtual void vmult (VECTOR &dst, const VECTOR&src) const;
00124 
00129     static std::string get_precondition_names();
00130 
00138     DeclException0 (ExcNoMatrixGivenToUse);
00139 
00141   protected:
00142 
00147     std::string preconditioning;
00148 
00149   private:
00155     SmartPointer<const MATRIX,PreconditionSelector<MATRIX,VECTOR> > A;
00156 
00161     const typename VECTOR::value_type omega;
00162 };
00163 
00165 /* --------------------- Inline and template functions ------------------- */
00166 
00167 
00168 template <class MATRIX, class VECTOR>
00169 PreconditionSelector<MATRIX,VECTOR>
00170 ::PreconditionSelector(const std::string                 &preconditioning,
00171                        const typename VECTOR::value_type &omega) :
00172                 preconditioning(preconditioning),
00173                 omega(omega)  {}
00174 
00175 
00176 template <class MATRIX, class VECTOR>
00177 PreconditionSelector<MATRIX,VECTOR>::~PreconditionSelector()
00178 {
00179                                    // release the matrix A
00180   A=0;
00181 }
00182 
00183 
00184 template <class MATRIX, class VECTOR>
00185 void PreconditionSelector<MATRIX,VECTOR>::use_matrix(const MATRIX &M)
00186 {
00187   A=&M;
00188 }
00189 
00190 template <class MATRIX, class VECTOR>
00191 void PreconditionSelector<MATRIX,VECTOR>::vmult (VECTOR &dst,
00192                                                  const VECTOR &src) const
00193 {
00194   if (preconditioning=="none")
00195     {
00196       dst=src;
00197     }
00198   else
00199     {
00200       Assert(A!=0, ExcNoMatrixGivenToUse());
00201 
00202       if (preconditioning=="jacobi")
00203         {
00204           A->precondition_Jacobi(dst,src,omega);
00205         }
00206       else if (preconditioning=="sor")
00207         {
00208           A->precondition_SOR(dst,src,omega);
00209         }
00210       else if (preconditioning=="ssor")
00211         {
00212           A->precondition_SSOR(dst,src,omega);
00213         }
00214       else
00215         Assert(false,ExcNotImplemented());
00216     }
00217 }
00218 
00219 
00220 template <class MATRIX, class VECTOR>
00221 std::string PreconditionSelector<MATRIX,VECTOR>::get_precondition_names()
00222 {
00223   return "none|jacobi|sor|ssor";
00224 }
00225 
00226 
00227 DEAL_II_NAMESPACE_CLOSE
00228 
00229 #endif
00230 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Wed May 23 2012 06:07:39 by doxygen 1.7.3