From: Wolfgang Bangerth Date: Thu, 15 Aug 2013 02:52:42 +0000 (+0000) Subject: Patch by Scott Miller (and testcases by me): Add scalar_product functions between... X-Git-Tag: v8.1.0~1059 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fb94c179cc40a7a3364960fc880efedf91c4df1;p=dealii.git Patch by Scott Miller (and testcases by me): Add scalar_product functions between tensors. git-svn-id: https://svn.dealii.org/trunk@30315 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 89bdcf8984..0b615ad489 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -56,6 +56,14 @@ inconvenience this causes.

Specific improvements

    +
  1. + New: There are now global functions scalar_product + that compute the scalar product (double contraction) between + tensors of rank 2. +
    + (Scott Miller, 2013/08/14) +
  2. +
  3. Fixed: Creating objects of type MappingQ was previously only possible for low order polynomials. For orders higher than around 6, one ran diff --git a/deal.II/include/deal.II/base/symmetric_tensor.h b/deal.II/include/deal.II/base/symmetric_tensor.h index 473792c92b..93ffc6296a 100644 --- a/deal.II/include/deal.II/base/symmetric_tensor.h +++ b/deal.II/include/deal.II/base/symmetric_tensor.h @@ -2842,8 +2842,68 @@ operator / (const SymmetricTensor &t, return tt; } +/** + * Compute the scalar product $a:b=\sum_{i,j} a_{ij}b_{ij}$ between two + * tensors $a,b$ of rank 2. In the current case where both arguments are + * symmetric tensors, this is equivalent to calling the expression + * t1*t2 which uses the overloaded operator* + * between two symmetric tensors of rank 2. + * + * @relates SymmetricTensor + */ +template +inline +Number +scalar_product (const SymmetricTensor<2,dim,Number> &t1, + const SymmetricTensor<2,dim,Number> &t2) +{ + return (t1*t2); +} + + +/** + * 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 operator* for this + * operation since the product between two tensors is usually assumed to be + * the contraction over the last index of the first tensor and the first index + * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$. + * + * @relates Tensor + * @relates SymmetricTensor + */ +template +inline +Number +scalar_product (const SymmetricTensor<2,dim,Number> &t1, + const Tensor<2,dim,Number> &t2) +{ + Number s = 0; + for (unsigned int i=0; ioperator* for this + * operation since the product between two tensors is usually assumed to be + * the contraction over the last index of the first tensor and the first index + * of the second tensor, for example $(a\cdot b)_{ij}=\sum_k a_{ik}b_{kj}$. + * + * @relates Tensor + * @relates SymmetricTensor + */ +template +inline +Number +scalar_product (const Tensor<2,dim,Number> &t1, + const SymmetricTensor<2,dim,Number> &t2) +{ + return scalar_product(t2, t1); +} + /** * Double contraction between a rank-4 and a rank-2 symmetric tensor, diff --git a/tests/base/symmetric_tensor_27.cc b/tests/base/symmetric_tensor_27.cc new file mode 100644 index 0000000000..4d03de1485 --- /dev/null +++ b/tests/base/symmetric_tensor_27.cc @@ -0,0 +1,72 @@ +// --------------------------------------------------------------------- +// $Id$ +// +// Copyright (C) 2005 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test scalar_product between tensors and symmetric tensors + +#include "../tests.h" +#include +#include +#include +#include + + +template +void test () +{ + deallog << "dim=" << dim << std::endl; + + // initialize symmetric and non-symmetric tensors. in the former case, we + // only need to initialize one half + SymmetricTensor<2,dim> s; + for (unsigned int i=0; i t; + for (unsigned int i=0; i (); + test<2> (); + test<3> (); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/symmetric_tensor_27/cmp/generic b/tests/base/symmetric_tensor_27/cmp/generic new file mode 100644 index 0000000000..48633ff75e --- /dev/null +++ b/tests/base/symmetric_tensor_27/cmp/generic @@ -0,0 +1,14 @@ + +DEAL::dim=1 +DEAL::1.00 +DEAL::1.00 +DEAL::1.00 +DEAL::dim=2 +DEAL::44.0 +DEAL::38.0 +DEAL::38.0 +DEAL::dim=3 +DEAL::425. +DEAL::381. +DEAL::381. +DEAL::OK