From 1e3667c013fc6bfb44e5df476148d69646e86f67 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Mon, 14 Sep 2015 23:46:28 -0500 Subject: [PATCH] tensor.h: Let outer_product return its result All other function signatures also return their result - do the same here and deprecate the old signatures --- include/deal.II/base/tensor.h | 120 +++++------------------ include/deal.II/base/tensor_deprecated.h | 64 +++++++++++- 2 files changed, 84 insertions(+), 100 deletions(-) diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index 44c295d0cc..71ee4d13dc 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -1506,6 +1506,30 @@ operator * (const Tensor &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 +inline +Tensor::type> +outer_product(const Tensor &src1, + const Tensor &src2) +{ + typename Tensor::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. dst[i][j] = - * src1[i] * src2[j]. - * - * @relates Tensor - * @author Wolfgang Bangerth, 2000 - */ -template -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; idst[i][j][k] = src1[i] * src2[j][k]. - * - * @relates Tensor - * @author Wolfgang Bangerth, 2000 - */ -template -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; idst[i][j][k] = src1[i][j] * src2[k]. - * - * @relates Tensor - * @author Wolfgang Bangerth, 2000 - */ -template -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; idst[i] = - * src1 * src2[i]. Of course, this is only a scaling of 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). - * - * @relates Tensor - * @author Wolfgang Bangerth, 2000 - */ -template -void outer_product (Tensor<1,dim,Number> &dst, - const Number src1, - const Tensor<1,dim,Number> &src2) -{ - for (unsigned int i=0; idst[i] = - * src1[i] * src2. Of course, this is only a scaling of 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). - * - * @relates Tensor - * @author Wolfgang Bangerth, 2000 - */ -template -void outer_product (Tensor<1,dim,Number> &dst, - const Tensor<1,dim,Number> src1, - const Number src2) -{ - for (unsigned int i=0; ioperator* for this diff --git a/include/deal.II/base/tensor_deprecated.h b/include/deal.II/base/tensor_deprecated.h index 9bc6663167..b6dfeb343a 100644 --- a/include/deal.II/base/tensor_deprecated.h +++ b/include/deal.II/base/tensor_deprecated.h @@ -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 +void outer_product(Tensor &dst, + const Tensor &src1, + const Tensor &src2) DEAL_II_DEPRECATED; -#ifndef DOXYGEN +/** + * Multiply a Tensor<1,dim,Number> with a Number. + * + * @deprecated Use operator* instead. + * @relates Tensor + */ +template +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 +void outer_product (Tensor<1,dim,Number> &dst, + const Tensor<1,dim,Number> src1, + const Number src2) DEAL_II_DEPRECATED; + +//@} + +#ifndef DOXYGEN template inline @@ -57,9 +89,33 @@ cross_product (Tensor<1,dim,Number> &dst, dst = cross_product(src1, src2); } -#endif /* DOXYGEN */ +template +void outer_product(Tensor &dst, + const Tensor &src1, + const Tensor &src2) +{ + TensorAccessors::contract<0, rank_1, rank_2, dim>(dst, src1, src2); +} -//@} +template +void outer_product (Tensor<1,dim,Number> &dst, + const Number src1, + const Tensor<1,dim,Number> &src2) +{ + for (unsigned int i=0; i +void outer_product (Tensor<1,dim,Number> &dst, + const Tensor<1,dim,Number> src1, + const Number src2) +{ + for (unsigned int i=0; i