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
include
deal.II
lac
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
19
#include <
deal.II/base/enable_observer_pointer.h
>
20
#include <
deal.II/base/logstream.h
>
21
#include <
deal.II/base/template_constraints.h
>
22
23
#include <
deal.II/lac/solver.h
>
24
#include <
deal.II/lac/solver_control.h
>
25
26
DEAL_II_NAMESPACE_OPEN
27
54
template
<
typename
VectorType = Vector<
double
>>
55
DEAL_II_CXX20_REQUIRES
(
concepts::is_vector_space_vector<VectorType>
)
56
class
SolverRelaxation
: public
SolverBase
<VectorType>
57
{
58
public
:
63
struct
AdditionalData
64
{};
65
69
SolverRelaxation
(
SolverControl
&cn,
70
const
AdditionalData
&
data
=
AdditionalData
());
71
77
template
<
typename
MatrixType,
typename
RelaxationType>
78
DEAL_II_CXX20_REQUIRES
(
79
(
concepts::is_linear_operator_on<MatrixType, VectorType>
&&
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
91
template
<
typename
VectorType>
92
DEAL_II_CXX20_REQUIRES
(
concepts::is_vector_space_vector<VectorType>
)
93
SolverRelaxation
<VectorType>::
SolverRelaxation
(
SolverControl
&cn,
94
const
AdditionalData
&)
95
:
SolverBase
<VectorType>(cn)
96
{}
97
98
99
100
template
<
typename
VectorType>
101
DEAL_II_CXX20_REQUIRES
(
concepts::is_vector_space_vector<VectorType>
)
102
template
<
typename
MatrixType,
typename
RelaxationType>
103
DEAL_II_CXX20_REQUIRES
(
104
(
concepts::is_linear_operator_on<MatrixType, VectorType>
&&
105
requires
(
const
RelaxationType &R, VectorType &a, VectorType &b) {
106
R.step(a, b);
107
}))
108
void
SolverRelaxation
<VectorType>::solve(const MatrixType &A,
109
VectorType &x,
110
const VectorType &b,
111
const RelaxationType &R)
112
{
113
GrowingVectorMemory<VectorType>
mem;
114
SolverControl::State
conv =
SolverControl::iterate
;
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
146
AssertThrow
(conv ==
SolverControl::success
,
147
SolverControl::NoConvergence
(iter, r.l2_norm()));
148
// otherwise exit as normal
149
}
150
151
152
DEAL_II_NAMESPACE_CLOSE
153
154
#endif
GrowingVectorMemory
Definition
vector_memory.h:312
LogStream::Prefix
Definition
logstream.h:99
SolverBase
Definition
solver.h:340
SolverControl::NoConvergence
Definition
solver_control.h:94
SolverControl
Definition
solver_control.h:66
SolverControl::State
State
Definition
solver_control.h:73
SolverControl::iterate
@ iterate
Continue iteration.
Definition
solver_control.h:75
SolverControl::success
@ success
Stop iteration, goal reached.
Definition
solver_control.h:77
SolverRelaxation
Definition
solver_relaxation.h:57
VectorMemory::Pointer
Definition
vector_memory.h:187
concepts::is_linear_operator_on
Definition
template_constraints.h:1134
concepts::is_vector_space_vector
Definition
template_constraints.h:1042
config.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition
config.h:38
DEAL_II_CXX20_REQUIRES
#define DEAL_II_CXX20_REQUIRES(condition)
Definition
config.h:249
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition
config.h:39
enable_observer_pointer.h
AssertThrow
#define AssertThrow(cond, exc)
Definition
exception_macros.h:647
logstream.h
data
std::vector< index_type > data
Definition
mpi.cc:734
solver.h
solver_control.h
SolverRelaxation::AdditionalData
Definition
solver_relaxation.h:64
template_constraints.h
Generated by
1.9.8