]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add symmetrize function
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 6 Apr 2005 18:52:36 +0000 (18:52 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 6 Apr 2005 18:52:36 +0000 (18:52 +0000)
git-svn-id: https://svn.dealii.org/trunk@10398 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/symmetric_tensor.h

index 59dfd96463ed419e3ff54e873137289d6291e028..dfb0a1b2fed5a73a5db8f1ad2457130fd8f2a9ea 100644 (file)
@@ -1834,6 +1834,32 @@ transpose (const SymmetricTensor<rank,dim> &t)
 }
 
 
+
+/**
+ * Return the symmetrized version of the full rank-2 tensor,
+ * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor.
+ *
+ * @relates SymmetricTensor
+ * @author Wolfgang Bangerth, 2005
+ */
+template <int dim>
+inline
+SymmetricTensor<2,dim>
+symmetrize (const Tensor<2,dim> &t)
+{
+  SymmetricTensor<2,dim> s;
+  for (unsigned int i=0; i<dim; ++i)
+    {
+      s(TableIndices<2>(i,i)) = t[i][i];
+  
+      for (unsigned int j=i+1; j<dim; ++j)
+       s(TableIndices<2>(i,j))
+         = (t[i][j] + t[j][i])/2;
+    }
+  return s;
+}
+
+
 /**
  * Multiplication of a symmetric tensor of general rank with a scalar double
  * from the right.

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.