Bayeux  3.4.1
Core Foundation library for SuperNEMO
one_dimensional_root_finding.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_ONE_DIMENSIONAL_ROOT_FINDING_H
4 #define MYGSL_ONE_DIMENSIONAL_ROOT_FINDING_H 1
5 
6 
7 // Third party:
8 // - GSL:
9 #include <gsl/gsl_roots.h>
10 
11 // This project:
12 #include <mygsl/i_unary_function.h>
14 #include <mygsl/best_value.h>
15 
16 namespace mygsl {
17 
20  {
21  public:
22 
23  static const std::string BISECTION_METHOD_LABEL;
24  static const std::string FALSEPOS_METHOD_LABEL;
25  static const std::string BRENT_METHOD_LABEL;
26 
27  static const std::string NEWTON_METHOD_LABEL;
28  static const std::string SECANT_METHOD_LABEL;
29  static const std::string STEFFENSON_METHOD_LABEL;
30  static const size_t DEFAULT_MAX_ITER;
31  static const double DEFAULT_EPSABS;
32 
33  enum mode_t
34  {
35  MODE_NULL = 0,
36  MODE_F = 1,
38  };
39 
41  {
42 
43  public:
44 
45  virtual void action (int status_,
46  size_t iter_,
47  double a_,
48  double b_,
49  double c_) = 0;
50 
51  void operator () (int status_,
52  size_t iter_,
53  double a_,
54  double b_,
55  double c_);
56  };
57 
59  {
60  virtual void action (int status_,
61  size_t iter_,
62  double a_,
63  double b_,
64  double c_);
65  };
66 
67  void unset_step_action ();
68 
70 
71  void set_step_action (at_step_action & action_);
72 
73  bool is_fsolver () const;
74 
75  bool is_fdfsolver () const;
76 
77  bool is_initialized () const;
78 
79  const best_value & get_root () const;
80 
81  std::string get_name () const;
82 
83  void set_debug (bool debug_ = true);
84 
85  bool is_debug () const;
86 
87  size_t get_iter () const;
88 
89  size_t get_max_iter () const;
90 
91  double get_epsabs () const;
92 
93  bool is_converged () const;
94 
95  one_dimensional_root_solver (bool debug_ = false);
96 
98 
99  void init (const i_unary_function & sys_, const std::string & method_ = BRENT_METHOD_LABEL);
100 
101  void init (const i_unary_function_with_derivative & sys_, const std::string & method_ = STEFFENSON_METHOD_LABEL);
102 
103  void reset ();
104 
105  int solve (double epsabs_, double a_, double b_);
106 
107  static double g_function (double x_, void * params_);
108 
109  static double g_dfunction (double x_, void * params_);
110 
111  static void g_fdfunction (double x_, void * params_, double * y_, double * dy_);
112 
113  static best_value solve (const i_unary_function & sys_,
114  double epsabs_,
115  double a_,
116  double b_,
117  const std::string & method_ = BRENT_METHOD_LABEL);
118 
120  double epsabs_,
121  double a_,
122  double b_,
123  const std::string & method_ = STEFFENSON_METHOD_LABEL);
124 
125  protected:
126 
127  void _at_step_hook (int status_,
128  size_t iter_,
129  double a_,
130  double b_,
131  double c_);
132 
133  private:
134 
135  static default_step_action _default_step_action_;
136 
137  private:
138 
139  bool _debug_;
140  const gsl_root_fsolver_type * _fsolver_type_;
141  const gsl_root_fdfsolver_type * _fdfsolver_type_;
142  gsl_root_fsolver * _fsolver_;
143  gsl_root_fdfsolver * _fdfsolver_;
144  int _mode_;
145  int _status_;
146  size_t _iter_;
147  size_t _max_iter_;
148  double _epsabs_;
149  bool _converged_;
150  const i_unary_function * _functor_f_;
151  const i_unary_function_with_derivative * _functor_fdf_;
152  const unary_function_promoted_with_numeric_derivative * _functor_numeric_fdf_;
153  best_value _root_;
154  gsl_function _function_;
155  gsl_function_fdf _fdfunction_;
156 
157  // hook step function:
158  at_step_action * _at_step_action_;
159 
160  };
161 
162 } // namespace mygsl
163 
164 #endif // MYGSL_ONE_DIMENSIONAL_ROOT_FINDING_H
165 
166 /* Local Variables: */
167 /* mode: c++ */
168 /* coding: utf-8 */
169 /* End: */
static void g_fdfunction(double x_, void *params_, double *y_, double *dy_)
void set_step_action(at_step_action &action_)
static const std::string STEFFENSON_METHOD_LABEL
Definition: one_dimensional_root_finding.h:29
static const std::string BRENT_METHOD_LABEL
Definition: one_dimensional_root_finding.h:25
int solve(double epsabs_, double a_, double b_)
Definition: one_dimensional_root_finding.h:36
virtual void action(int status_, size_t iter_, double a_, double b_, double c_)=0
Definition: one_dimensional_root_finding.h:37
static const std::string NEWTON_METHOD_LABEL
Definition: one_dimensional_root_finding.h:27
A data structure representing a numeric value and its associated error.
Definition: best_value.h:17
static const double DEFAULT_EPSABS
Definition: one_dimensional_root_finding.h:31
static const std::string BISECTION_METHOD_LABEL
Definition: one_dimensional_root_finding.h:23
Abstract interface for unary functions with derivative.
Definition: i_unary_function_with_derivative.h:28
virtual void action(int status_, size_t iter_, double a_, double b_, double c_)
static double g_function(double x_, void *params_)
static const std::string FALSEPOS_METHOD_LABEL
Definition: one_dimensional_root_finding.h:24
static const size_t DEFAULT_MAX_ITER
Definition: one_dimensional_root_finding.h:30
One dimensional root solver algorithm.
Definition: one_dimensional_root_finding.h:19
Definition: one_dimensional_root_finding.h:40
static const std::string SECANT_METHOD_LABEL
Definition: one_dimensional_root_finding.h:28
const best_value & get_root() const
one_dimensional_root_solver(bool debug_=false)
Definition: one_dimensional_root_finding.h:58
void init(const i_unary_function &sys_, const std::string &method_=BRENT_METHOD_LABEL)
Abstract interface for unary functions : R -> R.
Definition: i_unary_function.h:44
Unary functions wrapper that adds numeric derivative.
Definition: i_unary_function_with_derivative.h:52
static double g_dfunction(double x_, void *params_)
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
Definition: one_dimensional_root_finding.h:35
mode_t
Definition: one_dimensional_root_finding.h:33
void operator()(int status_, size_t iter_, double a_, double b_, double c_)
void set_debug(bool debug_=true)
void _at_step_hook(int status_, size_t iter_, double a_, double b_, double c_)