deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00: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
solver_relaxation.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) 2010 - 2024 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_solver_relaxation_h
14#define dealii_solver_relaxation_h
15
16
17#include <deal.II/base/config.h>
18
22
23#include <deal.II/lac/solver.h>
25
27
54template <typename VectorType = Vector<double>>
56class SolverRelaxation : public SolverBase<VectorType>
57{
58public:
64 {};
65
71
77 template <typename MatrixType, typename RelaxationType>
80 requires(const RelaxationType &R, VectorType &a, VectorType &b) {
81 R.step(a, b);
82 }))
83 void solve(const MatrixType &A,
84 VectorType &x,
85 const VectorType &b,
86 const RelaxationType &R);
87};
88
89//----------------------------------------------------------------------//
90
91template <typename VectorType>
94 const AdditionalData &)
95 : SolverBase<VectorType>(cn)
96{}
97
98
99
100template <typename VectorType>
102template <typename MatrixType, typename RelaxationType>
105 requires(const RelaxationType &R, VectorType &a, VectorType &b) {
106 R.step(a, b);
107 }))
108void SolverRelaxation<VectorType>::solve(const MatrixType &A,
109 VectorType &x,
110 const VectorType &b,
111 const RelaxationType &R)
112{
115
116 // Memory allocation
117 typename VectorMemory<VectorType>::Pointer Vr(mem);
118 VectorType &r = *Vr;
119 r.reinit(x);
120 typename VectorMemory<VectorType>::Pointer Vd(mem);
121 VectorType &d = *Vd;
122 d.reinit(x);
123
124 LogStream::Prefix prefix("Relaxation");
125
126 int iter = 0;
127 // Main loop
128 for (; conv == SolverControl::iterate; ++iter)
129 {
130 // Compute residual
131 A.vmult(r, x);
132 r.sadd(-1., 1., b);
133
134 // The required norm of the
135 // (preconditioned)
136 // residual is computed in
137 // criterion() and stored
138 // in res.
139 conv = this->iteration_status(iter, r.l2_norm(), x);
140 if (conv != SolverControl::iterate)
141 break;
142 R.step(x, b);
143 }
144
145 // in case of failure: throw exception
147 SolverControl::NoConvergence(iter, r.l2_norm()));
148 // otherwise exit as normal
149}
150
151
153
154#endif
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define AssertThrow(cond, exc)
std::vector< index_type > data
Definition mpi.cc:734