Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
ScalarRootFinder.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco, Mattia Piazza and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Mattia Piazza Enrico Bertolazzi *
7 * University of Trento University of Trento University of Trento *
8 * davide.stocco@unitn.it mattia.piazza@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_SCALAR_ROOT_FINDER_HH
14#define OPTIMIST_SCALAR_ROOT_FINDER_HH
15
16#include "Solver.hh"
17
18namespace Optimist
19{
20
25 {
26
27 /*\
28 | ____ _ ____ _ _____ _ _
29 | / ___| ___ __ _| | __ _ _ __| _ \ ___ ___ | |_| ___(_)_ __ __| | ___ _ __
30 | \___ \ / __/ _` | |/ _` | '__| |_) / _ \ / _ \| __| |_ | | '_ \ / _` |/ _ \ '__|
31 | ___) | (_| (_| | | (_| | | | _ < (_) | (_) | |_| _| | | | | | (_| | __/ |
32 | |____/ \___\__,_|_|\__,_|_| |_| \_\___/ \___/ \__|_| |_|_| |_|\__,_|\___|_|
33 |
34 \*/
35
44 template <typename Real, typename DerivedSolver>
45 class ScalarRootFinder : public Solver<Real, 1, 1, DerivedSolver>
46 {
47 public:
49
50 static constexpr bool is_rootfinder{true};
51 static constexpr bool is_optimizer{false};
52
53 static constexpr bool requires_function{DerivedSolver::requires_function};
54 static constexpr bool requires_first_derivative{DerivedSolver::requires_first_derivative};
55 static constexpr bool requires_second_derivative{DerivedSolver::requires_second_derivative};
56
58
59 using FunctionWrapper = typename Solver<Real, 1, 1, DerivedSolver>::FunctionWrapper;
60 using FirstDerivativeWrapper = typename Solver<Real, 1, 1, DerivedSolver>::FirstDerivativeWrapper;
61 using SecondDerivativeWrapper = typename Solver<Real, 1, 1, DerivedSolver>::SecondDerivativeWrapper;
62
67
72 std::string name() const {return static_cast<const DerivedSolver *>(this)->name_impl();}
73
81 bool solve(FunctionWrapper function, Real x_ini, Real & x_sol)
82 {
83 return static_cast<DerivedSolver *>(this)->solve_impl(function, x_ini, x_sol);
84 }
85
94 bool solve(FunctionWrapper function, FirstDerivativeWrapper first_derivative, Real x_ini,
95 Real & x_sol)
96 {
97 return static_cast<DerivedSolver *>(this)->solve_impl(function, first_derivative, x_ini, x_sol);
98 }
99
109 second_derivate, Real x_ini, Real & x_sol)
110 {
111 return static_cast<DerivedSolver *>(this)->solve_impl(function, first_derivative,
112 second_derivate, x_ini, x_sol);
113 }
114
115 }; // class ScalarRootFinder
116
117 } // namespace ScalarRootFinder
118
119} // namespace Optimist
120
121#endif // OPTIMIST_SCALAR_ROOT_FINDER_HH
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
Class container for the scalar scalar root-finder.
Definition ScalarRootFinder.hh:46
static constexpr bool requires_second_derivative
Definition ScalarRootFinder.hh:55
static constexpr bool is_rootfinder
Definition ScalarRootFinder.hh:50
bool solve(FunctionWrapper function, Real x_ini, Real &x_sol)
Definition ScalarRootFinder.hh:81
ScalarRootFinder()
Definition ScalarRootFinder.hh:66
std::string name() const
Definition ScalarRootFinder.hh:72
bool solve(FunctionWrapper function, FirstDerivativeWrapper first_derivative, Real x_ini, Real &x_sol)
Definition ScalarRootFinder.hh:94
static constexpr bool requires_function
Definition ScalarRootFinder.hh:53
typename Solver< Real, 1, 1, DerivedSolver >::FirstDerivativeWrapper FirstDerivativeWrapper
Definition ScalarRootFinder.hh:60
typename Solver< Real, 1, 1, DerivedSolver >::FunctionWrapper FunctionWrapper
Definition ScalarRootFinder.hh:59
static constexpr bool requires_first_derivative
Definition ScalarRootFinder.hh:54
bool solve(FunctionWrapper function, FirstDerivativeWrapper first_derivative, SecondDerivativeWrapper second_derivate, Real x_ini, Real &x_sol)
Definition ScalarRootFinder.hh:108
typename Solver< Real, 1, 1, DerivedSolver >::SecondDerivativeWrapper SecondDerivativeWrapper
Definition ScalarRootFinder.hh:61
static constexpr bool is_optimizer
Definition ScalarRootFinder.hh:51
Namespace for the Optimist library.
Definition Optimist.hh:87