Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
newton.h
Go to the documentation of this file.
1# ifndef _RHEO_NEWTON_H
2# define _RHEO_NEWTON_H
3//
4// This file is part of Rheolef.
5//
6// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
7//
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.
12//
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.
17//
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
21//
22// =========================================================================
23// AUTHOR: Pierre.Saramito@imag.fr
24// DATE: 14 oct 2009
25
26namespace rheolef {
91} // namespace rheolef
92
93namespace rheolef {
94
96// [verbatim_newton]
97template <class Problem, class Field>
98int newton (const Problem& P, Field& uh, Float& tol, size_t& max_iter, odiststream *p_derr = 0)
99// [verbatim_newton]
100{
101 if (p_derr) *p_derr << "# Newton:" << std::endl << "# n r" << std::endl << std::flush;
102 for (size_t n = 0; true; n++) {
103 Field rh = P.residue(uh);
104 Float r = P.dual_space_norm(rh);
105 if (p_derr) *p_derr << n << " " << r << std::endl << std::flush;
106 if (r <= tol) { tol = r; max_iter = n; return 0; }
107 if (n == max_iter) { tol = r; return 1; }
108 P.update_derivative (uh);
109 Field delta_uh = P.derivative_solve (-rh);
110 uh += delta_uh;
111 }
112}
113//>newton:
114}// namespace rheolef
115# endif // _RHEO_NEWTON_H
see the Float page for the full documentation
odiststream: see the diststream page for the full documentation
Definition diststream.h:137
This file is part of Rheolef.
int newton(const Problem &P, Field &uh, Float &tol, size_t &max_iter, odiststream *p_derr=0)
see the newton page for the full documentation
Definition newton.h:98