Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
precondition_selector.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2018 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.md at
12 // the top level directory of deal.II.
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 
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/subscriptor.h>
24 
25 #include <string>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 template <class number>
30 class Vector;
31 template <class number>
32 class SparseMatrix;
33 
34 
98 template <typename MatrixType = SparseMatrix<double>,
99  typename VectorType = ::Vector<double>>
101 {
102 public:
106  using size_type = typename MatrixType::size_type;
107 
112  PreconditionSelector(const std::string & preconditioning,
113  const typename VectorType::value_type &omega = 1.);
114 
118  virtual ~PreconditionSelector() override;
119 
124  void
125  use_matrix(const MatrixType &M);
126 
131  size_type
132  m() const;
133 
138  size_type
139  n() const;
140 
145  virtual void
146  vmult(VectorType &dst, const VectorType &src) const;
147 
152  virtual void
153  Tvmult(VectorType &dst, const VectorType &src) const;
154 
165  static std::string
167 
178 
180 protected:
184  std::string preconditioning;
185 
186 private:
192  A;
193 
197  const typename VectorType::value_type omega;
198 };
199 
201 /* --------------------- Inline and template functions ------------------- */
202 
203 
204 template <typename MatrixType, typename VectorType>
206  const std::string & preconditioning,
207  const typename VectorType::value_type &omega)
208  : preconditioning(preconditioning)
209  , omega(omega)
210 {}
211 
212 
213 template <typename MatrixType, typename VectorType>
215 {
216  // release the matrix A
217  A = nullptr;
218 }
219 
220 
221 template <typename MatrixType, typename VectorType>
222 void
224 {
225  A = &M;
226 }
227 
228 
229 template <typename MatrixType, typename VectorType>
232 {
233  Assert(A != nullptr, ExcNoMatrixGivenToUse());
234  return A->m();
235 }
236 
237 
238 template <typename MatrixType, typename VectorType>
241 {
242  Assert(A != nullptr, ExcNoMatrixGivenToUse());
243  return A->n();
244 }
245 
246 
247 
248 template <typename MatrixType, typename VectorType>
249 void
251  const VectorType &src) const
252 {
253  if (preconditioning == "none")
254  {
255  dst = src;
256  }
257  else
258  {
259  Assert(A != nullptr, ExcNoMatrixGivenToUse());
260 
261  if (preconditioning == "jacobi")
262  {
263  A->precondition_Jacobi(dst, src, omega);
264  }
265  else if (preconditioning == "sor")
266  {
267  A->precondition_SOR(dst, src, omega);
268  }
269  else if (preconditioning == "ssor")
270  {
271  A->precondition_SSOR(dst, src, omega);
272  }
273  else
274  Assert(false, ExcNotImplemented());
275  }
276 }
277 
278 
279 template <typename MatrixType, typename VectorType>
280 void
282  VectorType & dst,
283  const VectorType &src) const
284 {
285  if (preconditioning == "none")
286  {
287  dst = src;
288  }
289  else
290  {
291  Assert(A != nullptr, ExcNoMatrixGivenToUse());
292 
293  if (preconditioning == "jacobi")
294  {
295  A->precondition_Jacobi(dst, src, omega); // Symmetric operation
296  }
297  else if (preconditioning == "sor")
298  {
299  A->precondition_TSOR(dst, src, omega);
300  }
301  else if (preconditioning == "ssor")
302  {
303  A->precondition_SSOR(dst, src, omega); // Symmetric operation
304  }
305  else
306  Assert(false, ExcNotImplemented());
307  }
308 }
309 
310 
311 template <typename MatrixType, typename VectorType>
312 std::string
314 {
315  return "none|jacobi|sor|ssor";
316 }
317 
318 
319 DEAL_II_NAMESPACE_CLOSE
320 
321 #endif
SmartPointer< const MatrixType, PreconditionSelector< MatrixType, VectorType > > A
void use_matrix(const MatrixType &M)
const VectorType::value_type omega
static ::ExceptionBase & ExcNoMatrixGivenToUse()
LinearAlgebra::distributed::Vector< Number > Vector
#define Assert(cond, exc)
Definition: exceptions.h:1407
#define DeclException0(Exception0)
Definition: exceptions.h:473
PreconditionSelector(const std::string &preconditioning, const typename VectorType::value_type &omega=1.)
virtual ~PreconditionSelector() override
static std::string get_precondition_names()
virtual void Tvmult(VectorType &dst, const VectorType &src) const
typename MatrixType::size_type size_type
virtual void vmult(VectorType &dst, const VectorType &src) const
static ::ExceptionBase & ExcNotImplemented()