Reference documentation for deal.II version 8.4.2
precondition_selector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2015 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__precondition_selector_h
17 #define dealii__precondition_selector_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/smartpointer.h>
22 #include <string>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 template <class number> class Vector;
27 template <class number> class SparseMatrix;
28 
29 
93 template <typename MatrixType = SparseMatrix<double>,
94  typename VectorType = ::Vector<double> >
96 {
97 public:
101  typedef typename MatrixType::size_type size_type;
102 
107  PreconditionSelector (const std::string &preconditioning,
108  const typename VectorType::value_type &omega=1.);
109 
113  virtual ~PreconditionSelector();
114 
119  void use_matrix(const MatrixType &M);
120 
125  size_type m () const;
126 
131  size_type n () const;
132 
137  virtual void vmult (VectorType &dst, const VectorType &src) const;
138 
143  virtual void Tvmult (VectorType &dst, const VectorType &src) const;
144 
148  static std::string get_precondition_names();
149 
159  DeclException0 (ExcNoMatrixGivenToUse);
160 
162 protected:
163 
167  std::string preconditioning;
168 
169 private:
175 
179  const typename VectorType::value_type omega;
180 };
181 
183 /* --------------------- Inline and template functions ------------------- */
184 
185 
186 template <typename MatrixType, typename VectorType>
189  const typename VectorType::value_type &omega) :
190  preconditioning(preconditioning),
191  omega(omega) {}
192 
193 
194 template <typename MatrixType, typename VectorType>
196 {
197  // release the matrix A
198  A=0;
199 }
200 
201 
202 template <typename MatrixType, typename VectorType>
204 {
205  A=&M;
206 }
207 
208 
209 template <typename MatrixType, typename VectorType>
212 {
213  Assert(A!=0, ExcNoMatrixGivenToUse());
214  return A->m();
215 }
216 
217 
218 template <typename MatrixType, typename VectorType>
221 {
222  Assert(A!=0, ExcNoMatrixGivenToUse());
223  return A->n();
224 }
225 
226 
227 
228 template <typename MatrixType, typename VectorType>
230  const VectorType &src) const
231 {
232  if (preconditioning=="none")
233  {
234  dst=src;
235  }
236  else
237  {
238  Assert(A!=0, ExcNoMatrixGivenToUse());
239 
240  if (preconditioning=="jacobi")
241  {
242  A->precondition_Jacobi(dst,src,omega);
243  }
244  else if (preconditioning=="sor")
245  {
246  A->precondition_SOR(dst,src,omega);
247  }
248  else if (preconditioning=="ssor")
249  {
250  A->precondition_SSOR(dst,src,omega);
251  }
252  else
253  Assert(false,ExcNotImplemented());
254  }
255 }
256 
257 
258 template <typename MatrixType, typename VectorType>
260  const VectorType &src) const
261 {
262  if (preconditioning=="none")
263  {
264  dst=src;
265  }
266  else
267  {
268  Assert(A!=0, ExcNoMatrixGivenToUse());
269 
270  if (preconditioning=="jacobi")
271  {
272  A->precondition_Jacobi(dst,src,omega); // Symmetric operation
273  }
274  else if (preconditioning=="sor")
275  {
276  A->precondition_TSOR(dst,src,omega);
277  }
278  else if (preconditioning=="ssor")
279  {
280  A->precondition_SSOR(dst,src,omega); // Symmetric operation
281  }
282  else
283  Assert(false,ExcNotImplemented());
284  }
285 }
286 
287 
288 template <typename MatrixType, typename VectorType>
290 {
291  return "none|jacobi|sor|ssor";
292 }
293 
294 
295 DEAL_II_NAMESPACE_CLOSE
296 
297 #endif
MatrixType::size_type size_type
void use_matrix(const MatrixType &M)
DeclException0(ExcNoMatrixGivenToUse)
const VectorType::value_type omega
#define Assert(cond, exc)
Definition: exceptions.h:294
PreconditionSelector(const std::string &preconditioning, const typename VectorType::value_type &omega=1.)
static std::string get_precondition_names()
virtual void Tvmult(VectorType &dst, const VectorType &src) const
virtual void vmult(VectorType &dst, const VectorType &src) const
SmartPointer< const MatrixType, PreconditionSelector< MatrixType, VectorType > > A