]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
new version of function contract(), contracting a tensor of rank three with one of...
authorleicht <leicht@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 27 Sep 2006 09:08:53 +0000 (09:08 +0000)
committerleicht <leicht@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 27 Sep 2006 09:08:53 +0000 (09:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@13967 0785d39b-7218-0410-832d-ea1e28bc413d

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

index d452bfe2480abc8dadefb665007e3612f657d92a..f10be25e6ff445e1c1c2dbe372100a3bd6fc38e6 100644 (file)
@@ -880,6 +880,106 @@ void contract (Tensor<3,dim>       &dest,
 
 
 
+/**
+ * Contract a tensor of rank 3 with a tensor of rank 2. The
+ * contraction is performed over index <tt>index1</tt> of the first tensor,
+ * and <tt>index2</tt> of the second tensor. Thus, if <tt>index1==3</tt>,
+ * <tt>index2==1</tt>, the result is the usual contraction, but if for
+ * example <tt>index1==1</tt>, <tt>index2==2</tt>, then the result is
+ * <tt>dest[i][j][k] = sum_l src1[l][i][j] src2[k][l]</tt>.
+ *
+ * Note that the number of the index is counted from 1 on, not from
+ * zero as usual.
+ *
+ * @relates Tensor
+ */
+template <int dim>
+inline
+void contract (Tensor<3,dim>       &dest,
+              const Tensor<3,dim> &src1, const unsigned int index1,
+              const Tensor<2,dim> &src2, const unsigned int index2)
+{
+  dest.clear ();
+
+  switch (index1)
+    {
+      case 1:
+           switch (index2)
+             {
+               case 1:
+                     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)
+                             dest[i][j][k] += src1[l][i][j] * src2[l][k];
+                     break;
+               case 2:
+                     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)
+                             dest[i][j][k] += src1[l][i][j] * src2[k][l];
+                     break;
+               default:
+                     Assert (false,
+                             (typename Tensor<2,dim>::ExcInvalidTensorIndex (index2)));
+             }
+           
+           break;
+      case 2:
+           switch (index2)
+             {
+               case 1:
+                     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)
+                             dest[i][j][k] += src1[i][l][j] * src2[l][k];
+                     break;
+               case 2:
+                     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)
+                             dest[i][j][k] += src1[i][l][j] * src2[k][l];
+                     break;
+               default:
+                     Assert (false,
+                             (typename Tensor<2,dim>::ExcInvalidTensorIndex (index2)));
+             }
+           
+           break;
+      case 3:
+           switch (index2)
+             {
+               case 1:
+                     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)
+                             dest[i][j][k] += src1[i][j][l] * src2[l][k];
+                     break;
+               case 2:
+                     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)
+                             dest[i][j][k] += src1[i][j][l] * src2[k][l];
+                     break;
+               default:
+                     Assert (false,
+                             (typename Tensor<2,dim>::ExcInvalidTensorIndex (index2)));
+             }
+           
+           break;
+      default:
+           Assert (false,
+                   (typename Tensor<3,dim>::ExcInvalidTensorIndex (index1)));
+    }
+}
+
+
+   
 /**
  * Multiplication operator performing a contraction of the last index
  * of the first argument and the first index of the second
index b2103d03ff6a76f18645cfb91bf30e7f7ff96d2b..c4f3711fc60b6121554faf717ebea006056c26fa 100644 (file)
@@ -359,6 +359,15 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li> <p> Extended: The <code>contract</code> function family contracts two
+           tensors. There is now a new version of this function, that contracts a
+           tensor of rank three with a second one of rank two over given indices
+           <tt>index1</tt> and <tt>index2</tt> of the first and second tensor,
+           respectively, resulting in a tensor of rank three.
+           <br>
+                (Tobias Leicht 2006/09/27)
+       </p>
+
   <li> <p> Fixed: The
        <code>DataOutBase::write_deal_II_intermediate</code> function
        did not check whether it can actually write to the stream

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.