From: bangerth Date: Fri, 22 Feb 2008 20:59:23 +0000 (+0000) Subject: Add a couple of functions for SymmetricTensor X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ee76591ebc082e4133b76b32c01b2eb4b92dc67;p=dealii-svn.git Add a couple of functions for SymmetricTensor git-svn-id: https://svn.dealii.org/trunk@15755 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/symmetric_tensor.h b/deal.II/base/include/base/symmetric_tensor.h index be480252ff..7596302228 100644 --- a/deal.II/base/include/base/symmetric_tensor.h +++ b/deal.II/base/include/base/symmetric_tensor.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2005, 2006 by the deal.II authors +// Copyright (C) 2005, 2006, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -214,6 +214,14 @@ namespace internal static const unsigned int n_rank2_components = (dim*dim + dim)/2; + /** + * Number of independent components of a + * symmetric tensor of rank 4. + */ + static const unsigned int + n_independent_components = (n_rank2_components * + StorageType<2,dim>::n_independent_components); + /** * Declare the type in which we * actually store the data. Symmetric @@ -619,6 +627,18 @@ class SymmetricTensor * data types. */ static const unsigned int dimension = dim; + + /** + * An integer denoting the number of + * independent components that fully + * describe a symmetric tensor. In $d$ + * space dimensions, this number equals + * $\frac 12 (d^2+d)$ for symmetric + * tensors of rank 2. + */ + static const unsigned int n_independent_components + = internal::SymmetricTensorAccessors::StorageType:: + n_independent_components; /** * Default constructor. Creates a zero @@ -646,6 +666,21 @@ class SymmetricTensor */ SymmetricTensor (const Tensor<2,dim> &t); + /** + * A constructor that creates a symmetric + * tensor from an array holding its + * independent elements. Using this + * constructor assumes that the caller + * knows the order in which elements are + * stored in symmetric tensors; its use + * is therefore discouraged. + * + * This constructor is currently inly + * implemented for symmetric tensors of + * rank 2. + */ + SymmetricTensor (const double (&array) [n_independent_components]); + /** * Assignment operator. */ @@ -1018,6 +1053,14 @@ SymmetricTensor<2,3>::SymmetricTensor (const Tensor<2,3> &t) } +template +inline +SymmetricTensor::SymmetricTensor (const double (&array) [n_independent_components]) + : + data (array) +{} + + template inline SymmetricTensor & @@ -2666,6 +2709,64 @@ double_contract (SymmetricTensor<2,3> &tmp, } + +/** + * Output operator for symmetric tensors of rank 2. Print the elements + * consecutively, with a space in between, two spaces between rank 1 + * subtensors, three between rank 2 and so on. No special amends are made to + * represents the symmetry in the output, for example by outputting only the + * unique entries. + * + * @relates SymmetricTensor + */ +template +inline +std::ostream & operator << (std::ostream &out, + const SymmetricTensor<2,dim> &t) +{ + //make out lives a bit simpler by outputing + //the tensor through the operator for the + //general Tensor class + Tensor<2,dim> tt; + + for (unsigned int i=0; i +inline +std::ostream & operator << (std::ostream &out, + const SymmetricTensor<4,dim> &t) +{ + //make out lives a bit simpler by outputing + //the tensor through the operator for the + //general Tensor class + Tensor<4,dim> tt; + + for (unsigned int i=0; i +
  • New: The SymmetricTensor class now has a constructor that creates +an object from an array consisting its independent components. +
    +(WB 2008/02/21) +

  • + +
  • New: There are now output operators (i.e. operator@<@<) +for the SymmetricTensor class. +
    +(WB 2008/02/12) +

  • +
  • Improved: LogStream is now thread safe and output lines from different threads are separated now. Additionally, a function LogStream::log_thread_id() has been added to log the id of the thread printing the message. The semantics diff --git a/tests/base/symmetric_tensor_21.cc b/tests/base/symmetric_tensor_21.cc index 59d70166b8..fbe8bdae6f 100644 --- a/tests/base/symmetric_tensor_21.cc +++ b/tests/base/symmetric_tensor_21.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2006 by the deal.II authors +// Copyright (C) 2006, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -11,7 +11,7 @@ // //---------------------------- symmetric_tensor_21.cc --------------------------- -// check SymmetricTensor<2,dim>::operator= (double) +// check SymmetricTensor<4,dim>::operator= (double) #include "../tests.h" #include diff --git a/tests/base/symmetric_tensor_22.cc b/tests/base/symmetric_tensor_22.cc new file mode 100644 index 0000000000..76a21d78b4 --- /dev/null +++ b/tests/base/symmetric_tensor_22.cc @@ -0,0 +1,51 @@ +//---------------------------- symmetric_tensor_22.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2006, 2008 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_22.cc --------------------------- + +// check operator<< for SymmetricTensor<2,dim> and SymmetricTensor<4,dim> + +#include "../tests.h" +#include +#include +#include +#include +#include + +int main () +{ + std::ofstream logfile("symmetric_tensor_22/output"); + deallog << std::setprecision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + { + const unsigned int dim=2; + SymmetricTensor<2,dim> t; + t[0][0] = 1; + t[1][1] = 2; + t[0][1] = 3; + + deallog << t << std::endl; + } + + { + const unsigned int dim=3; + SymmetricTensor<4,dim> t; + t[0][0][0][0] = t[1][0][1][0] = t[1][1][1][1] + = t[2][2][2][2] = t[2][0][2][0] = 3; + + deallog << t << std::endl; + } + + deallog << "OK" << std::endl; +} diff --git a/tests/base/symmetric_tensor_22/cmp/generic b/tests/base/symmetric_tensor_22/cmp/generic new file mode 100644 index 0000000000..f995ff0d98 --- /dev/null +++ b/tests/base/symmetric_tensor_22/cmp/generic @@ -0,0 +1,4 @@ + +DEAL::1.00 3.00 3.00 2.00 +DEAL::3.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00 0.00 3.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00 0.00 0.00 0.00 3.00 0.00 0.00 0.00 3.00 0.00 3.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00 0.00 0.00 0.00 3.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 3.00 +DEAL::OK diff --git a/tests/base/symmetric_tensor_23.cc b/tests/base/symmetric_tensor_23.cc new file mode 100644 index 0000000000..4095062334 --- /dev/null +++ b/tests/base/symmetric_tensor_23.cc @@ -0,0 +1,66 @@ +//---------------------------- symmetric_tensor_23.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2006, 2008 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_23.cc --------------------------- + +// check operator<< for SymmetricTensor<2,dim> and SymmetricTensor<4,dim> + +#include "../tests.h" +#include +#include +#include +#include +#include + +int main () +{ + std::ofstream logfile("symmetric_tensor_23/output"); + deallog << std::setprecision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + { + SymmetricTensor<2,1> t; + t[0][0] = 1; + + double x[1] = { 1 }; + Assert ((t == SymmetricTensor<2,1>(x)), + ExcInternalError()); + } + + { + SymmetricTensor<2,2> t; + t[0][0] = 1; + t[1][1] = 2; + t[0][1] = 3; + + double x[3] = { 1, 2, 3 }; + Assert ((t == SymmetricTensor<2,2>(x)), + ExcInternalError()); + } + + { + SymmetricTensor<2,3> t; + t[0][0] = 1; + t[1][1] = 2; + t[2][2] = 3; + t[0][1] = 4; + t[0][2] = 5; + t[1][2] = 6; + + double x[6] = { 1, 2, 3, 4, 5, 6 }; + Assert ((t == SymmetricTensor<2,3>(x)), + ExcInternalError()); + } + + deallog << "OK" << std::endl; +} diff --git a/tests/base/symmetric_tensor_23/cmp/generic b/tests/base/symmetric_tensor_23/cmp/generic new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/base/symmetric_tensor_23/cmp/generic @@ -0,0 +1,2 @@ + +DEAL::OK