13#ifndef OPTIMIST_SCALAR_ROOT_FINDER_CHEBYSHEV_HH
14#define OPTIMIST_SCALAR_ROOT_FINDER_CHEBYSHEV_HH
20 namespace ScalarRootFinder
39 template <
typename Real>
77 #define CMD "Optimist::ScalarRootFinder::Chebyshev::solve(...): "
87 Real residuals, step_norm;
88 Real x_old, x_new, function_old, function_new, step_old, step_new;
89 Real first_derivative_old, second_derivative_old;
108 if (std::abs(first_derivative_old) < EPSILON_LOW) {
110 first_derivative_old = (first_derivative_old > 0.0) ? EPSILON_LOW : -EPSILON_LOW;
112 if (std::abs(second_derivative_old) < EPSILON_LOW) {
114 second_derivative_old = (second_derivative_old > 0.0) ? EPSILON_LOW : -EPSILON_LOW;
116 step_old = -(function_old / first_derivative_old) * (1.0 + (function_old * second_derivative_old) /
117 (first_derivative_old * first_derivative_old));
121 residuals = std::abs(function_old);
122 step_norm = std::abs(step_old);
124 if (residuals < tolerance_residuals || step_norm < tolerance_step_norm) {
131 damped = this->
damp(function, x_old, function_old, step_old, x_new, function_new, step_new);
135 x_new = x_old + step_old;
141 function_old = function_new;
#define OPTIMIST_WARNING(MSG)
Definition Optimist.hh:52
#define OPTIMIST_ASSERT_WARNING(COND, MSG)
Definition Optimist.hh:60
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
#define OPTIMIST_ASSERT(COND, MSG)
Definition Optimist.hh:43
typename ScalarRootFinder< Real, Chebyshev< Real > >::FunctionWrapper FunctionWrapper
Definition Chebyshev.hh:50
typename ScalarRootFinder< Real, Chebyshev< Real > >::FirstDerivativeWrapper FirstDerivativeWrapper
Definition Chebyshev.hh:51
static constexpr bool requires_first_derivative
Definition Chebyshev.hh:44
typename ScalarRootFinder< Real, Chebyshev< Real > >::SecondDerivativeWrapper SecondDerivativeWrapper
Definition Chebyshev.hh:52
static constexpr bool requires_second_derivative
Definition Chebyshev.hh:45
bool solve_impl(FunctionWrapper function, FirstDerivativeWrapper first_derivative, SecondDerivativeWrapper second_derivative, Real x_ini, Real &x_sol)
Definition Chebyshev.hh:74
std::string name_impl() const
Definition Chebyshev.hh:63
Chebyshev()
Definition Chebyshev.hh:57
static constexpr bool requires_function
Definition Chebyshev.hh:43
ScalarRootFinder()
Definition ScalarRootFinder.hh:66
Real m_tolerance
Definition Solver.hh:92
bool m_verbose
Definition Solver.hh:93
bool m_converged
Definition Solver.hh:99
bool m_damped
Definition Solver.hh:94
void store_trace(const InputType &x)
Definition Solver.hh:750
void header()
Definition Solver.hh:799
void reset()
Definition Solver.hh:693
bool damp(FunctionWrapper function, InputType const &x_old, InputType const &function_old, InputType const &step_old, InputType &x_new, InputType &function_new, InputType &step_new)
Definition Solver.hh:763
void evaluate_first_derivative(FirstDerivativeWrapper function, const InputType &x, FirstDerivativeType &out)
Definition Solver.hh:724
void bottom()
Definition Solver.hh:829
void evaluate_function(FunctionWrapper function, const InputType &x, OutputType &out)
Definition Solver.hh:710
void info(Real residuals, std::string const ¬es="-")
Definition Solver.hh:853
Integer m_iterations
Definition Solver.hh:85
Integer m_max_iterations
Definition Solver.hh:86
void evaluate_second_derivative(SecondDerivativeWrapper function, const InputType &x, SecondDerivativeType &out)
Definition Solver.hh:738
Namespace for the Optimist library.
Definition Optimist.hh:87
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95