From 3d88003e77fa2b6df40eb62b44b7a6ae045fd7a2 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Thu, 30 Apr 2009 20:31:13 +0100
Subject: [PATCH] order of creation consistent with cyclics

---
 .../createBaffles/createBaffles.C             | 349 +++++++++---------
 1 file changed, 166 insertions(+), 183 deletions(-)

diff --git a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
index 051f74968be..c802049f83c 100644
--- a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
+++ b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
@@ -48,157 +48,6 @@ using namespace Foam;
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-void createBaffles
-(
-    const polyMesh& mesh,
-    const label faceI,
-    const label oldPatchI,
-    const labelList& newPatches,
-    PackedBoolList& doneFace,
-    polyTopoChange& meshMod
-)
-{
-    const polyBoundaryMesh& patches = mesh.boundaryMesh();
-    const faceZoneMesh& faceZones = mesh.faceZones();
-
-    const face& f = mesh.faces()[faceI];
-    label zoneID = faceZones.whichZone(faceI);
-    bool zoneFlip = false;
-    if (zoneID >= 0)
-    {
-        const faceZone& fZone = faceZones[zoneID];
-        zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
-    }
-    label nei = -1;
-    if (oldPatchI == -1)
-    {
-        nei = mesh.faceNeighbour()[faceI];
-    }
-
-
-    face revFace(f.reverseFace());
-
-    forAll(newPatches, i)
-    {
-        if (oldPatchI == -1)
-        {
-            // Internal face
-            if (doneFace.set(faceI))
-            {
-                // First usage of face. Modify.
-                meshMod.setAction
-                (
-                    polyModifyFace
-                    (
-                        f,                          // modified face
-                        faceI,                      // label of face
-                        mesh.faceOwner()[faceI],    // owner
-                        -1,                         // neighbour
-                        false,                      // face flip
-                        newPatches[i],              // patch for face
-                        false,                      // remove from zone
-                        zoneID,                     // zone for face
-                        zoneFlip                    // face flip in zone
-                    )
-                );
-            }
-            else
-            {
-                // Second or more usage of face. Add.
-                meshMod.setAction
-                (
-                    polyAddFace
-                    (
-                        f,                          // modified face
-                        mesh.faceOwner()[faceI],    // owner
-                        -1,                         // neighbour
-                        -1,                         // master point
-                        -1,                         // master edge
-                        faceI,                      // master face
-                        false,                      // face flip
-                        newPatches[i],              // patch for face
-                        zoneID,                     // zone for face
-                        zoneFlip                    // face flip in zone
-                    )
-                );
-            }
-
-            meshMod.setAction
-            (
-                polyAddFace
-                (
-                    revFace,                    // modified face
-                    nei,                        // owner
-                    -1,                         // neighbour
-                    -1,                         // masterPointID
-                    -1,                         // masterEdgeID
-                    faceI,                      // masterFaceID,
-                    true,                       // face flip
-                    newPatches[i],              // patch for face
-                    zoneID,                     // zone for face
-                    zoneFlip                    // face flip in zone
-                )
-            );
-        }
-        else if
-        (
-            patches[oldPatchI].coupled()
-         && patches[newPatches[i]].coupled()
-        )
-        {
-            // Do not allow coupled patches to be moved to different coupled
-            // patches.
-            //WarningIn("createBaffles()")
-            //    << "Not moving face from coupled patch "
-            //    << patches[oldPatchI].name()
-            //    << " to another coupled patch " << patches[newPatches[i]]
-            //    << endl;
-        }
-        else
-        {
-            if (doneFace.set(faceI))
-            {
-                meshMod.setAction
-                (
-                    polyModifyFace
-                    (
-                        f,                          // modified face
-                        faceI,                      // label of face
-                        mesh.faceOwner()[faceI],    // owner
-                        -1,                         // neighbour
-                        false,                      // face flip
-                        newPatches[i],              // patch for face
-                        false,                      // remove from zone
-                        zoneID,                     // zone for face
-                        zoneFlip                    // face flip in zone
-                    )
-                );
-            }
-            else
-            {
-                meshMod.setAction
-                (
-                    polyAddFace
-                    (
-                        f,                          // modified face
-                        mesh.faceOwner()[faceI],    // owner
-                        -1,                         // neighbour
-                        -1,                         // master point
-                        -1,                         // master edge
-                        faceI,                      // master face
-                        false,                      // face flip
-                        newPatches[i],              // patch for face
-                        zoneID,                     // zone for face
-                        zoneFlip                    // face flip in zone
-                    )
-                );
-            }
-        }
-    }
-}
-
-
-
 // Main program:
 
 int main(int argc, char *argv[])
