]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add specializations for symmetrize for the various dimensions.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 11 Dec 2008 20:57:48 +0000 (20:57 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 11 Dec 2008 20:57:48 +0000 (20:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@17916 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 1cb86e4299b5c906cf072d7e692586ffe8ecc8df..9a75321aff282077d2700c8626f350954bd1b12b 100644 (file)
@@ -2452,27 +2452,61 @@ outer_product (const SymmetricTensor<2,dim> &t1,
 
 
 /**
- * Return the symmetrized version of the full rank-2 tensor,
- * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor.
+ * Return the symmetrized version of a full rank-2 tensor,
+ * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor. This is the version
+ * for dim==1.
  *
  * @relates SymmetricTensor
  * @author Wolfgang Bangerth, 2005
  */
-template <int dim>
 inline
-SymmetricTensor<2,dim>
-symmetrize (const Tensor<2,dim> &t)
+SymmetricTensor<2,1>
+symmetrize (const Tensor<2,1> &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;
+  const double array[1]
+    = { t[0][0] };
+  return SymmetricTensor<2,1>(array);
+}
+
+
+
+/**
+ * Return the symmetrized version of a full rank-2 tensor,
+ * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor. This is the version
+ * for dim==2.
+ *
+ * @relates SymmetricTensor
+ * @author Wolfgang Bangerth, 2005
+ */
+inline
+SymmetricTensor<2,2>
+symmetrize (const Tensor<2,2> &t)
+{
+  const double array[3]
+    = { t[0][0], t[1][1], (t[0][1] + t[1][0])/2 };
+  return SymmetricTensor<2,2>(array);
+}
+
+
+
+/**
+ * Return the symmetrized version of a full rank-2 tensor,
+ * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor. This is the version
+ * for dim==3.
+ *
+ * @relates SymmetricTensor
+ * @author Wolfgang Bangerth, 2005
+ */
+inline
+SymmetricTensor<2,3>
+symmetrize (const Tensor<2,3> &t)
+{
+  const double array[6]
+    = { t[0][0], t[1][1], t[2][2],
+       (t[0][1] + t[1][0])/2,
+       (t[0][2] + t[2][0])/2,
+       (t[1][2] + t[2][1])/2 };
+  return SymmetricTensor<2,3>(array);
 }
 
 

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.