ROOT
ROOT project
Loading...
Searching...
No Matches
solver_def.hpp
Go to the documentation of this file.
1
14#ifndef ROOT_SOLVER_DEF_HPP
15#define ROOT_SOLVER_DEF_HPP
16
17#include <Eigen/Dense>
18#include <Eigen/Sparse>
19#include <functional>
20#include <string>
21
22#include "method.hpp"
23#include "stepper_def.hpp"
24
25template <typename T>
26class StepperBase;
30template <typename T>
31class Solver {
32 private:
33 friend class SolverTester;
36 double tolerance;
38 bool verbose;
39 std::function<double(double)>
41 Eigen::MatrixX2d results;
43 std::function<double(double)>
52 void solver_step(int& iter, std::unique_ptr<StepperBase<T>>& stepper, double& err);
58 void save_results(int iter, Eigen::Vector2d result_to_save);
64 Eigen::Vector2d get_previous_result(int step_length);
71 double calculate_error(double x_prev, double x_next);
81 void convert_stepper(std::unique_ptr<StepperBase<T>>& stepper);
82
83 public:
95 Solver(std::function<double(double)> fun, T initial_guess, const Method method, int max_iterations,
96 double tolerance, bool aitken_mode, bool verbose);
109 Solver(std::function<double(double)> fun, T initial_guess, const Method method, int max_iterations,
110 double tolerance, bool aitken_mode, bool verbose, std::function<double(double)> derivative_or_function_g);
115 Eigen::MatrixX2d solve();
116};
117
118#endif // ROOT_SOLVER_DEF_HPP
Definition solver_tester.hpp:10
Class Solver managing the solving process and creating the Stepper object.
Definition solver_def.hpp:31
double tolerance
Stores the tolerance below which the process ends.
Definition solver_def.hpp:36
void save_results(int iter, Eigen::Vector2d result_to_save)
Saves the result of a step in a defined row of the results' matrix.
Definition solver.hpp:78
int max_iterations
Stores the maximum iterations for the method.
Definition solver_def.hpp:35
Eigen::MatrixX2d solve()
Calls everything required to Solve with a method.
Definition solver.hpp:108
void save_starting_point()
Saves the actual initial guess in the top row of the results' matrix, no matter what type will be the...
void convert_stepper(std::unique_ptr< StepperBase< T > > &stepper)
Converts the generic Abstract stepper into a typed one.
bool aitken_requirement
True if Aitken acceleration is required, 0 otherwise.
Definition solver_def.hpp:37
std::function< double(double)> function
Stores the function to find the root of and the starting guess for the process.
Definition solver_def.hpp:44
std::function< double(double)> derivative_or_function_g
Stores the derivative or g_function of the function if needed.
Definition solver_def.hpp:40
void solver_step(int &iter, std::unique_ptr< StepperBase< T > > &stepper, double &err)
Creates the stepper, calls the step computation, the error calculation and the results' saver.
Definition solver.hpp:149
Eigen::Vector2d get_previous_result(int step_length)
Returns a row of the results' matrix.
Definition solver.hpp:84
bool verbose
Verbose mode flag.
Definition solver_def.hpp:38
Eigen::MatrixX2d results
Definition solver_def.hpp:41
T initial_guess
Templated initial_guess for the method, whose type changes depending on the method itself.
Definition solver_def.hpp:45
double calculate_error(double x_prev, double x_next)
Computes the error of the latest iteration.
Definition solver.hpp:103
Method method
Method which will be used - defined thanks to.
Definition solver_def.hpp:34
The virtual mother stepper class which defines constructor and method in common for all the methods.
Definition stepper_def.hpp:24
Method
Enumeration of available root-finding methods.
Definition method.hpp:8
Contains definitions for all the Classes Stepper to compute steps of numerical methods to find the ro...