11#ifndef OPTIMIST_ROOTFINDER_NEWTONRAPHSON_HH
12#define OPTIMIST_ROOTFINDER_NEWTONRAPHSON_HH
37 template <
typename Real>
61 std::string
name_impl()
const {
return "NewtonRaphson";}
74 #define CMD "Optimist::RootFinder::NewtonRaphson::solve(...): "
84 Real residuals, step_norm;
85 Real x_old, x_new, function_old, function_new, step_old, step_new;
86 Real first_derivative_old;
104 if (std::abs(first_derivative_old) < EPSILON_LOW) {
106 first_derivative_old = (first_derivative_old > 0.0) ? EPSILON_LOW : -EPSILON_LOW;
108 step_old = -function_old/first_derivative_old;
112 residuals = std::abs(function_old);
113 step_norm = std::abs(step_old);
115 if (residuals < tolerance_residuals || step_norm < tolerance_step_norm) {
122 damped = this->
damp(function, x_old, function_old, step_old, x_new, function_new, step_new);
126 x_new = x_old + step_old;
132 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 RootFinder< Real, 1, NewtonRaphson< Real > >::FirstDerivativeWrapper FirstDerivativeWrapper
Definition NewtonRaphson.hh:49
static constexpr bool requires_first_derivative
Definition NewtonRaphson.hh:42
static constexpr bool requires_second_derivative
Definition NewtonRaphson.hh:43
NewtonRaphson()
Definition NewtonRaphson.hh:55
std::string name_impl() const
Definition NewtonRaphson.hh:61
static constexpr bool requires_function
Definition NewtonRaphson.hh:41
typename RootFinder< Real, 1, NewtonRaphson< Real > >::FunctionWrapper FunctionWrapper
Definition NewtonRaphson.hh:48
bool solve_impl(FunctionWrapper function, FirstDerivativeWrapper first_derivative, Real x_ini, Real &x_sol)
Definition NewtonRaphson.hh:71
typename RootFinder< Real, 1, NewtonRaphson< Real > >::SecondDerivativeWrapper SecondDerivativeWrapper
Definition NewtonRaphson.hh:50
RootFinder()
Definition RootFinder.hh:82
bool m_damped
Definition SolverBase.hh:95
void info(Real residuals, std::string const ¬es="-")
Definition SolverBase.hh:860
Integer m_iterations
Definition SolverBase.hh:86
Integer m_max_iterations
Definition SolverBase.hh:87
void header()
Definition SolverBase.hh:806
void reset()
Definition SolverBase.hh:700
bool m_verbose
Definition SolverBase.hh:94
void evaluate_first_derivative(FirstDerivativeWrapper function, const InputType &x, FirstDerivativeType &out)
Definition SolverBase.hh:731
bool m_converged
Definition SolverBase.hh:100
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 SolverBase.hh:770
void store_trace(const InputType &x)
Definition SolverBase.hh:757
void bottom()
Definition SolverBase.hh:836
Real m_tolerance
Definition SolverBase.hh:93
void evaluate_function(FunctionWrapper function, const InputType &x, OutputType &out)
Definition SolverBase.hh:717
Namespace for multi-dimensional root-finding algorithms.
Definition RootFinder.hh:25
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