From: Matthias Maier Date: Wed, 16 Sep 2015 04:36:32 +0000 (-0500) Subject: Generalize contract3 for arbitrary tensor ranks X-Git-Tag: v8.4.0-rc2~406^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f1b65ea771732b4446df7d9d584b60cd167b1c2;p=dealii.git Generalize contract3 for arbitrary tensor ranks --- diff --git a/include/deal.II/base/tensor.h b/include/deal.II/base/tensor.h index f5c2f28dd4..fdaac5fd74 100644 --- a/include/deal.II/base/tensor.h +++ b/include/deal.II/base/tensor.h @@ -1486,6 +1486,35 @@ operator * (const Tensor &src1, } +/** + * Full contraction of three tensors: Return a scalar Number that is the + * result of a full contraction of a tensor @p left of rank @p rank_1, a + * tensor @p middle of rank $(\text{rank_1}+\text{rank_2})$ and a tensor @p + * right of rank @p rank_2: + * @f[ + * \sum_{i_1,..,i_{r1},j_1,..,j_{r2}} + * \text{left}_{i_1,..,i_{r1}} + * \text{middle}_{i_1,..,i_{r1},j_1,..,j_{r2}} + * \text{right}_{j_1,..,j_{r2}} + * @f] + * + * @relates Tensor + * @author Matthias Maier, 2015 + */ +template +typename ProductType::type>::type +contract3 (const Tensor &left, + const Tensor &middle, + const Tensor &right) +{ + typedef typename ProductType::type>::type + return_type; + return TensorAccessors::contract3( + left, middle, right); +} + + /** * 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})$: @@ -1779,98 +1808,6 @@ void double_contract (Tensor<2,dim,Number> &dest, } -/** - * Contract three tensors, corresponding to the matrix vector product - * uT A v. - * - * @relates Tensor - * @author Guido Kanschat, 2004 - */ -template -inline -Number contract3 (const Tensor<1,dim,Number> &u, - const Tensor<2,dim,Number> &A, - const Tensor<1,dim,Number> &v) -{ - Number result = 0.; - - for (unsigned int i=0; i -inline -Number -contract3 (const Tensor<1,dim,Number> &t1, - const Tensor<3,dim,Number> &t2, - const Tensor<2,dim,Number> &t3) -{ - Number s = 0; - for (unsigned int i=0; i -inline -Number -contract3 (const Tensor<2,dim,Number> &t1, - const Tensor<3,dim,Number> &t2, - const Tensor<1,dim,Number> &t3) -{ - Number s = 0; - for (unsigned int i=0; i -inline -Number -contract3 (const Tensor<2,dim,Number> &t1, - const Tensor<4,dim,Number> &t2, - const Tensor<2,dim,Number> &t3) -{ - Number s = 0; - for (unsigned int i=0; ioperator* for this