]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use ranged-based for loop in source/numerics
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 9 Jan 2019 09:20:19 +0000 (10:20 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Mon, 14 Jan 2019 23:43:42 +0000 (00:43 +0100)
source/numerics/data_out_stack.cc
source/numerics/histogram.cc
source/numerics/matrix_tools_once.cc
source/numerics/point_value_history.cc
source/numerics/time_dependent.cc

index 5d5100278043e10620cfe70f3296704fc7b1fbf9..336ddeba53f128445d445af3b1fffb43433602dc 100644 (file)
@@ -112,23 +112,16 @@ DataOutStack<dim, spacedim, DoFHandlerType>::declare_data_vector(
 
   // also make sure that no name is
   // used twice
-  for (std::vector<std::string>::const_iterator name = names.begin();
-       name != names.end();
-       ++name)
+  for (const auto &name : names)
     {
-      for (typename std::vector<DataVector>::const_iterator data_set =
-             dof_data.begin();
-           data_set != dof_data.end();
-           ++data_set)
-        for (unsigned int i = 0; i < data_set->names.size(); ++i)
-          Assert(*name != data_set->names[i], ExcNameAlreadyUsed(*name));
-
-      for (typename std::vector<DataVector>::const_iterator data_set =
-             cell_data.begin();
-           data_set != cell_data.end();
-           ++data_set)
-        for (unsigned int i = 0; i < data_set->names.size(); ++i)
-          Assert(*name != data_set->names[i], ExcNameAlreadyUsed(*name));
+      (void)name;
+      for (const auto &data_set : dof_data)
+        for (const auto &data_set_name : data_set.names)
+          Assert(name != data_set_name, ExcNameAlreadyUsed(name));
+
+      for (const auto &data_set : cell_data)
+        for (const auto &data_set_name : data_set.names)
+          Assert(name != data_set_name, ExcNameAlreadyUsed(name));
     }
 
   switch (vector_type)
@@ -198,15 +191,18 @@ DataOutStack<dim, spacedim, DoFHandlerType>::add_data_vector(
             (names.size() == dof_handler->get_fe(0).n_components())),
          Exceptions::DataOutImplementation::ExcInvalidNumberOfNames(
            names.size(), dof_handler->get_fe(0).n_components()));
-  for (unsigned int i = 0; i < names.size(); ++i)
-    Assert(names[i].find_first_not_of("abcdefghijklmnopqrstuvwxyz"
+  for (const auto &name : names)
+    {
+      (void)name;
+      Assert(name.find_first_not_of("abcdefghijklmnopqrstuvwxyz"
+                                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+                                    "0123456789_<>()") == std::string::npos,
+             Exceptions::DataOutImplementation::ExcInvalidCharacter(
+               name,
+               name.find_first_not_of("abcdefghijklmnopqrstuvwxyz"
                                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                                      "0123456789_<>()") == std::string::npos,
-           Exceptions::DataOutImplementation::ExcInvalidCharacter(
-             names[i],
-             names[i].find_first_not_of("abcdefghijklmnopqrstuvwxyz"
-                                        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-                                        "0123456789_<>()")));
+                                      "0123456789_<>()")));
+    }
 
   if (vec.size() == dof_handler->n_dofs())
     {
index a5dd3f2deb45e035cd8d6895916654b061a2a6ad..51dfcfb54c9d5b45ccd0672f7f7197e95835d432 100644 (file)
@@ -233,11 +233,9 @@ Histogram::write_gnuplot(std::ostream &out) const
   // one data set is available
   if (intervals.size() == 1)
     {
-      for (unsigned int n = 0; n < intervals[0].size(); ++n)
-        out << intervals[0][n].left_point << ' ' << intervals[0][n].content
-            << std::endl
-            << intervals[0][n].right_point << ' ' << intervals[0][n].content
-            << std::endl;
+      for (const auto &interval : intervals[0])
+        out << interval.left_point << ' ' << interval.content << std::endl
+            << interval.right_point << ' ' << interval.content << std::endl;
     }
   else
     // otherwise create a whole 3d plot
index aded4396a49c5519c4f64bb4a0ff77e26bbde964..21efb2f41f07ad8917b4d052d5f3abe02b925f16 100644 (file)
@@ -106,13 +106,10 @@ namespace MatrixTools
         // figure out which rows of the matrix we
         // have to eliminate on this processor
         std::vector<types::global_dof_index> constrained_rows;
-        for (std::map<types::global_dof_index, PetscScalar>::const_iterator
-               dof = boundary_values.begin();
-             dof != boundary_values.end();
-             ++dof)
-          if ((dof->first >= local_range.first) &&
-              (dof->first < local_range.second))
-            constrained_rows.push_back(dof->first);
+        for (const auto &boundary_value : boundary_values)
+          if ((boundary_value.first >= local_range.first) &&
+              (boundary_value.first < local_range.second))
+            constrained_rows.push_back(boundary_value.first);
 
         // then eliminate these rows and set
         // their diagonal entry to what we have
@@ -129,22 +126,19 @@ namespace MatrixTools
 
         std::vector<types::global_dof_index> indices;
         std::vector<PetscScalar>             solution_values;
-        for (std::map<types::global_dof_index, PetscScalar>::const_iterator
-               dof = boundary_values.begin();
-             dof != boundary_values.end();
-             ++dof)
-          if ((dof->first >= local_range.first) &&
-              (dof->first < local_range.second))
+        for (const auto &boundary_value : boundary_values)
+          if ((boundary_value.first >= local_range.first) &&
+              (boundary_value.first < local_range.second))
             {
-              indices.push_back(dof->first);
-              solution_values.push_back(dof->second);
+              indices.push_back(boundary_value.first);
+              solution_values.push_back(boundary_value.second);
             }
         solution.set(indices, solution_values);
 
         // now also set appropriate values for
         // the rhs
-        for (unsigned int i = 0; i < solution_values.size(); ++i)
-          solution_values[i] *= average_nonzero_diagonal_entry;
+        for (double &solution_value : solution_values)
+          solution_value *= average_nonzero_diagonal_entry;
 
         right_hand_side.set(indices, solution_values);
       }
@@ -187,20 +181,17 @@ namespace MatrixTools
     {
       int                             block  = 0;
       dealii::types::global_dof_index offset = 0;
-      for (std::map<types::global_dof_index, PetscScalar>::const_iterator dof =
-             boundary_values.begin();
-           dof != boundary_values.end();
-           ++dof)
+      for (const auto &boundary_value : boundary_values)
         {
-          if (dof->first >= matrix.block(block, 0).m() + offset)
+          if (boundary_value.first >= matrix.block(block, 0).m() + offset)
             {
               offset += matrix.block(block, 0).m();
               block++;
             }
-          const types::global_dof_index index = dof->first - offset;
+          const types::global_dof_index index = boundary_value.first - offset;
           block_boundary_values[block].insert(
-            std::pair<types::global_dof_index, PetscScalar>(index,
-                                                            dof->second));
+            std::pair<types::global_dof_index, PetscScalar>(
+              index, boundary_value.second));
         }
     }
 
