]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify some functions by just deferring to member functions. 16864/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 6 Apr 2024 17:02:47 +0000 (11:02 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 6 Apr 2024 17:02:47 +0000 (11:02 -0600)
include/deal.II/base/tensor.h

index 158ca2c3478bbcc76734638818e61b34b675ad17..f9cfcda3a66f1710e00ca217eeb85cef52d0b454 100644 (file)
@@ -2119,10 +2119,8 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE
                               typename EnableIfScalar<OtherNumber>::type>::type>
   operator*(const Tensor<rank, dim, Number> &t, const OtherNumber &factor)
 {
-  // recurse over the base objects
-  Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tt;
-  for (unsigned int d = 0; d < dim; ++d)
-    tt[d] = t[d] * factor;
+  Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tt(t);
+  tt *= factor;
   return tt;
 }
 
@@ -2170,21 +2168,8 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE
                               typename EnableIfScalar<OtherNumber>::type>::type>
   operator/(const Tensor<rank, dim, Number> &t, const OtherNumber &factor)
 {
-  Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tt;
-  if constexpr (std::is_integral<
-                  typename ProductType<Number, OtherNumber>::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<rank, dim, typename ProductType<Number, OtherNumber>::type> tt(t);
+  tt /= factor;
   return tt;
 }
 
@@ -2205,10 +2190,7 @@ constexpr DEAL_II_HOST_DEVICE inline DEAL_II_ALWAYS_INLINE
             const Tensor<rank, dim, OtherNumber> &q)
 {
   Tensor<rank, dim, typename ProductType<Number, OtherNumber>::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<rank, dim, OtherNumber> &q)
 {
   Tensor<rank, dim, typename ProductType<Number, OtherNumber>::type> tmp(p);
-
-  for (unsigned int i = 0; i < dim; ++i)
-    tmp[i] -= q[i];
-
+  tmp -= q;
   return tmp;
 }
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.