Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
precondition_selector.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2020 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 
24 
25 #include <string>
26 
28 
29 // Forward declarations
30 #ifndef DOXYGEN
31 template <class number>
32 class Vector;
33 template <class number>
34 class SparseMatrix;
35 #endif
36 
37 
101 template <typename MatrixType = SparseMatrix<double>,
102  typename VectorType = ::Vector<double>>
104 {
105 public:
110 
115  PreconditionSelector(const std::string & preconditioning,
116  const typename VectorType::value_type &omega = 1.);
117 
121  virtual ~PreconditionSelector() override;
122 
127  void
128  use_matrix(const MatrixType &M);
129 
134  size_type
135  m() const;
136 
141  size_type
142  n() const;
143 
148  virtual void
149  vmult(VectorType &dst, const VectorType &src) const;
150 
155  virtual void
156  Tvmult(VectorType &dst, const VectorType &src) const;
157 
168  static std::string
170 
181 
183 protected:
187  std::string preconditioning;
188 
189 private:
195  A;
196 
200  const typename VectorType::value_type omega;
201 };
202 
204 /* --------------------- Inline and template functions ------------------- */
205 
206 
207 template <typename MatrixType, typename VectorType>
209  const std::string & preconditioning,
210  const typename VectorType::value_type &omega)
211  : preconditioning(preconditioning)
212  , omega(omega)
213 {}
214 
215 
216 template <typename MatrixType, typename VectorType>
218 {
219  // release the matrix A
220  A = nullptr;
221 }
222 
223 
224 template <typename MatrixType, typename VectorType>
225 void
227 {
228  A = &M;
229 }
230 
231 
232 template <typename MatrixType, typename VectorType>
235 {
236  Assert(A != nullptr, ExcNoMatrixGivenToUse());
237  return A->m();
238 }
239 
240 
241 template <typename MatrixType, typename VectorType>
244 {
245  Assert(A != nullptr, ExcNoMatrixGivenToUse());
246  return A->n();
247 }
248 
249 
250 
251 template <typename MatrixType, typename VectorType>
252 void
254  const VectorType &src) const
255 {
256  if (preconditioning == "none")
257  {
258  dst = src;
259  }
260  else
261  {
262  Assert(A != nullptr, ExcNoMatrixGivenToUse());
263 
264  if (preconditioning == "jacobi")
265  {
266  A->precondition_Jacobi(dst, src, omega);
267  }
268  else if (preconditioning == "sor")
269  {
270  A->precondition_SOR(dst, src, omega);
271  }
272  else if (preconditioning == "ssor")
273  {
274  A->precondition_SSOR(dst, src, omega);
275  }
276  else
277  Assert(false, ExcNotImplemented());
278  }
279 }
280 
281 
282 template <typename MatrixType, typename VectorType>
283 void
285  VectorType & dst,
286  const VectorType &src) const
287 {
288  if (preconditioning == "none")
289  {
290  dst = src;
291  }
292  else
293  {
294  Assert(A != nullptr, ExcNoMatrixGivenToUse());
295 
296  if (preconditioning == "jacobi")
297  {
298  A->precondition_Jacobi(dst, src, omega); // Symmetric operation
299  }
300  else if (preconditioning == "sor")
301  {
302  A->precondition_TSOR(dst, src, omega);
303  }
304  else if (preconditioning == "ssor")
305  {
306  A->precondition_SSOR(dst, src, omega); // Symmetric operation
307  }
308  else
309  Assert(false, ExcNotImplemented());
310  }
311 }
312 
313 
314 template <typename MatrixType, typename VectorType>
315 std::string
317 {
318  return "none|jacobi|sor|ssor";
319 }
320 
321 
323 
324 #endif
PreconditionSelector::Tvmult
virtual void Tvmult(VectorType &dst, const VectorType &src) const
Definition: precondition_selector.h:284
LinearAlgebraDealII::Vector
Vector< double > Vector
Definition: generic_linear_algebra.h:43
PreconditionSelector::use_matrix
void use_matrix(const MatrixType &M)
Definition: precondition_selector.h:226
StandardExceptions::ExcNotImplemented
static ::ExceptionBase & ExcNotImplemented()
SparseMatrix
Definition: sparse_matrix.h:497
PreconditionSelector
Definition: precondition_selector.h:103
PreconditionSelector::omega
const VectorType::value_type omega
Definition: precondition_selector.h:200
PreconditionSelector::~PreconditionSelector
virtual ~PreconditionSelector() override
Definition: precondition_selector.h:217
Subscriptor
Definition: subscriptor.h:62
PreconditionSelector::ExcNoMatrixGivenToUse
static ::ExceptionBase & ExcNoMatrixGivenToUse()
PreconditionSelector::vmult
virtual void vmult(VectorType &dst, const VectorType &src) const
Definition: precondition_selector.h:253
PreconditionSelector::m
size_type m() const
Definition: precondition_selector.h:234
subscriptor.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
PreconditionSelector::preconditioning
std::string preconditioning
Definition: precondition_selector.h:187
smartpointer.h
LAPACKSupport::A
static const char A
Definition: lapack_support.h:155
SmartPointer
Definition: smartpointer.h:68
PreconditionSelector::n
size_type n() const
Definition: precondition_selector.h:243
LinearAlgebra::CUDAWrappers::kernel::size_type
types::global_dof_index size_type
Definition: cuda_kernels.h:45
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
PreconditionSelector::PreconditionSelector
PreconditionSelector(const std::string &preconditioning, const typename VectorType::value_type &omega=1.)
Definition: precondition_selector.h:208
DeclException0
#define DeclException0(Exception0)
Definition: exceptions.h:473
config.h
PreconditionSelector::get_precondition_names
static std::string get_precondition_names()
Definition: precondition_selector.h:316
PreconditionSelector::A
SmartPointer< const MatrixType, PreconditionSelector< MatrixType, VectorType > > A
Definition: precondition_selector.h:195
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
PreconditionSelector::size_type
typename MatrixType::size_type size_type
Definition: precondition_selector.h:109