]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add multiplication operators. Still have to write comments for them.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 6 Apr 2005 04:20:27 +0000 (04:20 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 6 Apr 2005 04:20:27 +0000 (04:20 +0000)
git-svn-id: https://svn.dealii.org/trunk@10376 0785d39b-7218-0410-832d-ea1e28bc413d

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

index c8eb3592255a020e5ca7f1022d17dde28bd38b3c..05898ca5ccef098b4e58d725ba200beb2808e44f 100644 (file)
@@ -468,6 +468,18 @@ double contract (const Tensor<1,dim> &src1,
 }
 
 
+
+template <int dim>
+inline
+double
+operator * (const Tensor<1,dim> &src1,
+            const Tensor<1,dim> &src2)
+{
+  return contract(src1, src2);
+}
+
+
+
 /**
  * Contract a tensor of rank 2 with a tensor of rank 1. The result is
  * <tt>dest[i] = sum_j src1[i][j] src2[j]</tt>.
@@ -489,6 +501,20 @@ void contract (Tensor<1,dim>       &dest,
 
 
 
+template <int dim>
+Tensor<1,dim>
+operator * (const Tensor<2,dim> &src1,
+            const Tensor<1,dim> &src2)
+{
+  Tensor<1,dim> dest;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      dest[i] += src1[i][j] * src2[j];
+  return dest;
+}
+
+
+
 /**
  * Contract a tensor of rank 1 with a tensor of rank 2. The result is
  * <tt>dest[i] = sum_j src1[j] src2[j][i]</tt>.
@@ -510,6 +536,21 @@ void contract (Tensor<1,dim>       &dest,
 
 
 
+template <int dim>
+inline
+Tensor<1,dim>
+operator * (const Tensor<1,dim> &src1,
+            const Tensor<2,dim> &src2)
+{
+  Tensor<1,dim> dest;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      dest[i] += src1[j] * src2[j][i];
+  return dest;
+}
+
+
+
 /**
  * Contract a tensor of rank 2 with a tensor of rank 2. The result is
  * <tt>dest[i][k] = sum_j src1[i][j] src2[j][k]</tt>.
@@ -532,6 +573,22 @@ void contract (Tensor<2,dim>       &dest,
 
 
 
+template <int dim>
+inline
+Tensor<2,dim>
+operator * (const Tensor<2,dim> &src1,
+            const Tensor<2,dim> &src2)
+{
+  Tensor<2,dim> dest;
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+       dest[i][j] += src1[i][k] * src2[k][j];
+  return dest;
+}
+
+
+
 /**
  * Contract a tensor of rank 2 with a tensor of rank 2. The
  * contraction is performed over index <tt>index1</tt> of the first tensor,
@@ -679,6 +736,23 @@ void contract (Tensor<3,dim>       &dest,
 
 
 
+template <int dim>
+inline
+Tensor<3,dim>
+operator * (const Tensor<3,dim> &src1,
+            const Tensor<2,dim> &src2)
+{
+  Tensor<3,dim> dest;
+  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];
+  return dest;
+}
+
+
+
 /**
  * Contract a tensor of rank 2 with a tensor of rank 3. The result is
  * <tt>dest[i][j][l] = sum_k src1[i][k] src2[k][j][l]</tt>.
@@ -701,6 +775,23 @@ void contract (Tensor<3,dim>       &dest,
 }
 
 
+
+template <int dim>
+inline
+Tensor<3,dim>
+operator * (const Tensor<2,dim> &src1,
+            const Tensor<3,dim> &src2)
+{
+  Tensor<3,dim> dest;
+  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] * src2[l][j][k];
+  return dest;
+}
+
+
 /**
  * Contract a tensor of rank 3 with a tensor of rank 3. The result is
  * <tt>dest[i][j][k][l] = sum_m src1[i][j][m] src2[m][k][l]</tt>.
@@ -710,17 +801,18 @@ void contract (Tensor<3,dim>       &dest,
  */
 template <int dim>
 inline
-void contract (Tensor<4,dim>       &dest,
-              const Tensor<3,dim> &src1,
-              const Tensor<3,dim> &src2)
+Tensor<4,dim>
+operator * (const Tensor<3,dim> &src1,
+            const Tensor<3,dim> &src2)
 {
-  dest.clear ();
+  Tensor<4,dim> dest;
   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)
          for (unsigned int m=0; m<dim; ++m)
            dest[i][j][k][l] += src1[i][j][m] * src2[m][k][l];
+  return dest;
 }
 
 

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.