deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
precondition_selector.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1999 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_precondition_selector_h
14#define dealii_precondition_selector_h
15
16
17#include <deal.II/base/config.h>
18
22
23#include <string>
24
26
27// Forward declarations
28#ifndef DOXYGEN
29template <class number>
30class Vector;
31template <class number>
32class SparseMatrix;
33#endif
34
35
97template <typename MatrixType = SparseMatrix<double>,
98 typename VectorType = ::Vector<double>>
100{
101public:
105 using size_type = typename MatrixType::size_type;
106
111 PreconditionSelector(const std::string &preconditioning,
112 const typename VectorType::value_type &omega = 1.);
113
117 virtual ~PreconditionSelector() override;
118
123 void
124 use_matrix(const MatrixType &M);
125
131 m() const;
132
138 n() const;
139
144 virtual void
145 vmult(VectorType &dst, const VectorType &src) const;
146
151 virtual void
152 Tvmult(VectorType &dst, const VectorType &src) const;
153
164 static std::string
166
177
179protected:
183 std::string preconditioning;
184
185private:
190 ObserverPointer<const MatrixType,
193
197 const typename VectorType::value_type omega;
198};
199
201/* --------------------- Inline and template functions ------------------- */
202
203
204template <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
213template <typename MatrixType, typename VectorType>
215{
216 // release the matrix A
217 A = nullptr;
218}
219
220
221template <typename MatrixType, typename VectorType>
222void
224{
225 A = &M;
226}
227
228
229template <typename MatrixType, typename VectorType>
232{
233 Assert(A != nullptr, ExcNoMatrixGivenToUse());
234 return A->m();
235}
236
237
238template <typename MatrixType, typename VectorType>
241{
242 Assert(A != nullptr, ExcNoMatrixGivenToUse());
243 return A->n();
244}
245
246
247
248template <typename MatrixType, typename VectorType>
249void
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
275 }
276}
277
278
279template <typename MatrixType, typename VectorType>
280void
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
307 }
308}
309
310
311template <typename MatrixType, typename VectorType>
312std::string
314{
315 return "none|jacobi|sor|ssor";
316}
317
318
320
321#endif
virtual void vmult(VectorType &dst, const VectorType &src) const
virtual void Tvmult(VectorType &dst, const VectorType &src) const
typename MatrixType::size_type size_type
const VectorType::value_type omega
static std::string get_precondition_names()
void use_matrix(const MatrixType &M)
virtual ~PreconditionSelector() override
PreconditionSelector(const std::string &preconditioning, const typename VectorType::value_type &omega=1.)
ObserverPointer< const MatrixType, PreconditionSelector< MatrixType, VectorType > > A
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcNoMatrixGivenToUse()
#define DeclException0(Exception0)
#define Assert(cond, exc)