Loading...
Searching...
No Matches
damped-newton-generic.h
Go to the documentation of this file.
# ifndef _RHEO_DAMPED_NEWTON_GENERIC_H
# define _RHEO_DAMPED_NEWTON_GENERIC_H
#include "rheolef/dis_cpu_time.h"
#include "rheolef/newton-backtrack.h"
namespace rheolef {
template <class Problem, class Preconditioner, class Field, class Real, class Size>
int damped_newton (const Problem& P, const Preconditioner& T, Field& u, Real& tol, Size& max_iter, odiststream *p_derr = 0) {
const Real delta_u_max_factor = 100;
Real norm_delta_u_max = delta_u_max_factor*std::max(P.space_norm(u), Real(1.));
Real lambda = 1;
Real Tu = 0;
double t0 = dis_wall_time();
double c0 = dis_cpu_time();
if (p_derr) *p_derr << "# damped-Newton: n r T lambda wall-time cpu" << std::endl << std::flush;
for (Size n = 0; true; n++) {
P.update_derivative (u);
Field Fu = P.residue(u);
Field delta_u = -P.derivative_solve (Fu);
Tu = T(P,Fu,delta_u);
if (p_derr) *p_derr << n << " " << P.dual_space_norm(Fu) << " " << sqrt(2.*Tu)
<< " " << lambda << " " << dis_wall_time()-t0 << " " << dis_cpu_time()-c0 << std::endl << std::flush;
if (2.*Tu <= sqr(tol) || n >= max_iter) {
max_iter = n;
tol = sqrt(2.*Tu);
return 0;
}
Real slope = T.slope(P, Fu, delta_u);
Field u_old = u;
Real Tu_old = Tu;
lambda = 1;
int status = newton_backtrack (
P, T, u_old, Tu_old, delta_u, slope, norm_delta_u_max, u, Fu, Tu, lambda, p_derr);
if (status != 0) {
// check if grad(T)(u) approx 0 ?
// let T(u) = 0.5*|A*F(u)|_M
// compute grad(T) = F(u)^T A^T M A F(u)
// and compare to F(u) : |grad(T)(u)| / |F(u)| > tol ?
Field Gu = T.grad(P,Fu);
const Float eps_mach = std::numeric_limits<Float>::epsilon();
max_iter = n;
tol = sqrt(2.*Tu);
if (P.space_norm(Gu) > eps_mach*P.dual_space_norm(Fu)) {
if (p_derr) *p_derr << "# damped-Newton: warning: machine precision reached" << std::endl << std::flush;
return 0;
} else {
if (p_derr) *p_derr << "# damped-Newton: warning: gradient is zero up to machine precision" << std::endl << std::flush;
return 1;
}
}
}
tol = sqrt(2*Tu);
return 1;
}
struct newton_identity_preconditioner {
template <class Problem>
Float operator() (const Problem& P, const typename Problem::value_type& MFv) const {
return 0.5*sqr(P.dual_space_norm(MFv));
}
template <class Problem>
Float operator() (const Problem& P, const typename Problem::value_type& MFu, const typename Problem::value_type& delta_u) const {
return operator() (P, MFu);
}
template <class Problem>
typename Problem::value_type grad (const Problem& P, const typename Problem::value_type& MFu) const {
return P.derivative_trans_mult (MFu);
}
template <class Problem>
Float slope (const Problem& P, const typename Problem::value_type& MFu, const typename Problem::value_type& delta_u) const {
return -sqr(P.dual_space_norm(MFu));
}
};
}// namespace rheolef
# endif // _RHEO_DAMPED_NEWTON_GENERIC_H
Float
see the Float page for the full documentation
rheolef::odiststream
odiststream: see the diststream page for the full documentation
Definition diststream.h:137
rheolef::Float
double Float
see the Float page for the full documentation
Definition Float.h:143
T
Expr1::float_type T
Definition field_expr.h:230
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::dis_wall_time
double dis_wall_time()
Definition dis_cpu_time.cc:130
rheolef::damped_newton
int damped_newton(const Problem &P, const Preconditioner &T, Field &u, Real &tol, Size &max_iter, odiststream *p_derr=0)
see the damped_newton page for the full documentation
Definition damped-newton-generic.h:29
rheolef::newton_backtrack
int newton_backtrack(const Problem &P, const Preconditioner &T, const Field &u_old, Float Tu_old, Field &delta_u, Real slope, Real norm_delta_u_max, Field &u, Field &Fu, Real &Tu, Real &lambda, odiststream *p_derr=0)
Definition newton-backtrack.h:26
rheolef::dis_cpu_time
double dis_cpu_time()
Definition dis_cpu_time.cc:45
lambda
Definition yield_slip_circle.h:34
rheolef::newton_identity_preconditioner
Definition damped-newton-generic.h:77
rheolef::newton_identity_preconditioner::operator()
Float operator()(const Problem &P, const typename Problem::value_type &MFv) const
Definition damped-newton-generic.h:79
rheolef::newton_identity_preconditioner::slope
Float slope(const Problem &P, const typename Problem::value_type &MFu, const typename Problem::value_type &delta_u) const
Definition damped-newton-generic.h:91
rheolef::newton_identity_preconditioner::grad
Problem::value_type grad(const Problem &P, const typename Problem::value_type &MFu) const
Definition damped-newton-generic.h:87
u
Definition leveque.h:25