From 1d647efcf97e489451a88587b9845dfe464562f5 Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 31 May 2005 02:24:44 +0000 Subject: [PATCH] Add a way to get the tensor identity operator. git-svn-id: https://svn.dealii.org/trunk@10784 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/symmetric_tensor.h | 55 +++++++++++++++++- tests/base/symmetric_tensor_14.cc | 58 +++++++++++++++++++ .../base/symmetric_tensor_14.output | 22 +++++++ 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 tests/base/symmetric_tensor_14.cc create mode 100644 tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output diff --git a/deal.II/base/include/base/symmetric_tensor.h b/deal.II/base/include/base/symmetric_tensor.h index 68f93150e2..4a1f3eb20a 100644 --- a/deal.II/base/include/base/symmetric_tensor.h +++ b/deal.II/base/include/base/symmetric_tensor.h @@ -22,6 +22,7 @@ template class SymmetricTensor; template SymmetricTensor<2,dim> unit_symmetric_tensor (); template SymmetricTensor<4,dim> deviator_tensor (); +template SymmetricTensor<4,dim> identity_tensor (); namespace internal { @@ -882,6 +883,9 @@ class SymmetricTensor template friend SymmetricTensor<4,dim2> deviator_tensor (); + + template + friend SymmetricTensor<4,dim2> identity_tensor (); }; @@ -2039,7 +2043,15 @@ unit_symmetric_tensor<3> () /** - * Return a unit symmetric tensor of rank 2 and dimension 2. + * Return the tensor of rank 4 that, when multiplied by a symmetric rank 2 + * tensor t returns the deviator dev t. It is the operator + * representation of the linear deviator operator. + * + * For every tensor t, there holds the identity + * deviator(t)==deviator_tensor()*t, up to numerical + * round-off. The reason this operator representation is provided since one + * sometimes needs to invert operators like identity_tensor() + + * delta_t*deviator_tensor() or similar. * * @relates SymmetricTensor * @author Wolfgang Bangerth, 2005 @@ -2072,6 +2084,47 @@ deviator_tensor () +/** + * Return the tensor of rank 4 that, when multiplied by a symmetric rank 2 + * tensor t returns the deviator dev t. It is the operator + * representation of the linear deviator operator. + * + * For every tensor t, there holds the identity + * deviator(t)==deviator_tensor()*t, up to numerical + * round-off. The reason this operator representation is provided since one + * sometimes needs to invert operators like identity_tensor() + + * delta_t*deviator_tensor() or similar. + * + * @relates SymmetricTensor + * @author Wolfgang Bangerth, 2005 + */ +template +inline +SymmetricTensor<4,dim> +identity_tensor () +{ + SymmetricTensor<4,dim> tmp; + + // fill the elements treating the diagonal + for (unsigned int i=0; i + ::n_rank2_components; + ++i) + tmp.data[i][i] = 0.5; + + return tmp; +} + + + /** * Return the symmetrized version of the full rank-2 tensor, * i.e. (t+transpose(t))/2, as a symmetric rank-2 tensor. diff --git a/tests/base/symmetric_tensor_14.cc b/tests/base/symmetric_tensor_14.cc new file mode 100644 index 0000000000..ab755561b8 --- /dev/null +++ b/tests/base/symmetric_tensor_14.cc @@ -0,0 +1,58 @@ +//---------------------------- symmetric_tensor_14.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2005 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- symmetric_tensor_14.cc --------------------------- + +// test identity_tensor + +#include "../tests.h" +#include +#include +#include +#include + + +template +void test () +{ + deallog << "dim=" << dim << std::endl; + + SymmetricTensor<2,dim> t; + for (unsigned int i=0; i x = identity_tensor() * t; + Assert ((x-t).norm() < 1e-15*t.norm(), ExcInternalError()); + + deallog << "x=" << std::endl; + for (unsigned int i=0; i (); + test<2> (); + test<3> (); + + deallog << "OK" << std::endl; +} diff --git a/tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output b/tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output new file mode 100644 index 0000000000..e8901363ae --- /dev/null +++ b/tests/results/i686-pc-linux-gnu+gcc3.2/base/symmetric_tensor_14.output @@ -0,0 +1,22 @@ + +DEAL::dim=1 +DEAL::x= +DEAL::0 0 1.00 +DEAL::dim=2 +DEAL::x= +DEAL::0 0 1.00 +DEAL::0 1 3.00 +DEAL::1 0 3.00 +DEAL::1 1 5.00 +DEAL::dim=3 +DEAL::x= +DEAL::0 0 1.00 +DEAL::0 1 3.00 +DEAL::0 2 5.00 +DEAL::1 0 3.00 +DEAL::1 1 5.00 +DEAL::1 2 9.00 +DEAL::2 0 5.00 +DEAL::2 1 9.00 +DEAL::2 2 13.0 +DEAL::OK -- 2.39.5