From 45ec6288cdc9193ffd0c1456785bd63f78d81ec3 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Sat, 11 May 2019 12:32:03 -0400 Subject: [PATCH] Use range-based for loops --- examples/step-43/step-43.cc | 77 ++++++++++++------------------------- 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/examples/step-43/step-43.cc b/examples/step-43/step-43.cc index c6546c8e18..14e458f20a 100644 --- a/examples/step-43/step-43.cc +++ b/examples/step-43/step-43.cc @@ -881,12 +881,9 @@ namespace Step43 const FEValuesExtractors::Vector velocities(0); const FEValuesExtractors::Scalar pressure(dim); - typename DoFHandler::active_cell_iterator cell = darcy_dof_handler - .begin_active(), - endc = - darcy_dof_handler.end(); - typename DoFHandler::active_cell_iterator saturation_cell = - saturation_dof_handler.begin_active(); + auto cell = darcy_dof_handler.begin_active(); + const auto endc = darcy_dof_handler.end(); + auto saturation_cell = saturation_dof_handler.begin_active(); for (; cell != endc; ++cell, ++saturation_cell) { @@ -1083,12 +1080,9 @@ namespace Step43 // AffineConstraints class do the insertion of the cell matrix // elements to the global matrix, which already condenses the hanging node // constraints. - typename DoFHandler::active_cell_iterator cell = darcy_dof_handler - .begin_active(), - endc = - darcy_dof_handler.end(); - typename DoFHandler::active_cell_iterator saturation_cell = - saturation_dof_handler.begin_active(); + auto cell = darcy_dof_handler.begin_active(); + const auto endc = darcy_dof_handler.end(); + auto saturation_cell = saturation_dof_handler.begin_active(); for (; cell != endc; ++cell, ++saturation_cell) { @@ -1216,10 +1210,7 @@ namespace Step43 std::vector local_dof_indices(dofs_per_cell); - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - for (; cell != endc; ++cell) + for (const auto &cell : saturation_dof_handler.active_cell_iterators()) { saturation_fe_values.reinit(cell); local_matrix = 0; @@ -1303,11 +1294,9 @@ namespace Step43 const double global_S_variation = global_S_range.second - global_S_range.first; - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - typename DoFHandler::active_cell_iterator darcy_cell = - darcy_dof_handler.begin_active(); + auto cell = saturation_dof_handler.begin_active(); + const auto endc = saturation_dof_handler.end(); + auto darcy_cell = darcy_dof_handler.begin_active(); for (; cell != endc; ++cell, ++darcy_cell) { saturation_fe_values.reinit(cell); @@ -1662,11 +1651,9 @@ namespace Step43 time_step / old_time_step, old_saturation_solution); - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - for (unsigned int cell_no = 0; cell != endc; ++cell, ++cell_no) + for (const auto &cell : saturation_dof_handler.active_cell_iterators()) { + const unsigned int cell_no = cell->active_cell_index(); fe_values.reinit(cell); fe_values.get_function_gradients(extrapolated_saturation_solution, grad_saturation); @@ -1676,12 +1663,9 @@ namespace Step43 } { - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - - for (unsigned int cell_no = 0; cell != endc; ++cell, ++cell_no) + for (const auto &cell : saturation_dof_handler.active_cell_iterators()) { + const unsigned int cell_no = cell->active_cell_index(); cell->clear_coarsen_flag(); cell->clear_refine_flag(); @@ -1780,11 +1764,10 @@ namespace Step43 std::vector local_saturation_dof_indices( saturation_fe.dofs_per_cell); - typename DoFHandler::active_cell_iterator - joint_cell = joint_dof_handler.begin_active(), - joint_endc = joint_dof_handler.end(), - darcy_cell = darcy_dof_handler.begin_active(), - saturation_cell = saturation_dof_handler.begin_active(); + auto joint_cell = joint_dof_handler.begin_active(); + const auto joint_endc = joint_dof_handler.end(); + auto darcy_cell = darcy_dof_handler.begin_active(); + auto saturation_cell = saturation_dof_handler.begin_active(); for (; joint_cell != joint_endc; ++joint_cell, ++darcy_cell, ++saturation_cell) @@ -1887,10 +1870,7 @@ namespace Step43 double max_global_aop_indicator = 0.0; - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - for (; cell != endc; ++cell) + for (const auto &cell : saturation_dof_handler.active_cell_iterators()) { double max_local_mobility_reciprocal_difference = 0.0; double max_local_permeability_inverse_l1_norm = 0.0; @@ -1978,12 +1958,9 @@ namespace Step43 double max_velocity_times_dF_dS = 0; - typename DoFHandler::active_cell_iterator cell = darcy_dof_handler - .begin_active(), - endc = - darcy_dof_handler.end(); - typename DoFHandler::active_cell_iterator saturation_cell = - saturation_dof_handler.begin_active(); + auto cell = darcy_dof_handler.begin_active(); + const auto endc = darcy_dof_handler.end(); + auto saturation_cell = saturation_dof_handler.begin_active(); for (; cell != endc; ++cell, ++saturation_cell) { darcy_fe_values.reinit(cell); @@ -2038,10 +2015,7 @@ namespace Step43 double min_saturation = std::numeric_limits::max(), max_saturation = -std::numeric_limits::max(); - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - for (; cell != endc; ++cell) + for (const auto &cell : saturation_dof_handler.active_cell_iterators()) { fe_values.reinit(cell); fe_values.get_function_values(old_saturation_solution, @@ -2067,10 +2041,7 @@ namespace Step43 double min_saturation = std::numeric_limits::max(), max_saturation = -std::numeric_limits::max(); - typename DoFHandler::active_cell_iterator - cell = saturation_dof_handler.begin_active(), - endc = saturation_dof_handler.end(); - for (; cell != endc; ++cell) + for (const auto &cell : saturation_dof_handler.active_cell_iterators()) { fe_values.reinit(cell); fe_values.get_function_values(old_saturation_solution, -- 2.39.5