From: bangerth Date: Tue, 2 Jul 2013 19:36:17 +0000 (+0000) Subject: Use a non-recursive version of the unroll function. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd1258de0849b979417c632825fc71f1cd3e2c0c;p=dealii-svn.git Use a non-recursive version of the unroll function. git-svn-id: https://svn.dealii.org/trunk@29919 0785d39b-7218-0410-832d-ea1e28bc413d --- 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; }