From: Daniel Arndt Date: Sun, 6 Jan 2019 16:32:05 +0000 (+0100) Subject: Use ranged-based for loop in include/numerics X-Git-Tag: v9.1.0-rc1~436^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfef6182f169b71683303637152f2890193b4f99;p=dealii.git Use ranged-based for loop in include/numerics --- diff --git a/include/deal.II/numerics/matrix_creator.templates.h b/include/deal.II/numerics/matrix_creator.templates.h index 6e1d143aaa..c7fd8cfaa0 100644 --- a/include/deal.II/numerics/matrix_creator.templates.h +++ b/include/deal.II/numerics/matrix_creator.templates.h @@ -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(0); - for (std::vector::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; diff --git a/include/deal.II/numerics/time_dependent.h b/include/deal.II/numerics/time_dependent.h index c77e644863..57e7ab631a 100644 --- a/include/deal.II/numerics/time_dependent.h +++ b/include/deal.II/numerics/time_dependent.h @@ -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(timestepping_data.look_ahead); step < 0; + ++step) for (int look_ahead = 0; look_ahead <= static_cast(timestepping_data.look_ahead); ++look_ahead) diff --git a/include/deal.II/numerics/vector_tools.templates.h b/include/deal.II/numerics/vector_tools.templates.h index b9f6b2f47c..30e5fa5f1f 100644 --- a/include/deal.II/numerics/vector_tools.templates.h +++ b/include/deal.II/numerics/vector_tools.templates.h @@ -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 *> 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 & constraints, std::map &boundary_values) { - for (typename std::map::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 zero_function(dim); std::map *> function_map; - std::set::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 zero_function(dim); std::map *> function_map; - std::set::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, - internal::PointComparator>::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 b_value = dof_vector_to_b_values[*it]; + const Vector 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> *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 boundary_value = dof_vector_to_b_values[*it]; + Vector 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]); }