]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use ranged-based for loop in source/multigrid
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 9 Jan 2019 09:19:43 +0000 (10:19 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 14 Jan 2019 23:43:42 +0000 (00:43 +0100)
source/multigrid/mg_level_global_transfer.cc
source/multigrid/mg_transfer_block.cc
source/multigrid/mg_transfer_component.cc
source/multigrid/mg_transfer_internal.cc
source/multigrid/mg_transfer_matrix_free.cc

index 30052c40d3fcb1107d1eafc17b6d8dbe7089120d..fb6916cdc0447d43f2557455d200b613288af63d 100644 (file)
@@ -214,12 +214,11 @@ namespace
     for (unsigned int l = 0; l < mg_dof.get_triangulation().n_global_levels();
          ++l)
       {
-        for (unsigned int i = 0; i < my_copy_indices_level_mine[l].size(); ++i)
-          accessed_indices.push_back(my_copy_indices_level_mine[l][i].first);
+        for (const auto &indices : my_copy_indices_level_mine[l])
+          accessed_indices.push_back(indices.first);
         std::vector<types::global_dof_index> accessed_level_indices;
-        for (unsigned int i = 0; i < my_copy_indices_global_mine[l].size(); ++i)
-          accessed_level_indices.push_back(
-            my_copy_indices_global_mine[l][i].second);
+        for (const auto &indices : my_copy_indices_global_mine[l])
+          accessed_level_indices.push_back(indices.second);
         std::sort(accessed_level_indices.begin(), accessed_level_indices.end());
         level_index_set[l].set_size(mg_dof.locally_owned_mg_dofs(l).size());
         level_index_set[l].add_indices(accessed_level_indices.begin(),
index 6f02384712975d99c7fc3424673340abffe88286..d5741f1428630684a46c9ae0b287d7138dd2fac3 100644 (file)
@@ -236,13 +236,13 @@ MGTransferBlockBase::build_matrices(const DoFHandler<dim, spacedim> &,
   // for later use.
   mg_block_start = sizes;
   // Compute start indices from sizes
-  for (unsigned int l = 0; l < mg_block_start.size(); ++l)
+  for (auto &level_blocks : mg_block_start)
     {
       types::global_dof_index k = 0;
-      for (unsigned int i = 0; i < mg_block_start[l].size(); ++i)
+      for (types::global_dof_index &level_block_start : level_blocks)
         {
-          const types::global_dof_index t = mg_block_start[l][i];
-          mg_block_start[l][i]            = k;
+          const types::global_dof_index t = level_block_start;
+          level_block_start               = k;
           k += t;
         }
     }
@@ -252,10 +252,10 @@ MGTransferBlockBase::build_matrices(const DoFHandler<dim, spacedim> &,
     static_cast<const DoFHandler<dim, spacedim> &>(mg_dof), block_start);
 
   types::global_dof_index k = 0;
-  for (unsigned int i = 0; i < block_start.size(); ++i)
+  for (types::global_dof_index &first_index : block_start)
     {
-      const types::global_dof_index t = block_start[i];
-      block_start[i]                  = k;
+      const types::global_dof_index t = first_index;
+      first_index                     = k;
       k += t;
     }
   // Build index vectors for
index 3ae05945982d79387c2b24525d15aeaf816eb77d..af94fcb9d7b4830852b560c055f586b62365175e 100644 (file)
@@ -113,8 +113,8 @@ namespace
       {
         selected.resize(target_component.size());
         std::fill_n(selected.begin(), ncomp, false);
-        for (unsigned int i = 0; i < target_component.size(); ++i)
-          selected[target_component[i]] = true;
+        for (const unsigned int component : target_component)
+          selected[component] = true;
       }
 
     Assert(selected.size() == target_component.size(),
@@ -329,13 +329,13 @@ MGTransferComponentBase::build_matrices(const DoFHandler<dim, spacedim> &,
   // for later use.
   mg_component_start = sizes;
   // Compute start indices from sizes
-  for (unsigned int l = 0; l < mg_component_start.size(); ++l)
+  for (auto &level_components : mg_component_start)
     {
       types::global_dof_index k = 0;
-      for (unsigned int i = 0; i < mg_component_start[l].size(); ++i)
+      for (types::global_dof_index &level_component_start : level_components)
         {
-          const types::global_dof_index t = mg_component_start[l][i];
-          mg_component_start[l][i]        = k;
+          const types::global_dof_index t = level_component_start;
+          level_component_start           = k;
           k += t;
         }
     }
@@ -345,10 +345,10 @@ MGTransferComponentBase::build_matrices(const DoFHandler<dim, spacedim> &,
   DoFTools::count_dofs_per_block(mg_dof, component_start, target_component);
 
   types::global_dof_index k = 0;
-  for (unsigned int i = 0; i < component_start.size(); ++i)
+  for (types::global_dof_index &first_index : component_start)
     {
-      const types::global_dof_index t = component_start[i];
-      component_start[i]              = k;
+      const types::global_dof_index t = first_index;
+      first_index                     = k;
       k += t;
     }
 
index b884e92f71cf48ac083bcbcad89e2fc23c24c07b..f833459ac710dd4c216373d8a5f46206b520f51b 100644 (file)
@@ -193,20 +193,16 @@ namespace internal
 
           // * find owners of the level dofs and insert into send_data
           // accordingly
-          for (typename std::vector<DoFPair>::iterator dofpair =
-                 send_data_temp.begin();
-               dofpair != send_data_temp.end();
-               ++dofpair)
+          for (const auto &dofpair : send_data_temp)
             {
               std::set<types::subdomain_id>::iterator it;
               for (it = neighbors.begin(); it != neighbors.end(); ++it)
                 {
                   if (mg_dof
-                        .locally_owned_mg_dofs_per_processor(
-                          dofpair->level)[*it]
-                        .is_element(dofpair->level_dof_index))
+                        .locally_owned_mg_dofs_per_processor(dofpair.level)[*it]
+                        .is_element(dofpair.level_dof_index))
                     {
-                      send_data[*it].push_back(*dofpair);
+                      send_data[*it].push_back(dofpair);
                       break;
                     }
                 }
@@ -219,12 +215,9 @@ namespace internal
           // * send
           std::vector<MPI_Request> requests;
           {
-            for (std::set<types::subdomain_id>::iterator it = neighbors.begin();
-                 it != neighbors.end();
-                 ++it)
+            for (const auto dest : neighbors)
               {
                 requests.push_back(MPI_Request());
-                unsigned int          dest = *it;
                 std::vector<DoFPair> &data = send_data[dest];
                 // If there is nothing to send, we still need to send a message,
                 // because the receiving end will be waitng. In that case we
@@ -299,11 +292,10 @@ namespace internal
                                 &status);
                 AssertThrowMPI(ierr);
 
-                for (unsigned int i = 0; i < receive_buffer.size(); ++i)
+                for (const auto &dof_pair : receive_buffer)
                   {
-                    copy_indices_level_mine[receive_buffer[i].level]
-                      .emplace_back(receive_buffer[i].global_dof_index,
-                                    receive_buffer[i].level_dof_index);
+                    copy_indices_level_mine[dof_pair.level].emplace_back(
+                      dof_pair.global_dof_index, dof_pair.level_dof_index);
                   }
               }
           }
@@ -332,20 +324,12 @@ namespace internal
       // mode.
       std::less<std::pair<types::global_dof_index, types::global_dof_index>>
         compare;
-      for (unsigned int level = 0; level < copy_indices.size(); ++level)
-        std::sort(copy_indices[level].begin(),
-                  copy_indices[level].end(),
-                  compare);
-      for (unsigned int level = 0; level < copy_indices_level_mine.size();
-           ++level)
-        std::sort(copy_indices_level_mine[level].begin(),
-                  copy_indices_level_mine[level].end(),
-                  compare);
-      for (unsigned int level = 0; level < copy_indices_global_mine.size();
-           ++level)
-        std::sort(copy_indices_global_mine[level].begin(),
-                  copy_indices_global_mine[level].end(),
-                  compare);
+      for (auto &level_indices : copy_indices)
+        std::sort(level_indices.begin(), level_indices.end(), compare);
+      for (auto &level_indices : copy_indices_level_mine)
+        std::sort(level_indices.begin(), level_indices.end(), compare);
+      for (auto &level_indices : copy_indices_global_mine)
+        std::sort(level_indices.begin(), level_indices.end(), compare);
     }
 
 
@@ -376,11 +360,10 @@ namespace internal
           // partitioner that we are going to use for the vector
           const auto &part = ghosted_level_vector.get_partitioner();
           ghosted_dofs.add_indices(part->ghost_indices());
-          for (unsigned int i = 0; i < copy_indices_global_mine.size(); ++i)
-            copy_indices_global_mine[i].second =
-              locally_owned.n_elements() +
-              ghosted_dofs.index_within_set(
-                part->local_to_global(copy_indices_global_mine[i].second));
+          for (auto &indices : copy_indices_global_mine)
+            indices.second = locally_owned.n_elements() +
+                             ghosted_dofs.index_within_set(
+                               part->local_to_global(indices.second));
         }
       ghosted_level_vector.reinit(locally_owned, ghosted_dofs, communicator);
     }
@@ -701,9 +684,9 @@ namespace internal
 
                   const IndexSet &owned_level_dofs =
                     mg_dof.locally_owned_mg_dofs(level);
-                  for (unsigned int i = 0; i < local_dof_indices.size(); ++i)
-                    if (!owned_level_dofs.is_element(local_dof_indices[i]))
-                      ghosted_level_dofs.push_back(local_dof_indices[i]);
+                  for (const auto local_dof_index : local_dof_indices)
+                    if (!owned_level_dofs.is_element(local_dof_index))
+                      ghosted_level_dofs.push_back(local_dof_index);
 
                   add_child_indices<dim>(c,
                                          fe->dofs_per_cell -
@@ -772,9 +755,9 @@ namespace internal
 
                   const IndexSet &owned_level_dofs_l0 =
                     mg_dof.locally_owned_mg_dofs(0);
-                  for (unsigned int i = 0; i < local_dof_indices.size(); ++i)
-                    if (!owned_level_dofs_l0.is_element(local_dof_indices[i]))
-                      ghosted_level_dofs_l0.push_back(local_dof_indices[i]);
+                  for (const auto local_dof_index : local_dof_indices)
+                    if (!owned_level_dofs_l0.is_element(local_dof_index))
+                      ghosted_level_dofs_l0.push_back(local_dof_index);
 
                   const std::size_t start_index =
                     global_level_dof_indices_l0.size();
index 906fdda090f0ffdeae90fe6361a6f7f326ac3eea..6bd39c8cc111dc19a5580f7507af77696765016c 100644 (file)
@@ -612,8 +612,8 @@ MGTransferBlockMatrixFree<dim, Number>::MGTransferBlockMatrixFree(
   const std::vector<MGConstrainedDoFs> &mg_c)
   : same_for_all(false)
 {
-  for (unsigned int i = 0; i < mg_c.size(); ++i)
-    matrix_free_transfer_vector.emplace_back(mg_c[i]);
+  for (const auto &constrained_block_dofs : mg_c)
+    matrix_free_transfer_vector.emplace_back(constrained_block_dofs);
 }
 
 

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.