From: Peter Munch <peterrmuench@gmail.com>
Date: Mon, 31 Jul 2023 13:55:14 +0000 (+0200)
Subject: GT::vertex_to_cell_map(): check if tria has hn
X-Git-Tag: relicensing~632^2
X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4aceda49b3791821afc04468cf4f3aee5da3859b;p=dealii.git

GT::vertex_to_cell_map(): check if tria has hn
---

diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc
index 6d84bbd0ed..75d416c694 100644
--- a/source/grid/grid_tools.cc
+++ b/source/grid/grid_tools.cc
@@ -3423,33 +3423,42 @@ namespace GridTools
       for (const unsigned int i : cell->vertex_indices())
         vertex_to_cell_map[cell->vertex_index(i)].insert(cell);
 
-    // Take care of hanging nodes
-    cell = triangulation.begin_active();
-    for (; cell != endc; ++cell)
+    // Check if mesh has hanging nodes. Do this only locally to
+    // prevent communication and possible deadlock.
+    if (triangulation.Triangulation<dim, spacedim>::has_hanging_nodes())
       {
-        for (const unsigned int i : cell->face_indices())
+        Assert(triangulation.all_reference_cells_are_hyper_cube(),
+               ExcNotImplemented());
+
+        // Take care of hanging nodes
+        cell = triangulation.begin_active();
+        for (; cell != endc; ++cell)
           {
-            if ((cell->at_boundary(i) == false) &&
-                (cell->neighbor(i)->is_active()))
+            for (const unsigned int i : cell->face_indices())
               {
-                typename Triangulation<dim, spacedim>::active_cell_iterator
-                  adjacent_cell = cell->neighbor(i);
-                for (unsigned int j = 0; j < cell->face(i)->n_vertices(); ++j)
-                  vertex_to_cell_map[cell->face(i)->vertex_index(j)].insert(
-                    adjacent_cell);
+                if ((cell->at_boundary(i) == false) &&
+                    (cell->neighbor(i)->is_active()))
+                  {
+                    typename Triangulation<dim, spacedim>::active_cell_iterator
+                      adjacent_cell = cell->neighbor(i);
+                    for (unsigned int j = 0; j < cell->face(i)->n_vertices();
+                         ++j)
+                      vertex_to_cell_map[cell->face(i)->vertex_index(j)].insert(
+                        adjacent_cell);
+                  }
               }
-          }
 
-        // in 3d also loop over the edges
-        if (dim == 3)
-          {
-            for (unsigned int i = 0; i < cell->n_lines(); ++i)
-              if (cell->line(i)->has_children())
-                // the only place where this vertex could have been
-                // hiding is on the mid-edge point of the edge we
-                // are looking at
-                vertex_to_cell_map[cell->line(i)->child(0)->vertex_index(1)]
-                  .insert(cell);
+            // in 3d also loop over the edges
+            if (dim == 3)
+              {
+                for (unsigned int i = 0; i < cell->n_lines(); ++i)
+                  if (cell->line(i)->has_children())
+                    // the only place where this vertex could have been
+                    // hiding is on the mid-edge point of the edge we
+                    // are looking at
+                    vertex_to_cell_map[cell->line(i)->child(0)->vertex_index(1)]
+                      .insert(cell);
+              }
           }
       }