Reference documentation for deal.II version 8.5.1
precondition_selector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2016 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 
155  static std::string get_precondition_names();
156 
167 
169 protected:
170 
174  std::string preconditioning;
175 
176 private:
182 
186  const typename VectorType::value_type omega;
187 };
188 
190 /* --------------------- Inline and template functions ------------------- */
191 
192 
193 template <typename MatrixType, typename VectorType>
195 ::PreconditionSelector(const std::string &preconditioning,
196  const typename VectorType::value_type &omega) :
197  preconditioning(preconditioning),
198  omega(omega) {}
199 
200 
201 template <typename MatrixType, typename VectorType>
203 {
204  // release the matrix A
205  A=0;
206 }
207 
208 
209 template <typename MatrixType, typename VectorType>
211 {
212  A=&M;
213 }
214 
215 
216 template <typename MatrixType, typename VectorType>
219 {
220  Assert(A!=0, ExcNoMatrixGivenToUse());
221  return A->m();
222 }
223 
224 
225 template <typename MatrixType, typename VectorType>
228 {
229  Assert(A!=0, ExcNoMatrixGivenToUse());
230  return A->n();
231 }
232 
233 
234 
235 template <typename MatrixType, typename VectorType>
237  const VectorType &src) const
238 {
239  if (preconditioning=="none")
240  {
241  dst=src;
242  }
243  else
244  {
245  Assert(A!=0, ExcNoMatrixGivenToUse());
246 
247  if (preconditioning=="jacobi")
248  {
249  A->precondition_Jacobi(dst,src,omega);
250  }
251  else if (preconditioning=="sor")
252  {
253  A->precondition_SOR(dst,src,omega);
254  }
255  else if (preconditioning=="ssor")
256  {
257  A->precondition_SSOR(dst,src,omega);
258  }
259  else
260  Assert(false,ExcNotImplemented());
261  }
262 }
263 
264 
265 template <typename MatrixType, typename VectorType>
267  const VectorType &src) const
268 {
269  if (preconditioning=="none")
270  {
271  dst=src;
272  }
273  else
274  {
275  Assert(A!=0, ExcNoMatrixGivenToUse());
276 
277  if (preconditioning=="jacobi")
278  {
279  A->precondition_Jacobi(dst,src,omega); // Symmetric operation
280  }
281  else if (preconditioning=="sor")
282  {
283  A->precondition_TSOR(dst,src,omega);
284  }
285  else if (preconditioning=="ssor")
286  {
287  A->precondition_SSOR(dst,src,omega); // Symmetric operation
288  }
289  else
290  Assert(false,ExcNotImplemented());
291  }
292 }
293 
294 
295 template <typename MatrixType, typename VectorType>
297 {
298  return "none|jacobi|sor|ssor";
299 }
300 
301 
302 DEAL_II_NAMESPACE_CLOSE
303 
304 #endif
MatrixType::size_type size_type
void use_matrix(const MatrixType &M)
const VectorType::value_type omega
static ::ExceptionBase & ExcNoMatrixGivenToUse()
#define Assert(cond, exc)
Definition: exceptions.h:313
#define DeclException0(Exception0)
Definition: exceptions.h:541
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
static ::ExceptionBase & ExcNotImplemented()
SmartPointer< const MatrixType, PreconditionSelector< MatrixType, VectorType > > A