13#ifndef OPTIMIST_ROOTFINDER_VARONA_HH
14#define OPTIMIST_ROOTFINDER_VARONA_HH
20 namespace RootFinder {
27 template <
typename Scalar>
28 requires TypeTrait<Scalar>::IsScalar
69 return this->m_method;
77 this->m_method = t_method;
84 this->m_method = Method::ORDER_4;
91 this->m_method = Method::ORDER_8;
98 this->m_method = Method::ORDER_16;
105 this->m_method = Method::ORDER_32;
120 template <
typename FunctionLambda>
125 [[maybe_unused]]
const Scalar ddf) {
126#define CMD "Optimist::RootFinder::Varona::step_impl(...): "
133 auto next = [&](
Scalar &value) ->
bool {
135 CMD "function evaluation failed.");
139 Scalar f_y, f_z, f_w, f_h;
144 if (std::abs(t) > 0.5) {
147 step -=
Q(t) * f_y / df;
148 if (order < 8 || !next(f_z)) {
151 const Scalar s{f_z / f_y};
152 step -=
W(t, s) * f_z / df;
153 if (order < 16 || !next(f_w)) {
156 const Scalar u{f_w / f_z};
157 step -=
H(t, s, u) * f_w / df;
158 if (order < 32 || !next(f_h)) {
161 const Scalar w{f_h / f_w};
162 return step -
J(t, s, u, w) * f_h / df;
174 return 1.0 + 2.0 * t;
184 return t * t * (1.0 - 4.0 * t) + (4.0 * s + 2.0) * t + s + 1.0;
200 return ((8.0 * u + 6.0 * t2 + 4.0) * s -
201 (6.0 * t8 + 4.0 * (s + u + 1.0)) * t1 + 2.0 * t8 - 4.0 * t17 +
204 t1 * (t8 + s + u + 1.0) + (1.0 - 3.0 * t2 + t23) * s + u - t17 +
226 Scalar t76{
static_cast<Scalar>(-2.0 * t22 + u + 4.0 * v + 2.0) * u};
227 return (-1.0 + 2.0 * t) * (2.0 + 5.0 * t) * u * t * t2 +
228 (4.0 * t + 1.0) * u * s * t2 +
229 (u * t22 - 2.0 * u * v - u - v - 1.0) *
230 (4.0 * t17 + 3.0 * t + 1.0) * (-1.0 + t) -
232 (t22 * (t17 / 2.0 - 1.0 / 4.0) +
233 u * (t17 * t32 - 5.0 / 8.0 * t34 - 3.0 / 4.0 * t32 +
234 3.0 / 8.0 * t37 + 3.0 / 4.0 * t17 - t / 8.0 -
236 3.0 / 4.0 * t46 * (t + 1.0 / 2.0) * (t - 2.0 / 3.0)) *
239 (t22 * (-3.0 / 2.0 * t - 1.0 / 4.0) +
240 u * (t34 - t32 - 3.0 / 2.0 * t37 + t17 / 4.0 - t -
242 t46 * (t + 1.0 / 4.0)) *
244 (1.0 + v + t65 * t17 - 4.0 * t65 * t37 - 3.0 * t65 * t32 +
245 6.0 * t65 * t34 + t76 + 4.0 * (1.0 + v + t76) * t) *
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
#define OPTIMIST_ASSERT(COND, MSG)
Definition Optimist.hh:48
Base class for the open (i.e., non-bracketing) one-dimensional root finders of Newton type.
Definition OpenMethod.hh:46
typename TypeTrait< Scalar >::Scalar Scalar
Definition RootFinder.hh:47
void enable_16th_order_method()
Definition Varona.hh:97
static Scalar W(Scalar t, Scalar s)
Definition Varona.hh:183
Method method() const
Definition Varona.hh:68
static Scalar J(Scalar t, Scalar s, Scalar u, Scalar v)
Definition Varona.hh:216
void enable_4th_order_method()
Definition Varona.hh:83
void enable_8th_order_method()
Definition Varona.hh:90
static Scalar H(Scalar t, Scalar s, Scalar u)
Definition Varona.hh:194
void enable_32th_order_method()
Definition Varona.hh:104
Method m_method
Definition Varona.hh:48
constexpr std::string name_impl() const
Definition Varona.hh:60
static constexpr bool RequiresFirstDerivative
Definition Varona.hh:32
Varona()
Definition Varona.hh:54
Scalar step_impl(FunctionLambda &function, const Scalar x, const Scalar f, const Scalar df, const Scalar ddf)
Definition Varona.hh:121
static constexpr bool RequiresSecondDerivative
Definition Varona.hh:33
static Scalar Q(Scalar t)
Definition Varona.hh:173
void method(const Method t_method)
Definition Varona.hh:76
static constexpr bool RequiresFunction
Definition Varona.hh:31
enum class Method :Integer { ORDER_4=4, ORDER_8=8, ORDER_16=16, ORDER_32=32 } Method
Definition Varona.hh:40
bool evaluate_function(FunctionLambda &&function, const Scalar &x, Scalar &out)
Definition SolverBase.hh:1026
Scalar m_tolerance
Definition SolverBase.hh:108
Scalar tolerance() const
Definition SolverBase.hh:458
Namespace for the Optimist library.
Definition Optimist.hh:90
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98