]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Use a non-recursive version of the unroll function.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 2 Jul 2013 19:36:17 +0000 (19:36 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 2 Jul 2013 19:36:17 +0000 (19:36 +0000)
git-svn-id: https://svn.dealii.org/trunk@29919 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/tensor.h

index dc5dd68407e6deba77193b14ad412d23491f2718..eaceaee41b4678210b35a43364c146b11a6dddd7 100644 (file)
@@ -605,14 +605,13 @@ inline
 unsigned int
 Tensor<rank_, dim, Number>::component_to_unrolled_index(const TableIndices<rank_> &indices)
 {
-   TableIndices<rank_-1> 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<rank_-1,dim,Number>::component_to_unrolled_index(indices1) * dim + indices[rank_-1]);
+  TableIndices<rank_-1> 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<rank_-1,dim,Number>::component_to_unrolled_index(indices1) * dim + indices[rank_-1]);
 }
 
 template <int rank_, int dim, typename Number>
@@ -620,16 +619,18 @@ inline
 TableIndices<rank_>
 Tensor<rank_, dim, Number>::unrolled_to_component_indices(const unsigned int i)
 {
-  TableIndices<rank_-1> indices1;
-  TableIndices<rank_>   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<rank_-1,dim,Number>::unrolled_to_component_indices(i1);
+  TableIndices<rank_>   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;
 }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.