From 5ea75f8a95a2b95dfe79d649f8761ee2542576e3 Mon Sep 17 00:00:00 2001
From: Henry Weller <http://openfoam.org>
Date: Fri, 1 Dec 2017 11:01:30 +0000
Subject: [PATCH] ENH: blockMesh: Added support for automatically reordering
 cyclic patches

Patch contributed by Mattijs Janssens
Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1692
---
 .../mesh/generation/blockMesh/blockMesh.C     | 30 +++++++++++++++++--
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/applications/utilities/mesh/generation/blockMesh/blockMesh.C b/applications/utilities/mesh/generation/blockMesh/blockMesh.C
index 2e112570a1c..41e03bde293 100644
--- a/applications/utilities/mesh/generation/blockMesh/blockMesh.C
+++ b/applications/utilities/mesh/generation/blockMesh/blockMesh.C
@@ -60,7 +60,9 @@ Usage
 
 #include "blockMesh.H"
 #include "attachPolyTopoChanger.H"
+#include "polyTopoChange.H"
 #include "emptyPolyPatch.H"
+#include "cyclicPolyPatch.H"
 #include "cellSet.H"
 
 #include "argList.H"
@@ -381,6 +383,30 @@ int main(int argc, char *argv[])
         mesh.addZones(List<pointZone*>(0), List<faceZone*>(0), cz);
     }
 
+
+    // Detect any cyclic patches and force re-ordering of the faces
+    {
+        const polyPatchList& patches = mesh.boundaryMesh();
+        bool hasCyclic = false;
+        forAll(patches, patchi)
+        {
+            if (isA<cyclicPolyPatch>(patches[patchi]))
+            {
+                hasCyclic = true;
+                break;
+            }
+        }
+
+        if (hasCyclic)
+        {
+            Info<< nl << "Detected cyclic patches; ordering boundary faces"
+                << endl;
+            polyTopoChange meshMod(mesh);
+            meshMod.changeMesh(mesh, false);
+        }
+    }
+
+
     // Set the precision of the points data to 10
     IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision()));
 
@@ -409,9 +435,7 @@ int main(int argc, char *argv[])
         }
     }
 
-    //
-    // write some information
-    //
+    // Write summary
     {
         const polyPatchList& patches = mesh.boundaryMesh();
 
-- 
GitLab