From 5b2fea880f67aecfb8c786e817c8beef9c8c76ef Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 2 Jul 2013 19:36:17 +0000 Subject: [PATCH] Use a non-recursive version of the unroll function. git-svn-id: https://svn.dealii.org/trunk@29919 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/tensor.h | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/deal.II/include/deal.II/base/tensor.h b/deal.II/include/deal.II/base/tensor.h index dc5dd68407..eaceaee41b 100644 --- a/deal.II/include/deal.II/base/tensor.h +++ b/deal.II/include/deal.II/base/tensor.h @@ -605,14 +605,13 @@ inline unsigned int Tensor::component_to_unrolled_index(const TableIndices &indices) { - TableIndices indices1; - for (unsigned int i = 0; i < rank_-1;i++) - indices1[i] = indices[i]; - - Assert (indices[rank_-1] < dim, - ExcIndexRange (indices[rank_-1], 0, dim)); - return ( Tensor::component_to_unrolled_index(indices1) * dim + indices[rank_-1]); + TableIndices indices1; + for (unsigned int i = 0; i < rank_-1;i++) + indices1[i] = indices[i]; + Assert (indices[rank_-1] < dim, + ExcIndexRange (indices[rank_-1], 0, dim)); + return ( Tensor::component_to_unrolled_index(indices1) * dim + indices[rank_-1]); } template @@ -620,16 +619,18 @@ inline TableIndices Tensor::unrolled_to_component_indices(const unsigned int i) { - TableIndices indices1; - TableIndices indices; + Assert (i < n_independent_components, + ExcIndexRange (i, 0, n_independent_components)); - indices[rank_-1] = (i % dim); - const unsigned int i1 = i / dim; - - indices1 = Tensor::unrolled_to_component_indices(i1); + TableIndices indices; - for (unsigned int i = 0; i < rank-1;i++) - indices[i] = indices1[i]; + unsigned int remainder = i; + for (int r=rank_-1; r>=0; ++r) + { + indices[r] = (remainder % dim); + remainder /= dim; + } + Assert (remainder == 0, ExcInternalError()); return indices; } -- 2.39.5