]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use ranged-based for loop in include/numerics
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 6 Jan 2019 16:32:05 +0000 (17:32 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 14 Jan 2019 23:43:42 +0000 (00:43 +0100)
include/deal.II/numerics/matrix_creator.templates.h
include/deal.II/numerics/time_dependent.h
include/deal.II/numerics/vector_tools.templates.h

index 6e1d143aaa8e17f9cef0ad92b5315f6690f6a516..c7fd8cfaa06ebddd8cf469959c15218f8aff2b85 100644 (file)
@@ -1756,14 +1756,11 @@ namespace MatrixCreator
               // for this purpose we seek the diagonal of the matrix, where
               // there must be an element belonging to the boundary. we take the
               // maximum diagonal entry.
-              types::global_dof_index max_element =
-                static_cast<types::global_dof_index>(0);
-              for (std::vector<types::global_dof_index>::const_iterator i =
-                     dof_to_boundary_mapping.begin();
-                   i != dof_to_boundary_mapping.end();
-                   ++i)
-                if ((*i != numbers::invalid_dof_index) && (*i > max_element))
-                  max_element = *i;
+              types::global_dof_index max_element = 0;
+              for (const auto index : dof_to_boundary_mapping)
+                if ((index != numbers::invalid_dof_index) &&
+                    (index > max_element))
+                  max_element = index;
               Assert(max_element == matrix.n() - 1, ExcInternalError());
 
               double max_diag_entry = 0;
index c77e644863fd6ab275dcd428325e3ccc6ac436ae..57e7ab631a4eae549b23f3ac89af8b9bb28790da 100644 (file)
@@ -1559,7 +1559,8 @@ TimeDependent::do_loop(InitFunctionObject      init_function,
 
 
   // wake up the first few time levels
-  for (int step = -timestepping_data.look_ahead; step < 0; ++step)
+  for (int step = -static_cast<int>(timestepping_data.look_ahead); step < 0;
+       ++step)
     for (int look_ahead = 0;
          look_ahead <= static_cast<int>(timestepping_data.look_ahead);
          ++look_ahead)
index b9f6b2f47c031c418e644e44b130cc9fd6c9e3e5..30e5fa5f1fe5e531e2d97c05a731c8a973ac0d1b 100644 (file)
@@ -386,7 +386,7 @@ namespace VectorTools
       // Now loop over all locally owned, active cells.
       //
 
-      for (auto cell : dof_handler.active_cell_iterators())
+      for (const auto &cell : dof_handler.active_cell_iterators())
         {
           // If this cell is not locally owned, do nothing.
           if (!cell->is_locally_owned())
@@ -938,8 +938,8 @@ namespace VectorTools
 
           std::map<types::boundary_id, const Function<spacedim, number> *>
             boundary_functions;
-          for (unsigned int i = 0; i < used_boundary_ids.size(); ++i)
-            boundary_functions[used_boundary_ids[i]] = &function;
+          for (const auto used_boundary_id : used_boundary_ids)
+            boundary_functions[used_boundary_id] = &function;
           project_boundary_values(
             mapping, dof, boundary_functions, q_boundary, boundary_values);
         }
@@ -957,15 +957,14 @@ namespace VectorTools
       const AffineConstraints<number> &          constraints,
       std::map<types::global_dof_index, number> &boundary_values)
     {
-      for (typename std::map<types::global_dof_index, number>::iterator it =
-             boundary_values.begin();
-           it != boundary_values.end();
-           ++it)
-        if (constraints.is_constrained(it->first))
+      for (const auto &boundary_value : boundary_values)
+        if (constraints.is_constrained(boundary_value.first))
           // TODO: This looks wrong -- shouldn't it be ==0 in the first
           // condition and && ?
-          if (!(constraints.get_constraint_entries(it->first)->size() > 0 ||
-                (constraints.get_inhomogeneity(it->first) == it->second)))
+          if (!(constraints.get_constraint_entries(boundary_value.first)
+                    ->size() > 0 ||
+                (constraints.get_inhomogeneity(boundary_value.first) ==
+                 boundary_value.second)))
             return false;
 
       return true;
@@ -6940,9 +6939,8 @@ namespace VectorTools
   {
     ZeroFunction<dim>                                        zero_function(dim);
     std::map<types::boundary_id, const Function<spacedim> *> function_map;
-    std::set<types::boundary_id>::const_iterator it = boundary_ids.begin();
-    for (; it != boundary_ids.end(); ++it)
-      function_map[*it] = &zero_function;
+    for (const types::boundary_id boundary_id : boundary_ids)
+      function_map[boundary_id] = &zero_function;
     compute_nonzero_normal_flux_constraints(dof_handler,
                                             first_vector_component,
                                             boundary_ids,
@@ -7550,9 +7548,8 @@ namespace VectorTools
   {
     ZeroFunction<dim>                                        zero_function(dim);
     std::map<types::boundary_id, const Function<spacedim> *> function_map;
-    std::set<types::boundary_id>::const_iterator it = boundary_ids.begin();
-    for (; it != boundary_ids.end(); ++it)
-      function_map[*it] = &zero_function;
+    for (const types::boundary_id boundary_id : boundary_ids)
+      function_map[boundary_id] = &zero_function;
     compute_nonzero_tangential_flux_constraints(dof_handler,
                                                 first_vector_component,
                                                 boundary_ids,
@@ -7692,16 +7689,12 @@ namespace VectorTools
     // iterate over the list of all vector components we found and see if we
     // can find constrained ones
     unsigned int n_total_constraints_found = 0;
-    for (typename std::set<std::array<types::global_dof_index, dim>,
-                           internal::PointComparator<dim>>::const_iterator it =
-           vector_dofs.begin();
-         it != vector_dofs.end();
-         ++it)
+    for (const auto &dofs : vector_dofs)
       {
         unsigned int n_constraints = 0;
         bool         is_constrained[dim];
         for (unsigned int d = 0; d < dim; ++d)
-          if (no_normal_flux_constraints.is_constrained((*it)[d]))
+          if (no_normal_flux_constraints.is_constrained(dofs[d]))
             {
               is_constrained[d] = true;
               ++n_constraints;
@@ -7718,11 +7711,11 @@ namespace VectorTools
             // function.).
             if (n_constraints > 1)
               {
-                const Vector<double> b_value = dof_vector_to_b_values[*it];
+                const Vector<double> b_value = dof_vector_to_b_values[dofs];
                 for (unsigned int d = 0; d < dim; ++d)
                   {
-                    constraints.add_line((*it)[d]);
-                    constraints.set_inhomogeneity((*it)[d], b_value(d));
+                    constraints.add_line(dofs[d]);
+                    constraints.set_inhomogeneity(dofs[d], b_value(d));
                   }
                 continue;
               }
@@ -7742,31 +7735,31 @@ namespace VectorTools
             AssertIndexRange(constrained_index, dim);
             const std::vector<std::pair<types::global_dof_index, double>>
               *constrained = no_normal_flux_constraints.get_constraint_entries(
-                (*it)[constrained_index]);
+                dofs[constrained_index]);
             // find components to which this index is constrained to
             Assert(constrained != nullptr, ExcInternalError());
             Assert(constrained->size() < dim, ExcInternalError());
-            for (unsigned int c = 0; c < constrained->size(); ++c)
+            for (const auto &entry : *constrained)
               {
                 int index = -1;
                 for (unsigned int d = 0; d < dim; ++d)
-                  if ((*constrained)[c].first == (*it)[d])
+                  if (entry.first == dofs[d])
                     index = d;
                 Assert(index != -1, ExcInternalError());
-                normal[index] = (*constrained)[c].second;
+                normal[index] = entry.second;
               }
-            Vector<double> boundary_value = dof_vector_to_b_values[*it];
+            Vector<double> boundary_value = dof_vector_to_b_values[dofs];
             for (unsigned int d = 0; d < dim; ++d)
               {
                 if (is_constrained[d])
                   continue;
-                const unsigned int new_index = (*it)[d];
+                const unsigned int new_index = dofs[d];
                 if (!constraints.is_constrained(new_index))
                   {
                     constraints.add_line(new_index);
                     if (std::abs(normal[d]) > 1e-13)
                       constraints.add_entry(new_index,
-                                            (*it)[constrained_index],
+                                            dofs[constrained_index],
                                             -normal[d]);
                     constraints.set_inhomogeneity(new_index, boundary_value[d]);
                   }

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.