isce3 0.25.0
Loading...
Searching...
No Matches
RootFind1dBase.h
1// Base class for all 1-D Root finding classes
2#pragma once
3
4#include <functional>
5#include <optional>
6
7#include <isce3/core/Poly1d.h>
8#include <isce3/except/Error.h>
9
10namespace isce3 { namespace math { namespace detail {
11
21
22public:
23 // constructors
37 RootFind1dBase(double f_tol = 1e-5, int max_iter = 20,
38 std::optional<double> x_tol = {})
39 : f_tol {f_tol}, max_iter {max_iter}, x_tol {x_tol}
40 {
41 if (max_iter < 1)
42 throw isce3::except::InvalidArgument(
43 ISCE_SRCINFO(), "Max number of iterations must be >=1!");
44 if (!(f_tol > 0.0))
45 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
46 "Tolerance for function value must be positive!");
47 if (x_tol)
48 if (!(*x_tol > 0.0))
49 throw isce3::except::InvalidArgument(ISCE_SRCINFO(),
50 "Tolerance for function variable must be positive!");
51 }
52
59 RootFind1dBase(int max_iter) : RootFind1dBase(1e-5, max_iter, {}) {}
60
61 // Abstract virtual method needed by all derived class
62 // virtual std::tuple<double, double, bool, int> root(arg, ...) const = 0;
63
64 // non-virtual public methods
65
70 double func_tol() const { return f_tol; }
71
76 int max_num_iter() const { return max_iter; }
77
83 std::optional<double> var_tol() const
84 {
85 return x_tol ? *x_tol : std::optional<double> {};
86 }
87
93 static std::function<double(double)> poly2func(const isce3::core::Poly1d& f)
94 {
95 return [=](double x) { return f.eval(x); };
96 }
97
98 // members
99protected:
100 double f_tol;
101 int max_iter;
102 std::optional<double> x_tol;
103};
104
105}}} // namespace isce3::math::detail
Data structure for representing 1D polynomials.
Definition Poly1d.h:23
double eval(double x) const
Evaluate polynomial at x.
Definition Poly1d.cpp:12
RootFind1dBase(double f_tol=1e-5, int max_iter=20, std::optional< double > x_tol={})
A default constructor with absolute tolerances for "x" and "f(x)" plus max number of iterations.
Definition RootFind1dBase.h:37
RootFind1dBase(int max_iter)
A constructor with max number of iterations.
Definition RootFind1dBase.h:59
static std::function< double(double)> poly2func(const isce3::core::Poly1d &f)
Convert isce3 Poly1d object into a single-variavle function object "f(x)".
Definition RootFind1dBase.h:93
std::optional< double > var_tol() const
Get the absolute tolerance for function variable "x" if set It returns std::nullopt if "x_tol" is not...
Definition RootFind1dBase.h:83
int max_num_iter() const
Get max number of iteration being set.
Definition RootFind1dBase.h:76
double func_tol() const
Get the absolute tolerance for function value.
Definition RootFind1dBase.h:70
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.