From 86a138f65cd5f4884a8216762b004597651f391f Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 17 Aug 2008 23:21:57 +0000 Subject: [PATCH] Improve clarity of code even further, by putting things into a predicate. git-svn-id: https://svn.dealii.org/trunk@16585 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/source/grid/tria.cc | 49 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 98ae30b105..94c66adf2b 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -36,14 +36,36 @@ DEAL_II_NAMESPACE_OPEN // anonymous namespace for internal helper functions -namespace{ +namespace +{ + // return whether the given cell is + // patch_level_1, i.e. determine + // whether either all or none of + // its children are further + // refined. this function can only + // be called for non-active cells. + template + bool cell_is_patch_level_1 (const TriaIterator > &cell) + { + Assert (cell->active() == false, ExcInternalError()); + + unsigned int n_active_children = 0; + for (unsigned int i=0; in_children(); ++i) + if (cell->child(i)->active()) + ++n_active_children; + + return (n_active_children == 0) || (n_active_children == cell->n_children()); + } + + + // return, wheter a given @p cell will be // coarsened, which is the case if all // children are active and have their coarsen // flag set. In case only part of the coarsen // flags are set, remove them. template - bool cell_will_be_coarsened(const TriaIterator > &cell) + bool cell_will_be_coarsened (const TriaIterator > &cell) { // only cells with children should be // considered for coarsening @@ -11158,16 +11180,18 @@ bool Triangulation::prepare_coarsening_and_refinement () for (cell_iterator cell = begin(); cell != end(); ++cell) if (!cell->active()) { - bool n_active_children = 0; - for (unsigned int i=0; in_children(); ++i) - if (cell->child(i)->active()) - ++n_active_children; - - // if none of the + // ensure the + // invariant. we can + // then check whether + // all of its // children are - // active, continue - // with next cell - if (n_active_children == 0) + // further refined or + // not by simply + // looking at the + // first child + Assert (cell_is_patch_level_1(cell), + ExcInternalError()); + if (cell->child(0)->has_children() == true) continue; // cell is found to @@ -11175,9 +11199,6 @@ bool Triangulation::prepare_coarsening_and_refinement () // combine the refine // cases of all // children - Assert (n_active_children == cell->n_children(), - ExcInternalError()); - RefinementCase combined_ref_case = RefinementCase::no_refinement; for (unsigned int i=0; in_children(); ++i) combined_ref_case = combined_ref_case | -- 2.39.5