Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
deal.II
lac
solver_relaxation.h
1
// ---------------------------------------------------------------------
2
//
3
// Copyright (C) 2010 - 2019 by the deal.II authors
4
//
5
// This file is part of the deal.II library.
6
//
7
// The deal.II library is free software; you can use it, redistribute
8
// it, and/or modify it under the terms of the GNU Lesser General
9
// Public License as published by the Free Software Foundation; either
10
// version 2.1 of the License, or (at your option) any later version.
11
// The full text of the license can be found in the file LICENSE.md at
12
// the top level directory of deal.II.
13
//
14
// ---------------------------------------------------------------------
15
16
#ifndef dealii_solver_relaxation_h
17
#define dealii_solver_relaxation_h
18
19
20
#include <deal.II/base/config.h>
21
22
#include <deal.II/base/logstream.h>
23
#include <deal.II/base/subscriptor.h>
24
25
#include <deal.II/lac/solver.h>
26
#include <deal.II/lac/solver_control.h>
27
28
DEAL_II_NAMESPACE_OPEN
29
58
template
<
typename
VectorType = Vector<
double
>>
59
class
SolverRelaxation
:
public
SolverBase
<VectorType>
60
{
61
public
:
66
struct
AdditionalData
67
{};
68
72
SolverRelaxation
(
SolverControl
& cn,
73
const
AdditionalData
&data =
AdditionalData
());
74
78
virtual
~SolverRelaxation
();
79
85
template
<
typename
MatrixType,
class
RelaxationType>
86
void
87
solve
(
const
MatrixType & A,
88
VectorType & x,
89
const
VectorType & b,
90
const
RelaxationType &R);
91
};
92
93
//----------------------------------------------------------------------//
94
95
template
<
class
VectorType>
96
SolverRelaxation<VectorType>::SolverRelaxation
(
SolverControl
&cn,
97
const
AdditionalData
&)
98
:
SolverBase
<VectorType>(cn)
99
{}
100
101
102
103
template
<
class
VectorType>
104
SolverRelaxation<VectorType>::~SolverRelaxation
()
105
{}
106
107
108
template
<
class
VectorType>
109
template
<
typename
MatrixType,
class
RelaxationType>
110
void
111
SolverRelaxation<VectorType>::solve
(
const
MatrixType & A,
112
VectorType & x,
113
const
VectorType & b,
114
const
RelaxationType &R)
115
{
116
GrowingVectorMemory<VectorType>
mem;
117
SolverControl::State
conv =
SolverControl::iterate
;
118
119
// Memory allocation
120
typename
VectorMemory<VectorType>::Pointer
Vr(mem);
121
VectorType & r = *Vr;
122
r.reinit(x);
123
typename
VectorMemory<VectorType>::Pointer
Vd(mem);
124
VectorType & d = *Vd;
125
d.reinit(x);
126
127
LogStream::Prefix
prefix(
"Relaxation"
);
128
129
int
iter = 0;
130
// Main loop
131
for
(; conv ==
SolverControl::iterate
; iter++)
132
{
133
// Compute residual
134
A.vmult(r, x);
135
r.sadd(-1., 1., b);
136
137
// The required norm of the
138
// (preconditioned)
139
// residual is computed in
140
// criterion() and stored
141
// in res.
142
conv = this->iteration_status(iter, r.l2_norm(), x);
143
if
(conv !=
SolverControl::iterate
)
144
break
;
145
R.step(x, b);
146
}
147
148
// in case of failure: throw exception
149
AssertThrow
(conv ==
SolverControl::success
,
150
SolverControl::NoConvergence
(iter, r.l2_norm()));
151
// otherwise exit as normal
152
}
153
154
155
DEAL_II_NAMESPACE_CLOSE
156
157
#endif
LogStream::Prefix
Definition:
logstream.h:103
SolverControl::State
State
Definition:
solver_control.h:72
SolverControl::NoConvergence
Definition:
solver_control.h:94
SolverRelaxation::SolverRelaxation
SolverRelaxation(SolverControl &cn, const AdditionalData &data=AdditionalData())
Definition:
solver_relaxation.h:96
SolverBase
Definition:
solver.h:328
GrowingVectorMemory
Definition:
vector_memory.h:320
SolverControl::iterate
Continue iteration.
Definition:
solver_control.h:75
SolverRelaxation::solve
void solve(const MatrixType &A, VectorType &x, const VectorType &b, const RelaxationType &R)
Definition:
solver_relaxation.h:111
SolverRelaxation::~SolverRelaxation
virtual ~SolverRelaxation()
Definition:
solver_relaxation.h:104
VectorMemory::Pointer
Definition:
vector_memory.h:192
SolverRelaxation::AdditionalData
Definition:
solver_relaxation.h:66
SolverControl::success
Stop iteration, goal reached.
Definition:
solver_control.h:77
SolverControl
Definition:
solver_control.h:65
SolverRelaxation
Definition:
solver_relaxation.h:59
AssertThrow
#define AssertThrow(cond, exc)
Definition:
exceptions.h:1519
Generated by
1.8.16