@@ -294,14 +285,10 @@ namespace MatrixTools
             // figure out which rows of the matrix we
             // have to eliminate on this processor
             std::vector<types::global_dof_index> constrained_rows;
-            for (std::map<types::global_dof_index,
-                          TrilinosScalar>::const_iterator dof =
-                   boundary_values.begin();
-                 dof != boundary_values.end();
-                 ++dof)
-              if ((dof->first >= local_range.first) &&
-                  (dof->first < local_range.second))
-                constrained_rows.push_back(dof->first);
+            for (const auto &boundary_value : boundary_values)
+              if ((boundary_value.first >= local_range.first) &&
+                  (boundary_value.first < local_range.second))
+                constrained_rows.push_back(boundary_value.first);
 
             // then eliminate these rows and
             // set their diagonal entry to
@@ -314,16 +301,12 @@ namespace MatrixTools
 
             std::vector<types::global_dof_index> indices;
             std::vector<TrilinosScalar>          solution_values;
-            for (std::map<types::global_dof_index,
-                          TrilinosScalar>::const_iterator dof =
-                   boundary_values.begin();
-                 dof != boundary_values.end();
-                 ++dof)
-              if ((dof->first >= local_range.first) &&
-                  (dof->first < local_range.second))
+            for (const auto &boundary_value : boundary_values)
+              if ((boundary_value.first >= local_range.first) &&
+                  (boundary_value.first < local_range.second))
                 {
-                  indices.push_back(dof->first);
-                  solution_values.push_back(dof->second);
+                  indices.push_back(boundary_value.first);
+                  solution_values.push_back(boundary_value.second);
                 }
             solution.set(indices, solution_values);
 
