13#ifndef OPTIMIST_ROOTFINDER_OPENMETHOD_HH
14#define OPTIMIST_ROOTFINDER_OPENMETHOD_HH
20 namespace RootFinder {
44 template <
typename Scalar,
typename DerivedSolver>
45 requires TypeTrait<Scalar>::IsScalar
58 template <
typename FunctionLambda,
typename FirstDerivativeLambda>
60 FirstDerivativeLambda &&first_derivative,
63 return this->
iterate(function, first_derivative,
nullptr, x_ini, x_sol);
75 template <
typename FunctionLambda,
76 typename FirstDerivativeLambda,
77 typename SecondDerivativeLambda>
79 FirstDerivativeLambda &&first_derivative,
80 SecondDerivativeLambda &&second_derivative,
95 template <
typename FunctionLambda,
96 typename FirstDerivativeLambda,
97 typename SecondDerivativePointer>
99 FirstDerivativeLambda &first_derivative,
100 SecondDerivativePointer second_derivative,
103#define CMD "Optimist::RootFinder::" << this->name() << "::solve(...): "
110 Scalar x{x_ini}, f{0}, df{0}, ddf{0}, step{0};
111 Scalar x_new{0}, f_new{0}, step_new{0};
113 CMD "function evaluation failed at the initial point.");
124 CMD "first derivative evaluation failed at iteration "
126 if constexpr (!std::is_same_v<SecondDerivativePointer,
130 CMD "second derivative evaluation failed at iteration "
135 std::string notes{
"-"};
136 if (std::abs(df) < SQRT_EPSILON) {
137 df = std::copysign(SQRT_EPSILON, df);
138 notes =
"Singular derivative";
140 step =
static_cast<DerivedSolver *
>(
this)->step_impl(function,
147 <<
" is not finite.");
151 this->
info(std::abs(f), notes);
153 if (std::abs(f) < tolerance_residuals ||
154 std::abs(step) < tolerance_step) {
161 this->
damp(function, x, f, step, x_new, f_new, step_new);
165 CMD "function evaluation failed at iteration "
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
#define OPTIMIST_ASSERT(COND, MSG)
Definition Optimist.hh:48
Base class for the open (i.e., non-bracketing) one-dimensional root finders of Newton type.
Definition OpenMethod.hh:46
bool solve_impl(FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, Scalar x_ini, Scalar &x_sol)
Definition OpenMethod.hh:59
bool solve_impl(FunctionLambda &&function, FirstDerivativeLambda &&first_derivative, SecondDerivativeLambda &&second_derivative, Scalar x_ini, Scalar &x_sol)
Definition OpenMethod.hh:78
bool iterate(FunctionLambda &function, FirstDerivativeLambda &first_derivative, SecondDerivativePointer second_derivative, const Scalar x_ini, Scalar &x_sol)
Definition OpenMethod.hh:98
RootFinder()
Definition RootFinder.hh:60
typename TypeTrait< Scalar >::Scalar Scalar
Definition RootFinder.hh:47
bool damp(FunctionLambda &&function, const Scalar &x_old, const Scalar &function_old, const Scalar &step_old, Scalar &x_new, Scalar &function_new, Scalar &step_new)
Definition SolverBase.hh:1095
void info(Scalar residuals, const std::string ¬es="-")
Definition SolverBase.hh:1218
bool evaluate_function(FunctionLambda &&function, const Scalar &x, Scalar &out)
Definition SolverBase.hh:1026
bool evaluate_first_derivative(FirstDerivativeLambda &&function, const Scalar &x, FirstDerivative &out)
Definition SolverBase.hh:1047
bool m_damped
Definition SolverBase.hh:111
bool evaluate_second_derivative(SecondDerivativeLambda &&function, const Scalar &x, SecondDerivative &out)
Definition SolverBase.hh:1068
Integer m_max_iterations
Definition SolverBase.hh:101
Scalar m_tolerance
Definition SolverBase.hh:108
void header()
Definition SolverBase.hh:1154
void reset_counters()
Definition SolverBase.hh:1008
Integer m_iterations
Definition SolverBase.hh:100
bool m_verbose
Definition SolverBase.hh:110
bool m_converged
Definition SolverBase.hh:116
void bottom()
Definition SolverBase.hh:1191
Namespace for the Optimist library.
Definition Optimist.hh:90