13#ifndef OPTIMIST_ROOTFINDER_NEWTON_HH
14#define OPTIMIST_ROOTFINDER_NEWTON_HH
40 template <
typename Real, Integer N>
54 Eigen::FullPivLU<Matrix>
m_lu;
79 template <
typename FunctionLambda,
typename JacobianLambda>
80 bool solve_impl(FunctionLambda && function, JacobianLambda && jacobian,
Vector const & x_ini,
83 #define CMD "Optimist::RootFinder::Newton::solve(...): "
93 Real residuals, step_norm;
94 Vector x_old, x_new, function_old, function_new, step_old, step_new;
99 success = this->
evaluate_function(std::forward<FunctionLambda>(function), x_old, function_old);
101 CMD "function evaluation failed at the initial point.");
114 CMD "jacobian evaluation failed at iteration " << this->
m_iterations <<
".");
115 this->m_lu.compute(jacobian_old);
117 "Optimist::RootFinder::Newton::solve(...): singular Jacobian detected.");
118 step_old = -this->m_lu.solve(function_old);
121 residuals = function_old.norm();
122 step_norm = step_old.norm();
124 if (residuals < tolerance_residuals || step_norm < tolerance_step_norm) {
132 damped = this->
damp(std::forward<FunctionLambda>(function), x_old, function_old, step_old, x_new, function_new, step_new);
134 "Optimist::RootFinder::Newton::solve(...): damping failed.");
137 x_new = x_old + step_old;
138 success = this->
evaluate_function(std::forward<FunctionLambda>(function), x_new, function_new);
140 CMD "function evaluation failed at iteration " << this->
m_iterations <<
".");
145 function_old = function_new;
#define OPTIMIST_ASSERT_WARNING(COND, MSG)
Definition Optimist.hh:61
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:71
#define OPTIMIST_ASSERT(COND, MSG)
Definition Optimist.hh:44
Newton()
Definition Newton.hh:60
static constexpr bool requires_function
Definition Newton.hh:44
static constexpr bool requires_first_derivative
Definition Newton.hh:45
std::string name_impl() const
Definition Newton.hh:66
Eigen::FullPivLU< Matrix > m_lu
Definition Newton.hh:54
static constexpr bool requires_second_derivative
Definition Newton.hh:46
bool solve_impl(FunctionLambda &&function, JacobianLambda &&jacobian, Vector const &x_ini, Vector &x_sol)
Definition Newton.hh:80
Class container for the multi-dimensional root finder.
Definition RootFinder.hh:48
typename SolverBase< Real, N, N, Newton< Real, N >, ForceEigen >::InputType Vector
Definition RootFinder.hh:61
RootFinder()
Definition RootFinder.hh:70
bool evaluate_jacobian(JacobianLambda &&jacobian, Vector const &x, Matrix &out)
Definition RootFinder.hh:130
typename SolverBase< Real, N, N, Newton< Real, N >, ForceEigen >::FirstDerivativeType Matrix
Definition RootFinder.hh:64
bool m_damped
Definition SolverBase.hh:93
void info(Real residuals, std::string const ¬es="-")
Definition SolverBase.hh:924
Integer m_iterations
Definition SolverBase.hh:84
bool damp(FunctionLambda &&function, InputType const &x_old, InputType const &function_old, InputType const &step_old, InputType &x_new, InputType &function_new, InputType &step_new)
Definition SolverBase.hh:828
Integer m_max_iterations
Definition SolverBase.hh:85
void store_trace(InputType const &x)
Definition SolverBase.hh:813
void header()
Definition SolverBase.hh:870
void reset()
Definition SolverBase.hh:748
bool m_verbose
Definition SolverBase.hh:92
bool m_converged
Definition SolverBase.hh:98
void bottom()
Definition SolverBase.hh:900
bool evaluate_function(FunctionLambda &&function, InputType const &x, OutputType &out)
Definition SolverBase.hh:768
Real m_tolerance
Definition SolverBase.hh:91
Namespace for the Optimist library.
Definition Optimist.hh:88