5#ifndef DUNE_GEOMETRY_UTILITY_ALGORITHMS_HH
6#define DUNE_GEOMETRY_UTILITY_ALGORITHMS_HH
23template <
class R =
double>
24struct GaussNewtonOptions
41enum class GaussNewtonErrorCode
44 JACOBIAN_NOT_INVERTIBLE,
62template <
class F,
class DF,
class Domain,
65GaussNewtonErrorCode gaussNewton (
const F& f,
const DF& df, Range y, Domain& x0,
66 GaussNewtonOptions<R> opts = {})
71 R resNorm0 = dy.two_norm();
74 if (resNorm0 < opts.absTol)
75 return GaussNewtonErrorCode::OK;
77 for (
int i = 0; i < opts.maxIt; ++i)
80 const bool invertible = FieldMatrixHelper<R>::xTRightInvA(df(x), dy, dx);
84 return GaussNewtonErrorCode::JACOBIAN_NOT_INVERTIBLE;
88 for (
int j = 0; j < opts.maxInnerIt; ++j) {
91 resNorm = dy.two_norm();
93 if (resNorm < resNorm0)
100 if (!(resNorm < resNorm0))
101 return GaussNewtonErrorCode::STAGNATION;
107 if (resNorm < opts.absTol)
108 return GaussNewtonErrorCode::OK;
112 if (!(resNorm < opts.absTol))
113 return GaussNewtonErrorCode::TOLERANCE_NOT_REACHED;
115 return GaussNewtonErrorCode::OK;