From d5fd97d991540824584227a76e1b7b4e8936bfb9 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 1 Sep 2021 08:29:32 +0100
Subject: [PATCH] ENH: createPatch: check for overlapping patches. Fixes #2193

---
 .../manipulation/createPatch/createPatch.C    | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C
index 19f3603e185..888281fb13a 100644
--- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C
+++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C
@@ -656,6 +656,9 @@ int main(int argc, char *argv[])
 
     polyTopoChange meshMod(mesh);
 
+    // Mark all repatched faces. This makes sure that the faces to repatch
+    // do not overlap
+    bitSet isRepatchedBoundary(mesh.nBoundaryFaces());
 
     for (const dictionary& dict : patchSources)
     {
@@ -695,6 +698,15 @@ int main(int argc, char *argv[])
                         destPatchi,
                         meshMod
                     );
+
+                    if (!isRepatchedBoundary.set(pp.offset()+i))
+                    {
+                        FatalErrorInFunction
+                            << "Face " << pp.start() + i << " from patch "
+                            << pp.name() << " is already marked to be moved"
+                            << " to patch " << meshMod.region()[pp.start() + i]
+                            << exit(FatalError);
+                    }
                 }
             }
         }
@@ -722,6 +734,15 @@ int main(int argc, char *argv[])
                         << " faces." << exit(FatalError);
                 }
 
+                if (!isRepatchedBoundary.set(facei-mesh.nInternalFaces()))
+                {
+                    FatalErrorInFunction
+                        << "Face " << facei << " from set "
+                        << set.name() << " is already marked to be moved"
+                        << " to patch " << meshMod.region()[facei]
+                        << exit(FatalError);
+                }
+
                 changePatchID
                 (
                     mesh,
-- 
GitLab