10 #ifndef SRC_INCLUDE_SMASH_ROOTSOLVER_H_
11 #define SRC_INCLUDE_SMASH_ROOTSOLVER_H_
18 #include "gsl/gsl_errno.h"
19 #include "gsl/gsl_math.h"
20 #include "gsl/gsl_roots.h"
38 root_eq_ = std::make_unique<std::function<double(
double)>>(eq);
52 double initial_guess_high,
57 <<
"Function has same sign at both ends of the interval ["
58 << initial_guess_low <<
", " << initial_guess_high
59 <<
"]. Root can't be found in this interval.";
62 gsl_function function_GSL = {&(
gsl_func),
nullptr};
63 int status = GSL_CONTINUE;
66 gsl_root_fsolver_set(
Root_finder_, &function_GSL, initial_guess_low,
71 if (status != GSL_SUCCESS) {
73 static_cast<std::string
>(gsl_strerror(status)));
79 if (status == GSL_SUCCESS) {
80 double root = 0.5 * (xlow + xhigh);
84 }
while (status == GSL_CONTINUE && iter < itermax);
91 const gsl_root_fsolver_type *
Solver_name_ = gsl_root_fsolver_brent;
103 static inline std::unique_ptr<std::function<double(
double)>>
root_eq_ =
A class used for calculating the root of a one-dimensional equation.
RootSolver1D(std::function< double(double)> eq)
Construct a new Root Solver 1D object.
double solution_precision_
Expected precision of the root.
gsl_root_fsolver * Root_finder_
GSL root finding object to take care of root finding.
const gsl_root_fsolver_type * Solver_name_
GSL solver to use for root finding.
static double gsl_func(const double x, void *)
The function of which a root should be found in the form that GSL expects.
std::optional< double > try_find_root(double initial_guess_low, double initial_guess_high, size_t itermax)
Attempt to find a root in a given interval.
static std::unique_ptr< std::function< double(double)> > root_eq_
Static pointer to the function to solve.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
static constexpr int LRootSolver