13#ifndef OPTIMIST_ROOTFINDER_QUASINEWTON_HH
14#define OPTIMIST_ROOTFINDER_QUASINEWTON_HH
40 template <
typename Real, Integer N,
typename DerivedSolver>
69 return static_cast<const DerivedSolver *
>(
this)->
name_impl();
83 template <
typename FunctionLambda,
typename JacobianLambda>
84 bool solve_impl(FunctionLambda && function, JacobianLambda && jacobian,
Vector const & x_ini,
87 #define CMD "Optimist::RootFinder::QuasiNewton::solve(...): "
97 Real residuals, step_norm;
98 Vector x_old, x_new, function_old, function_new, step_old, step_new, delta_x_old, delta_x_new,
99 delta_function_old, delta_function_new;
100 Matrix jacobian_old, jacobian_new;
104 success = this->
evaluate_function(std::forward<FunctionLambda>(function), x_old, function_old);
106 CMD "function evaluation failed at the initial point.");
109 CMD "jacobian evaluation failed at the initial point.");
120 step_old = -jacobian_old * function_old;
123 residuals = function_old.norm();
124 step_norm = step_old.norm();
126 if (residuals < tolerance_residuals || step_norm < tolerance_step_norm) {
134 damped = this->
damp(std::forward<FunctionLambda>(function), x_old, function_old, step_old, x_new, function_new, step_new);
136 "Optimist::RootFinder::QuasiNewton::solve(...): damping failed.");
139 x_new = x_old + step_old;
140 success = this->
evaluate_function(std::forward<FunctionLambda>(function), x_new, function_new);
142 CMD "function evaluation failed at iteration " << this->
m_iterations <<
".");
146 delta_x_new = x_new - x_old;
147 delta_function_new = function_new - function_old;
149 delta_x_old, delta_function_old, jacobian_old,
150 delta_x_new, delta_function_new, function_new, jacobian_new
155 function_old = function_new;
156 delta_x_old = delta_x_new;
157 delta_function_old = delta_function_new;
159 jacobian_old = jacobian_new;
183 Vector const & delta_x_old,
Vector const & delta_function_old,
Matrix const & jacobian_old,
184 Vector const & delta_x_new,
Vector const & delta_function_new,
Vector const & function_new,
187 static_cast<DerivedSolver *
>(
this)->update_impl(
188 delta_x_old, delta_function_old, jacobian_old,
189 delta_x_new, delta_function_new, function_new, jacobian_new
#define OPTIMIST_ASSERT_WARNING(COND, MSG)
Definition Optimist.hh:61
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:71
void update(Vector const &delta_x_old, Vector const &delta_function_old, Matrix const &jacobian_old, Vector const &delta_x_new, Vector const &delta_function_new, Vector const &function_new, Matrix &jacobian_new)
Definition QuasiNewton.hh:182
QuasiNewton()
Definition QuasiNewton.hh:61
bool solve_impl(FunctionLambda &&function, JacobianLambda &&jacobian, Vector const &x_ini, Vector &x_sol)
Definition QuasiNewton.hh:84
Method m_method
Definition QuasiNewton.hh:55
enum class Method :Integer {GOOD=0, BAD=1, COMBINED=2} Method
Definition QuasiNewton.hh:52
std::string name_impl() const
Definition QuasiNewton.hh:67
typename SolverBase< Real, N, N, DerivedSolver, 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, DerivedSolver, 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
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:96