ROOT
ROOT project
Loading...
Searching...
No Matches
stepper_def.hpp
Go to the documentation of this file.
1
14#ifndef ROOT_STEPPER_DEF_HPP
15#define ROOT_STEPPER_DEF_HPP
16
17#include <Eigen/Dense>
18#include <functional>
19
23template <typename T>
25 protected:
26 std::function<double(double)> function;
34 virtual Eigen::Vector2d compute_step(Eigen::Vector2d) = 0;
41 Eigen::Vector2d aitken_step(Eigen::Vector2d previous_iter);
42
43 public:
50 StepperBase(std::function<double(double)> fun, bool aitken_mode);
51 virtual ~StepperBase() = default;
58 Eigen::Vector2d step(Eigen::Vector2d previous_step);
59};
60
64template <typename T>
66 private:
67 std::function<double(double)> derivative;
68
69 public:
76 NewtonRaphsonStepper(std::function<double(double)> fun, bool aitken_mode, std::function<double(double)> der);
82 Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override;
83};
84
86template <typename T>
87class FixedPointStepper : public StepperBase<T> {
88 private:
89 std::function<double(double)> fixed_point_function;
90
91 public:
98 FixedPointStepper(std::function<double(double)> fun, bool aitken_mode, std::function<double(double)> g_fun);
105 Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override;
106};
107
109template <typename T>
110class ChordsStepper : public StepperBase<T> {
111 private:
113 // It could seem a bit redundant because the latest iteration is input in the compute_step method too, passed from
114 // the Solver class, but it was more important to unify the compute_step calling with just one syntax.
115 public:
122 ChordsStepper(std::function<double(double)> fun, bool aitken_mode, Eigen::Vector2d _int);
131 Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override;
132};
133
135template <typename T>
136class BisectionStepper : public StepperBase<T> {
137 private:
139
140 public:
147 BisectionStepper(std::function<double(double)> fun, bool aitken_mode, Eigen::Vector2d _int);
156 Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override;
157};
158
159#endif // ROOT_STEPPER_DEF_HPP
The specialized Stepper to compute a step with the Bisection Method.
Definition stepper_def.hpp:136
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with Bisection. Let left_edge = a,...
BisectionStepper(std::function< double(double)> fun, bool aitken_mode, Eigen::Vector2d _int)
Constructor of a BisectionStepper object.
double right_edge
Bounds of the interval to use (updated at each step)
Definition stepper_def.hpp:138
double left_edge
Definition stepper_def.hpp:138
The specialized Stepper to compute a step with the Chords Method (also called Secants in literature)
Definition stepper_def.hpp:110
double iter_zero
The two previous guesses required at each iteration.
Definition stepper_def.hpp:112
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with Chords.
ChordsStepper(std::function< double(double)> fun, bool aitken_mode, Eigen::Vector2d _int)
Constructor for the ChordsStepper class.
double iter_minus_1
Definition stepper_def.hpp:112
The specialized Stepper to compute a step with the Fixed Point method.
Definition stepper_def.hpp:87
FixedPointStepper(std::function< double(double)> fun, bool aitken_mode, std::function< double(double)> g_fun)
The specialized constructor - initializes the function and the fixed point function.
std::function< double(double)> fixed_point_function
tores the fixed point to use in the steps
Definition stepper_def.hpp:89
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with FP.
The specialized Stepper to compute a step with the Newton-Raphson method.
Definition stepper_def.hpp:65
std::function< double(double)> derivative
Stores the derivative of the function.
Definition stepper_def.hpp:67
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with NR.
NewtonRaphsonStepper(std::function< double(double)> fun, bool aitken_mode, std::function< double(double)> der)
The specialized constructor - initializes the function and the derivative.
The virtual mother stepper class which defines constructor and method in common for all the methods.
Definition stepper_def.hpp:24
Eigen::Vector2d step(Eigen::Vector2d previous_step)
Method handling all the steps involved in computing the new guess.
Definition stepper.hpp:17
bool aitken_requirement
Option to use Aitken's acceleration.
Definition stepper_def.hpp:27
std::function< double(double)> function
Function to compute the root of.
Definition stepper_def.hpp:26
virtual ~StepperBase()=default
Eigen::Vector2d aitken_step(Eigen::Vector2d previous_iter)
Method to handle the computation of a step using Aitken's acceleration.
Definition stepper.hpp:26
virtual Eigen::Vector2d compute_step(Eigen::Vector2d)=0
Virtual function to compute the step for the method -> overridden by all the methods.