From 74eedd7a81029eabe0573080ab0029e1b9f51bb9 Mon Sep 17 00:00:00 2001 From: "Toby D. Young" Date: Wed, 12 Jan 2011 09:10:30 +0000 Subject: [PATCH] First set of extended tensor operations git-svn-id: https://svn.dealii.org/trunk@23178 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 5 ++- deal.II/include/deal.II/base/tensor.h | 49 +++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index b977e1863d..fe3bd375a4 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -31,11 +31,10 @@ inconvenience this causes.

General

    -
  1. +
  2. Extended: base/tensor.h has an additional collection of contractions between three tensors ie. contract3). This can be useful for writing matrix/vector assembly in a more compact form than before.
    +(Toby D. Young, 2011/01/12)
- -

Specific improvements

diff --git a/deal.II/include/deal.II/base/tensor.h b/deal.II/include/deal.II/base/tensor.h index d0950abdb1..4af007f069 100644 --- a/deal.II/include/deal.II/base/tensor.h +++ b/deal.II/include/deal.II/base/tensor.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -1154,6 +1154,52 @@ double contract3 (const Tensor<1,dim>& u, } +/** + * Compute the contraction of three tensors $s=\sum_{i,j,k,l} + * a_{ij}b_{ijkl}c_{kl}$. + * + * @relates Tensor + */ +template +inline +double +contract3 (const Tensor<2,dim> &t1, + const Tensor<4,dim> &t2, + const Tensor<2,dim> &t3) +{ + double s = 0; + for (unsigned int i=0; i +inline +double +contract3 (const Tensor<1,dim> &t1, + const Tensor<3,dim> &t2, + const Tensor<2,dim> &t3) +{ + double s = 0; + for (unsigned int i=0; idst[i][j] = src1[i] * src2[j]. @@ -1333,7 +1379,6 @@ scalar_product (const Tensor<2,dim> &t1, } - /** * Compute the determinant of a tensor of arbitrary rank and dimension * one. Since this is a number, the return value is, of course, the -- 2.39.5