]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use range-based iterators in tria.cc
authorPeter Munch <peterrmuench@gmail.com>
Mon, 1 Jun 2020 12:12:34 +0000 (14:12 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Mon, 1 Jun 2020 12:12:34 +0000 (14:12 +0200)
source/grid/tria.cc

index 61eb5a207ba718d835097159ffbf778753c99af6..0301d61c151469b7ec91bb9c9f127037072a5474 100644 (file)
@@ -4206,8 +4206,8 @@ namespace internal
         typename Triangulation<2, spacedim>::raw_line_iterator
           &next_unused_line,
         typename Triangulation<2, spacedim>::raw_cell_iterator
-          &                                                 next_unused_cell,
-        typename Triangulation<2, spacedim>::cell_iterator &cell)
+          &next_unused_cell,
+        const typename Triangulation<2, spacedim>::cell_iterator &cell)
       {
         const unsigned int dim = 2;
         // clear refinement flag
@@ -4665,10 +4665,9 @@ namespace internal
             // count number of flagged
             // cells on this level
             unsigned int flagged_cells = 0;
-            typename Triangulation<dim, spacedim>::active_cell_iterator
-              acell = triangulation.begin_active(level),
-              aendc = triangulation.begin_active(level + 1);
-            for (; acell != aendc; ++acell)
+
+            for (auto &acell :
+                 triangulation.active_cell_iterators_on_level(level))
               if (acell->refine_flag_set())
                 ++flagged_cells;
 
@@ -4718,14 +4717,11 @@ namespace internal
 
         for (int level = triangulation.levels.size() - 2; level >= 0; --level)
           {
-            typename Triangulation<dim, spacedim>::active_cell_iterator
-              cell = triangulation.begin_active(level),
-              endc = triangulation.begin_active(level + 1);
-
             typename Triangulation<dim, spacedim>::raw_cell_iterator
               next_unused_cell = triangulation.begin_raw(level + 1);
 
-            for (; (cell != endc) && (cell->level() == level); ++cell)
+            for (auto &cell :
+                 triangulation.active_cell_iterators_on_level(level))
               if (cell->refine_flag_set())
                 {
                   // clear refinement flag
@@ -4928,10 +4924,8 @@ namespace internal
             // how many new vertices and new lines will be needed
             unsigned int needed_cells = 0;
 
-            typename Triangulation<dim, spacedim>::active_cell_iterator
-              cell = triangulation.begin_active(level),
-              endc = triangulation.begin_active(level + 1);
-            for (; cell != endc; ++cell)
+            for (auto &cell :
+                 triangulation.active_cell_iterators_on_level(level))
               if (cell->refine_flag_set())
                 {
                   if (cell->refine_flag_set() == RefinementCase<dim>::cut_xy)
@@ -5149,16 +5143,11 @@ namespace internal
              level < static_cast<int>(triangulation.levels.size()) - 1;
              ++level)
           {
-            // Remember: as we don't operate on the finest level,
-            // begin_*(level+1) is allowed
-            typename Triangulation<dim, spacedim>::active_cell_iterator
-              cell = triangulation.begin_active(level),
-              endc = triangulation.begin_active(level + 1);
-
             typename Triangulation<dim, spacedim>::raw_cell_iterator
               next_unused_cell = triangulation.begin_raw(level + 1);
 
-            for (; cell != endc; ++cell)
+            for (auto &cell :
+                 triangulation.active_cell_iterators_on_level(level))
               if (cell->refine_flag_set())
                 {
                   // set the user flag to indicate, that at least one
@@ -5277,10 +5266,8 @@ namespace internal
             // how many new vertices and new lines will be needed
             unsigned int new_cells = 0;
 
-            typename Triangulation<dim, spacedim>::active_cell_iterator
-              acell = triangulation.begin_active(level),
-              aendc = triangulation.begin_active(level + 1);
-            for (; acell != aendc; ++acell)
+            for (auto &acell :
+                 triangulation.active_cell_iterators_on_level(level))
               if (acell->refine_flag_set())
                 {
                   RefinementCase<dim> ref_case = acell->refine_flag_set();
@@ -10232,11 +10219,7 @@ Triangulation<dim, spacedim>::set_all_manifold_ids(
     ExcMessage(
       "Error: set_all_manifold_ids() can not be called on an empty Triangulation."));
 
-  typename Triangulation<dim, spacedim>::active_cell_iterator
-    cell = this->begin_active(),
-    endc = this->end();
-
-  for (; cell != endc; ++cell)
+  for (auto &cell : this->active_cell_iterators())
     cell->set_all_manifold_ids(m_number);
 }
 
@@ -10251,11 +10234,7 @@ Triangulation<dim, spacedim>::set_all_manifold_ids_on_boundary(
     ExcMessage(
       "Error: set_all_manifold_ids_on_boundary() can not be called on an empty Triangulation."));
 
-  typename Triangulation<dim, spacedim>::active_cell_iterator
-    cell = this->begin_active(),
-    endc = this->end();
-
-  for (; cell != endc; ++cell)
+  for (auto &cell : this->active_cell_iterators())
     for (auto f : GeometryInfo<dim>::face_indices())
       if (cell->face(f)->at_boundary())
         cell->face(f)->set_all_manifold_ids(m_number);
@@ -10274,11 +10253,8 @@ Triangulation<dim, spacedim>::set_all_manifold_ids_on_boundary(
       "Error: set_all_manifold_ids_on_boundary() can not be called on an empty Triangulation."));
 
   bool boundary_found = false;
-  typename Triangulation<dim, spacedim>::active_cell_iterator
-    cell = this->begin_active(),
-    endc = this->end();
 
-  for (; cell != endc; ++cell)
+  for (auto &cell : this->active_cell_iterators())
     {
       // loop on faces
       for (auto f : GeometryInfo<dim>::face_indices())
@@ -10785,9 +10761,8 @@ Triangulation<dim, spacedim>::set_all_refine_flags()
 {
   Assert(n_cells() > 0,
          ExcMessage("Error: An empty Triangulation can not be refined."));
-  active_cell_iterator cell = begin_active(), endc = end();
 
-  for (; cell != endc; ++cell)
+  for (auto &cell : this->active_cell_iterators())
     {
       cell->clear_coarsen_flag();
       cell->set_refine_flag();
@@ -10818,9 +10793,9 @@ void
 Triangulation<dim, spacedim>::save_refine_flags(std::vector<bool> &v) const
 {
   v.resize(dim * n_active_cells(), false);
-  std::vector<bool>::iterator i    = v.begin();
-  active_cell_iterator        cell = begin_active(), endc = end();
-  for (; cell != endc; ++cell)
+  std::vector<bool>::iterator i = v.begin();
+
+  for (auto &cell : this->active_cell_iterators())
     for (unsigned int j = 0; j < dim; ++j, ++i)
       if (cell->refine_flag_set() & (1 << j))
         *i = true;
@@ -10861,9 +10836,8 @@ Triangulation<dim, spacedim>::load_refine_flags(const std::vector<bool> &v)
 {
   AssertThrow(v.size() == dim * n_active_cells(), ExcGridReadError());
 
-  active_cell_iterator              cell = begin_active(), endc = end();
   std::vector<bool>::const_iterator i = v.begin();
-  for (; cell != endc; ++cell)
+  for (auto &cell : this->active_cell_iterators())
     {
       unsigned int ref_case = 0;
 
@@ -10888,10 +10862,12 @@ void
 Triangulation<dim, spacedim>::save_coarsen_flags(std::vector<bool> &v) const
 {
   v.resize(n_active_cells(), false);
-  std::vector<bool>::iterator i    = v.begin();
-  active_cell_iterator        cell = begin_active(), endc = end();
-  for (; cell != endc; ++cell, ++i)
-    *i = cell->coarsen_flag_set();
+  std::vector<bool>::iterator i = v.begin();
+  for (auto &cell : this->active_cell_iterators())
+    {
+      *i = cell->coarsen_flag_set();
+      ++i;
+    }
 
   Assert(i == v.end(), ExcInternalError());
 }
@@ -10932,13 +10908,15 @@ Triangulation<dim, spacedim>::load_coarsen_flags(const std::vector<bool> &v)
 {
   Assert(v.size() == n_active_cells(), ExcGridReadError());
 
-  active_cell_iterator              cell = begin_active(), endc = end();
   std::vector<bool>::const_iterator i = v.begin();
-  for (; cell != endc; ++cell, ++i)
-    if (*i == true)
-      cell->set_coarsen_flag();
-    else
-      cell->clear_coarsen_flag();
+  for (auto &cell : this->active_cell_iterators())
+    {
+      if (*i == true)
+        cell->set_coarsen_flag();
+      else
+        cell->clear_coarsen_flag();
+      ++i;
+    }
 
   Assert(i == v.end(), ExcInternalError());
 }
@@ -13606,8 +13584,7 @@ Triangulation<dim, spacedim>::fix_coarsen_flags()
           // store highest level one of the cells adjacent to a vertex
           // belongs to
           std::fill(vertex_level.begin(), vertex_level.end(), 0);
-          active_cell_iterator cell = begin_active(), endc = end();
-          for (; cell != endc; ++cell)
+          for (auto &cell : this->active_cell_iterators())
             {
               if (cell->refine_flag_set())
                 for (const unsigned int vertex :
@@ -13648,6 +13625,7 @@ Triangulation<dim, spacedim>::fix_coarsen_flags()
           // refinement flags, but we will also have to remove
           // coarsening flags on cells adjacent to vertices that will
           // see refinement
+          active_cell_iterator cell = begin_active(), endc = end();
           for (cell = last_active(); cell != endc; --cell)
             if (cell->refine_flag_set() == false)
               {
@@ -13696,8 +13674,7 @@ Triangulation<dim, spacedim>::fix_coarsen_flags()
       clear_user_flags();
       // Coarsen flags of cells with no mother cell, i.e. on the
       // coarsest level are deleted explicitly.
-      active_cell_iterator acell = begin_active(0), end_ac = end_active(0);
-      for (; acell != end_ac; ++acell)
+      for (auto &acell : this->active_cell_iterators_on_level(0))
         acell->clear_coarsen_flag();
 
       cell_iterator cell = begin(), endc = end();

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.