From 1f4524453eb0d8db21ca1556ba1b41ff5ea3d79f Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Mon, 1 Jun 2020 14:12:34 +0200 Subject: [PATCH] Use range-based iterators in tria.cc --- source/grid/tria.cc | 99 +++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 61 deletions(-) diff --git a/source/grid/tria.cc b/source/grid/tria.cc index 61eb5a207b..0301d61c15 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -4206,8 +4206,8 @@ namespace internal typename Triangulation<2, spacedim>::raw_line_iterator &next_unused_line, typename Triangulation<2, spacedim>::raw_cell_iterator - & next_unused_cell, - typename Triangulation<2, spacedim>::cell_iterator &cell) + &next_unused_cell, + const typename Triangulation<2, spacedim>::cell_iterator &cell) { const unsigned int dim = 2; // clear refinement flag @@ -4665,10 +4665,9 @@ namespace internal // count number of flagged // cells on this level unsigned int flagged_cells = 0; - typename Triangulation::active_cell_iterator - acell = triangulation.begin_active(level), - aendc = triangulation.begin_active(level + 1); - for (; acell != aendc; ++acell) + + for (auto &acell : + triangulation.active_cell_iterators_on_level(level)) if (acell->refine_flag_set()) ++flagged_cells; @@ -4718,14 +4717,11 @@ namespace internal for (int level = triangulation.levels.size() - 2; level >= 0; --level) { - typename Triangulation::active_cell_iterator - cell = triangulation.begin_active(level), - endc = triangulation.begin_active(level + 1); - typename Triangulation::raw_cell_iterator next_unused_cell = triangulation.begin_raw(level + 1); - for (; (cell != endc) && (cell->level() == level); ++cell) + for (auto &cell : + triangulation.active_cell_iterators_on_level(level)) if (cell->refine_flag_set()) { // clear refinement flag @@ -4928,10 +4924,8 @@ namespace internal // how many new vertices and new lines will be needed unsigned int needed_cells = 0; - typename Triangulation::active_cell_iterator - cell = triangulation.begin_active(level), - endc = triangulation.begin_active(level + 1); - for (; cell != endc; ++cell) + for (auto &cell : + triangulation.active_cell_iterators_on_level(level)) if (cell->refine_flag_set()) { if (cell->refine_flag_set() == RefinementCase::cut_xy) @@ -5149,16 +5143,11 @@ namespace internal level < static_cast(triangulation.levels.size()) - 1; ++level) { - // Remember: as we don't operate on the finest level, - // begin_*(level+1) is allowed - typename Triangulation::active_cell_iterator - cell = triangulation.begin_active(level), - endc = triangulation.begin_active(level + 1); - typename Triangulation::raw_cell_iterator next_unused_cell = triangulation.begin_raw(level + 1); - for (; cell != endc; ++cell) + for (auto &cell : + triangulation.active_cell_iterators_on_level(level)) if (cell->refine_flag_set()) { // set the user flag to indicate, that at least one @@ -5277,10 +5266,8 @@ namespace internal // how many new vertices and new lines will be needed unsigned int new_cells = 0; - typename Triangulation::active_cell_iterator - acell = triangulation.begin_active(level), - aendc = triangulation.begin_active(level + 1); - for (; acell != aendc; ++acell) + for (auto &acell : + triangulation.active_cell_iterators_on_level(level)) if (acell->refine_flag_set()) { RefinementCase ref_case = acell->refine_flag_set(); @@ -10232,11 +10219,7 @@ Triangulation::set_all_manifold_ids( ExcMessage( "Error: set_all_manifold_ids() can not be called on an empty Triangulation.")); - typename Triangulation::active_cell_iterator - cell = this->begin_active(), - endc = this->end(); - - for (; cell != endc; ++cell) + for (auto &cell : this->active_cell_iterators()) cell->set_all_manifold_ids(m_number); } @@ -10251,11 +10234,7 @@ Triangulation::set_all_manifold_ids_on_boundary( ExcMessage( "Error: set_all_manifold_ids_on_boundary() can not be called on an empty Triangulation.")); - typename Triangulation::active_cell_iterator - cell = this->begin_active(), - endc = this->end(); - - for (; cell != endc; ++cell) + for (auto &cell : this->active_cell_iterators()) for (auto f : GeometryInfo::face_indices()) if (cell->face(f)->at_boundary()) cell->face(f)->set_all_manifold_ids(m_number); @@ -10274,11 +10253,8 @@ Triangulation::set_all_manifold_ids_on_boundary( "Error: set_all_manifold_ids_on_boundary() can not be called on an empty Triangulation.")); bool boundary_found = false; - typename Triangulation::active_cell_iterator - cell = this->begin_active(), - endc = this->end(); - for (; cell != endc; ++cell) + for (auto &cell : this->active_cell_iterators()) { // loop on faces for (auto f : GeometryInfo::face_indices()) @@ -10785,9 +10761,8 @@ Triangulation::set_all_refine_flags() { Assert(n_cells() > 0, ExcMessage("Error: An empty Triangulation can not be refined.")); - active_cell_iterator cell = begin_active(), endc = end(); - for (; cell != endc; ++cell) + for (auto &cell : this->active_cell_iterators()) { cell->clear_coarsen_flag(); cell->set_refine_flag(); @@ -10818,9 +10793,9 @@ void Triangulation::save_refine_flags(std::vector &v) const { v.resize(dim * n_active_cells(), false); - std::vector::iterator i = v.begin(); - active_cell_iterator cell = begin_active(), endc = end(); - for (; cell != endc; ++cell) + std::vector::iterator i = v.begin(); + + for (auto &cell : this->active_cell_iterators()) for (unsigned int j = 0; j < dim; ++j, ++i) if (cell->refine_flag_set() & (1 << j)) *i = true; @@ -10861,9 +10836,8 @@ Triangulation::load_refine_flags(const std::vector &v) { AssertThrow(v.size() == dim * n_active_cells(), ExcGridReadError()); - active_cell_iterator cell = begin_active(), endc = end(); std::vector::const_iterator i = v.begin(); - for (; cell != endc; ++cell) + for (auto &cell : this->active_cell_iterators()) { unsigned int ref_case = 0; @@ -10888,10 +10862,12 @@ void Triangulation::save_coarsen_flags(std::vector &v) const { v.resize(n_active_cells(), false); - std::vector::iterator i = v.begin(); - active_cell_iterator cell = begin_active(), endc = end(); - for (; cell != endc; ++cell, ++i) - *i = cell->coarsen_flag_set(); + std::vector::iterator i = v.begin(); + for (auto &cell : this->active_cell_iterators()) + { + *i = cell->coarsen_flag_set(); + ++i; + } Assert(i == v.end(), ExcInternalError()); } @@ -10932,13 +10908,15 @@ Triangulation::load_coarsen_flags(const std::vector &v) { Assert(v.size() == n_active_cells(), ExcGridReadError()); - active_cell_iterator cell = begin_active(), endc = end(); std::vector::const_iterator i = v.begin(); - for (; cell != endc; ++cell, ++i) - if (*i == true) - cell->set_coarsen_flag(); - else - cell->clear_coarsen_flag(); + for (auto &cell : this->active_cell_iterators()) + { + if (*i == true) + cell->set_coarsen_flag(); + else + cell->clear_coarsen_flag(); + ++i; + } Assert(i == v.end(), ExcInternalError()); } @@ -13606,8 +13584,7 @@ Triangulation::fix_coarsen_flags() // store highest level one of the cells adjacent to a vertex // belongs to std::fill(vertex_level.begin(), vertex_level.end(), 0); - active_cell_iterator cell = begin_active(), endc = end(); - for (; cell != endc; ++cell) + for (auto &cell : this->active_cell_iterators()) { if (cell->refine_flag_set()) for (const unsigned int vertex : @@ -13648,6 +13625,7 @@ Triangulation::fix_coarsen_flags() // refinement flags, but we will also have to remove // coarsening flags on cells adjacent to vertices that will // see refinement + active_cell_iterator cell = begin_active(), endc = end(); for (cell = last_active(); cell != endc; --cell) if (cell->refine_flag_set() == false) { @@ -13696,8 +13674,7 @@ Triangulation::fix_coarsen_flags() clear_user_flags(); // Coarsen flags of cells with no mother cell, i.e. on the // coarsest level are deleted explicitly. - active_cell_iterator acell = begin_active(0), end_ac = end_active(0); - for (; acell != end_ac; ++acell) + for (auto &acell : this->active_cell_iterators_on_level(0)) acell->clear_coarsen_flag(); cell_iterator cell = begin(), endc = end(); -- 2.39.5