]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Explicitly initialise tensor contraction results to zero.
authorJean-Paul Pelteret <jppelteret@gmail.com>
Sat, 12 Aug 2017 07:05:43 +0000 (01:05 -0600)
committerJean-Paul Pelteret <jppelteret@gmail.com>
Tue, 15 Aug 2017 15:03:48 +0000 (09:03 -0600)
include/deal.II/base/tensor_accessors.h

index 52c7ca7bf1ab576d94d57122ad90dec485b33ce8..2ca2674e47f7068fcd4168abb428ded36b3c09d0 100644 (file)
@@ -665,7 +665,9 @@ namespace TensorAccessors
       inline DEAL_II_ALWAYS_INLINE static
       T1 contract2(const T2 &left, const T3 &right)
       {
-        T1 result = T1();
+        // Some auto-differentiable numbers need explicit
+        // zero initialization.
+        T1 result = dealii::internal::NumberType<T1>::value(0.0);
         for (unsigned int i = 0; i < dim; ++i)
           result += Contract2<no_contr - 1, dim>::template contract2<T1>(left[i], right[i]);
         return result;
@@ -710,7 +712,9 @@ namespace TensorAccessors
       static inline
       T1 contract3(const T2 &left, const T3 &middle, const T4 &right)
       {
-        T1 result = T1();
+        // Some auto-differentiable numbers need explicit
+        // zero initialization.
+        T1 result = dealii::internal::NumberType<T1>::value(0.0);
         for (unsigned int i = 0; i < dim; ++i)
           result += Contract3<rank_1 - 1, rank_2, dim>::template contract3<T1>(left[i], middle[i], right);
         return result;
@@ -736,7 +740,9 @@ namespace TensorAccessors
       static inline
       T1 contract3(const T2 &left, const T3 &middle, const T4 &right)
       {
-        T1 result = T1();
+        // Some auto-differentiable numbers need explicit
+        // zero initialization.
+        T1 result = dealii::internal::NumberType<T1>::value(0.0);
         for (unsigned int i = 0; i < dim; ++i)
           result += Contract3<0, rank_2 - 1, dim>::template contract3<T1>(left, middle[i], right[i]);
         return result;

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.