@@ -215,15 +64,16 @@ int main(int argc, char *argv[])
     const word oldInstance = mesh.pointsInstance();
 
     const polyBoundaryMesh& patches = mesh.boundaryMesh();
+    const faceZoneMesh& faceZones = mesh.faceZones();
 
     // Faces to baffle
     word setName(args.additionalArgs()[0]);
-    Pout<< "Reading faceSet from " << setName << nl << endl;
+    Info<< "Reading faceSet from " << setName << nl << endl;
     faceSet facesToSplit(mesh, setName);
     // Make sure set is synchronised across couples
     facesToSplit.sync(mesh);
-    Pout<< "Read " << facesToSplit.size() << " faces from " << setName
-        << nl << endl;
+    Info<< "Read " << returnReduce(facesToSplit.size(), sumOp<label>())
+        << " faces from " << setName << nl << endl;
 
 
     // Patches to put baffles into
@@ -231,7 +81,7 @@ int main(int argc, char *argv[])
 
     word patchName(args.additionalArgs()[1]);
     newPatches[0] = patches.findPatchID(patchName);
-    Pout<< "Using patch " << patchName
+    Info<< "Using patch " << patchName
         << " at index " << newPatches[0] << endl;
 
     if (newPatches[0] == -1)
@@ -316,48 +166,181 @@ int main(int argc, char *argv[])
 
 
     // Do the actual changes
+    // Note order in which faces are modified/added is so they end up correctly
+    // for cyclic patches (original faces first and then reversed faces)
+    // since otherwise it will have trouble matching baffles.
 
     label nBaffled = 0;
