1
# ifndef _SKIT_PUZAWA_H
2
# define _SKIT_PUZAWA_H
4
/// This file is part of Rheolef.
6
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
8
/// Rheolef is free software; you can redistribute it and/or modify
9
/// it under the terms of the GNU General Public License as published by
10
/// the Free Software Foundation; either version 2 of the License, or
11
/// (at your option) any later version.
13
/// Rheolef is distributed in the hope that it will be useful,
14
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
/// GNU General Public License for more details.
18
/// You should have received a copy of the GNU General Public License
19
/// along with Rheolef; if not, write to the Free Software
20
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
/// =========================================================================
23
#include "rheolef/diststream.h"
27
NAME: @code{puzawa} -- Uzawa algorithm.
29
@cindex Uzawa algorithm
30
@cindex iterative solver
31
@cindex preconditioner
34
template <class Matrix, class Vector, class Preconditioner, class Real>
35
int puzawa (const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M,
36
int &max_iter, Real &tol, const Real& rho, odiststream *p_derr=0);
41
The simplest call to 'puzawa' has the folling form:
43
size_t max_iter = 100;
45
int status = puzawa(A, x, b, EYE, max_iter, tol, 1.0, &derr);
50
@code{puzawa} solves the linear
51
system A*x=b using the Uzawa method. The Uzawa method is a
52
descent method in the direction opposite to the gradient,
53
with a constant step length 'rho'. The convergence is assured
54
when the step length 'rho' is small enough.
55
If matrix A is symmetric positive definite, please uses 'pcg' that
56
computes automatically the optimal descdnt step length at
60
The return value indicates convergence within max_iter (input)
61
iterations (0), or no convergence within max_iter iterations (1).
62
Upon successful return, output arguments have the following values:
65
approximate solution to Ax = b
68
the number of iterations performed before the tolerance was reached
71
the residual after the final iteration
76
| Pierre.Saramito@imag.fr
77
LJK-IMAG, 38041 Grenoble cedex 9, France
84
template < class Matrix, class Vector, class Preconditioner, class Real, class Size>
85
int puzawa(const Matrix &A, Vector &x, const Vector &Mb, const Preconditioner &M,
86
Size &max_iter, Real &tol, const Real& rho,
87
odiststream *p_derr, std::string label)
89
Vector b = M.solve(Mb);
90
Real norm2_b = dot(Mb,b);
91
Real norm2_r = norm2_b;
92
if (norm2_b == Real(0)) norm2_b = 1;
93
if (p_derr) (*p_derr) << "[" << label << "] #iteration residue" << std::endl;
94
for (Size n = 0; n <= max_iter; n++) {
96
Vector r = M.solve(Mr);
98
if (p_derr) (*p_derr) << "[" << label << "] " << n << " " << sqrt(norm2_r/norm2_b) << std::endl;
99
if (norm2_r <= sqr(tol)*norm2_b) {
100
tol = sqrt(norm2_r/norm2_b);
106
tol = sqrt(norm2_r/norm2_b);
110
}// namespace rheolef
111
# endif // _SKIT_PUZAWA_H