From: Wolfgang Bangerth Date: Mon, 13 Apr 2015 22:55:28 +0000 (-0500) Subject: Refactor common code into a function of its own. X-Git-Tag: v8.3.0-rc1~274^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aec15f7445a69d68034f9713b0e04e815ef8fdd9;p=dealii.git Refactor common code into a function of its own. --- diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index c6dc8f0314..2cbb457225 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -3025,6 +3025,14 @@ private: */ void clear_despite_subscriptions (); + /** + * For all cells, set the active cell indices so that active cells know + * the how many-th active cell they are, and all other cells have an invalid + * value. This function is called after mesh creation, refinement, and + * serialization. + */ + void reset_active_cell_indices (); + /** * Refine all cells on all levels which were previously flagged for * refinement. @@ -3321,18 +3329,7 @@ Triangulation::load (Archive &ar, { for (unsigned int l=0; lactive_cell_indices.resize (levels[l]->refine_flags.size()); - - unsigned int active_cell_index = 0; - for (cell_iterator cell=begin(); cell!=end(); ++cell) - if (cell->has_children()) - cell->set_active_cell_index (numbers::invalid_unsigned_int); - else - { - cell->set_active_cell_index (active_cell_index); - ++active_cell_index; - } - - Assert (active_cell_index == n_active_cells(), ExcInternalError()); + reset_active_cell_indices (); } diff --git a/source/grid/tria.cc b/source/grid/tria.cc index b10c57b73d..c7d2bb8fe0 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -9073,6 +9073,7 @@ create_triangulation_compatibility (const std::vector > &v, } + template void Triangulation:: @@ -9105,19 +9106,7 @@ create_triangulation (const std::vector > &v, // active_cell_indices of all cells internal::Triangulation::Implementation ::compute_number_cache (*this, levels.size(), number_cache); - { - unsigned int active_cell_index = 0; - for (cell_iterator cell=begin(); cell!=end(); ++cell) - if (cell->has_children()) - cell->set_active_cell_index (numbers::invalid_unsigned_int); - else - { - cell->set_active_cell_index (active_cell_index); - ++active_cell_index; - } - - Assert (active_cell_index == n_active_cells(), ExcInternalError()); - } + reset_active_cell_indices (); // now verify that there are indeed no distorted cells. as per the // documentation of this class, we first collect all distorted cells @@ -11515,19 +11504,7 @@ Triangulation::execute_coarsening_and_refinement () // finally build up neighbor connectivity information, and set // active cell indices update_neighbors(*this); - { - unsigned int active_cell_index = 0; - for (cell_iterator cell=begin(); cell!=end(); ++cell) - if (cell->has_children()) - cell->set_active_cell_index (numbers::invalid_unsigned_int); - else - { - cell->set_active_cell_index (active_cell_index); - ++active_cell_index; - } - - Assert (active_cell_index == n_active_cells(), ExcInternalError()); - } + reset_active_cell_indices (); // Inform all listeners about end of refinement. signals.post_refinement(); @@ -11537,6 +11514,26 @@ Triangulation::execute_coarsening_and_refinement () } + +template +void +Triangulation::reset_active_cell_indices () +{ + unsigned int active_cell_index = 0; + for (raw_cell_iterator cell=begin_raw(); cell!=end(); ++cell) + if ((cell->used() == false) || cell->has_children()) + cell->set_active_cell_index (numbers::invalid_unsigned_int); + else + { + cell->set_active_cell_index (active_cell_index); + ++active_cell_index; + } + + Assert (active_cell_index == n_active_cells(), ExcInternalError()); +} + + + template void Triangulation::clear_despite_subscriptions()