13#ifndef OPTIMIST_ROOTFINDER_QUASINEWTON_HH
14#define OPTIMIST_ROOTFINDER_QUASINEWTON_HH
19 namespace RootFinder {
38 template <
typename Vector,
typename DerivedSolver>
39 requires TypeTrait<Vector>::IsEigen &&
40 (!TypeTrait<Vector>::IsFixed || TypeTrait<Vector>::Dimension > 0)
59 return static_cast<const DerivedSolver *
>(
this)->
name_impl();
74 template <
typename FunctionLambda,
typename JacobianLambda>
76 JacobianLambda &&jacobian,
79#define CMD "Optimist::RootFinder::QuasiNewton::solve(...): "
91 Scalar residuals, step_norm;
92 Vector x_old, x_new, function_old, function_new, step_old, step_new,
93 delta_x_old, delta_x_new, delta_function_old, delta_function_new;
103 CMD "function evaluation failed at the initial point.");
106 CMD "jacobian evaluation failed at the initial point.");
115 step_old = -jacobian_old * function_old;
118 residuals = function_old.norm();
119 step_norm = step_old.norm();
121 this->
info(residuals);
123 if (residuals < tolerance_residuals ||
124 step_norm < tolerance_step_norm) {
131 damped = this->
damp(std::forward<FunctionLambda>(function),
139 "Optimist::RootFinder::QuasiNewton::solve(."
140 "..): damping failed.");
143 x_new = x_old + step_old;
149 CMD "function evaluation failed at iteration "
154 delta_x_new = x_new - x_old;
155 delta_function_new = function_new - function_old;
167 function_old = function_new;
168 delta_x_old = delta_x_new;
169 delta_function_old = delta_function_new;
171 jacobian_old = jacobian_new;
197 const Vector &delta_function_old,
199 const Vector &delta_x_new,
200 const Vector &delta_function_new,
201 const Vector &function_new,
203 static_cast<DerivedSolver *
>(
this)->update_impl(
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
#define OPTIMIST_ASSERT_WARNING(COND, MSG)
Definition Optimist.hh:62
#define OPTIMIST_ASSERT(COND, MSG)
Definition Optimist.hh:48
QuasiNewton()
Definition QuasiNewton.hh:52
void update(const Vector &delta_x_old, const Vector &delta_function_old, const FirstDerivative &jacobian_old, const Vector &delta_x_new, const Vector &delta_function_new, const Vector &function_new, FirstDerivative &jacobian_new)
Definition QuasiNewton.hh:196
constexpr std::string name_impl() const
Definition QuasiNewton.hh:58
TypeTrait< Vector > VectorTrait
Definition QuasiNewton.hh:43
typename TypeTrait< Vector >::Scalar Scalar
Definition QuasiNewton.hh:44
bool solve_impl(FunctionLambda &&function, JacobianLambda &&jacobian, const Vector &x_ini, Vector &x_sol)
Definition QuasiNewton.hh:75
RootFinder()
Definition RootFinder.hh:66
bool evaluate_jacobian(JacobianLambda &&jacobian, const Input &x, FirstDerivative &out)
Definition RootFinder.hh:136
bool damp(FunctionLambda &&function, const Vector &x_old, const Vector &function_old, const Vector &step_old, Vector &x_new, Vector &function_new, Vector &step_new)
Definition SolverBase.hh:1109
void info(Scalar residuals, const std::string ¬es="-")
Definition SolverBase.hh:1232
std::conditional_t< InputTrait::IsEigen||OutputTrait::IsEigen, std::conditional_t< InputTrait::IsSparse||OutputTrait::IsSparse, Eigen::SparseMatrix< Scalar >, Eigen::Matrix< Scalar, OutputTrait::Dimension, InputTrait::Dimension > >, Scalar > FirstDerivative
Definition SolverBase.hh:80
bool evaluate_function(FunctionLambda &&function, const Vector &x, Vector &out)
Definition SolverBase.hh:1040
bool m_damped
Definition SolverBase.hh:131
Integer m_max_iterations
Definition SolverBase.hh:121
Scalar m_tolerance
Definition SolverBase.hh:128
void header()
Definition SolverBase.hh:1168
void reset_counters()
Definition SolverBase.hh:1022
Integer m_iterations
Definition SolverBase.hh:120
bool m_verbose
Definition SolverBase.hh:130
bool m_converged
Definition SolverBase.hh:136
void bottom()
Definition SolverBase.hh:1205
Namespace for the Optimist library.
Definition Optimist.hh:90
Definition Optimist.hh:114