TBCI Numerical high perf. C++ Library
2.8.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
home
abuild
rpmbuild
BUILD
libtbcinumlib2_8-2.8.2-build
numerix-2.0
lina
include
solver
cheby.h
Go to the documentation of this file.
1
4
5
// $Id: cheby.h,v 1.9.2.4 2019/05/28 11:13:02 garloff Exp $
6
7
#ifndef TBCI_SOLVER_CHEBY_H
8
#define TBCI_SOLVER_CHEBY_H
9
10
#include "tbci/basics.h"
11
#include "tbci/solver/precond.h"
12
13
NAMESPACE_TBCI
14
15
INST3
(
template
<
typename
T
,
Matrix<T>
,
Vector<T>
>
class
NN
friend
\
16
int
CHEBY
(
const
Matrix<T>
&,
Vector<T>
&,
const
Vector<T>
&,\
17
const
Preconditioner_Sig
<
T
,
Matrix<T>
>&,
unsigned
int
&,
double
&,
T
,
T
);)
18
INST3
(
template
<
typename
T
,
BdMatrix<T>
,
Vector<T>
>
class
NN
friend
\
19
int
CHEBY
(
const
BdMatrix<T>
&,
Vector<T>
&,
const
Vector<T>
&,\
20
const
Preconditioner_Sig
<
T
,
BdMatrix<T>
>&,
unsigned
int
&,
double
&,
T
,
T
);)
21
22
23
/*statt:
24
template < class Matrix, class Vector, class Preconditioner, class Real,
25
class Type >
26
int
27
CHEBY(const Matrix &A, Vector &x, const Vector &b,
28
const Preconditioner &M, int &max_iter, Real &tol,
29
Type eigmin, Type eigmax)*/
30
31
#ifndef HAVE_BCXX_TYPENAME_BUG
32
# define
VALUE_TYPE
typename
SysVector::value_type
33
#
else
34
# define
VALUE_TYPE
SysVector::value_type
35
#endif
36
37
58
59
template < typename T, typename SysMatrix, typename SysVector >
60
int
CHEBY
(
const
SysMatrix
&A, SysVector &
x
,
const
SysVector &
b
,
61
const
Preconditioner_Sig<T, SysMatrix>
&M,
unsigned
int
&max_iter,
double
&tol,
62
T
eigmin,
T
eigmax)
63
{
64
double
resid;
65
unsigned
int
dim = A.rows();
66
T
alpha(0), beta,
c
, d;
67
SysVector
p
(dim), q(dim), z(dim);
68
69
double
normb =
b
.fabs();
70
SysVector r(
b
- A *
x
);
71
72
if
(normb == 0.0)
73
normb = 1;
74
75
if
((resid = r.fabs() / normb) <= tol)
76
{
77
tol = resid;
78
max_iter = 0;
79
return
0;
80
}
81
82
c
= (eigmax - eigmin) / 2.0;
83
d = (eigmax + eigmin) / 2.0;
84
85
for
(
unsigned
int
i
= 1;
i
<= max_iter;
i
++)
86
{
87
z = M.
solve
(r);
88
89
if
(
i
== 1)
90
{
91
p
= z;
92
alpha = 2.0 / d;
93
}
else
94
{
95
beta =
c
* alpha / 2.0;
// calculate new beta
96
beta = beta * beta;
97
alpha = 1.0 / (d - beta);
// calculate new alpha
98
p
= z + (
VALUE_TYPE
)beta *
p
;
// update search direction
99
}
100
101
q = A *
p
;
102
x
+=
VALUE_TYPE
(alpha) *
p
;
// update approximation vector
103
r -=
VALUE_TYPE
(alpha) * q;
// compute residual
104
105
if
((resid = r.fabs() / normb) <= tol)
106
{
107
tol = resid;
108
max_iter =
i
;
109
return
0;
// convergence
110
}
111
}
112
113
tol = resid;
114
return
1;
// no convergence
115
}
116
117
NAMESPACE_END
118
119
#endif
/* TBCI_SOLVER_CHEBY_H */
p
const Vector< T > const Vector< T > const Vector< T > & p
Definition
LM_fit.h:98
x
const Vector< T > const Vector< T > & x
Definition
LM_fit.h:97
i
int i
Definition
LM_fit.h:71
INST3
#define INST3(x, y, z)
Definition
basics.h:240
NAMESPACE_END
#define NAMESPACE_END
Definition
basics.h:323
NAMESPACE_TBCI
#define NAMESPACE_TBCI
Definition
basics.h:317
T
#define T
Definition
bdmatlib.cc:20
SysMatrix
SysMatrix
Definition
bicgstab.h:90
CHEBY
NAMESPACE_TBCI Vector< T > class NN friend int CHEBY(const BdMatrix< T > &, Vector< T > &, const Vector< T > &, const Preconditioner_Sig< T, BdMatrix< T > > &, unsigned int &, double &, T, T)
VALUE_TYPE
#define VALUE_TYPE
Definition
cheby.h:32
BdMatrix
The class BdMatrix is an implementation to store and do operations on sparse Matrices with a band str...
Definition
band_matrix.h:104
Matrix
Definition
matrix.h:1575
Preconditioner_Sig
Abstract base class for all Preconditioners.
Definition
precond.h:41
Preconditioner_Sig::solve
virtual TVector< T > solve(const Vector< T > &) const =0
Vector
Definition
vector.h:1527
c
return c
Definition
f_matrix.h:760
b
F_TMatrix< T > b
Definition
f_matrix.h:736
Generated by
1.16.1