Reference documentation for deal.II version 9.6.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\}}\)
Loading...
Searching...
No Matches
solver_relaxation.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2010 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_solver_relaxation_h
16#define dealii_solver_relaxation_h
17
18
19#include <deal.II/base/config.h>
20
24
25#include <deal.II/lac/solver.h>
27
29
56template <typename VectorType = Vector<double>>
58class SolverRelaxation : public SolverBase<VectorType>
59{
60public:
66 {};
67
72 const AdditionalData &data = AdditionalData());
73
79 template <typename MatrixType, typename RelaxationType>
82 requires(const RelaxationType &R, VectorType &a, VectorType &b) {
83 R.step(a, b);
84 }))
85 void solve(const MatrixType &A,
86 VectorType &x,
87 const VectorType &b,
88 const RelaxationType &R);
89};
90
91//----------------------------------------------------------------------//
92
93template <typename VectorType>
96 const AdditionalData &)
97 : SolverBase<VectorType>(cn)
98{}
99
100
101
102template <typename VectorType>
104template <typename MatrixType, typename RelaxationType>
107 requires(const RelaxationType &R, VectorType &a, VectorType &b) {
108 R.step(a, b);
109 }))
110void SolverRelaxation<VectorType>::solve(const MatrixType &A,
111 VectorType &x,
112 const VectorType &b,
113 const RelaxationType &R)
114{
117
118 // Memory allocation
119 typename VectorMemory<VectorType>::Pointer Vr(mem);
120 VectorType &r = *Vr;
121 r.reinit(x);
122 typename VectorMemory<VectorType>::Pointer Vd(mem);
123 VectorType &d = *Vd;
124 d.reinit(x);
125
126 LogStream::Prefix prefix("Relaxation");
127
128 int iter = 0;
129 // Main loop
130 for (; conv == SolverControl::iterate; ++iter)
131 {
132 // Compute residual
133 A.vmult(r, x);
134 r.sadd(-1., 1., b);
135
136 // The required norm of the
137 // (preconditioned)
138 // residual is computed in
139 // criterion() and stored
140 // in res.
141 conv = this->iteration_status(iter, r.l2_norm(), x);
142 if (conv != SolverControl::iterate)
143 break;
144 R.step(x, b);
145 }
146
147 // in case of failure: throw exception
149 SolverControl::NoConvergence(iter, r.l2_norm()));
150 // otherwise exit as normal
151}
152
153
155
156#endif
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:177
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#define AssertThrow(cond, exc)