13#ifndef OPTIMIST_ROOTFINDER_HH
14#define OPTIMIST_ROOTFINDER_HH
46 template <
typename Real, Integer N,
typename DerivedSolver,
bool ForceEigen = false>
51 static_assert(N !=
static_cast<Integer>(0),
52 "Are you sure you want to solve a zero-dimensional system of equations?");
88 std::string
name()
const {
return static_cast<const DerivedSolver *
>(
this)->name_impl();}
165 #define CMD "Optimist::RootFinder::solve(...): "
167 static_assert(DerivedSolver::requires_function,
168 CMD "the solver requires a function.");
169 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, x_ini, x_sol);
184 #define CMD "Optimist::RootFinder::solve(...): "
186 static_assert(DerivedSolver::requires_function,
187 CMD "the solver requires a function.");
188 static_assert(DerivedSolver::requires_first_derivative,
189 CMD "the solver requires the first derivative.");
190 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, jacobian, x_ini, x_sol);
205 const & x_ini,
Vector & x_sol)
207 #define CMD "Optimist::RootFinder::solve(...): "
209 static_assert(DerivedSolver::requires_function,
210 CMD "the solver requires the function.");
211 static_assert(DerivedSolver::requires_first_derivative,
212 CMD "the solver requires the first derivative.");
213 static_assert(DerivedSolver::requires_second_derivative,
214 CMD "the solver requires the second derivative.");
215 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, jacobian, hessian, x_ini, x_sol);
232 template <
typename Real,
typename DerivedSolver>
260 std::string
name()
const {
return static_cast<const DerivedSolver *
>(
this)->name_impl();}
271 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, x_ini, x_sol);
285 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, first_derivative, x_ini, x_sol);
298 second_derivate, Real x_ini, Real & x_sol)
300 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, first_derivative,
301 second_derivate, x_ini, x_sol);
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
static constexpr bool requires_function
Definition RootFinder.hh:241
bool solve(FunctionWrapper function, FirstDerivativeWrapper first_derivative, SecondDerivativeWrapper second_derivate, Real x_ini, Real &x_sol)
Definition RootFinder.hh:297
bool solve(FunctionWrapper function, Real x_ini, Real &x_sol)
Definition RootFinder.hh:269
typename SolverBase< Real, 1, 1, DerivedSolver >::FunctionWrapper FunctionWrapper
Definition RootFinder.hh:247
typename SolverBase< Real, 1, 1, DerivedSolver >::SecondDerivativeWrapper SecondDerivativeWrapper
Definition RootFinder.hh:249
static constexpr bool requires_second_derivative
Definition RootFinder.hh:243
bool solve(FunctionWrapper function, FirstDerivativeWrapper first_derivative, Real x_ini, Real &x_sol)
Definition RootFinder.hh:282
static constexpr bool is_optimizer
Definition RootFinder.hh:239
std::string name() const
Definition RootFinder.hh:260
typename SolverBase< Real, 1, 1, DerivedSolver >::FirstDerivativeWrapper FirstDerivativeWrapper
Definition RootFinder.hh:248
static constexpr bool requires_first_derivative
Definition RootFinder.hh:242
RootFinder()
Definition RootFinder.hh:254
static constexpr bool is_rootfinder
Definition RootFinder.hh:238
Class container for the multi-dimensional root finder.
Definition RootFinder.hh:48
static constexpr bool is_optimizer
Definition RootFinder.hh:57
void max_jacobian_evaluations(Integer t_jacobian_evaluations)
Definition RootFinder.hh:106
static constexpr bool requires_first_derivative
Definition RootFinder.hh:60
bool solve(FunctionWrapper function, JacobianWrapper jacobian, HessianWrapper hessian, Vector const &x_ini, Vector &x_sol)
Definition RootFinder.hh:204
std::string name() const
Definition RootFinder.hh:88
bool solve(FunctionWrapper function, Vector const &x_ini, Vector &x_sol)
Definition RootFinder.hh:163
typename SolverBase< Real, N, N, DerivedSolver, ForceEigen >::InputType Vector
Definition RootFinder.hh:68
typename SolverBase< Real, N, N, DerivedSolver, ForceEigen >::SecondDerivativeWrapper HessianWrapper
Definition RootFinder.hh:77
void max_hessian_evaluations(Integer t_hessian_evaluations)
Definition RootFinder.hh:127
typename SolverBase< Real, N, N, DerivedSolver, ForceEigen >::FunctionWrapper FunctionWrapper
Definition RootFinder.hh:75
bool solve(FunctionWrapper function, JacobianWrapper jacobian, Vector const &x_ini, Vector &x_sol)
Definition RootFinder.hh:182
typename SolverBase< Real, N, N, DerivedSolver, ForceEigen >::SecondDerivativeType Tensor
Definition RootFinder.hh:72
RootFinder()
Definition RootFinder.hh:82
void evaluate_jacobian(JacobianWrapper jacobian, const Vector &x, Matrix &out)
Definition RootFinder.hh:139
typename SolverBase< Real, N, N, DerivedSolver, ForceEigen >::FirstDerivativeType Matrix
Definition RootFinder.hh:71
Integer hessian_evaluations() const
Definition RootFinder.hh:115
Integer jacobian_evaluations() const
Definition RootFinder.hh:94
void evaluate_hessian(HessianWrapper hessian, const Vector &x, Matrix &out)
Definition RootFinder.hh:150
static constexpr bool is_rootfinder
Definition RootFinder.hh:56
typename SolverBase< Real, N, N, DerivedSolver, ForceEigen >::FirstDerivativeWrapper JacobianWrapper
Definition RootFinder.hh:76
static constexpr bool requires_second_derivative
Definition RootFinder.hh:61
static constexpr bool requires_function
Definition RootFinder.hh:59
Integer max_jacobian_evaluations() const
Definition RootFinder.hh:100
Integer max_hessian_evaluations() const
Definition RootFinder.hh:121
Class container for the generic root-finding/optimization problem solver.
Definition SolverBase.hh:44
std::conditional_t< ForceEigen||(SolInDim > 1)||(SolOutDim > 1), Eigen::Matrix< Real, SolOutDim, SolInDim >, Real > FirstDerivativeType
Definition SolverBase.hh:61
Integer max_first_derivative_evaluations() const
Definition SolverBase.hh:273
typename std::function< void(const InputType &, SecondDerivativeType &)> SecondDerivativeWrapper
Definition SolverBase.hh:69
typename std::conditional_t< ForceEigen||(SolInDim > 1), Eigen::Vector< Real, SolInDim >, Real > InputType
Definition SolverBase.hh:54
void evaluate_second_derivative(SecondDerivativeWrapper function, const InputType &x, SecondDerivativeType &out)
Definition SolverBase.hh:745
typename std::function< void(const InputType &, OutputType &)> FunctionWrapper
Definition SolverBase.hh:67
void evaluate_first_derivative(FirstDerivativeWrapper function, const InputType &x, FirstDerivativeType &out)
Definition SolverBase.hh:731
SolverBase()
Definition SolverBase.hh:107
std::conditional_t< ForceEigen||(SolInDim > 1)||(SolOutDim > 1), std::conditional_t< SolInDim==1||SolOutDim==1, Eigen::Matrix< Real, SolInDim, SolInDim >, std::vector< Eigen::Matrix< Real, SolInDim, SolInDim > > >, Real > SecondDerivativeType
Definition SolverBase.hh:62
Integer first_derivative_evaluations() const
Definition SolverBase.hh:267
typename std::function< void(const InputType &, FirstDerivativeType &)> FirstDerivativeWrapper
Definition SolverBase.hh:68
Namespace for the Optimist library.
Definition Optimist.hh:87
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95