#pragma once #include #include #include #include #include #include namespace AMDiS { namespace Math { /// Implementation of the absolute value \f\$|a|\f\$ of arithmetic types. template constexpr T abs(T const& a) { return a < 0 ? -a : a; } /// Implementation of the square \f\$ a^2 \f\$ of arithmetic types. template constexpr auto sqr(T const& a) { return a*a; } /// Implementation of the power \f\$ v^p \f\$ of arithmetic types `T`. template constexpr auto pow(T const& v) { static_assert( p >= 0, "Exponent p in `pow

(v)` should be >= 0," ); return Dune::Power

::eval(v); } /// Implementation of the minimum of values \f\$ min(a,b)\f\$ of any type /// supporting the `<` relation. /// @{ template constexpr auto min(T0 a, T1 b) { using T = std::conditional_t<(sizeof(T0)>sizeof(T1)),T0,T1>; return a < b ? T(a) : T(b); } template constexpr T0 min(T0 a) { return a; } template constexpr auto min(T0 a, Ts... ts) { return min(a, min(ts...)); } /// @} /// Implementation of the maximum of values \f\$ max(a,b)\f\$ of any type /// supporting the `<` relation. /// @{ template constexpr auto max(T0 a, T1 b) { using T = std::conditional_t<(sizeof(T0)>sizeof(T1)),T0,T1>; return a < b ? T(b) : T(a); } template constexpr T0 max(T0 a) { return a; } template constexpr auto max(T0 a, Ts... ts) { return max(a, max(ts...)); } /// @} // sum over empty set is zero constexpr double sum() { return 0.0; } template constexpr auto sum(Ts const&... ts) { return (ts + ...); } } // end namespace Math template constexpr T threshold = std::numeric_limits::epsilon(); } // end namespace AMDiS