From 95e717acab9196d3c2f447e5c6b34af17e846e6f Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Wed, 27 Jan 2016 18:41:16 +0100 Subject: [PATCH] Overload perpare_coarsening_and_refinement for the periodic case --- include/deal.II/distributed/tria.h | 8 +++ include/deal.II/grid/tria.h | 2 +- source/distributed/tria.cc | 50 +++++++++++++++---- ...ute_mg_dofs_periodicity_02.mpirun=7.output | 4 ++ 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/include/deal.II/distributed/tria.h b/include/deal.II/distributed/tria.h index 4e4184d4e6..7d5a97a824 100644 --- a/include/deal.II/distributed/tria.h +++ b/include/deal.II/distributed/tria.h @@ -501,6 +501,14 @@ namespace parallel */ virtual void execute_coarsening_and_refinement (); + /** + * Override the implementation of prepare_coarsening_and_refinement from + * the base class. This is necessary if periodic boundaries are enabled + * and the level difference over vertices over the periodic boundary + * must be not more than 2:1. + */ + virtual bool prepare_coarsening_and_refinement (); + /** * Manually repartition the active cells between processors. Normally * this repartitioning will happen automatically when calling diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index d243cf37d9..89a1016540 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -1897,7 +1897,7 @@ public: * This function uses the user flags, so store them if you still need them * afterwards. */ - bool prepare_coarsening_and_refinement (); + virtual bool prepare_coarsening_and_refinement (); /* * @} diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index fe6b63bd7a..f025a84549 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -3192,21 +3192,26 @@ namespace parallel } template - void enforce_mesh_balance_over_periodic_boundaries + bool enforce_mesh_balance_over_periodic_boundaries (Triangulation &tria, std::vector::cell_iterator> > periodic_face_pairs_level_0) { if (periodic_face_pairs_level_0.empty()) - return; + return false; + + std::vector flags_before[2]; + tria.save_coarsen_flags (flags_before[0]); + tria.save_refine_flags (flags_before[1]); std::vector topological_vertex_numbering(tria.n_vertices()); for (unsigned int i=0; ichild(child)->clear_coarsen_flag(); } } + std::vector flags_after[2]; + tria.save_coarsen_flags (flags_after[0]); + tria.save_refine_flags (flags_after[1]); + return ((flags_before[0] != flags_after[0]) || + (flags_before[1] != flags_after[1])); } } + template + bool + Triangulation::prepare_coarsening_and_refinement() + { + std::vector flags_before[2]; + this->save_coarsen_flags (flags_before[0]); + this->save_refine_flags (flags_before[1]); + + do + { + this->dealii::Triangulation::prepare_coarsening_and_refinement(); + } + // enforce 2:1 mesh balance over periodic boundaries + while ((this->smooth_grid & dealii::Triangulation::limit_level_difference_at_vertices) + && + enforce_mesh_balance_over_periodic_boundaries(*this, + periodic_face_pairs_level_0)); + + std::vector flags_after[2]; + this->save_coarsen_flags (flags_after[0]); + this->save_refine_flags (flags_after[1]); + return ((flags_before[0] != flags_after[0]) || + (flags_before[1] != flags_after[1])); + } + + + template void Triangulation::copy_local_forest_to_triangulation () @@ -3471,11 +3508,6 @@ namespace parallel // fix all the flags to make sure we have a consistent mesh this->prepare_coarsening_and_refinement (); - // enforce 2:1 mesh balance over periodic boundaries - if (this->smooth_grid & dealii::Triangulation::limit_level_difference_at_vertices) - enforce_mesh_balance_over_periodic_boundaries(*this, - periodic_face_pairs_level_0); - // see if any flags are still set mesh_changed = false; for (typename Triangulation::active_cell_iterator diff --git a/tests/mpi/distribute_mg_dofs_periodicity_02.mpirun=7.output b/tests/mpi/distribute_mg_dofs_periodicity_02.mpirun=7.output index b74e1dedec..eed327ead0 100644 --- a/tests/mpi/distribute_mg_dofs_periodicity_02.mpirun=7.output +++ b/tests/mpi/distribute_mg_dofs_periodicity_02.mpirun=7.output @@ -50,6 +50,10 @@ DEAL:1::6_1:0 4294967294 DEAL:1::6_1:1 4294967294 DEAL:1::6_1:2 4 DEAL:1::6_1:3 4 +DEAL:1::8_1:0 4294967294 +DEAL:1::8_1:1 4294967294 +DEAL:1::8_1:2 4294967294 +DEAL:1::8_1:3 4294967294 DEAL:1::0_2:00 4294967294 DEAL:1::0_2:01 0 DEAL:1::0_2:02 0 -- 2.39.5