From: bangerth Date: Mon, 18 Aug 2008 21:58:07 +0000 (+0000) Subject: Fix the mesh_smoothing_0[12] testcases. A description of the problem is found in... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=15352463eb5c4b84d0b70e94ad8ed193ddb461dd;p=dealii-svn.git Fix the mesh_smoothing_0[12] testcases. A description of the problem is found in the mesh_smoothing_02.cc testcase. git-svn-id: https://svn.dealii.org/trunk@16591 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 94c66adf2b..7e06e88d63 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -11213,93 +11213,162 @@ bool Triangulation::prepare_coarsening_and_refinement () } } - // Loop over all patches of - // level 2, i.e. over all - // cells whose - // grandchildren are all - // active. Coarsen the - // children (and remove the + // The code above dealt + // with the case where we + // may get a + // non-patch_level_1 mesh + // from refinement. Now + // also deal with the case + // where we could get such + // a mesh by coarsening. + // Coarsen the children + // (and remove the // grandchildren) only if // all cell->grandchild(i) - // ->coarsen_flag_set() + // ->coarsen_flag_set() // are set. - for (cell_iterator cell = begin(); cell != end(); ++cell) - if (!cell->active() && - !cell->child(0)->active() && - cell->child(0)->child(0)->active()) - { - const unsigned int n_children=cell->n_children(); - unsigned int n_grandchildren=0; - // count all coarsen - // flags of the - // grandchildren. - unsigned int n_coarsen_flags=0; - // cell is not a - // patch (of level 1) - // as it has a - // grandchild. Is - // cell a patch of - // level 2?? - // Therefore: find - // out whether all - // cell->child(i) are - // patches - for (unsigned int c=0; cactive() + || + cell->child(0)->active()) + continue; + + // cell is not active, + // and so are none of + // its children. check + // the + // grandchildren. note + // that the children + // are also + // patch_level_1, and + // so we only ever need + // to check their first + // child + const unsigned int n_children=cell->n_children(); + bool has_active_grandchildren = false; + + for (unsigned int i=0; ichild(i)->child(0)->active()) { - cell_iterator child=cell->child(c); - // check - // consistency: - // cell is not a - // patch of level - // 1. - Assert(!child->active(), ExcInternalError()); - - if (child->child(0)->active()) - { - // child is - // found to - // be a patch - const unsigned int nn_children=child->n_children(); - n_grandchildren += nn_children; - for (unsigned int cc=0; ccchild(cc); - // check - // consistency: - // child is - // a patch - Assert(grand_child->active(), ExcInternalError()); - - if (grand_child->coarsen_flag_set()) - ++n_coarsen_flags; - } - } + has_active_grandchildren = true; + break; } - - if (n_coarsen_flags!=n_grandchildren) + + if (has_active_grandchildren == false) + continue; + + + // ok, there are active + // grandchildren. see + // if either all or + // none of them are + // flagged for + // coarsening + unsigned int n_grandchildren=0; + // count all coarsen + // flags of the + // grandchildren. + unsigned int n_coarsen_flags=0; + // cell is not a + // patch (of level 1) + // as it has a + // grandchild. Is + // cell a patch of + // level 2?? + // Therefore: find + // out whether all + // cell->child(i) are + // patches + for (unsigned int c=0; cchild(c); + + const unsigned int nn_children=child->n_children(); + n_grandchildren += nn_children; + + // if child is + // found to be a + // patch of + // active cells + // itself, then + // add up how + // many of its + // children are + // supposed to be + // coarsened + if (child->child(0)->active()) + for (unsigned int cc=0; ccchild(cc)->coarsen_flag_set()) + ++n_coarsen_flags; + } + + // if not all + // grandchildren are + // supposed to be + // coarsened + // (e.g. because some + // simply don't have + // the flag set, or + // because they are not + // active and therefore + // cannot carry the + // flag), then remove + // the coarsen flag + // from all of the + // active + // grandchildren. note + // that there may be + // coarsen flags on the + // grandgrandchildren + // -- we don't clear + // them here, but we'll + // get to them in later + // iterations if + // necessary + // + // there is nothing + // we have to do if + // no coarsen flags + // have been set at + // all + if ((n_coarsen_flags != n_grandchildren) + && + (n_coarsen_flags > 0)) + for (unsigned int c=0; cchild(c); - Assert(!child->active(), ExcInternalError()); - - if (child->child(0)->active()) - { - const unsigned int nn_children=child->n_children(); - for (unsigned int cc=0; ccchild(cc); - Assert(grand_child->active(), ExcInternalError()); - - grand_child->clear_coarsen_flag(); - } - } - } + const cell_iterator child = cell->child(c); + if (child->child(0)->active()) + for (unsigned int cc=0; ccn_children(); ++cc) + child->child(cc)->clear_coarsen_flag(); } - } + } } ////////////////////////////////// diff --git a/tests/deal.II/Makefile b/tests/deal.II/Makefile index 895643a368..fe05766403 100644 --- a/tests/deal.II/Makefile +++ b/tests/deal.II/Makefile @@ -72,6 +72,7 @@ tests_x = block_matrices \ maximal_cell_diameter \ union_triangulation \ refine_flag_set \ + mesh_smoothing_* \ create_* \ line_coarsening_3d \ no_flux_* \ diff --git a/tests/fail/mesh_smoothing_01.cc b/tests/deal.II/mesh_smoothing_01.cc similarity index 100% rename from tests/fail/mesh_smoothing_01.cc rename to tests/deal.II/mesh_smoothing_01.cc diff --git a/tests/fail/mesh_smoothing_01/cmp/generic b/tests/deal.II/mesh_smoothing_01/cmp/generic similarity index 100% rename from tests/fail/mesh_smoothing_01/cmp/generic rename to tests/deal.II/mesh_smoothing_01/cmp/generic diff --git a/tests/fail/mesh_smoothing_02.cc b/tests/deal.II/mesh_smoothing_02.cc similarity index 100% rename from tests/fail/mesh_smoothing_02.cc rename to tests/deal.II/mesh_smoothing_02.cc diff --git a/tests/fail/mesh_smoothing_02/cmp/generic b/tests/deal.II/mesh_smoothing_02/cmp/generic similarity index 100% rename from tests/fail/mesh_smoothing_02/cmp/generic rename to tests/deal.II/mesh_smoothing_02/cmp/generic