From: Wolfgang Bangerth Date: Sat, 6 Apr 2024 17:02:47 +0000 (-0600) Subject: Simplify some functions by just deferring to member functions. X-Git-Tag: v9.6.0-rc1~394^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16864%2Fhead;p=dealii.git Simplify some functions by just deferring to member functions. --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 158ca2c347..f9cfcda3a6 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -2119,10 +2119,8 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE typename EnableIfScalar::type>::type> operator*(const Tensor &t, const OtherNumber &factor) { - // recurse over the base objects - Tensor::type> tt; - for (unsigned int d = 0; d < dim; ++d) - tt[d] = t[d] * factor; + Tensor::type> tt(t); + tt *= factor; return tt; } @@ -2170,21 +2168,8 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE typename EnableIfScalar::type>::type> operator/(const Tensor &t, const OtherNumber &factor) { - Tensor::type> tt; - if constexpr (std::is_integral< - typename ProductType::type>::value) - { - // recurse over the base objects - for (unsigned int d = 0; d < dim; ++d) - tt[d] = t[d] / factor; - } - else - { - const Number inverse_factor = Number(1.) / factor; - // recurse over the base objects - for (unsigned int d = 0; d < dim; ++d) - tt[d] = t[d] * inverse_factor; - } + Tensor::type> tt(t); + tt /= factor; return tt; } @@ -2205,10 +2190,7 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE const Tensor &q) { Tensor::type> tmp(p); - - for (unsigned int i = 0; i < dim; ++i) - tmp[i] += q[i]; - + tmp += q; return tmp; } @@ -2229,10 +2211,7 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE const Tensor &q) { Tensor::type> tmp(p); - - for (unsigned int i = 0; i < dim; ++i) - tmp[i] -= q[i]; - + tmp -= q; return tmp; }