]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Trace of a tensor.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 12 Apr 2001 10:21:01 +0000 (10:21 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 12 Apr 2001 10:21:01 +0000 (10:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@4451 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/tensor.h

index 825256a229a55dc1a0b52ea9738fde8c196eb7af..e4ee3b97d4b021308825e8280a7b937b42128ff4 100644 (file)
@@ -921,6 +921,23 @@ double determinant (const Tensor<2,3> &t)
 
 
 
+/**
+ * Compute and return the trace of a tensor of rank 2, i.e. the sum of
+ * its diagonal entries.
+ *
+ * @author Wolfgang Bangerth, 2001
+ */
+template <int dim>
+double trace (const Tensor<2,dim> &d)
+{
+  double t=0;
+  for (unsigned int i=0; i<dim; ++i)
+    t += d[i][i];
+  return t;
+};
+
+
+
 /**
  * Compute and return the inverse of the given tensor. Since the
  * compiler can perform the return value optimization, and since the

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.