@@ -380,20 +363,18 @@ namespace MatrixTools
         {
           int                     block  = 0;
           types::global_dof_index offset = 0;
-          for (std::map<types::global_dof_index, TrilinosScalar>::const_iterator
-                 dof = boundary_values.begin();
-               dof != boundary_values.end();
-               ++dof)
+          for (const auto &boundary_value : boundary_values)
             {
-              if (dof->first >= matrix.block(block, 0).m() + offset)
+              if (boundary_value.first >= matrix.block(block, 0).m() + offset)
                 {
                   offset += matrix.block(block, 0).m();
                   block++;
                 }
-              const types::global_dof_index index = dof->first - offset;
+              const types::global_dof_index index =
+                boundary_value.first - offset;
               block_boundary_values[block].insert(
                 std::pair<types::global_dof_index, TrilinosScalar>(
-                  index, dof->second));
+                  index, boundary_value.second));
             }
         }
 
index 8c3cbdeda94bd570ba99e14f5595486eb6cab047..58231c2cb1e92904dd95211f32d000f6a0c89209 100644 (file)
@@ -1157,10 +1157,9 @@ PointValueHistory<dim>::write_gnuplot(
                 {
                   AssertThrow(names.size() == n_stored,
                               ExcDimensionMismatch(names.size(), n_stored));
-                  for (unsigned int component = 0; component < names.size();
-                       component++)
+                  for (const auto &name : names)
                     {
-                      to_gnuplot << "<" << names[component] << "> ";
+                      to_gnuplot << "<" << name << "> ";
                     }
                 }
               else
@@ -1432,10 +1431,9 @@ PointValueHistory<dim>::status(std::ostream &out)
       // add names, if available
       if (component_names->second.size() > 0)
         {
-          for (unsigned int name = 0; name < component_names->second.size();
-               name++)
+          for (const auto &name : component_names->second)
             {
-              out << "<" << component_names->second[name] << "> ";
+              out << "<" << name << "> ";
             }
           out << "\n";
         }
index 9ec4a97ebc6fa47efeba8f0c7591d68f3bc25030..58264342d1e8495765836514b5c704b620344649 100644 (file)
@@ -218,8 +218,8 @@ TimeDependent::start_sweep(const unsigned int s)
       timesteps[step]->set_sweep_no(sweep_no);
     }
 
-  for (unsigned int step = 0; step < timesteps.size(); ++step)
-    timesteps[step]->start_sweep();
+  for (const auto &timestep : timesteps)
+    timestep->start_sweep();
 }
 
 
@@ -255,8 +255,8 @@ TimeDependent::memory_consumption() const
      MemoryConsumption::memory_consumption(sweep_no) +
      sizeof(timestepping_data_primal) + sizeof(timestepping_data_dual) +
      sizeof(timestepping_data_postprocess));
-  for (unsigned int i = 0; i < timesteps.size(); ++i)
-    mem += MemoryConsumption::memory_consumption(*timesteps[i]);
+  for (const auto &timestep : timesteps)
+    mem += MemoryConsumption::memory_consumption(*timestep);
 
   return mem;
 }

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.