1 #ifndef theplu_yat_utility_root_finder_ 2 #define theplu_yat_utility_root_finder_ 25 #include "univariable/f.h" 26 #include "yat_assert.h" 28 #include <gsl/gsl_errno.h> 29 #include <gsl/gsl_roots.h> 57 unsigned int epochs(
void)
const;
62 const char*
name(
void)
const;
70 virtual bool operator()(
const gsl_root_fsolver*)=0;
82 Interval(
double epsabs,
double epsrel);
105 Delta(
double epsabs,
double epsrel);
115 std::unique_ptr<double> prev_;
129 : func_(func), epsabs_(epsabs)
148 double operator()(FUNC& func,
double lower,
double upper,Stopper&& stopper);
154 double operator()(FUNC& func,
double lower,
double upper,
155 Stopper&& stopper,
unsigned int max_epochs);
165 const gsl_root_fsolver_type* type_;
170 std::unique_ptr<gsl_root_fsolver, GslFree> solver_;
171 unsigned int epochs_;
181 return (*
this)(func, lower, upper, std::move(stopper), max_epochs);
189 unsigned int max_epochs)
191 gsl_function gsl_func;
192 gsl_func.function = univariable::f<FUNC>;
193 gsl_func.params = &func;
194 gsl_root_fsolver_set(solver_.get(), &gsl_func, lower, upper);
196 for (epochs_=0; epochs_<max_epochs && !stopper(solver_.get()); ++epochs_) {
197 int status = gsl_root_fsolver_iterate(solver_.get());
199 std::ostringstream ss;
200 ss <<
"RootFinder: at x = " 201 << gsl_root_fsolver_root(solver_.get());
207 return gsl_root_fsolver_root(solver_.get());
214 double x = gsl_root_fsolver_root(s);
216 return gsl_root_test_residual(f, epsabs_) == GSL_SUCCESS;
Delta(double epsabs, double epsrel)
virtual bool operator()(const gsl_root_fsolver *)=0
return true is search should stop
Interval(double epsabs, double epsrel)
Class for errors reported from underlying GSL calls.
Definition: Exception.h:102
The Department of Theoretical Physics namespace as we define it.
bool operator()(const gsl_root_fsolver *)
Definition: RootFinder.h:212
Definition: RootFinder.h:98
double operator()(FUNC &func, double lower, double upper, Stopper &&stopper)
Definition: RootFinder.h:177
Definition: RootFinder.h:66
Definition: RootFinder.h:121
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:699
const char * name(void) const
unsigned int epochs(void) const
Number of epochs (iterations) used in last minimisation.
Definition: RootFinder.h:45
RootFinder & operator=(const RootFinder &)=delete
Assignment is not allowed.
bool operator()(const gsl_root_fsolver *)
RootFinder(const RootFinder &)=delete
Copy is not allowed.
bool operator()(const gsl_root_fsolver *)
Residual(const FUNC &func, double epsabs)
Definition: RootFinder.h:128
Definition: RootFinder.h:75