]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Implement outer_product functions for tensors.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 24 Jul 2000 07:42:00 +0000 (07:42 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 24 Jul 2000 07:42:00 +0000 (07:42 +0000)
git-svn-id: https://svn.dealii.org/trunk@3191 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 7541b23d55dde9c270921dbb65f87dc171fb4478..207cec5af517f4bad432a1ccb302c6781a005541 100644 (file)
@@ -587,6 +587,105 @@ void contract (Tensor<4,dim>       &dest,
 };
 
 
+
+/**
+ * Form the outer product of two tensors of rank 1 and 1, i.e.
+ * @p{dst[i][j] = src1[i] * src2[j]}.
+ *
+ * @author Wolfgang Bangerth, 2000
+ */
+template <int dim>
+void outer_product (Tensor<2,dim>       &dst,
+                   const Tensor<1,dim> &src1,
+                   const Tensor<1,dim> &src2) 
+{
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      dst[i][j] = src1[i] * src2[j];
+};
+
+
+
+/**
+ * Form the outer product of two tensors of rank 1 and 2, i.e.
+ * @p{dst[i][j][k] = src1[i] * src2[j][k]}.
+ *
+ * @author Wolfgang Bangerth, 2000
+ */
+template <int dim>
+void outer_product (Tensor<3,dim>       &dst,
+                   const Tensor<1,dim> &src1,
+                   const Tensor<2,dim> &src2) 
+{
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+      dst[i][j][k] = src1[i] * src2[j][k];
+};
+
+
+
+/**
+ * Form the outer product of two tensors of rank 2 and 1, i.e.
+ * @p{dst[i][j][k] = src1[i][j] * src2[k]}.
+ *
+ * @author Wolfgang Bangerth, 2000
+ */
+template <int dim>
+void outer_product (Tensor<3,dim>       &dst,
+                   const Tensor<2,dim> &src1,
+                   const Tensor<1,dim> &src2) 
+{
+  for (unsigned int i=0; i<dim; ++i)
+    for (unsigned int j=0; j<dim; ++j)
+      for (unsigned int k=0; k<dim; ++k)
+      dst[i][j][k] = src1[i][j] * src2[k];
+};
+
+
+
+/**
+ * Form the outer product of two tensors of rank 0 and 1, i.e.
+ * @p{dst[i] = src1 * src2[i]}. Of course, this is only a scaling of
+ * @p{src2}, but we consider this an outer product for completeness of
+ * these functions and since this is sometimes needed when writing
+ * templates that depend on the rank of a tensor, which may sometimes
+ * be zero (i.e. a scalar).
+ *
+ * @author Wolfgang Bangerth, 2000
+ */
+template <int dim>
+void outer_product (Tensor<1,dim>       &dst,
+                   const double         src1,
+                   const Tensor<1,dim> &src2) 
+{
+  for (unsigned int i=0; i<dim; ++i)
+    dst[i] = src1 * src2[i];
+};
+
+
+
+/**
+ * Form the outer product of two tensors of rank 1 and 0, i.e.
+ * @p{dst[i] = src1[i] * src2}. Of course, this is only a scaling of
+ * @p{src1}, but we consider this an outer product for completeness of
+ * these functions and since this is sometimes needed when writing
+ * templates that depend on the rank of a tensor, which may sometimes
+ * be zero (i.e. a scalar).
+ *
+ * @author Wolfgang Bangerth, 2000
+ */
+template <int dim>
+void outer_product (Tensor<1,dim>       &dst,
+                   const Tensor<1,dim>  src1,
+                   const double         src2) 
+{
+  for (unsigned int i=0; i<dim; ++i)
+    dst[i] = src1[i] * src2;
+};
+
+
+      
 /**
  * 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.