63 template<
typename Lambda,
typename Vec>
68 typename Vec::value_type eps;
123 template<
typename F,
typename X>
137 typedef std::size_t size_type;
142 : maxit(25), linesearchsteps(10), verbosity(0),
143 reduction(1
e-14), abslimit(1
e-30), converged(
false)
152 void set_sigma (
double sigma_)
185 typedef typename M::number_type
N;
187 using Real =
typename std::conditional<std::is_same<std::complex<double>,
N>::value,
double,
N>::type;
201 std::cout <<
"Newton "
202 <<
" norm=" << std::scientific << std::showpoint
203 << std::setprecision(4) <<
R0
208 for (size_type
i=1;
i<=maxit;
i++)
230 for (size_type
k=0;
k<linesearchsteps;
k++)
238 std::cout <<
" line search " << std::setw(2) <<
k
239 <<
" lambda=" << std::scientific << std::showpoint
240 << std::setprecision(4) << lambda
241 <<
" norm=" << std::scientific << std::showpoint
242 << std::setprecision(4) <<
newR
243 <<
" red=" << std::scientific << std::showpoint
244 << std::setprecision(4) <<
newR/
R
247 if (
newR<(1.0-0.25*lambda)*
R)
251 std::cout <<
" step" << std::setw(3) <<
i
252 <<
" norm=" << std::scientific << std::showpoint
253 << std::setprecision(4) <<
newR
254 <<
" red=" << std::scientific << std::showpoint
255 << std::setprecision(4) <<
newR/
R
263 if (
k==linesearchsteps-1)
266 std::cout <<
" line search not converged within " << linesearchsteps <<
" steps" << std::endl;
276 std::cout <<
"Newton converged in " <<
i <<
" steps"
277 <<
" reduction=" << std::scientific << std::showpoint
278 << std::setprecision(4) <<
R/
R0
281 iterations_taken =
i;
287 iterations_taken =
i;
289 std::cout <<
"Newton not converged within " << maxit <<
" iterations" << std::endl;
294 bool has_converged ()
const
298 size_type iterations()
const {
299 return iterations_taken;
305 mutable size_type iterations_taken = -1;
306 size_type linesearchsteps;
310 mutable bool converged;
325 typedef std::size_t size_type;
330 : maxit(25), linesearchsteps(10), verbosity(0),
331 reduction(1
e-14), abslimit(1
e-30), sigma(1.0), converged(
false)
374 typedef typename M::number_type
N;
383 std::cout <<
"Banach "
384 <<
" norm=" << std::scientific << std::showpoint
385 << std::setprecision(4) <<
R0
390 for (size_type
i=1;
i<=maxit;
i++)
406 std::cout <<
" " << std::setw(3) <<
i
407 <<
" norm=" << std::scientific << std::showpoint
408 << std::setprecision(4) <<
newR
409 <<
" red=" << std::scientific << std::showpoint
410 << std::setprecision(4) <<
newR/
R
417 if (
R<=reduction*
R0 ||
R<=abslimit)
421 std::cout <<
"Banach converged in " <<
i <<
" steps"
422 <<
" reduction=" << std::scientific << std::showpoint
423 << std::setprecision(4) <<
R/
R0
432 bool has_converged ()
const
439 size_type linesearchsteps;
444 mutable bool converged;
Solve nonlinear problem using a fixed point iteration.
Definition newton.hh:324
void set_linesearchsteps(size_type n)
maximum number of steps in linesearch before giving up
Definition newton.hh:347
void set_abslimit(double l)
basolute limit for defect
Definition newton.hh:359
void set_verbosity(size_type n)
control output given 0=nothing, 1=summary, 2=every step, 3=include line search
Definition newton.hh:353
void set_sigma(double sigma_)
damping parameter
Definition newton.hh:341
void set_maxit(size_type n)
maximum number of iterations before giving up
Definition newton.hh:335
void solve(const M &model, Vector< typename M::number_type > &x) const
do one step
Definition newton.hh:372
void set_reduction(double l)
reduction factor
Definition newton.hh:365
Banach()
constructor stores reference to the model
Definition newton.hh:329
Class with mathematical matrix operations.
Definition densematrix.hh:33
void update(const REAL s, const DenseMatrix &B)
Scaled update of a Matrix.
Definition densematrix.hh:489
size_t rowsize() const
get number of rows of the matrix
Definition densematrix.hh:136
size_t colsize() const
get number of columns of the matrix
Definition densematrix.hh:153
A generic problem class that can be set up with a lambda defining F(x)=0.
Definition newton.hh:65
Vec::value_type number_type
export number_type
Definition newton.hh:75
GenericNonlinearProblem(const Lambda &l_, const Vec &x_, number_type eps_=1e-7)
constructor stores parameter lambda
Definition newton.hh:78
void F(const Vec &x, Vec &result) const
model evaluation
Definition newton.hh:89
void F_x(const Vec &x, DenseMatrix< number_type > &result) const
jacobian evaluation needed for implicit solvers
Definition newton.hh:95
std::size_t size() const
return number of componentes for the model
Definition newton.hh:83
std::size_t size_type
export size_type
Definition newton.hh:72
Solve nonlinear problem using a damped Newton method.
Definition newton.hh:136
void set_abslimit(double l)
basolute limit for defect
Definition newton.hh:170
void set_verbosity(size_type n)
control output given 0=nothing, 1=summary, 2=every step, 3=include line search
Definition newton.hh:164
void set_linesearchsteps(size_type n)
maximum number of steps in linesearch before giving up
Definition newton.hh:158
void set_maxit(size_type n)
maximum number of iterations before giving up
Definition newton.hh:147
void set_reduction(double l)
reduction factor
Definition newton.hh:176
Newton()
constructor stores reference to the model
Definition newton.hh:141
void solve(const M &model, Vector< typename M::number_type > &x) const
do one step
Definition newton.hh:183
Example class for a nonlinear model F(x) = 0;.
Definition newton.hh:22
N number_type
export number_type
Definition newton.hh:28
void F_x(const Vector< N > &x, DenseMatrix< N > &result) const
jacobian evaluation needed for implicit solvers
Definition newton.hh:48
SquareRootProblem(number_type a_)
constructor stores parameter lambda
Definition newton.hh:31
void F(const Vector< N > &x, Vector< N > &result) const
model evaluation
Definition newton.hh:42
std::size_t size() const
return number of componentes for the model
Definition newton.hh:36
std::size_t size_type
export size_type
Definition newton.hh:25
This file implements LU decomposition.
void permute_forward(const Vector< std::size_t > &p, Vector< T > &b)
apply permutations to a right hand side vector
Definition lr.hh:160
T abs(const T &t)
our own abs class that works also for multiprecision types
Definition lr.hh:55
void lr_fullpivot(DenseMatrix< T > &A, Vector< std::size_t > &p, Vector< std::size_t > &q)
lr decomposition of A with full pivoting
Definition lr.hh:107
void permute_backward(const Vector< std::size_t > &q, Vector< T > &z)
apply permutations to a solution vector
Definition lr.hh:171
void apply_equilibrate(Vector< T > &s, Vector< T > &b)
apply row equilibration to right hand side vector
Definition lr.hh:203
void solveR(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume R = upper triangle of A and solve R x = b.
Definition lr.hh:233
void solveL(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume L = lower triangle of A with l_ii=1, solve L x = b.
Definition lr.hh:215
void row_equilibrate(DenseMatrix< T > &A, Vector< T > &s)
perform a row equilibration of a matrix; return scaling for later use
Definition lr.hh:182
GenericNonlinearProblem< F, X > getNonlinearProblem(const F &f, const X &x, typename X::value_type eps=1e-7)
A function returning a problem class.
Definition newton.hh:124