From: bangerth Date: Thu, 24 Sep 2009 22:08:57 +0000 (+0000) Subject: More conversion functions between symmetric tensor indices and the indices of an... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59d3ca060eff98a553d84064e56e878ab50a7f3b;p=dealii-svn.git More conversion functions between symmetric tensor indices and the indices of an unrolled tensor. git-svn-id: https://svn.dealii.org/trunk@19532 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 320ccabc8f..2fbc062406 100644 --- a/deal.II/base/include/base/symmetric_tensor.h +++ b/deal.II/base/include/base/symmetric_tensor.h @@ -908,7 +908,21 @@ class SymmetricTensor */ static unsigned int - unrolled_index (const TableIndices &indices); + component_to_unrolled_index (const TableIndices &indices); + + /** + * The opposite of the previous + * function: given an index $i$ + * in the unrolled form of the + * tensor, return what set of + * indices $(k,l)$ (for rank-2 + * tensors) or $(k,l,m,n)$ (for + * rank-4 tensors) corresponds to + * it. + */ + static + TableIndices + unrolled_to_component_indices (const unsigned int i); /** * Reset all values to zero. @@ -1988,7 +2002,7 @@ SymmetricTensor<4,3>::norm () const template <> inline unsigned int -SymmetricTensor<2,1>::unrolled_index (const TableIndices<2> &indices) +SymmetricTensor<2,1>::component_to_unrolled_index (const TableIndices<2> &indices) { const unsigned int dim = 1; Assert (indices[0] < dim, ExcIndexRange(indices[0], 0, dim)); @@ -2002,7 +2016,7 @@ SymmetricTensor<2,1>::unrolled_index (const TableIndices<2> &indices) template <> inline unsigned int -SymmetricTensor<2,2>::unrolled_index (const TableIndices<2> &indices) +SymmetricTensor<2,2>::component_to_unrolled_index (const TableIndices<2> &indices) { const unsigned int dim = 2; Assert (indices[0] < dim, ExcIndexRange(indices[0], 0, dim)); @@ -2019,7 +2033,7 @@ SymmetricTensor<2,2>::unrolled_index (const TableIndices<2> &indices) template <> inline unsigned int -SymmetricTensor<2,3>::unrolled_index (const TableIndices<2> &indices) +SymmetricTensor<2,3>::component_to_unrolled_index (const TableIndices<2> &indices) { const unsigned int dim = 3; Assert (indices[0] < dim, ExcIndexRange(indices[0], 0, dim)); @@ -2034,6 +2048,55 @@ SymmetricTensor<2,3>::unrolled_index (const TableIndices<2> &indices) +template <> +inline +TableIndices<2> +SymmetricTensor<2,1>::unrolled_to_component_indices (const unsigned int i) +{ + Assert (i < n_independent_components, ExcIndexRange(i, 0, n_independent_components)); + + return TableIndices<2>(0,0); +} + + + +template <> +inline +TableIndices<2> +SymmetricTensor<2,2>::unrolled_to_component_indices (const unsigned int i) +{ + Assert (i < n_independent_components, ExcIndexRange(i, 0, n_independent_components)); + + static const TableIndices<2> table[n_independent_components] = + { TableIndices<2> (0,0), + TableIndices<2> (1,1), + TableIndices<2> (0,1) }; + + return table[i]; +} + + + +template <> +inline +TableIndices<2> +SymmetricTensor<2,3>::unrolled_to_component_indices (const unsigned int i) +{ + Assert (i < n_independent_components, ExcIndexRange(i, 0, n_independent_components)); + + static const TableIndices<2> table[n_independent_components] = + { TableIndices<2> (0,0), + TableIndices<2> (1,1), + TableIndices<2> (2,2), + TableIndices<2> (0,1), + TableIndices<2> (0,2), + TableIndices<2> (1,2) }; + + return table[i]; +} + + + #endif // DOXYGEN diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 620070ca9f..80021ecc9b 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -231,8 +231,9 @@ inconvenience this causes.

-
  • New: SymmetricTensor::unrolled_index() returns the index of an element of - a symmetric tensor within an unrolled vector. +

  • New: SymmetricTensor::component_to_unrolled_index() and + SymmetricTensor::unrolled_to_component_indices() allow to convert between the + indices of an element of a symmetric tensor and the index within an unrolled vector.
    (WB 2009/09/23)

  • diff --git a/tests/base/symmetric_tensor_24.cc b/tests/base/symmetric_tensor_24.cc new file mode 100644 index 0000000000..9d7b8e94f3 --- /dev/null +++ b/tests/base/symmetric_tensor_24.cc @@ -0,0 +1,56 @@ +//---------------------------- symmetric_tensor_24.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2006, 2008, 2009 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_24.cc --------------------------- + +// check SymmetricTensor<2,dim>::component_to_unrolled_index and the +// other way round + +#include "../tests.h" +#include +#include +#include +#include +#include + + +template +void check () +{ + typedef SymmetricTensor<2,dim> S; + for (unsigned int i=0; i (); + check<2> (); + check<3> (); + + deallog << "OK" << std::endl; +} diff --git a/tests/base/symmetric_tensor_24/cmp/generic b/tests/base/symmetric_tensor_24/cmp/generic new file mode 100644 index 0000000000..78b208ba8f --- /dev/null +++ b/tests/base/symmetric_tensor_24/cmp/generic @@ -0,0 +1,12 @@ +JobId unknown Thu Sep 24 17:05:12 2009 +DEAL::0 -- [0,0] +DEAL::0 -- [0,0] +DEAL::1 -- [1,1] +DEAL::2 -- [0,1] +DEAL::0 -- [0,0] +DEAL::1 -- [1,1] +DEAL::2 -- [2,2] +DEAL::3 -- [0,1] +DEAL::4 -- [0,2] +DEAL::5 -- [1,2] +DEAL::OK