]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use range-based for loops in source/grid
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 9 Jan 2019 08:51:21 +0000 (09:51 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 11 Jan 2019 17:07:12 +0000 (18:07 +0100)
source/grid/cell_id.cc
source/grid/grid_generator.cc
source/grid/grid_in.cc
source/grid/grid_out.cc
source/grid/grid_reordering.cc
source/grid/grid_tools.cc
source/grid/grid_tools_cache.cc
source/grid/grid_tools_dof_handlers.cc
source/grid/manifold_lib.cc
source/grid/tria.cc

index c995495da08198b712d5d934d5e55f9fcff3e0be..7941bccaf944e6bb86d5844655b79e442ec76a72 100644 (file)
@@ -28,8 +28,9 @@ CellId::CellId()
   // initialize the child indices to invalid values
   // (the only allowed values are between zero and
   // GeometryInfo<dim>::max_children_per_cell)
-  for (unsigned int i = 0; i < child_indices.size(); ++i)
-    child_indices[i] = std::numeric_limits<char>::max();
+  std::fill(child_indices.begin(),
+            child_indices.end(),
+            std::numeric_limits<char>::max());
 }
 
 
index a51cbe29a31239f7b02c27141db7dcc7514fa70a..b6a71f349064f725cfbc1d4956a6fe560813a64c 100644 (file)
@@ -2088,7 +2088,7 @@ namespace GridGenerator
     static constexpr double tol =
       std::numeric_limits<double>::epsilon() * 10000;
     if (colorize)
-      for (auto &cell : tria.active_cell_iterators())
+      for (const auto &cell : tria.active_cell_iterators())
         for (unsigned int face_n = 0; face_n < GeometryInfo<2>::faces_per_cell;
              ++face_n)
           {
@@ -2257,7 +2257,7 @@ namespace GridGenerator
     // The bulk cells are not quite squares, so we need to move the left
     // and right sides of cylinder_tria inwards so that it fits in
     // bulk_tria:
-    for (auto &cell : cylinder_tria.active_cell_iterators())
+    for (const auto &cell : cylinder_tria.active_cell_iterators())
       for (unsigned int vertex_n = 0;
            vertex_n < GeometryInfo<2>::vertices_per_cell;
            ++vertex_n)
@@ -2269,7 +2269,7 @@ namespace GridGenerator
         }
 
     // Assign interior manifold ids to be the TFI id.
