]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Replace a double loop over cells and indices by a single loop and the use of cell...
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 14 Apr 2015 21:46:56 +0000 (16:46 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 15 Apr 2015 12:47:38 +0000 (07:47 -0500)
source/grid/grid_tools.cc

index 3e68b4d91b1292f961004b78f88d7ab999e7f715..e78afd109da25ac48cbefd0fd1d6b404de2efc1b 100644 (file)
@@ -1531,11 +1531,10 @@ next_cell:
     // works, but this map can get quite big. Not sure about more efficient solutions.
     std::map< std::pair<unsigned int,unsigned int>, unsigned int >
     indexmap;
-    unsigned int index = 0;
     for (typename dealii::internal::ActiveCellIterator<dim, spacedim, Triangulation<dim, spacedim> >::type
          cell = triangulation.begin_active();
-         cell != triangulation.end(); ++cell, ++index)
-      indexmap[std::pair<unsigned int,unsigned int>(cell->level(),cell->index())] = index;
+         cell != triangulation.end(); ++cell)
+      indexmap[std::pair<unsigned int,unsigned int>(cell->level(),cell->index())] = cell->active_cell_index();
 
     // next loop over all cells and their neighbors to build the sparsity
     // pattern. note that it's a bit hard to enter all the connections when a
@@ -1544,11 +1543,11 @@ next_cell:
     // if we only do something if the neighbor has no children -- in that case
     // it is either on the same or a coarser level than we are. in return, we
     // have to add entries in both directions for both cells
-    index = 0;
     for (typename dealii::internal::ActiveCellIterator<dim, spacedim, Triangulation<dim, spacedim> >::type
          cell = triangulation.begin_active();
-         cell != triangulation.end(); ++cell, ++index)
+         cell != triangulation.end(); ++cell)
       {
+        const unsigned int index = cell->active_cell_index();
         cell_connectivity.add (index, index);
         for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
           if ((cell->at_boundary(f) == false)
@@ -1583,23 +1582,21 @@ next_cell:
                                     DynamicSparsityPattern            &cell_connectivity)
   {
     std::vector<std::vector<unsigned int> > vertex_to_cell(triangulation.n_vertices());
-    unsigned int index = 0;
     for (typename Triangulation<dim,spacedim>::active_cell_iterator cell=
-           triangulation.begin_active(); cell != triangulation.end(); ++cell, ++index)
+           triangulation.begin_active(); cell != triangulation.end(); ++cell)
       {
         for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
-          vertex_to_cell[cell->vertex_index(v)].push_back(index);
+          vertex_to_cell[cell->vertex_index(v)].push_back(cell->active_cell_index());
       }
 
     cell_connectivity.reinit (triangulation.n_active_cells(),
                               triangulation.n_active_cells());
-    index = 0;
     for (typename Triangulation<dim,spacedim>::active_cell_iterator cell=
-           triangulation.begin_active(); cell != triangulation.end(); ++cell, ++index)
+           triangulation.begin_active(); cell != triangulation.end(); ++cell)
       {
         for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
           for (unsigned int n=0; n<vertex_to_cell[cell->vertex_index(v)].size(); ++n)
-            cell_connectivity.add(index, vertex_to_cell[cell->vertex_index(v)][n]);
+            cell_connectivity.add(cell->active_cell_index(), vertex_to_cell[cell->vertex_index(v)][n]);
       }
   }
 
@@ -1681,11 +1678,10 @@ next_cell:
 
     // finally loop over all cells and set the
     // subdomain ids
-    unsigned int index = 0;
     for (typename dealii::internal::ActiveCellIterator<dim, spacedim, Triangulation<dim, spacedim> >::type
          cell = triangulation.begin_active();
-         cell != triangulation.end(); ++cell, ++index)
-      cell->set_subdomain_id (partition_indices[index]);
+         cell != triangulation.end(); ++cell)
+      cell->set_subdomain_id (partition_indices[cell->active_cell_index()]);
   }
 
 
@@ -1698,13 +1694,9 @@ next_cell:
     Assert (subdomain.size() == triangulation.n_active_cells(),
             ExcDimensionMismatch (subdomain.size(),
                                   triangulation.n_active_cells()));
-    unsigned int index = 0;
     for (typename Triangulation<dim, spacedim>::active_cell_iterator
-         cell = triangulation.begin_active();
-         cell!=triangulation.end(); ++cell, ++index)
-      subdomain[index] = cell->subdomain_id();
-
-    Assert (index == subdomain.size(), ExcInternalError());
+         cell = triangulation.begin_active(); cell!=triangulation.end(); ++cell)
+      subdomain[cell->active_cell_index()] = cell->subdomain_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.