Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
precondition_selector.h
1 // ---------------------------------------------------------------------
2 // @f$Id: precondition_selector.h 31932 2013-12-08 02:15:54Z heister @f$
3 //
4 // Copyright (C) 1999 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__precondition_selector_h
18 #define __deal2__precondition_selector_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <string>
24 
26 
27 template <class number> class Vector;
28 template <class number> class SparseMatrix;
29 
30 
96 template <class MATRIX = SparseMatrix<double>,
97  class VECTOR = ::Vector<double> >
99 {
100 public:
101 
107  PreconditionSelector(const std::string &preconditioning,
108  const typename VECTOR::value_type &omega=1.);
109 
113  virtual ~PreconditionSelector();
114 
121  void use_matrix(const MATRIX &M);
122 
128  virtual void vmult (VECTOR &dst, const VECTOR &src) const;
129 
134  static std::string get_precondition_names();
135 
143  DeclException0 (ExcNoMatrixGivenToUse);
144 
146 protected:
147 
152  std::string preconditioning;
153 
154 private:
161 
166  const typename VECTOR::value_type omega;
167 };
168 
170 /* --------------------- Inline and template functions ------------------- */
171 
172 
173 template <class MATRIX, class VECTOR>
175 ::PreconditionSelector(const std::string &preconditioning,
176  const typename VECTOR::value_type &omega) :
177  preconditioning(preconditioning),
178  omega(omega) {}
179 
180 
181 template <class MATRIX, class VECTOR>
183 {
184  // release the matrix A
185  A=0;
186 }
187 
188 
189 template <class MATRIX, class VECTOR>
191 {
192  A=&M;
193 }
194 
195 template <class MATRIX, class VECTOR>
197  const VECTOR &src) const
198 {
199  if (preconditioning=="none")
200  {
201  dst=src;
202  }
203  else
204  {
205  Assert(A!=0, ExcNoMatrixGivenToUse());
206 
207  if (preconditioning=="jacobi")
208  {
209  A->precondition_Jacobi(dst,src,omega);
210  }
211  else if (preconditioning=="sor")
212  {
213  A->precondition_SOR(dst,src,omega);
214  }
215  else if (preconditioning=="ssor")
216  {
217  A->precondition_SSOR(dst,src,omega);
218  }
219  else
220  Assert(false,ExcNotImplemented());
221  }
222 }
223 
224 
225 template <class MATRIX, class VECTOR>
227 {
228  return "none|jacobi|sor|ssor";
229 }
230 
231 
232 DEAL_II_NAMESPACE_CLOSE
233 
234 #endif
PreconditionSelector(const std::string &preconditioning, const typename VECTOR::value_type &omega=1.)
SmartPointer< const MATRIX, PreconditionSelector< MATRIX, VECTOR > > A
static std::string get_precondition_names()
#define Assert(cond, exc)
Definition: exceptions.h:299
DeclException0(ExcNoMatrixGivenToUse)
void use_matrix(const MATRIX &M)
const VECTOR::value_type omega
virtual void vmult(VECTOR &dst, const VECTOR &src) const
::ExceptionBase & ExcNotImplemented()