]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement the conversion of a SymmetricTensor<4,dim> to Tensor<4,dim>.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 11 Aug 2016 17:06:39 +0000 (12:06 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 11 Aug 2016 17:15:08 +0000 (12:15 -0500)
include/deal.II/base/symmetric_tensor.h

index 501c0ec94063cae37a2b1c72c8995885ef8852d0..609f2e668da6f519f293e63689000d40977c0c86 100644 (file)
@@ -1054,10 +1054,24 @@ namespace internal
 
     template <int dim, typename Number>
     dealii::Tensor<4,dim,Number>
-    convert_to_tensor (const dealii::SymmetricTensor<4,dim,Number> &)
+    convert_to_tensor (const dealii::SymmetricTensor<4,dim,Number> &st)
     {
-      Assert (false, ExcNotImplemented());
-      return dealii::Tensor<4,dim,Number>();
+      // utilize the symmetry properties of SymmetricTensor<4,dim>
+      // discussed in the class documentation to avoid accessing all
+      // independent elements of the input tensor more than once
+      dealii::Tensor<4,dim,Number> t;
+
+      for (unsigned int i=0; i<dim; ++i)
+        for (unsigned int j=i; j<dim; ++j)
+          for (unsigned int k=0; k<dim; ++k)
+            for (unsigned int l=k; l<dim; ++l)
+              t[TableIndices<4>(i,j,k,l)]
+                = t[TableIndices<4>(i,j,l,k)]
+                  = t[TableIndices<4>(j,i,k,l)]
+                    = t[TableIndices<4>(j,i,l,k)]
+                      = st[TableIndices<4>(i,j,k,l)];
+
+      return t;
     }
   }
 }

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.