]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Peel off first element of the sequence. 16468/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sun, 14 Jan 2024 04:12:02 +0000 (21:12 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 14 Jan 2024 04:12:02 +0000 (21:12 -0700)
include/deal.II/base/tensor.h

index c375d0c5a8c059284b7dbe2b00e81a768be9e383..259215e74d24914577620f13699e972c56ebc07c 100644 (file)
@@ -1698,14 +1698,16 @@ constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE
   typename numbers::NumberTraits<Number>::real_type
   Tensor<rank_, dim, Number>::norm_square() const
 {
-  if constexpr (rank_ == 1)
+  if constexpr (dim == 0)
+    return internal::NumberType<
+      typename numbers::NumberTraits<Number>::real_type>::value(0.0);
+  else if constexpr (rank_ == 1)
     {
       // For rank-1 tensors, the square of the norm is simply the sum of
       // squares of the elements:
       typename numbers::NumberTraits<Number>::real_type s =
-        internal::NumberType<
-          typename numbers::NumberTraits<Number>::real_type>::value(0.0);
-      for (unsigned int i = 0; i < dim; ++i)
+        numbers::NumberTraits<Number>::abs_square(values[0]);
+      for (unsigned int i = 1; i < dim; ++i)
         s += numbers::NumberTraits<Number>::abs_square(values[i]);
 
       return s;
@@ -1715,9 +1717,8 @@ constexpr DEAL_II_HOST_DEVICE_ALWAYS_INLINE
       // For higher-rank tensors, the square of the norm is the sum
       // of squares of sub-tensors
       typename numbers::NumberTraits<Number>::real_type s =
-        internal::NumberType<
-          typename numbers::NumberTraits<Number>::real_type>::value(0.0);
-      for (unsigned int i = 0; i < dim; ++i)
+        values[0].norm_square();
+      for (unsigned int i = 1; i < dim; ++i)
         s += values[i].norm_square();
 
       return s;

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.