00001
00002
00003
00004
00005
00006
00007
00008
00009
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
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
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