]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify a function by using range-based for loops. 14128/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 11 Jul 2022 23:30:20 +0000 (17:30 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 11 Jul 2022 23:30:50 +0000 (17:30 -0600)
source/grid/grid_tools.cc

index 4dd3f7e305489f1bce8fec73db6712ee732189fe..b94f8c147a6303be300fb16defcb3982dafc3238 100644 (file)
@@ -3462,31 +3462,26 @@ namespace GridTools
              std::vector<std::tuple<types::global_vertex_index,
                                     types::global_vertex_index,
                                     std::string>>>
-                         vertices_to_send;
-    active_cell_iterator cell = triangulation.begin_active(),
-                         endc = triangulation.end();
+                                   vertices_to_send;
     std::set<active_cell_iterator> missing_vert_cells;
     std::set<unsigned int>         used_vertex_index;
-    for (; cell != endc; ++cell)
+    for (const auto &cell : triangulation.active_cell_iterators())
       {
         if (cell->is_locally_owned())
           {
             for (const unsigned int i : cell->vertex_indices())
               {
                 types::subdomain_id lowest_subdomain_id = cell->subdomain_id();
-                typename std::set<active_cell_iterator>::iterator
-                  adjacent_cell = vertex_to_cell[cell->vertex_index(i)].begin(),
-                  end_adj_cell  = vertex_to_cell[cell->vertex_index(i)].end();
-                for (; adjacent_cell != end_adj_cell; ++adjacent_cell)
-                  lowest_subdomain_id =
-                    std::min(lowest_subdomain_id,
-                             (*adjacent_cell)->subdomain_id());
-
-                // See if I "own" this vertex
+                for (const auto &adjacent_cell :
+                     vertex_to_cell[cell->vertex_index(i)])
+                  lowest_subdomain_id = std::min(lowest_subdomain_id,
+                                                 adjacent_cell->subdomain_id());
+
+                // See if this process "owns" this vertex
                 if (lowest_subdomain_id == cell->subdomain_id())
                   {
-                    // Check that the vertex we are working on a vertex that has
-                    // not be dealt with yet
+                    // Check that the vertex we are working on is a vertex that
+                    // has not been dealt with yet
                     if (used_vertex_index.find(cell->vertex_index(i)) ==
                         used_vertex_index.end())
                       {
@@ -3496,20 +3491,19 @@ namespace GridTools
 
                         // Store the information that will be sent to the
                         // adjacent cells on other subdomains
-                        adjacent_cell =
-                          vertex_to_cell[cell->vertex_index(i)].begin();
-                        for (; adjacent_cell != end_adj_cell; ++adjacent_cell)
-                          if ((*adjacent_cell)->subdomain_id() !=
+                        for (const auto &adjacent_cell :
+                             vertex_to_cell[cell->vertex_index(i)])
+                          if (adjacent_cell->subdomain_id() !=
                               cell->subdomain_id())
                             {
                               std::pair<types::subdomain_id,
                                         types::global_vertex_index>
-                                tmp((*adjacent_cell)->subdomain_id(),
+                                tmp(adjacent_cell->subdomain_id(),
                                     cell->vertex_index(i));
                               if (vertices_added.find(tmp) ==
                                   vertices_added.end())
                                 {
-                                  vertices_to_send[(*adjacent_cell)
+                                  vertices_to_send[adjacent_cell
                                                      ->subdomain_id()]
                                     .emplace_back(i,
                                                   cell->vertex_index(i),
@@ -3583,11 +3577,8 @@ namespace GridTools
                           triangulation.get_communicator());
     AssertThrowMPI(ierr);
 
-    std::map<unsigned int, types::global_vertex_index>::iterator
-      global_index_it  = local_to_global_vertex_index.begin(),
-      global_index_end = local_to_global_vertex_index.end();
-    for (; global_index_it != global_index_end; ++global_index_it)
-      global_index_it->second += shift;
+    for (auto &global_index_it : local_to_global_vertex_index)
+      global_index_it.second += shift;
 
 
     const int mpi_tag = Utilities::MPI::internal::Tags::

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.