From da992fabeb7e83758912dd37c72eb29a97f2bdb9 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Thu, 16 Jul 2020 12:22:43 -0400 Subject: [PATCH] detect inifinite loop in periodic refinement As witnessed by ASPECT, see https://github.com/geodynamics/aspect/issues/3604 , we might end up in an infinite loop while trying to prepare refinement flags in parallel::distributed::Triangulation::prepare_coarsening_and_refinement(). Add a check and abort (instead of a hang). --- source/distributed/tria.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index f0f395dde4..40c3148bce 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -3438,7 +3438,8 @@ namespace parallel this->save_coarsen_flags(flags_before[0]); this->save_refine_flags(flags_before[1]); - bool mesh_changed = false; + bool mesh_changed = false; + unsigned int loop_counter = 0; do { this->dealii::Triangulation:: @@ -3446,6 +3447,17 @@ namespace parallel this->update_periodic_face_map(); // enforce 2:1 mesh balance over periodic boundaries mesh_changed = enforce_mesh_balance_over_periodic_boundaries(*this); + + // We can't be sure that we won't run into a situation where we can + // not reconcile mesh smoothing and balancing of periodic faces. As we + // don't know what else to do, at least abort with an error message. + ++loop_counter; + AssertThrow( + loop_counter < 32, + ExcMessage( + "Infinite loop in " + "parallel::distributed::Triangulation::prepare_coarsening_and_refinement() " + "for periodic boundaries detected. Aborting.")); } while (mesh_changed); -- 2.39.5