-    for (auto &cell : cylinder_tria.active_cell_iterators())
+    for (const auto &cell : cylinder_tria.active_cell_iterators())
       {
         cell->set_manifold_id(tfi_manifold_id);
         for (unsigned int face_n = 0; face_n < GeometryInfo<2>::faces_per_cell;
@@ -2317,7 +2317,7 @@ namespace GridGenerator
 
     // Ensure that all manifold ids on a polar cell really are set to the
     // polar manifold id:
-    for (auto &cell : tria.active_cell_iterators())
+    for (const auto &cell : tria.active_cell_iterators())
       if (cell->manifold_id() == polar_manifold_id)
         cell->set_all_manifold_ids(polar_manifold_id);
 
@@ -2360,7 +2360,7 @@ namespace GridGenerator
     tria.set_manifold(tfi_manifold_id, inner_manifold);
 
     if (colorize)
-      for (auto &face : tria.active_face_iterators())
+      for (const auto &face : tria.active_face_iterators())
         if (face->at_boundary())
           {
             const Point<2> center = face->center();
@@ -2418,7 +2418,7 @@ namespace GridGenerator
     // 3, the bottom boundary id is 4 and the top is 5: both are walls, so set
     // them to 3
     if (colorize)
-      for (auto &face : tria.active_face_iterators())
+      for (const auto &face : tria.active_face_iterators())
         if (face->boundary_id() == 4 || face->boundary_id() == 5)
           face->set_boundary_id(3);
   }
@@ -2633,9 +2633,9 @@ namespace GridGenerator
     coords[3] = right + thickness;
 
     unsigned int k = 0;
-    for (unsigned int i0 = 0; i0 < 4; ++i0)
-      for (unsigned int i1 = 0; i1 < 4; ++i1)
-        vertices[k++] = Point<2>(coords[i1], coords[i0]);
+    for (const double y : coords)
+      for (const double x : coords)
+        vertices[k++] = Point<2>(x, y);
 
     const types::material_id materials[9] = {5, 4, 6, 1, 0, 2, 9, 8, 10};
 
@@ -3318,10 +3318,10 @@ namespace GridGenerator
     coords[3] = right + thickness;
 
     unsigned int k = 0;
-    for (unsigned int z = 0; z < 4; ++z)
-      for (unsigned int y = 0; y < 4; ++y)
-        for (unsigned int x = 0; x < 4; ++x)
-          vertices[k++] = Point<3>(coords[x], coords[y], coords[z]);
+    for (const double z : coords)
+      for (const double y : coords)
+        for (const double x : coords)
+          vertices[k++] = Point<3>(x, y, z);
 
     const types::material_id materials[27] = {21, 20, 22, 17, 16, 18, 25,
                                               24, 26, 5,  4,  6,  1,  0,
@@ -3388,7 +3388,7 @@ namespace GridGenerator
 
     // Set boundary ids at -half_length to 1 and at half_length to 2. Set the
     // manifold id on hull faces (i.e., faces not on either end) to 0.
-    for (auto face : triangulation.active_face_iterators())
+    for (const auto &face : triangulation.active_face_iterators())
       if (face->at_boundary())
         {
           if (std::abs(face->center()[0] - -half_length) < 1e-8 * half_length)
@@ -3596,11 +3596,11 @@ namespace GridGenerator
       Point<3>(d, half_length, d),
     };
     // Turn cylinder such that y->x
-    for (unsigned int i = 0; i < 24; ++i)
+    for (auto &vertex : vertices)
       {
-        const double h = vertices[i](1);
-        vertices[i](1) = -vertices[i](0);
-        vertices[i](0) = h;
+        const double h = vertex(1);
+        vertex(1)      = -vertex(0);
+        vertex(0)      = h;
       }
 
     int cell_vertices[10][8] = {{0, 1, 8, 9, 2, 3, 10, 11},
@@ -4741,10 +4741,8 @@ namespace GridGenerator
         quads.push_back(quad);
 
         quad.boundary_id = top_boundary_id;
-        for (unsigned int vertex_n = 0;
-             vertex_n < GeometryInfo<3>::vertices_per_face;
-             ++vertex_n)
-          quad.vertices[vertex_n] += (n_slices - 1) * input.n_vertices();
+        for (unsigned int &vertex : quad.vertices)
+          vertex += (n_slices - 1) * input.n_vertices();
         if (copy_manifold_ids)
           quad.manifold_id = cell->manifold_id();
         quads.push_back(quad);
@@ -4763,7 +4761,7 @@ namespace GridGenerator
     for (auto manifold_id_it = priorities.rbegin();
          manifold_id_it != priorities.rend();
          ++manifold_id_it)
-      for (auto &face : result.active_face_iterators())
+      for (const auto &face : result.active_face_iterators())
         if (face->manifold_id() == *manifold_id_it)
           for (unsigned int line_n = 0;
                line_n < GeometryInfo<3>::lines_per_face;
@@ -5347,20 +5345,18 @@ namespace GridGenerator
                     // orientation. if so, skip it.
                     {
                       bool edge_found = false;
-                      for (unsigned int i = 0;
-                           i < subcell_data.boundary_lines.size();
-                           ++i)
-                        if (((subcell_data.boundary_lines[i].vertices[0] ==
+                      for (auto &boundary_line : subcell_data.boundary_lines)
+                        if (((boundary_line.vertices[0] ==
                               map_vert_index[face->line(e)->vertex_index(0)]) &&
-                             (subcell_data.boundary_lines[i].vertices[1] ==
+                             (boundary_line.vertices[1] ==
                               map_vert_index[face->line(e)->vertex_index(
                                 1)])) ||
-                            ((subcell_data.boundary_lines[i].vertices[0] ==
+                            ((boundary_line.vertices[0] ==
                               map_vert_index[face->line(e)->vertex_index(1)]) &&
-                             (subcell_data.boundary_lines[i].vertices[1] ==
+                             (boundary_line.vertices[1] ==
                               map_vert_index[face->line(e)->vertex_index(0)])))
                           {
-                            subcell_data.boundary_lines[i].boundary_id =
+                            boundary_line.boundary_id =
                               numbers::internal_face_boundary_id;
                             edge_found = true;
                             break;
index 2f4afa41681a47c0cc156aa22c4dbfc6273095f9..21d848abe7788eb3ee826e0d6df3e028bb1bbd6c 100644 (file)
@@ -426,32 +426,28 @@ GridIn<dim, spacedim>::read_vtk(std::istream &in)
 
                       if (dim == 3)
                         {
-                          for (unsigned int i = 0;
-                               i < subcelldata.boundary_quads.size();
-                               i++)
+                          for (auto &boundary_quad : subcelldata.boundary_quads)
                             {
                               double id;
                               in >> id;
                               if (set == "MaterialID")
-                                subcelldata.boundary_quads[i].material_id =
+                                boundary_quad.material_id =
                                   static_cast<types::material_id>(id);
                               else if (set == "ManifoldID")
-                                subcelldata.boundary_quads[i].manifold_id =
+                                boundary_quad.manifold_id =
                                   static_cast<types::manifold_id>(id);
                               else
                                 Assert(false, ExcInternalError());
                             }
-                          for (unsigned int i = 0;
-                               i < subcelldata.boundary_lines.size();
-                               i++)
+                          for (auto &boundary_line : subcelldata.boundary_lines)
                             {
                               double id;
                               in >> id;
                               if (set == "MaterialID")
-                                subcelldata.boundary_lines[i].material_id =
+                                boundary_line.material_id =
                                   static_cast<types::material_id>(id);
                               else if (set == "ManifoldID")
-                                subcelldata.boundary_lines[i].manifold_id =
+                                boundary_line.manifold_id =
                                   static_cast<types::manifold_id>(id);
                               else
                                 Assert(false, ExcInternalError());
@@ -459,17 +455,15 @@ GridIn<dim, spacedim>::read_vtk(std::istream &in)
                         }
                       else if (dim == 2)
                         {
-                          for (unsigned int i = 0;
-                               i < subcelldata.boundary_lines.size();
-                               i++)
+                          for (auto &boundary_line : subcelldata.boundary_lines)
                             {
                               double id;
                               in >> id;
                               if (set == "MaterialID")
-                                subcelldata.boundary_lines[i].material_id =
+                                boundary_line.material_id =
                                   static_cast<types::material_id>(id);
                               else if (set == "ManifoldID")
-                                subcelldata.boundary_lines[i].manifold_id =
+                                boundary_line.manifold_id =
                                   static_cast<types::manifold_id>(id);
                               else
                                 Assert(false, ExcInternalError());
@@ -624,14 +618,15 @@ GridIn<dim, spacedim>::read_unv(std::istream &in)
           subcelldata.boundary_lines.emplace_back();
 
           AssertThrow(in, ExcIO());
-          for (unsigned int v = 0; v < 2; v++)
-            in >> subcelldata.boundary_lines.back().vertices[v];
+          for (unsigned int &vertex :
+               subcelldata.boundary_lines.back().vertices)
+            in >> vertex;
 
           subcelldata.boundary_lines.back().material_id = 0;
 
-          for (unsigned int v = 0; v < 2; v++)
-            subcelldata.boundary_lines.back().vertices[v] =
-              vertex_indices[subcelldata.boundary_lines.back().vertices[v]];
+          for (unsigned int &vertex :
+               subcelldata.boundary_lines.back().vertices)
+            vertex = vertex_indices[vertex];
 
           line_indices[no] = no_line;
 
@@ -642,14 +637,15 @@ GridIn<dim, spacedim>::read_unv(std::istream &in)
           subcelldata.boundary_quads.emplace_back();
 
           AssertThrow(in, ExcIO());
-          for (unsigned int v = 0; v < 4; v++)
-            in >> subcelldata.boundary_quads.back().vertices[v];
+          for (unsigned int &vertex :
+               subcelldata.boundary_quads.back().vertices)
+            in >> vertex;
 
           subcelldata.boundary_quads.back().material_id = 0;
 
-          for (unsigned int v = 0; v < 4; v++)
-            subcelldata.boundary_quads.back().vertices[v] =
-              vertex_indices[subcelldata.boundary_quads.back().vertices[v]];
+          for (unsigned int &vertex :
+               subcelldata.boundary_quads.back().vertices)
+            vertex = vertex_indices[vertex];
 
           quad_indices[no] = no_quad;
 
@@ -900,22 +896,16 @@ GridIn<dim, spacedim>::read_ucd(std::istream &in,
 
           // transform from ucd to
           // consecutive numbering
-          for (unsigned int i = 0; i < 2; ++i)
-            if (vertex_indices.find(
-                  subcelldata.boundary_lines.back().vertices[i]) !=
-                vertex_indices.end())
+          for (unsigned int &vertex :
+               subcelldata.boundary_lines.back().vertices)
+            if (vertex_indices.find(vertex) != vertex_indices.end())
               // vertex with this index exists
-              subcelldata.boundary_lines.back().vertices[i] =
-                vertex_indices[subcelldata.boundary_lines.back().vertices[i]];
+              vertex = vertex_indices[vertex];
             else
               {
                 // no such vertex index
-                AssertThrow(false,
-                            ExcInvalidVertexIndex(
-                              cell,
-                              subcelldata.boundary_lines.back().vertices[i]));
-                subcelldata.boundary_lines.back().vertices[i] =
-                  numbers::invalid_unsigned_int;
+                AssertThrow(false, ExcInvalidVertexIndex(cell, vertex));
+                vertex = numbers::invalid_unsigned_int;
               };
         }
       else if ((cell_type == "quad") && (dim == 3))
@@ -960,21 +950,16 @@ GridIn<dim, spacedim>::read_ucd(std::istream &in,
 
           // transform from ucd to
           // consecutive numbering
-          for (unsigned int i = 0; i < 4; ++i)
-            if (vertex_indices.find(
-                  subcelldata.boundary_quads.back().vertices[i]) !=
-                vertex_indices.end())
+          for (unsigned int &vertex :
+               subcelldata.boundary_quads.back().vertices)
+            if (vertex_indices.find(vertex) != vertex_indices.end())
               // vertex with this index exists
-              subcelldata.boundary_quads.back().vertices[i] =
-                vertex_indices[subcelldata.boundary_quads.back().vertices[i]];
+              vertex = vertex_indices[vertex];
             else
               {
                 // no such vertex index
-                Assert(false,
-                       ExcInvalidVertexIndex(
-                         cell, subcelldata.boundary_quads.back().vertices[i]));
-                subcelldata.boundary_quads.back().vertices[i] =
-                  numbers::invalid_unsigned_int;
+                Assert(false, ExcInvalidVertexIndex(cell, vertex));
+                vertex = numbers::invalid_unsigned_int;
               };
         }
       else
@@ -1303,8 +1288,8 @@ GridIn<2>::read_xda(std::istream &in)
       AssertThrow(in, ExcIO());
       Assert(GeometryInfo<2>::vertices_per_cell == 4, ExcInternalError());
 
-      for (unsigned int i = 0; i < 4; ++i)
-        in >> cells[cell].vertices[i];
+      for (unsigned int &vertex : cells[cell].vertices)
+        in >> vertex;
     };
 
 
@@ -1378,8 +1363,8 @@ GridIn<3>::read_xda(std::istream &in)
 
       unsigned int xda_ordered_nodes[8];
 
-      for (unsigned int i = 0; i < 8; ++i)
-        in >> xda_ordered_nodes[i];
+      for (unsigned int &xda_ordered_node : xda_ordered_nodes)
+        in >> xda_ordered_node;
 
       for (unsigned int i = 0; i < 8; i++)
         cells[cell].vertices[i] = xda_ordered_nodes[xda_to_dealII_map[i]];
@@ -1778,24 +1763,18 @@ GridIn<dim, spacedim>::read_msh(std::istream &in)
 
                 // transform from ucd to
                 // consecutive numbering
-                for (unsigned int i = 0; i < 2; ++i)
-                  if (vertex_indices.find(
-                        subcelldata.boundary_lines.back().vertices[i]) !=
-                      vertex_indices.end())
+                for (unsigned int &vertex :
+                     subcelldata.boundary_lines.back().vertices)
+                  if (vertex_indices.find(vertex) != vertex_indices.end())
                     // vertex with this index exists
-                    subcelldata.boundary_lines.back().vertices[i] =
-                      vertex_indices[subcelldata.boundary_lines.back()
-                                       .vertices[i]];
+                    vertex = vertex_indices[vertex];
                   else
                     {
                       // no such vertex index
-                      AssertThrow(
-                        false,
-                        ExcInvalidVertexIndex(
-                          cell_per_entity,
-                          subcelldata.boundary_lines.back().vertices[i]));
-                      subcelldata.boundary_lines.back().vertices[i] =
-                        numbers::invalid_unsigned_int;
+                      AssertThrow(false,
+                                  ExcInvalidVertexIndex(cell_per_entity,
+                                                        vertex));
+                      vertex = numbers::invalid_unsigned_int;
                     };
               }
             else if ((cell_type == 3) && (dim == 3))
@@ -1826,23 +1805,17 @@ GridIn<dim, spacedim>::read_msh(std::istream &in)
 
                 // transform from gmsh to
                 // consecutive numbering
-                for (unsigned int i = 0; i < 4; ++i)
-                  if (vertex_indices.find(
-                        subcelldata.boundary_quads.back().vertices[i]) !=
-                      vertex_indices.end())
+                for (unsigned int &vertex :
+                     subcelldata.boundary_quads.back().vertices)
+                  if (vertex_indices.find(vertex) != vertex_indices.end())
                     // vertex with this index exists
-                    subcelldata.boundary_quads.back().vertices[i] =
-                      vertex_indices[subcelldata.boundary_quads.back()
-                                       .vertices[i]];
+                    vertex = vertex_indices[vertex];
                   else
                     {
                       // no such vertex index
                       Assert(false,
-                             ExcInvalidVertexIndex(
-                               cell_per_entity,
-                               subcelldata.boundary_quads.back().vertices[i]));
-                      subcelldata.boundary_quads.back().vertices[i] =
-                        numbers::invalid_unsigned_int;
+                             ExcInvalidVertexIndex(cell_per_entity, vertex));
+                      vertex = numbers::invalid_unsigned_int;
                     }
               }
             else if (cell_type == 15)
@@ -2842,9 +2815,8 @@ GridIn<2>::read_tecplot(std::istream &in)
           // get the connectivity from the
           // input file. the vertices are
           // ordered like in the ucd format
-          for (unsigned int j = 0; j < GeometryInfo<dim>::vertices_per_cell;
-               ++j)
-            in >> cells[i].vertices[j];
+          for (unsigned int &vertex : cells[i].vertices)
+            in >> vertex;
         }
       // do some clean-up on vertices
       GridTools::delete_unused_vertices(vertices, cells, subcelldata);
@@ -3115,9 +3087,9 @@ GridIn<2>::debug_output_grid(const std::vector<CellData<2>> &cells,
 
   for (unsigned int i = 0; i < cells.size(); ++i)
     {
-      for (unsigned int v = 0; v < 4; ++v)
+      for (const auto vertex : cells[i].vertices)
         {
-          const Point<2> &p = vertices[cells[i].vertices[v]];
+          const Point<2> &p = vertices[vertex];
 
           if (p(0) < min_x)
             min_x = p(0);
@@ -3131,8 +3103,8 @@ GridIn<2>::debug_output_grid(const std::vector<CellData<2>> &cells,
 
       out << "# cell " << i << std::endl;
       Point<2> center;
-      for (unsigned int f = 0; f < 4; ++f)
-        center += vertices[cells[i].vertices[f]];
+      for (const auto vertex : cells[i].vertices)
+        center += vertices[vertex];
       center /= 4;
 
       out << "set label \"" << i << "\" at " << center(0) << ',' << center(1)
@@ -3169,66 +3141,66 @@ GridIn<3>::debug_output_grid(const std::vector<CellData<3>> &cells,
                              const std::vector<Point<3>> &   vertices,
                              std::ostream &                  out)
 {
-  for (unsigned int cell = 0; cell < cells.size(); ++cell)
+  for (const auto &cell : cells)
     {
       // line 0
-      out << vertices[cells[cell].vertices[0]] << std::endl
-          << vertices[cells[cell].vertices[1]] << std::endl
+      out << vertices[cell.vertices[0]] << std::endl
+          << vertices[cell.vertices[1]] << std::endl
           << std::endl
           << std::endl;
       // line 1
-      out << vertices[cells[cell].vertices[1]] << std::endl
-          << vertices[cells[cell].vertices[2]] << std::endl
+      out << vertices[cell.vertices[1]] << std::endl
+          << vertices[cell.vertices[2]] << std::endl
           << std::endl
           << std::endl;
       // line 2
-      out << vertices[cells[cell].vertices[3]] << std::endl
-          << vertices[cells[cell].vertices[2]] << std::endl
+      out << vertices[cell.vertices[3]] << std::endl
+          << vertices[cell.vertices[2]] << std::endl
           << std::endl
           << std::endl;
       // line 3
-      out << vertices[cells[cell].vertices[0]] << std::endl
-          << vertices[cells[cell].vertices[3]] << std::endl
+      out << vertices[cell.vertices[0]] << std::endl
+          << vertices[cell.vertices[3]] << std::endl
           << std::endl
           << std::endl;
       // line 4
-      out << vertices[cells[cell].vertices[4]] << std::endl
-          << vertices[cells[cell].vertices[5]] << std::endl
+      out << vertices[cell.vertices[4]] << std::endl
+          << vertices[cell.vertices[5]] << std::endl
           << std::endl
           << std::endl;
       // line 5
-      out << vertices[cells[cell].vertices[5]] << std::endl
-          << vertices[cells[cell].vertices[6]] << std::endl
+      out << vertices[cell.vertices[5]] << std::endl
+          << vertices[cell.vertices[6]] << std::endl
           << std::endl
           << std::endl;
       // line 6
-      out << vertices[cells[cell].vertices[7]] << std::endl
-          << vertices[cells[cell].vertices[6]] << std::endl
+      out << vertices[cell.vertices[7]] << std::endl
+          << vertices[cell.vertices[6]] << std::endl
           << std::endl
           << std::endl;
       // line 7
-      out << vertices[cells[cell].vertices[4]] << std::endl
-          << vertices[cells[cell].vertices[7]] << std::endl
+      out << vertices[cell.vertices[4]] << std::endl
+          << vertices[cell.vertices[7]] << std::endl
           << std::endl
           << std::endl;
       // line 8
-      out << vertices[cells[cell].vertices[0]] << std::endl
-          << vertices[cells[cell].vertices[4]] << std::endl
+      out << vertices[cell.vertices[0]] << std::endl
+          << vertices[cell.vertices[4]] << std::endl
           << std::endl
           << std::endl;
       // line 9
-      out << vertices[cells[cell].vertices[1]] << std::endl
-          << vertices[cells[cell].vertices[5]] << std::endl
+      out << vertices[cell.vertices[1]] << std::endl
+          << vertices[cell.vertices[5]] << std::endl
           << std::endl
           << std::endl;
       // line 10
-      out << vertices[cells[cell].vertices[2]] << std::endl
-          << vertices[cells[cell].vertices[6]] << std::endl
+      out << vertices[cell.vertices[2]] << std::endl
+          << vertices[cell.vertices[6]] << std::endl
           << std::endl
           << std::endl;
       // line 11
-      out << vertices[cells[cell].vertices[3]] << std::endl
-          << vertices[cells[cell].vertices[7]] << std::endl
+      out << vertices[cell.vertices[3]] << std::endl
+          << vertices[cell.vertices[7]] << std::endl
           << std::endl
           << std::endl;
     };
@@ -3460,11 +3432,11 @@ namespace
   extract_int(const std::string &s)
   {
     std::string tmp;
-    for (unsigned int i = 0; i < s.size(); ++i)
+    for (const char c : s)
       {
-        if (isdigit(s[i]))
+        if (isdigit(c))
           {
-            tmp += s[i];
+            tmp += c;
           }
       }
 
@@ -3636,9 +3608,9 @@ namespace
                     iss >> stmp >> temp >> face_number;
 
                     const std::vector<int> cells = elsets_list[elset_name];
-                    for (unsigned int i = 0; i < cells.size(); ++i)
+                    for (const int cell : cells)
                       {
-                        el_idx = cells[i];
+                        el_idx = cell;
                         quad_node_list =
                           get_global_node_numbers(el_idx, face_number);
                         quad_node_list.insert(quad_node_list.begin(),
@@ -3806,9 +3778,9 @@ namespace
 
             // Assign material id to cells
             const std::vector<int> &elset_cells = elsets_list[elset_name];
-            for (unsigned int i = 0; i < elset_cells.size(); ++i)
+            for (const int elset_cell : elset_cells)
               {
-                const int cell_id     = elset_cells[i] - 1;
+                const int cell_id     = elset_cell - 1;
                 cell_list[cell_id][0] = material_id;
               }
           }
index 325e78dbae2adb2faf42965fe9f690f15edaea58..9e22f390ae9ff07731f6d688327982871dbe6cef 100644 (file)
@@ -1331,9 +1331,7 @@ GridOut::write_xfig(const Triangulation<2> &tria,
   const int dim      = 2;
   const int spacedim = 2;
 
-  const unsigned int nv  = GeometryInfo<dim>::vertices_per_cell;
-  const unsigned int nf  = GeometryInfo<dim>::faces_per_cell;
-  const unsigned int nvf = GeometryInfo<dim>::vertices_per_face;
+  const unsigned int nv = GeometryInfo<dim>::vertices_per_cell;
 
   // The following text was copied
   // from an existing XFig file.
@@ -1463,10 +1461,9 @@ GridOut::write_xfig(const Triangulation<2> &tria,
       // Now write boundary edges
       static const unsigned int face_reorder[4] = {2, 1, 3, 0};
       if (xfig_flags.draw_boundary)
-        for (unsigned int f = 0; f < nf; ++f)
+        for (const unsigned int f : face_reorder)
           {
-            Triangulation<dim, spacedim>::face_iterator face =
-              cell->face(face_reorder[f]);
+            Triangulation<dim, spacedim>::face_iterator face = cell->face(f);
             const types::boundary_id bi = face->boundary_id();
             if (bi != numbers::internal_face_boundary_id)
               {
@@ -1485,14 +1482,16 @@ GridOut::write_xfig(const Triangulation<2> &tria,
                     // some style parameters
                     << " 0 0 -1 0 0 "
                     // number of points
-                    << nvf << std::endl;
+                    << GeometryInfo<dim>::vertices_per_face << std::endl;
 
                 // For each point, write scaled
                 // and shifted coordinates
                 // multiplied by 1200
                 // (dots/inch)
 
-                for (unsigned int k = 0; k < nvf; ++k)
+                for (unsigned int k = 0;
+                     k < GeometryInfo<dim>::vertices_per_face;
+                     ++k)
                   {
                     const Point<dim> &p = face->vertex(k % nv);
                     for (unsigned int d = 0; d < static_cast<unsigned int>(dim);
@@ -1530,11 +1529,6 @@ GridOut::write_svg(const Triangulation<dim, spacedim> &,
 void
 GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const
 {
-  unsigned int n_materials        = 0;
-  unsigned int n_levels           = 0;
-  unsigned int n_subdomains       = 0;
-  unsigned int n_level_subdomains = 0;
-
   unsigned int n = 0;
 
   unsigned int min_level, max_level;
@@ -1587,26 +1581,16 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const
   min_level = max_level = tria.begin()->level();
 
   // auxiliary array for the materials being used (material ids 255 max.)
-  unsigned int materials[256];
-  for (unsigned int material_index = 0; material_index < 256; material_index++)
-    materials[material_index] = 0;
+  std::array<unsigned int, 256> materials{};
 
   // auxiliary array for the levels being used (level number 255 max.)
-  unsigned int levels[256];
-  for (unsigned int level_index = 0; level_index < 256; level_index++)
-    levels[level_index] = 0;
+  std::array<unsigned int, 256> levels{};
 
   // auxiliary array for the subdomains being used (subdomain id 255 max.)
-  unsigned int subdomains[256];
-  for (unsigned int subdomain_index = 0; subdomain_index < 256;
-       subdomain_index++)
-    subdomains[subdomain_index] = 0;
+  std::array<unsigned int, 256> subdomains{};
 
   // auxiliary array for the level subdomains being used
-  int level_subdomains[256];
-  for (int level_subdomain_index = 0; level_subdomain_index < 256;
-       level_subdomain_index++)
-    level_subdomains[level_subdomain_index] = 0;
+  std::array<int, 256> level_subdomains{};
 
   // We use an active cell iterator to determine the
   // bounding box of the given triangulation and check
@@ -1643,34 +1627,30 @@ GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const
   y_dimension = y_max - y_min;
 
   // count the materials being used
-  for (unsigned int material_index = 0; material_index < 256; material_index++)
-    {
-      if (materials[material_index])
-        n_materials++;
-    }
+  const unsigned int n_materials =
+    std::count_if(materials.begin(),
+                  materials.end(),
+                  [](const unsigned int material) { return material != 0; });
 
   // count the levels being used
-  for (unsigned int level_index = 0; level_index < 256; level_index++)
-    {
-      if (levels[level_index])
-        n_levels++;
-    }
+  const unsigned int n_levels =
+    std::count_if(levels.begin(), levels.end(), [](const unsigned int level) {
+      return level != 0;
+    });
 
   // count the subdomains being used
-  for (unsigned int subdomain_index = 0; subdomain_index < 256;
-       subdomain_index++)
-    {
-      if (subdomains[subdomain_index])
-        n_subdomains++;
-    }
+  const unsigned int n_subdomains =
+    std::count_if(subdomains.begin(),
+                  subdomains.end(),
+                  [](const unsigned int subdomain) { return subdomain != 0; });
 
   // count the level subdomains being used
-  for (int level_subdomain_index = 0; level_subdomain_index < 256;
-       level_subdomain_index++)
-    {
-      if (level_subdomains[level_subdomain_index])
-        n_level_subdomains++;
-    }
+  const unsigned int n_level_subdomains =
+    std::count_if(level_subdomains.begin(),
+                  level_subdomains.end(),
+                  [](const int level_subdomain) {
+                    return level_subdomain != 0;
+                  });
 
   switch (svg_flags.coloring)
     {
@@ -3042,7 +3022,7 @@ GridOut::write_vtk(const Triangulation<dim, spacedim> &tria,
       << "POINTS " << n_vertices << " double\n";
 
   // actually write the vertices.
-  for (auto v : vertices)
+  for (const auto &v : vertices)
     {
       out << v;
       for (unsigned int d = spacedim + 1; d <= 3; ++d)
@@ -3083,7 +3063,7 @@ GridOut::write_vtk(const Triangulation<dim, spacedim> &tria,
   const int co_face_type = (dim == 1 ? -1 : dim == 2 ? -1 : 3);
 
   // write cells.
-  for (auto cell : tria.active_cell_iterators())
+  for (const auto &cell : tria.active_cell_iterators())
     {
       out << GeometryInfo<dim>::vertices_per_cell;
       for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell; ++i)
@@ -3092,7 +3072,7 @@ GridOut::write_vtk(const Triangulation<dim, spacedim> &tria,
         }
       out << '\n';
     }
-  for (auto face : faces)
+  for (const auto &face : faces)
     {
       out << GeometryInfo<dim>::vertices_per_face;
       for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
@@ -3103,7 +3083,7 @@ GridOut::write_vtk(const Triangulation<dim, spacedim> &tria,
         }
       out << '\n';
     }
-  for (auto co_face : co_faces)
+  for (const auto &co_face : co_faces)
     {
       out << 2;
       for (unsigned int i = 0; i < 2; ++i)
@@ -3132,21 +3112,21 @@ GridOut::write_vtk(const Triangulation<dim, spacedim> &tria,
       << "LOOKUP_TABLE default\n";
 
   // Now material id and boundary id
-  for (auto cell : tria.active_cell_iterators())
+  for (const auto &cell : tria.active_cell_iterators())
     {
       out << static_cast<std::make_signed<types::material_id>::type>(
                cell->material_id())
           << ' ';
     }
   out << '\n';
-  for (auto face : faces)
+  for (const auto &face : faces)
     {
       out << static_cast<std::make_signed<types::boundary_id>::type>(
                face->boundary_id())
           << ' ';
     }
   out << '\n';
-  for (auto co_face : co_faces)
+  for (const auto &co_face : co_faces)
     {
       out << static_cast<std::make_signed<types::boundary_id>::type>(
                co_face->boundary_id())
@@ -3157,21 +3137,21 @@ GridOut::write_vtk(const Triangulation<dim, spacedim> &tria,
       << "LOOKUP_TABLE default\n";
 
   // Now material id and boundary id
-  for (auto cell : tria.active_cell_iterators())
+  for (const auto &cell : tria.active_cell_iterators())
     {
       out << static_cast<std::make_signed<types::boundary_id>::type>(
                cell->manifold_id())
           << ' ';
     }
   out << '\n';
-  for (auto face : faces)
+  for (const auto &face : faces)
     {
       out << static_cast<std::make_signed<types::boundary_id>::type>(
                face->manifold_id())
           << ' ';
     }
   out << '\n';
-  for (auto co_face : co_faces)
+  for (const auto &co_face : co_faces)
     {
       out << static_cast<std::make_signed<types::boundary_id>::type>(
                co_face->manifold_id())
index 3030f6678a0084344bf79d48344565dd878a636c..70f34fdf252dfd104b219aea617aa1998c1b7602 100644 (file)
@@ -1027,20 +1027,20 @@ namespace
 
   void reorder_new_to_old_style(std::vector<CellData<2>> &cells)
   {
-    for (unsigned int cell = 0; cell < cells.size(); ++cell)
-      std::swap(cells[cell].vertices[2], cells[cell].vertices[3]);
+    for (auto &cell : cells)
+      std::swap(cell.vertices[2], cell.vertices[3]);
   }
 
 
   void reorder_new_to_old_style(std::vector<CellData<3>> &cells)
   {
     unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
-    for (unsigned int cell = 0; cell < cells.size(); ++cell)
+    for (auto &cell : cells)
       {
         for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-          tmp[i] = cells[cell].vertices[i];
+          tmp[i] = cell.vertices[i];
         for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-          cells[cell].vertices[i] = tmp[GeometryInfo<3>::ucd_to_deal[i]];
+          cell.vertices[i] = tmp[GeometryInfo<3>::ucd_to_deal[i]];
       }
   }
 
@@ -1063,12 +1063,12 @@ namespace
   {
     // undo the ordering above
     unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
-    for (unsigned int cell = 0; cell < cells.size(); ++cell)
+    for (auto &cell : cells)
       {
         for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-          tmp[i] = cells[cell].vertices[i];
+          tmp[i] = cell.vertices[i];
         for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-          cells[cell].vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i];
+          cell.vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i];
       }
   }
 } // namespace
@@ -1154,18 +1154,17 @@ GridReordering<2>::invert_all_cells_of_negative_grid(
 {
   unsigned int vertices_lex[GeometryInfo<2>::vertices_per_cell];
   unsigned int n_negative_cells = 0;
-  for (unsigned int cell_no = 0; cell_no < cells.size(); ++cell_no)
+  for (auto &cell : cells)
     {
       // GridTools::cell_measure
       // requires the vertices to be
       // in lexicographic ordering
       for (unsigned int i = 0; i < GeometryInfo<2>::vertices_per_cell; ++i)
-        vertices_lex[GeometryInfo<2>::ucd_to_deal[i]] =
-          cells[cell_no].vertices[i];
+        vertices_lex[GeometryInfo<2>::ucd_to_deal[i]] = cell.vertices[i];
       if (GridTools::cell_measure<2>(all_vertices, vertices_lex) < 0)
         {
           ++n_negative_cells;
-          std::swap(cells[cell_no].vertices[1], cells[cell_no].vertices[3]);
+          std::swap(cell.vertices[1], cell.vertices[3]);
 
           // check whether the
           // resulting cell is now ok.
@@ -1174,8 +1173,7 @@ GridReordering<2>::invert_all_cells_of_negative_grid(
           // should be sticked into the
           // bin
           for (unsigned int i = 0; i < GeometryInfo<2>::vertices_per_cell; ++i)
-            vertices_lex[GeometryInfo<2>::ucd_to_deal[i]] =
-              cells[cell_no].vertices[i];
+            vertices_lex[GeometryInfo<2>::ucd_to_deal[i]] = cell.vertices[i];
           AssertThrow(GridTools::cell_measure<2>(all_vertices, vertices_lex) >
                         0,
                       ExcInternalError());
@@ -1226,21 +1224,19 @@ GridReordering<3>::invert_all_cells_of_negative_grid(
 {
   unsigned int vertices_lex[GeometryInfo<3>::vertices_per_cell];
   unsigned int n_negative_cells = 0;
-  for (unsigned int cell_no = 0; cell_no < cells.size(); ++cell_no)
+  for (auto &cell : cells)
     {
       // GridTools::cell_measure
       // requires the vertices to be
       // in lexicographic ordering
       for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-        vertices_lex[GeometryInfo<3>::ucd_to_deal[i]] =
-          cells[cell_no].vertices[i];
+        vertices_lex[GeometryInfo<3>::ucd_to_deal[i]] = cell.vertices[i];
       if (GridTools::cell_measure<3>(all_vertices, vertices_lex) < 0)
         {
           ++n_negative_cells;
           // reorder vertices: swap front and back face
           for (unsigned int i = 0; i < 4; ++i)
-            std::swap(cells[cell_no].vertices[i],
-                      cells[cell_no].vertices[i + 4]);
+            std::swap(cell.vertices[i], cell.vertices[i + 4]);
 
           // check whether the
           // resulting cell is now ok.
@@ -1249,8 +1245,7 @@ GridReordering<3>::invert_all_cells_of_negative_grid(
           // should be sticked into the
           // bin
           for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-            vertices_lex[GeometryInfo<3>::ucd_to_deal[i]] =
-              cells[cell_no].vertices[i];
+            vertices_lex[GeometryInfo<3>::ucd_to_deal[i]] = cell.vertices[i];
           AssertThrow(GridTools::cell_measure<3>(all_vertices, vertices_lex) >
                         0,
                       ExcInternalError());
index e48689f582321069caacbef20ec52ff2fd221999..5cd5d14e083ee0cffcb8f75bc7824b65f39bc944 100644 (file)
@@ -655,7 +655,8 @@ namespace GridTools
         cells[c].vertices[v] = new_vertex_numbers[cells[c].vertices[v]];
 
     // same for boundary data
-    for (unsigned int c = 0; c < subcelldata.boundary_lines.size(); ++c)
+    for (unsigned int c = 0; c < subcelldata.boundary_lines.size(); // NOLINT
+         ++c)
       for (unsigned int v = 0; v < GeometryInfo<1>::vertices_per_cell; ++v)
         {
           Assert(subcelldata.boundary_lines[c].vertices[v] <
@@ -674,7 +675,8 @@ namespace GridTools
             new_vertex_numbers[subcelldata.boundary_lines[c].vertices[v]];
         }
 
-    for (unsigned int c = 0; c < subcelldata.boundary_quads.size(); ++c)
+    for (unsigned int c = 0; c < subcelldata.boundary_quads.size(); // NOLINT
+         ++c)
       for (unsigned int v = 0; v < GeometryInfo<2>::vertices_per_cell; ++v)
         {
           Assert(subcelldata.boundary_quads[c].vertices[v] <
@@ -3643,7 +3645,7 @@ namespace GridTools
     const auto                      src_boundary_ids = tria.get_boundary_ids();
     std::vector<types::manifold_id> dst_manifold_ids(src_boundary_ids.size());
     auto                            m_it = dst_manifold_ids.begin();
-    for (auto b : src_boundary_ids)
+    for (const auto b : src_boundary_ids)
       {
         *m_it = static_cast<types::manifold_id>(b);
         ++m_it;
@@ -3886,7 +3888,7 @@ namespace GridTools
       {
         has_cells_with_more_than_dim_faces_on_boundary = false;
 
-        for (auto cell : tria.active_cell_iterators())
+        for (const auto &cell : tria.active_cell_iterators())
           {
             unsigned int boundary_face_counter = 0;
             for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
@@ -3916,7 +3918,7 @@ namespace GridTools
       {
         while (refinement_cycles > 0)
           {
-            for (auto cell : tria.active_cell_iterators())
+            for (const auto &cell : tria.active_cell_iterators())
               cell->set_coarsen_flag();
             tria.execute_coarsening_and_refinement();
             refinement_cycles--;
@@ -3936,7 +3938,7 @@ namespace GridTools
     const unsigned int v0 = 0, v1 = 1, v2 = (dim > 1 ? 2 : 0),
                        v3 = (dim > 1 ? 3 : 0);
 
-    for (auto cell : tria.active_cell_iterators())
+    for (const auto &cell : tria.active_cell_iterators())
       {
         double       angle_fraction   = 0;
         unsigned int vertex_at_corner = numbers::invalid_unsigned_int;
@@ -4085,7 +4087,7 @@ namespace GridTools
       {
         while (refinement_cycles > 0)
           {
-            for (auto cell : tria.active_cell_iterators())
+            for (const auto &cell : tria.active_cell_iterators())
               cell->set_coarsen_flag();
             tria.execute_coarsening_and_refinement();
             refinement_cycles--;
@@ -4094,7 +4096,7 @@ namespace GridTools
       }
 
     // add the cells that were not marked as skipped
-    for (auto cell : tria.active_cell_iterators())
+    for (const auto &cell : tria.active_cell_iterators())
       {
         if (cells_to_remove[cell->active_cell_index()] == false)
           {
@@ -4161,7 +4163,7 @@ namespace GridTools
     std::map<types::manifold_id, std::unique_ptr<Manifold<dim, spacedim>>>
       manifolds;
     // Set manifolds in new Triangulation
-    for (auto manifold_id : manifold_ids)
+    for (const auto manifold_id : manifold_ids)
       if (manifold_id != numbers::flat_manifold_id)
         manifolds[manifold_id] = tria.get_manifold(manifold_id).clone();
 
@@ -4170,7 +4172,7 @@ namespace GridTools
     tria.create_triangulation(vertices, cells_to_add, subcelldata_to_add);
 
     // Restore manifolds
-    for (auto manifold_id : manifold_ids)
+    for (const auto manifold_id : manifold_ids)
       if (manifold_id != numbers::flat_manifold_id)
         tria.set_manifold(manifold_id, *manifolds[manifold_id]);
   }
@@ -4535,7 +4537,7 @@ namespace GridTools
 
         // Alayzing the output discarding artificial cell
         // and storing in the proper container locally owned and ghost cells
-        for (auto const &cell_tuples : cpt_loc_pts)
+        for (const auto &cell_tuples : cpt_loc_pts)
           {
             auto &cell_loc    = cell_tuples.first;
             auto &q_loc       = std::get<0>(cell_tuples.second);
@@ -4621,7 +4623,7 @@ namespace GridTools
 
         // rank and points is a pair: first rank, then a pair of vectors
         // (points, indices)
-        for (auto const &rank_and_points : map_pts)
+        for (const auto &rank_and_points : map_pts)
           {
             // Rewriting the contents of the map in human readable format
             const auto &received_process = rank_and_points.first;
@@ -4849,11 +4851,11 @@ namespace GridTools
                                 point_idx))
           // The point wasn't found in ghost or locally owned cells: adding it
           // to the map
-          for (unsigned int i = 0; i < probable_owners_rks.size(); ++i)
-            if (probable_owners_rks[i] != my_rank)
+          for (const unsigned int probable_owners_rk : probable_owners_rks)
+            if (probable_owners_rk != my_rank)
               {
                 // add to the data for process probable_owners_rks[i]
-                auto &current_pts = other_check_pts[probable_owners_rks[i]];
+                auto &current_pts = other_check_pts[probable_owners_rk];
                 // The point local_points[point_idx]
                 current_pts.first.emplace_back(local_points[point_idx]);
                 // and its index in the current process
index 96219c99966f464241931430459621c8b5d4ca50..5899540f878f3b46af82e6fc756224abe71c6a8a 100644 (file)
@@ -127,7 +127,7 @@ namespace GridTools
           typename Triangulation<dim, spacedim>::active_cell_iterator>>
                      boxes(tria->n_active_cells());
         unsigned int i = 0;
-        for (auto cell : tria->active_cell_iterators())
+        for (const auto &cell : tria->active_cell_iterators())
           boxes[i++] = std::make_pair(cell->bounding_box(), cell);
         cell_bounding_boxes_rtree = pack_rtree(boxes);
       }
index 1882e6e985904581a09fc20270b18c96bb338315..16012d59e543f8521dc1f41cb877d3ddd764717a 100644 (file)
@@ -704,7 +704,7 @@ namespace GridTools
 
         const double original_distance_to_unit_cell =
           GeometryInfo<dim>::distance_to_unit_cell(unit_point);
-        for (auto cell : cells_to_add)
+        for (const auto &cell : cells_to_add)
           {
             if (cell != my_cell)
               try
index 7387e35f89abfabaebfa33e262165665e1c6756a..99ea39747bc98c68c6caca4317bd7b8e80ccb78f 100644 (file)
@@ -1804,10 +1804,7 @@ namespace
         // identify the weights for the lines to be accumulated (vertex
         // weights are set outside and coincide with the flat manifold case)
 
-        double weights_lines[GeometryInfo<3>::lines_per_cell];
-        for (unsigned int line = 0; line < GeometryInfo<3>::lines_per_cell;
-             ++line)
-          weights_lines[line] = 0;
+        std::array<double, GeometryInfo<3>::lines_per_cell> weights_lines{};
 
         // start with the contributions of the faces
         std::array<double, GeometryInfo<2>::vertices_per_cell>          weights;
index 3f1da7e21136ab1264024a6b682967b67be1b454..b730503da0d3dbcf653b44b038cf78d8e705936b 100644 (file)
@@ -501,8 +501,8 @@ namespace
   void reorder_compatibility(std::vector<CellData<2>> &cells,
                              const SubCellData &)
   {
-    for (unsigned int cell = 0; cell < cells.size(); ++cell)
-      std::swap(cells[cell].vertices[2], cells[cell].vertices[3]);
+    for (auto &cell : cells)
+      std::swap(cell.vertices[2], cell.vertices[3]);
   }
 
 
@@ -510,12 +510,12 @@ namespace
                              SubCellData &             subcelldata)
   {
     unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
-    for (unsigned int cell = 0; cell < cells.size(); ++cell)
+    for (auto &cell : cells)
       {
         for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-          tmp[i] = cells[cell].vertices[i];
+          tmp[i] = cell.vertices[i];
         for (unsigned int i = 0; i < GeometryInfo<3>::vertices_per_cell; ++i)
-          cells[cell].vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i];
+          cell.vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i];
       }
 
     // now points in boundary quads
@@ -1779,8 +1779,8 @@ namespace internal
         // some security tests
         {
           unsigned int boundary_nodes = 0;
-          for (unsigned int i = 0; i < lines_at_vertex.size(); ++i)
-            switch (lines_at_vertex[i].size())
+          for (const auto &line : lines_at_vertex)
+            switch (line.size())
               {
                 case 1:
                   // this vertex has only
@@ -1958,11 +1958,10 @@ namespace internal
           needed_lines;
         for (unsigned int cell = 0; cell < cells.size(); ++cell)
           {
-            for (unsigned int vertex = 0; vertex < 4; ++vertex)
-              AssertThrow(cells[cell].vertices[vertex] <
-                            triangulation.vertices.size(),
+            for (const auto vertex : cells[cell].vertices)
+              AssertThrow(vertex < triangulation.vertices.size(),
                           ExcInvalidVertexIndex(cell,
-                                                cells[cell].vertices[vertex],
+                                                vertex,
                                                 triangulation.vertices.size()));
 
             for (unsigned int line = 0;
@@ -2105,10 +2104,8 @@ namespace internal
               // note that this cell is
               // adjacent to the four
               // lines
-              for (unsigned int line = 0;
-                   line < GeometryInfo<dim>::lines_per_cell;
-                   ++line)
-                adjacent_cells[lines[line]->index()].push_back(cell);
+              for (const auto &line : lines)
+                adjacent_cells[line->index()].push_back(cell);
             }
         }
 
@@ -2343,13 +2340,10 @@ namespace internal
           {
             // check whether vertex indices
             // are valid ones
-            for (unsigned int vertex = 0;
-                 vertex < GeometryInfo<dim>::vertices_per_cell;
-                 ++vertex)
-              AssertThrow(cells[cell].vertices[vertex] <
-                            triangulation.vertices.size(),
+            for (const auto vertex : cells[cell].vertices)
+              AssertThrow(vertex < triangulation.vertices.size(),
                           ExcInvalidVertexIndex(cell,
-                                                cells[cell].vertices[vertex],
+                                                vertex,
                                                 triangulation.vertices.size()));
 
             for (unsigned int line = 0;
@@ -2472,7 +2466,7 @@ namespace internal
                            std::array<bool, GeometryInfo<dim>::lines_per_face>>,
                  QuadComparator>
           needed_quads;
-        for (unsigned int cell = 0; cell < cells.size(); ++cell)
+        for (const auto &cell : cells)
           {
             // the faces are quads which
             // consist of four numbers
@@ -2507,15 +2501,15 @@ namespace internal
                  ++line)
               {
                 line_list[line] = std::pair<int, int>(
-                  cells[cell].vertices[GeometryInfo<dim>::line_to_cell_vertices(
-                    line, 0)],
-                  cells[cell].vertices[GeometryInfo<dim>::line_to_cell_vertices(
-                    line, 1)]);
+                  cell.vertices[GeometryInfo<dim>::line_to_cell_vertices(line,
+                                                                         0)],
+                  cell.vertices[GeometryInfo<dim>::line_to_cell_vertices(line,
+                                                                         1)]);
                 inverse_line_list[line] = std::pair<int, int>(
-                  cells[cell].vertices[GeometryInfo<dim>::line_to_cell_vertices(
-                    line, 1)],
-                  cells[cell].vertices[GeometryInfo<dim>::line_to_cell_vertices(
-                    line, 0)]);
+                  cell.vertices[GeometryInfo<dim>::line_to_cell_vertices(line,
+                                                                         1)],
+                  cell.vertices[GeometryInfo<dim>::line_to_cell_vertices(line,
+                                                                         0)]);
               }
 
             for (unsigned int face = 0;
@@ -2933,10 +2927,8 @@ namespace internal
               // note that this cell is
               // adjacent to the six
               // quads
-              for (unsigned int quad = 0;
-                   quad < GeometryInfo<dim>::faces_per_cell;
-                   ++quad)
-                adjacent_cells[face_iterator[quad]->index()].push_back(cell);
+              for (const auto &quad : face_iterator)
+                adjacent_cells[quad->index()].push_back(cell);
 
 #ifdef DEBUG
               // make some checks on the
@@ -5869,22 +5861,21 @@ namespace internal
                             quad->line_index(3)));
                       }
 
-                    for (unsigned int i = 0; i < 2; ++i)
+                    for (const auto &new_quad : new_quads)
                       {
-                        new_quads[i]->set_used_flag();
-                        new_quads[i]->clear_user_flag();
-                        new_quads[i]->clear_user_data();
-                        new_quads[i]->clear_children();
-                        new_quads[i]->set_boundary_id_internal(
-                          quad->boundary_id());
-                        new_quads[i]->set_manifold_id(quad->manifold_id());
+                        new_quad->set_used_flag();
+                        new_quad->clear_user_flag();
+                        new_quad->clear_user_data();
+                        new_quad->clear_children();
+                        new_quad->set_boundary_id_internal(quad->boundary_id());
+                        new_quad->set_manifold_id(quad->manifold_id());
                         // set all line orientations to true, change
                         // this after the loop, as we have to consider
                         // different lines for each child
                         for (unsigned int j = 0;
                              j < GeometryInfo<dim>::lines_per_face;
                              ++j)
-                          new_quads[i]->set_line_orientation(j, true);
+                          new_quad->set_line_orientation(j, true);
                       }
                     // now set the line orientation of children of
                     // outer lines correctly, the lines in the
@@ -6446,15 +6437,14 @@ namespace internal
                       internal::TriangulationImplementation::TriaObject<1>(
                         vertex_indices[4], vertex_indices[1]));
 
-                    for (unsigned int i = 0; i < 4; ++i)
+                    for (const auto &new_line : new_lines)
                       {
-                        new_lines[i]->set_used_flag();
-                        new_lines[i]->clear_user_flag();
-                        new_lines[i]->clear_user_data();
-                        new_lines[i]->clear_children();
-                        new_lines[i]->set_boundary_id_internal(
-                          quad->boundary_id());
-                        new_lines[i]->set_manifold_id(quad->manifold_id());
+                        new_line->set_used_flag();
+                        new_line->clear_user_flag();
+                        new_line->clear_user_data();
+                        new_line->clear_children();
+                        new_line->set_boundary_id_internal(quad->boundary_id());
+                        new_line->set_manifold_id(quad->manifold_id());
                       }
 
                     // now for the quads. again, first collect some
@@ -6582,22 +6572,21 @@ namespace internal
                         line_indices[3],
                         line_indices[11],
                         line_indices[7]));
-                    for (unsigned int i = 0; i < 4; ++i)
+                    for (const auto &new_quad : new_quads)
                       {
-                        new_quads[i]->set_used_flag();
-                        new_quads[i]->clear_user_flag();
-                        new_quads[i]->clear_user_data();
-                        new_quads[i]->clear_children();
-                        new_quads[i]->set_boundary_id_internal(
-                          quad->boundary_id());
-                        new_quads[i]->set_manifold_id(quad->manifold_id());
+                        new_quad->set_used_flag();
+                        new_quad->clear_user_flag();
+                        new_quad->clear_user_data();
+                        new_quad->clear_children();
+                        new_quad->set_boundary_id_internal(quad->boundary_id());
+                        new_quad->set_manifold_id(quad->manifold_id());
                         // set all line orientations to true, change
                         // this after the loop, as we have to consider
                         // different lines for each child
                         for (unsigned int j = 0;
                              j < GeometryInfo<dim>::lines_per_face;
                              ++j)
-                          new_quads[i]->set_line_orientation(j, true);
+                          new_quad->set_line_orientation(j, true);
                       }
                     // now set the line orientation of children of
                     // outer lines correctly, the lines in the
@@ -6972,7 +6961,7 @@ namespace internal
                           // and fill it with the respective values
                           bool line_orientation[4];
 
-                          // the middle vertice marked as m0 above is the
+                          // the middle vertex marked as m0 above is the
                           // start vertex for lines 0 and 2 in standard
                           // orientation, whereas m1 is the end vertex of
                           // lines 1 and 3 in standard orientation
@@ -7202,7 +7191,7 @@ namespace internal
                           // and fill it with the respective values
                           bool line_orientation[4];
 
-                          // the middle vertice marked as m0 above is the
+                          // the middle vertex marked as m0 above is the
                           // start vertex for lines 0 and 2 in standard
                           // orientation, whereas m1 is the end vertex of
                           // lines 1 and 3 in standard orientation
@@ -10989,8 +10978,8 @@ namespace
       &levels,
     internal::TriangulationImplementation::TriaFaces<1> *)
   {
-    for (unsigned int level = 0; level < levels.size(); ++level)
-      levels[level]->cells.clear_user_flags();
+    for (const auto &level : levels)
+      level->cells.clear_user_flags();
   }
 
   template <int dim>
@@ -11030,8 +11019,8 @@ namespace
       &levels,
     internal::TriangulationImplementation::TriaFaces<2> *)
   {
-    for (unsigned int level = 0; level < levels.size(); ++level)
-      levels[level]->cells.clear_user_flags();
+    for (const auto &level : levels)
+      level->cells.clear_user_flags();
   }
 
   template <int dim>
@@ -11080,8 +11069,8 @@ namespace
       &levels,
     internal::TriangulationImplementation::TriaFaces<3> *)
   {
-    for (unsigned int level = 0; level < levels.size(); ++level)
-      levels[level]->cells.clear_user_flags();
+    for (const auto &level : levels)
+      level->cells.clear_user_flags();
   }
 } // namespace
 

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.