-    PackedBoolList doneFace(mesh.nFaces());
-
-    for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
+ 
+    forAll(newPatches, i)
     {
-        if (facesToSplit.found(faceI))
+        label newPatchI = newPatches[i];
+
+        for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
         {
-            createBaffles
-            (
-                mesh,
-                faceI,
-                -1,                             // oldPatchI,
-                newPatches,
-                doneFace,
-                meshMod
-            );
-            nBaffled++;
+            if (facesToSplit.found(faceI))
+            {
+                const face& f = mesh.faces()[faceI];
+                label zoneID = faceZones.whichZone(faceI);
+                bool zoneFlip = false;
+                if (zoneID >= 0)
+                {
+                    const faceZone& fZone = faceZones[zoneID];
+                    zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
+                }
+
+                if (i == 0)
+                {
+                    // First usage of face. Modify.
+                    meshMod.setAction
+                    (
+                        polyModifyFace
+                        (
+                            f,                          // modified face
+                            faceI,                      // label of face
+                            mesh.faceOwner()[faceI],    // owner
+                            -1,                         // neighbour
+                            false,                      // face flip
+                            newPatchI,                  // patch for face
+                            false,                      // remove from zone
+                            zoneID,                     // zone for face
+                            zoneFlip                    // face flip in zone
+                        )
+                    );
+                }
+                else
+                {
+                    // Second or more usage of face. Add.
+                    meshMod.setAction
+                    (
+                        polyAddFace
+                        (
+                            f,                          // modified face
+                            mesh.faceOwner()[faceI],    // owner
+                            -1,                         // neighbour
+                            -1,                         // master point
+                            -1,                         // master edge
+                            faceI,                      // master face
+                            false,                      // face flip
+                            newPatchI,                  // patch for face
+                            zoneID,                     // zone for face
+                            zoneFlip                    // face flip in zone
+                        )
+                    );
+                }
+
+                nBaffled++;
+            }
         }
-    }
-    forAll(patches, patchI)
-    {
-        const polyPatch& pp = patches[patchI];
 
-        forAll(pp, i)
+        // Add the reversed face.
+        for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
         {
-            label faceI = pp.start()+i;
-
             if (facesToSplit.found(faceI))
             {
-                createBaffles
+                const face& f = mesh.faces()[faceI];
+                label zoneID = faceZones.whichZone(faceI);
+                bool zoneFlip = false;
+                if (zoneID >= 0)
+                {
+                    const faceZone& fZone = faceZones[zoneID];
+                    zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
+                }
+                label nei = mesh.faceNeighbour()[faceI];
+
+                meshMod.setAction
                 (
-                    mesh,
-                    faceI,
-                    patchI,                     // oldPatchI,
-                    newPatches,
-                    doneFace,
-                    meshMod
+                    polyAddFace
+                    (
+                        f.reverseFace(),            // modified face
+                        nei,                        // owner
+                        -1,                         // neighbour
+                        -1,                         // masterPointID
+                        -1,                         // masterEdgeID
+                        faceI,                      // masterFaceID,
+                        true,                       // face flip
+                        newPatchI,                  // patch for face
+                        zoneID,                     // zone for face
+                        zoneFlip                    // face flip in zone
+                    )
                 );
+
                 nBaffled++;
             }
         }
+
+        // Modify any boundary faces
+        forAll(patches, patchI)
+        {
+            const polyPatch& pp = patches[patchI];
+
+            if (patches[newPatchI].coupled() && pp.coupled())
+            {
+                // Do not allow coupled faces to be moved to different coupled
+                // patches.
+            }
+            else
+            {
+                forAll(pp, i)
+                {
+                    label faceI = pp.start()+i;
+
+                    if (facesToSplit.found(faceI))
+                    {
+                        const face& f = mesh.faces()[faceI];
+                        label zoneID = faceZones.whichZone(faceI);
+                        bool zoneFlip = false;
+                        if (zoneID >= 0)
+                        {
+                            const faceZone& fZone = faceZones[zoneID];
+                            zoneFlip = fZone.flipMap()[fZone.whichFace(faceI)];
+                        }
+
+                        if (i == 0)
+                        {
+                            // First usage of face. Modify.
+                            meshMod.setAction
+                            (
+                                polyModifyFace
+                                (
+                                    f,                      // modified face
+                                    faceI,                  // label of face
+                                    mesh.faceOwner()[faceI],// owner
+                                    -1,                     // neighbour
+                                    false,                  // face flip
+                                    newPatchI,              // patch for face
+                                    false,                  // remove from zone
+                                    zoneID,                 // zone for face
+                                    zoneFlip                // face flip in zone
+                                )
+                            );
+                        }
+                        else
+                        {
+                            // Second or more usage of face. Add.
+                            meshMod.setAction
+                            (
+                                polyAddFace
+                                (
+                                    f,                      // modified face
+                                    mesh.faceOwner()[faceI],// owner
+                                    -1,                     // neighbour
+                                    -1,                     // master point
+                                    -1,                     // master edge
+                                    faceI,                  // master face
+                                    false,                  // face flip
+                                    newPatchI,              // patch for face
+                                    zoneID,                 // zone for face
+                                    zoneFlip                // face flip in zone
+                                )
+                            );
+                        }
+
+                        nBaffled++;
+                    }
+                }
+            }
+        }
     }
 
 
-- 
GitLab