From 6d98049f5094016692a66e5269da37df848d8d01 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 12 Jul 2019 13:29:20 +0200
Subject: [PATCH] BUG: incorrect blocked face synchronisation crashes
 regionSplit (#1370)

- now catch these and emit a warning.
  Still need to investigate the root cause in the caller(s) or regionSplit.
---
 src/meshTools/regionSplit/regionSplit.C | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/meshTools/regionSplit/regionSplit.C b/src/meshTools/regionSplit/regionSplit.C
index 47056b2092..71a98de02d 100644
--- a/src/meshTools/regionSplit/regionSplit.C
+++ b/src/meshTools/regionSplit/regionSplit.C
@@ -532,6 +532,8 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::reduceRegions
     // Buffer for swapping boundary information
     labelList nbrRegion(mesh().nBoundaryFaces());
 
+    bool emitWarning = true;
+
     do
     {
         if (debug)
@@ -597,9 +599,22 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::reduceRegions
                         const label sent = localToGlobal[orig];
                         const label recv = patchNbrRegion[patchFacei];
 
-                        // Record the minimum value seen
-                        if (recv < sent)
+                        if (recv == UNASSIGNED)
+                        {
+                            if (emitWarning)
+                            {
+                                Pout<<"Warning in regionSplit:"
+                                    " received unassigned on "
+                                    << pp.name() << " at patchFace "
+                                    << patchFacei
+                                    << ". Check synchronisation in caller"
+                                    << nl;
+                            }
+                        }
+                        else if (recv < sent)
                         {
+                            // Record the minimum value seen
+
                             auto fnd = updateLookup.find(sent);
                             if (!fnd.found())
                             {
@@ -644,6 +659,7 @@ Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::reduceRegions
                 << " local regions" << endl;
         }
 
+        emitWarning = false;
         // Continue until there are no further changes
     }
     while (returnReduce(!updateLookup.empty(), orOp<bool>()));
-- 
GitLab