deal.II version GIT relicensing-2167-g9622207b8f 2024-11-21 12:40:00+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: 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
21
#include <
deal.II/base/enable_observer_pointer.h
>
22
#include <
deal.II/base/logstream.h
>
23
#include <
deal.II/base/template_constraints.h
>
24
25
#include <
deal.II/lac/solver.h
>
26
#include <
deal.II/lac/solver_control.h
>
27
28
DEAL_II_NAMESPACE_OPEN
29
56
template
<
typename
VectorType = Vector<
double
>>
57
DEAL_II_CXX20_REQUIRES
(
concepts::is_vector_space_vector<VectorType>
)
58
class
SolverRelaxation
: public
SolverBase
<VectorType>
59
{
60
public
:
65
struct
AdditionalData
66
{};
67
71
SolverRelaxation
(
SolverControl
&cn,
72
const
AdditionalData
&
data
=
AdditionalData
());
73
79
template
<
typename
MatrixType,
typename
RelaxationType>
80
DEAL_II_CXX20_REQUIRES
(
81
(
concepts::is_linear_operator_on<MatrixType, VectorType>
&&
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
93
template
<
typename
VectorType>
94
DEAL_II_CXX20_REQUIRES
(
concepts::is_vector_space_vector<VectorType>
)
95
SolverRelaxation
<VectorType>::
SolverRelaxation
(
SolverControl
&cn,
96
const
AdditionalData
&)
97
:
SolverBase
<VectorType>(cn)
98
{}
99
100
101
102
template
<
typename
VectorType>
103
DEAL_II_CXX20_REQUIRES
(
concepts::is_vector_space_vector<VectorType>
)
104
template
<
typename
MatrixType,
typename
RelaxationType>
105
DEAL_II_CXX20_REQUIRES
(
106
(
concepts::is_linear_operator_on<MatrixType, VectorType>
&&
107
requires
(
const
RelaxationType &R, VectorType &a, VectorType &b) {
108
R.step(a, b);
109
}))
110
void
SolverRelaxation
<VectorType>::solve(const MatrixType &A,
111
VectorType &x,
112
const VectorType &b,
113
const RelaxationType &R)
114
{
115
GrowingVectorMemory<VectorType>
mem;
116
SolverControl::State
conv =
SolverControl::iterate
;
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
148
AssertThrow
(conv ==
SolverControl::success
,
149
SolverControl::NoConvergence
(iter, r.l2_norm()));
150
// otherwise exit as normal
151
}
152
153
154
DEAL_II_NAMESPACE_CLOSE
155
156
#endif
GrowingVectorMemory
Definition
vector_memory.h:314
LogStream::Prefix
Definition
logstream.h:101
SolverBase
Definition
solver.h:342
SolverControl::NoConvergence
Definition
solver_control.h:95
SolverControl
Definition
solver_control.h:67
SolverControl::State
State
Definition
solver_control.h:74
SolverControl::iterate
@ iterate
Continue iteration.
Definition
solver_control.h:76
SolverControl::success
@ success
Stop iteration, goal reached.
Definition
solver_control.h:78
SolverRelaxation
Definition
solver_relaxation.h:59
VectorMemory::Pointer
Definition
vector_memory.h:189
concepts::is_linear_operator_on
Definition
template_constraints.h:1071
concepts::is_vector_space_vector
Definition
template_constraints.h:985
config.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition
config.h:498
DEAL_II_CXX20_REQUIRES
#define DEAL_II_CXX20_REQUIRES(condition)
Definition
config.h:175
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition
config.h:499
enable_observer_pointer.h
AssertThrow
#define AssertThrow(cond, exc)
Definition
exceptions.h:1780
logstream.h
data
std::vector< index_type > data
Definition
mpi.cc:735
solver.h
solver_control.h
SolverRelaxation::AdditionalData
Definition
solver_relaxation.h:66
template_constraints.h
Generated by
1.9.8