]> https://gitweb.dealii.org/ - dealii.git/commitdiff
First set of extended tensor operations
authorToby D. Young <tyoung@ippt.pan.pl>
Wed, 12 Jan 2011 09:10:30 +0000 (09:10 +0000)
committerToby D. Young <tyoung@ippt.pan.pl>
Wed, 12 Jan 2011 09:10:30 +0000 (09:10 +0000)
git-svn-id: https://svn.dealii.org/trunk@23178 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/tensor.h

index b977e1863d20ba23d0df9bf2ea94687bdde64b5b..fe3bd375a4dfd0004ce71580216495b8b91d6ffd 100644 (file)
@@ -31,11 +31,10 @@ inconvenience this causes.
 <h3>General</h3>
 
 <ol>
-  <li>
+<li> Extended: <code>base/tensor.h</code> has an additional collection of contractions between three tensors <i>ie</i>. <code>contract3</code>). This can be useful for writing matrix/vector assembly in a more compact form than before.<br>
+(Toby D. Young, 2011/01/12)
 </ol>
 
-
-
 <a name="specific"></a>
 <h3>Specific improvements</h3>
 
index d0950abdb1ccbcda8d91e66411ed03665d058496..4af007f0692e9ba43943319b7729d6db203c4c6e 100644 (file)
@@ -2,7 +2,7 @@
 //    $Id$
 //    Version: $Name$
 //
-//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 by the deal.II authors
+//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -1154,6 +1154,52 @@ double contract3 (const Tensor<1,dim>& u,
 }
 
 
+/**
+ * Compute the contraction of three tensors $s=\sum_{i,j,k,l}
+ * a_{ij}b_{ijkl}c_{kl}$.
+ *
+ * @relates Tensor
+ */
+template <int dim>
+inline
+double
+contract3 (const Tensor<2,dim> &t1,
+          const Tensor<4,dim> &t2,
+          const Tensor<2,dim> &t3)
+{
+  double s = 0;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+       for (unsigned int l=0; l<dim; ++l)
+         s += t1[i][j] * t2[i][j][k][l] * t3[k][l];
+  return s;
+}
+
+
+/**
+ * Compute the contraction of three tensors $s=\sum_{i,j,k,l}
+ * a_{i}b_{ijk}c_{kl}$.
+ *
+ * @relates Tensor
+ */
+template <int dim>
+inline
+double
+contract3 (const Tensor<1,dim> &t1,
+          const Tensor<3,dim> &t2,
+          const Tensor<2,dim> &t3)
+{
+  double s = 0;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+       for (unsigned int l=0; l<dim; ++l)
+         s += t1[i] * t2[i][j][k] * t3[k][l];
+  return s;
+}
+
+
 /**
  * Form the outer product of two tensors of rank 1 and 1, i.e.
  * <tt>dst[i][j] = src1[i] * src2[j]</tt>.
@@ -1333,7 +1379,6 @@ scalar_product (const Tensor<2,dim> &t1,
 }
 
 
-
 /**
  * Compute the determinant of a tensor of arbitrary rank and dimension
  * one. Since this is a number, the return value is, of course, 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.