From a8662c5898b66b6aff3acbe528b73dad862844ee Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 15 Jun 2018 18:55:37 -0500 Subject: [PATCH] step-7: Use foreach loop and make a code snippet more readable --- examples/step-7/step-7.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/examples/step-7/step-7.cc b/examples/step-7/step-7.cc index d6c30eab7b..22a06f81da 100644 --- a/examples/step-7/step-7.cc +++ b/examples/step-7/step-7.cc @@ -635,13 +635,10 @@ namespace Step7 // Now for the main loop over all cells. This is mostly unchanged from // previous examples, so we only comment on the things that have changed. - typename DoFHandler::active_cell_iterator cell = - dof_handler.begin_active(), - endc = dof_handler.end(); - for (; cell != endc; ++cell) + for (const auto cell : dof_handler.active_cell_iterators()) { - cell_matrix = 0; - cell_rhs = 0; + cell_matrix = 0.; + cell_rhs = 0.; fe_values.reinit(cell); @@ -1003,19 +1000,16 @@ namespace Step7 GridGenerator::hyper_cube(triangulation, -1, 1); triangulation.refine_global(3); - typename Triangulation::cell_iterator cell = - triangulation.begin(), - endc = - triangulation.end(); - for (; cell != endc; ++cell) + for (const auto cell : triangulation.cell_iterators()) for (unsigned int face_number = 0; face_number < GeometryInfo::faces_per_cell; ++face_number) - if ((std::fabs(cell->face(face_number)->center()(0) - (-1)) < - 1e-12) || - (std::fabs(cell->face(face_number)->center()(1) - (-1)) < - 1e-12)) - cell->face(face_number)->set_boundary_id(1); + { + const auto ¢er = cell->face(face_number)->center(); + if ((std::fabs(center(0) - (-1)) < 1e-12) || + (std::fabs(center(1) - (-1)) < 1e-12)) + cell->face(face_number)->set_boundary_id(1); + } } else refine_grid(); -- 2.39.5