]> https://gitweb.dealii.org/ - dealii.git/commitdiff
tensor.h: Let outer_product return its result
authorMatthias Maier <tamiko@43-1.org>
Tue, 15 Sep 2015 04:46:28 +0000 (23:46 -0500)
committerMatthias Maier <tamiko@43-1.org>
Tue, 15 Sep 2015 17:11:31 +0000 (12:11 -0500)
All other function signatures also return their result - do the same here
and deprecate the old signatures

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

index 44c295d0cc4934f304087d3026641232b4d33724..71ee4d13dc4c3a42d41d0fe63b9a7b2554f10632 100644 (file)
@@ -1506,6 +1506,30 @@ operator * (const Tensor<rank_1, dim, Number> &src1,
 }
 
 
+/**
+ * The outer product of two tensors of @p rank_1 and @p rank_2: Returns a
+ * tensor of rank $(\text{rank\_1} + \text{rank\_2})$:
+ * @f[
+ *   \text{result}_{i_1,..,i_{r1},j_1,..,j_{r2}}
+ *   = \text{left}_{i_1,..,i_{r1}}\,\text{right}_{j_1,..,j_{r2}.}
+ * @f]
+ *
+ * @relates Tensor
+ * @relates ProductType
+ */
+template <int rank_1, int rank_2, int dim,
+          typename Number, typename OtherNumber>
+inline
+Tensor<rank_1 + rank_2, dim, typename ProductType<Number, OtherNumber>::type>
+outer_product(const Tensor<rank_1, dim, Number> &src1,
+              const Tensor<rank_2, dim, OtherNumber> &src2)
+{
+  typename Tensor<rank_1 + rank_2, dim, typename ProductType<Number, OtherNumber>::type>::tensor_type result;
+  TensorAccessors::contract<0, rank_1, rank_2, dim>(result, src1, src2);
+  return result;
+}
+
+
 //@}
 /**
  * @name To be refactored
@@ -2000,102 +2024,6 @@ contract3 (const Tensor<2,dim,Number> &t1,
 }
 
 
-/**
- * Form the outer product of two tensors of rank 1 and 1, i.e. <tt>dst[i][j] =
- * src1[i] * src2[j]</tt>.
- *
- * @relates Tensor
- * @author Wolfgang Bangerth, 2000
- */
-template <int dim, typename Number>
-void outer_product (Tensor<2,dim,Number>       &dst,
-                    const Tensor<1,dim,Number> &src1,
-                    const Tensor<1,dim,Number> &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.
- * <tt>dst[i][j][k] = src1[i] * src2[j][k]</tt>.
- *
- * @relates Tensor
- * @author Wolfgang Bangerth, 2000
- */
-template <int dim, typename Number>
-void outer_product (Tensor<3,dim,Number>       &dst,
-                    const Tensor<1,dim,Number> &src1,
-                    const Tensor<2,dim,Number> &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.
- * <tt>dst[i][j][k] = src1[i][j] * src2[k]</tt>.
- *
- * @relates Tensor
- * @author Wolfgang Bangerth, 2000
- */
-template <int dim, typename Number>
-void outer_product (Tensor<3,dim,Number>       &dst,
-                    const Tensor<2,dim,Number> &src1,
-                    const Tensor<1,dim,Number> &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. <tt>dst[i] =
- * src1 * src2[i]</tt>. Of course, this is only a scaling of <tt>src2</tt>,
- * 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).
- *
- * @relates Tensor
- * @author Wolfgang Bangerth, 2000
- */
-template <int dim, typename Number>
-void outer_product (Tensor<1,dim,Number>       &dst,
-                    const Number                src1,
-                    const Tensor<1,dim,Number> &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. <tt>dst[i] =
- * src1[i] * src2</tt>. Of course, this is only a scaling of <tt>src1</tt>,
- * 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).
- *
- * @relates Tensor
- * @author Wolfgang Bangerth, 2000
- */
-template <int dim, typename Number>
-void outer_product (Tensor<1,dim,Number>       &dst,
-                    const Tensor<1,dim,Number>  src1,
-                    const Number         src2)
-{
-  for (unsigned int i=0; i<dim; ++i)
-    dst[i] = src1[i] * src2;
-}
-
-
 /**
  * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two
  * tensors $a,b$ of rank 2. We don't use <code>operator*</code> for this
index 9bc666316793b97004718a240d43647f05520785..b6dfeb343a2667662a139863c9ddeea93e1e73bd 100644 (file)
@@ -29,7 +29,6 @@ DEAL_II_NAMESPACE_OPEN
  */
 //@{
 
-
 /**
  * The cross-product of 2 vectors in 3d.
  *
@@ -43,9 +42,42 @@ cross_product (Tensor<1,dim,Number>       &dst,
                const Tensor<1,dim,Number> &src1,
                const Tensor<1,dim,Number> &src2) DEAL_II_DEPRECATED;
 
+/**
+ * Form the outer product of two tensors.
+ *
+ * @deprecated Use the generic version that returns its result instead.
+ * @relates Tensor
+ */
+template <int rank_1, int rank_2, int dim, typename Number>
+void outer_product(Tensor<rank_1 + rank_2, dim, Number> &dst,
+                   const Tensor<rank_1, dim, Number>    &src1,
+                   const Tensor<rank_2, dim, Number>    &src2) DEAL_II_DEPRECATED;
 
-#ifndef DOXYGEN
+/**
+ * Multiply a Tensor<1,dim,Number> with a Number.
+ *
+ * @deprecated Use operator* instead.
+ * @relates Tensor
+ */
+template <int dim, typename Number>
+void outer_product (Tensor<1,dim,Number>       &dst,
+                    const Number                src1,
+                    const Tensor<1,dim,Number> &src2) DEAL_II_DEPRECATED;
 
+/**
+ * Multiply a Tensor<1,dim,Number> with a Number.
+ *
+ * @deprecated Use operator* instead.
+ * @relates Tensor
+ */
+template <int dim, typename Number>
+void outer_product (Tensor<1,dim,Number>       &dst,
+                    const Tensor<1,dim,Number>  src1,
+                    const Number                src2) DEAL_II_DEPRECATED;
+
+//@}
+
+#ifndef DOXYGEN
 
 template <int dim, typename Number>
 inline
@@ -57,9 +89,33 @@ cross_product (Tensor<1,dim,Number>       &dst,
   dst = cross_product(src1, src2);
 }
 
-#endif /* DOXYGEN */
+template <int rank_1, int rank_2, int dim, typename Number>
+void outer_product(Tensor<rank_1 + rank_2, dim, Number> &dst,
+                   const Tensor<rank_1, dim, Number>    &src1,
+                   const Tensor<rank_2, dim, Number>    &src2)
+{
+  TensorAccessors::contract<0, rank_1, rank_2, dim>(dst, src1, src2);
+}
 
-//@}
+template <int dim, typename Number>
+void outer_product (Tensor<1,dim,Number>       &dst,
+                    const Number                src1,
+                    const Tensor<1,dim,Number> &src2)
+{
+  for (unsigned int i=0; i<dim; ++i)
+    dst[i] = src1 * src2[i];
+}
+
+template <int dim, typename Number>
+void outer_product (Tensor<1,dim,Number>       &dst,
+                    const Tensor<1,dim,Number>  src1,
+                    const Number         src2)
+{
+  for (unsigned int i=0; i<dim; ++i)
+    dst[i] = src1[i] * src2;
+}
+
+#endif /* DOXYGEN */
 
 DEAL_II_NAMESPACE_CLOSE
 

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.