]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid memory allocation in CellIDTranslator 15857/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Tue, 8 Aug 2023 14:34:32 +0000 (16:34 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Tue, 8 Aug 2023 14:34:32 +0000 (16:34 +0200)
include/deal.II/grid/cell_id_translator.h

index 8055535fd054aa047d375a2d06ea8ad854719218..ee207c19c225afe49d7ac21f47c2f2ced35c4c69 100644 (file)
@@ -269,8 +269,8 @@ namespace internal
     unsigned int child_level  = 0;
     unsigned int binary_entry = 2;
 
-    // path to the get to the cell
-    std::vector<unsigned int> cell_indices;
+    // compute new coarse-grid id: c_{i+1} = c_{i}*2^dim + q on path to cell
+    types::global_cell_index level_coarse_cell_id = coarse_cell_id;
     while (child_level < n_child_indices)
       {
         Assert(binary_entry < binary_representation.size(), ExcInternalError());
@@ -280,7 +280,9 @@ namespace internal
             unsigned int cell_index =
               (((binary_representation[binary_entry] >> (j * dim))) &
                (GeometryInfo<dim>::max_children_per_cell - 1));
-            cell_indices.push_back(cell_index);
+            level_coarse_cell_id =
+              level_coarse_cell_id * GeometryInfo<dim>::max_children_per_cell +
+              cell_index;
             ++child_level;
             if (child_level == n_child_indices)
               break;
@@ -288,12 +290,6 @@ namespace internal
         ++binary_entry;
       }
 
-    // compute new coarse-grid id: c_{i+1} = c_{i}*2^dim + q;
-    types::global_cell_index level_coarse_cell_id = coarse_cell_id;
-    for (auto i : cell_indices)
-      level_coarse_cell_id =
-        level_coarse_cell_id * GeometryInfo<dim>::max_children_per_cell + i;
-
     return level_coarse_cell_id;
   }
 

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.