1
# ifndef _RHEO_NEWTON_H
2
# define _RHEO_NEWTON_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
/// =========================================================================
25
NAME: @code{newton} -- Newton nonlinear algorithm
27
@cindex nonlinear problem
31
Nonlinear Newton algorithm for the resolution of the following problem:
35
A simple call to the algorithm writes:
39
newton (P, uh, tol, max_iter);
41
The @code{my_problem} class may contains methods for the evaluation
42
of F (aka residue) and its derivative:
47
field residue (const field& uh) const;
48
void update_derivative (const field& uh) const;
49
field derivative_solve (const field& mrh) const;
50
Float norm (const field& uh) const;
51
Float dual_norm (const field& Muh) const;
54
See the example @code{p-laplacian.h} in the user's documentation
57
| Pierre.Saramito@imag.fr
58
LJK, 38041 Grenoble cedex 9, France
65
template <class Problem, class Field>
66
int newton (Problem P, Field& uh, Float& tol, size_t& max_iter, std::ostream *p_cerr = 0) {
67
if (p_cerr) *p_cerr << "# Newton: n r" << std::endl;
68
for (size_t n = 0; true; n++) {
69
Field rh = P.residue(uh);
70
Float r = P.dual_norm(rh);
71
if (p_cerr) *p_cerr << n << " " << r << std::endl;
72
if (r <= tol) { tol = r; max_iter = n; return 0; }
73
if (n == max_iter) { tol = r; return 1; }
74
P.update_derivative (uh);
75
Field delta_uh = P.derivative_solve (-rh);
80
# endif // _RHEO_NEWTON_H