Function utils::minNonZeroMagnitude
Defined in File MiscUtils.hpp
Function Documentation
-
inline auto utils::minNonZeroMagnitude(const std::vector<double> &v, const double fallback = 1.0) -> double
The smallest nonzero magnitude among a set of values.
Used to put a vector-valued integrand whose elements span many orders of magnitude, and may include exact zeros, on a common dimensionless scale before integrating it, so that a single absolute tolerance (SimControls::intAbsTol()) is meaningful for every element: an element that integrates to (nearly) zero can then still meet the absolute tolerance, rather than failing the relative one forever. Pass fallback = +infinity to combine the results over several vectors with std::min.
- Parameters:
v – The values to scan
fallback – Value to return if every element of v is zero (or v is empty)
- Returns:
min |v[i]| over every nonzero v[i], or fallback if there are none