3 #include <Eigen/Sparse> 9 namespace NewtonRaphson
16 NoConvergence(
const std::string& caller =
"",
const std::string& message =
"")
25 static double Solve(
double dr,
double r)
37 template <
typename TR,
typename TDR,
typename TNorm,
typename TTol,
typename TInfo>
49 template <
typename TR,
typename TDR,
typename TNorm,
typename TTol,
typename TInfo = Vo
idInfo>
62 template <
typename TNonlinearProblem,
typename TX,
typename TSolver,
typename TLineSearchAlgorithm = NoLineSearch>
63 auto Solve(TNonlinearProblem&& problem, TX&& x0, TSolver&&
solver,
int maxIterations = 20,
64 TLineSearchAlgorithm&& lineSearch =
NoLineSearch(),
int* numIterations =
nullptr)
67 auto r = problem.Residual(x);
70 problem.Info(iteration, x, r);
72 if (problem.Norm(r) < problem.mTolerance)
75 while (iteration < maxIterations)
77 auto dr = problem.Derivative(x);
78 auto dx =
solver.Solve(dr, r);
82 if (lineSearch(problem, &r, &x, dx))
85 *numIterations = iteration;
86 problem.Info(iteration, x, r);
89 problem.Info(iteration, x, r);
92 *numIterations = iteration;
93 throw NoConvergence(__PRETTY_FUNCTION__,
"No convergence after " + std::to_string(iteration) +
" iterations.");
NoConvergence(const std::string &caller="", const std::string &message="")
Definition: NewtonRaphson.h:16
auto DefineProblem(TR residual, TDR derivative, TNorm norm, TTol tolerance, TInfo info=VoidInfo())
defines the problem, basically just to enable automatic template deduction.
Definition: NewtonRaphson.h:50
Base class for all exceptions thrown in NuTo.
Definition: Exception.h:9
auto Solve(TNonlinearProblem &&problem, TX &&x0, TSolver &&solver, int maxIterations=20, TLineSearchAlgorithm &&lineSearch=NoLineSearch(), int *numIterations=nullptr)
solves the Problem using the newton raphson iteration with linesearch
Definition: NewtonRaphson.h:63
TTol mTolerance
Definition: NewtonRaphson.h:43
constexpr double tolerance
Definition: NewtonRaphsonBenchmark.cpp:11
just a normal continuation of the newton scheme without using line search while keeping the interface...
Definition: LineSearch.h:79
solver
Definition: SparseDirectSolverMKLDSS.py:51
takes any argument and does nothing...
Definition: LineSearch.h:9
problem definition
Definition: NewtonRaphson.h:38
static double Solve(double dr, double r)
Definition: NewtonRaphson.h:25
TR Residual
Definition: NewtonRaphson.h:40
residual
Definition: Brick8NCoupling.py:135
Definition: Exception.h:6
TInfo Info
Definition: NewtonRaphson.h:44
TDR Derivative
Definition: NewtonRaphson.h:41
custom exception for the newton algorithm
Definition: NewtonRaphson.h:13
"Solver" for scalar values
Definition: NewtonRaphson.h:23
TNorm Norm
Definition: NewtonRaphson.h:42