From da7b7b799e07778d1ce0de1b02b5f3979d34f7a2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 6 Apr 2024 11:02:47 -0600 Subject: [PATCH] Simplify some functions by just deferring to member functions. --- include/deal.II/base/tensor.h | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) 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; } -- 2.39.5