]> https://gitweb.dealii.org/ - dealii.git/commitdiff
step-28: use ranged-for loops.
authorDavid Wells <drwells@email.unc.edu>
Tue, 7 May 2019 00:28:07 +0000 (20:28 -0400)
committerDavid Wells <drwells@email.unc.edu>
Tue, 7 May 2019 02:34:47 +0000 (22:34 -0400)
examples/step-28/step-28.cc

index 5e6bed8f421727d2eb4ed1861b184c79007af6da..b45df6eb6a3ad1b1668ac34f624825f8d3751b5f 100644 (file)
@@ -668,11 +668,7 @@ namespace Step28
 
     std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
 
-    typename DoFHandler<dim>::active_cell_iterator cell =
-                                                     dof_handler.begin_active(),
-                                                   endc = dof_handler.end();
-
-    for (; cell != endc; ++cell)
+    for (const auto &cell : dof_handler.active_cell_iterators())
       {
         cell_matrix = 0;
 
@@ -743,11 +739,7 @@ namespace Step28
 
     std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
 
-    typename DoFHandler<dim>::active_cell_iterator cell =
-                                                     dof_handler.begin_active(),
-                                                   endc = dof_handler.end();
-
-    for (; cell != endc; ++cell)
+    for (const auto &cell : dof_handler.active_cell_iterators())
       {
         cell_rhs = 0;
 
@@ -803,18 +795,14 @@ namespace Step28
       cell_list =
         GridTools::get_finest_common_cells(dof_handler, g_prime.dof_handler);
 
-    typename std::list<std::pair<typename DoFHandler<dim>::cell_iterator,
-                                 typename DoFHandler<dim>::cell_iterator>>::
-      const_iterator cell_iter = cell_list.begin();
-
-    for (; cell_iter != cell_list.end(); ++cell_iter)
+    for (const auto &cell_pair : cell_list)
       {
         FullMatrix<double> unit_matrix(fe.dofs_per_cell);
         for (unsigned int i = 0; i < unit_matrix.m(); ++i)
           unit_matrix(i, i) = 1;
         assemble_cross_group_rhs_recursive(g_prime,
-                                           cell_iter->first,
-                                           cell_iter->second,
+                                           cell_pair.first,
+                                           cell_pair.second,
                                            unit_matrix);
       }
   }
@@ -993,10 +981,7 @@ namespace Step28
 
     double fission_source = 0;
 
-    typename DoFHandler<dim>::active_cell_iterator cell =
-                                                     dof_handler.begin_active(),
-                                                   endc = dof_handler.end();
-    for (; cell != endc; ++cell)
+    for (const auto &cell : dof_handler.active_cell_iterators())
       {
         fe_values.reinit(cell);
 
@@ -1080,12 +1065,7 @@ namespace Step28
                                      const double         refine_threshold,
                                      const double         coarsen_threshold)
   {
-    typename Triangulation<dim>::active_cell_iterator cell = triangulation
-                                                               .begin_active(),
-                                                      endc =
-                                                        triangulation.end();
-
-    for (; cell != endc; ++cell)
+    for (const auto &cell : triangulation.active_cell_iterators())
       if (error_indicators(cell->active_cell_index()) > refine_threshold)
         cell->set_refine_flag();
       else if (error_indicators(cell->active_cell_index()) < coarsen_threshold)
@@ -1456,10 +1436,7 @@ namespace Step28
     // add a few checks to see that the locations we compute are within the
     // bounds of the arrays in which we have to look up materials.) At the end
     // of the loop, we set material identifiers accordingly:
-    for (typename Triangulation<dim>::active_cell_iterator cell =
-           coarse_grid.begin_active();
-         cell != coarse_grid.end();
-         ++cell)
+    for (auto &cell : coarse_grid.active_cell_iterators())
       {
         const Point<dim> cell_center = cell->center();
 

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.