40template <base::concepts::real_scalar Scalar>
48template <base::concepts::real_scalar Scalar>
58template <
typename Variable>
66template <base::concepts::real_scalar_dense_vector Variable>
79 : tol_rel_error_(impl::default_tol_rel_error<
scalar_type>),
80 tol_abs_error_(impl::default_tol_abs_error<
scalar_type>) {}
95 : variable_(variable), error_(error) {}
97 [[nodiscard]]
auto operator()(
const scalar_type& tol_rel_error,
99 return (error_.array().abs() <=
100 (tol_rel_error * variable_.array().abs() + tol_abs_error))
104 [[nodiscard]]
auto operator()(
const variable_type& tol_rel_error,
106 return (error_.array().abs() <=
107 (tol_rel_error.array() * variable_.array().abs() +
112 [[nodiscard]]
auto operator()(
const scalar_type& tol_rel_error,
114 return (error_.array().abs() <=
115 (tol_rel_error * variable_.array().abs() +
116 tol_abs_error.array()))
120 [[nodiscard]]
auto operator()(
const variable_type& tol_rel_error,
122 return (error_.array().abs() <=
123 (tol_rel_error.array() * variable_.array().abs() +
124 tol_abs_error.array()))
133 evaluator eval{variable, error};
134 return std::visit(eval, tol_rel_error_, tol_abs_error_);
149 : variable_(variable), error_(error) {}
151 [[nodiscard]]
auto operator()(
const scalar_type& tol_rel_error,
154 return sqrt((error_.array() /
155 (tol_rel_error * variable_.array().abs() +
162 [[nodiscard]]
auto operator()(
const variable_type& tol_rel_error,
167 (tol_rel_error.array() * variable_.array().abs() +
174 [[nodiscard]]
auto operator()(
const scalar_type& tol_rel_error,
177 return sqrt((error_.array() /
178 (tol_rel_error * variable_.array().abs() +
179 tol_abs_error.array()))
185 [[nodiscard]]
auto operator()(
const variable_type& tol_rel_error,
190 (tol_rel_error.array() * variable_.array().abs() +
191 tol_abs_error.array()))
202 evaluator eval{variable, error};
203 return std::visit(eval, tol_rel_error_, tol_abs_error_);
214 "Tolerance of relative error must be a non-negative value.");
215 tol_rel_error_ = val;
227 (val.array() >=
static_cast<scalar_type>(0)).all(),
228 "Tolerance of relative error must be non-negative values.");
229 tol_rel_error_ = val;
241 "Tolerance of absolute error must be a non-negative value.");
242 tol_abs_error_ = val;
254 (val.array() >=
static_cast<scalar_type>(0)).all(),
255 "Tolerance of absolute error must be non-negative values.");
256 tol_abs_error_ = val;
276template <base::concepts::real_scalar Variable>
289 : tol_rel_error_(impl::default_tol_rel_error<
scalar_type>),
290 tol_abs_error_(impl::default_tol_abs_error<
scalar_type>) {}
303 return abs(error) <= tol_rel_error_ * abs(variable) + tol_abs_error_;
316 return abs(error / (tol_rel_error_ * abs(variable) + tol_abs_error_));
327 "Tolerance of relative error must be a non-negative value.");
328 tol_rel_error_ = val;
340 "Tolerance of absolute error must be a non-negative value.");
341 tol_abs_error_ = val;
variant_type tol_abs_error_
Tolerance of absolute error.
variable_type tol_rel_error_
Tolerance of relative error.
auto tol_abs_error(const variable_type &val) -> error_tolerances &
Set the tolerance of absolute error.
variant_type tol_rel_error_
Tolerance of relative error.
auto check(const variable_type &variable, const variable_type &error) const -> bool
Check whether the given error satisfies tolerances.
std::variant< scalar_type, variable_type > variant_type
Type of variant used for tolerances.
error_tolerances()
Constructor.
auto calc_norm(const variable_type &variable, const variable_type &error) const -> scalar_type
Calculate the norm of the error determined by tolerances.
auto tol_rel_error(const scalar_type &val) -> error_tolerances &
Set the tolerance of relative error.
auto tol_abs_error(const scalar_type &val) -> error_tolerances &
Set the tolerance of absolute error.
typename variable_type::Scalar scalar_type
Type of scalars.
variable_type tol_abs_error_
Tolerance of absolute error.
Variable variable_type
Type of variables.
auto tol_rel_error(const variable_type &val) -> error_tolerances &
Set the tolerance of relative error.
Class of error tolerances hairer1993.
Definition of exceptions.
Definition of macros for logging.
constexpr Scalar default_tol_rel_error
Default tolerance of relative errors.
constexpr Scalar default_tol_abs_error
Default tolerance of absolute errors.
Namespace of solvers of ordinary differential equations (ODE).
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of real_scalar concept.
Definition of real_scalar_dense_vector concept.