From 93aa05103fef4964d58271163bdddcba09f0787f Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 4 Dec 2012 10:43:46 +0000
Subject: [PATCH] BUG: fvMeshTools: append, not insert, processor patches

---
 .../fvMeshDistribute/fvMeshDistribute.C        |  6 ++++--
 src/dynamicMesh/fvMeshTools/fvMeshTools.C      | 18 +++++++++++-------
 src/dynamicMesh/fvMeshTools/fvMeshTools.H      |  6 +++---
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
index 7fe993522a7..e4794b634b5 100644
--- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
+++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C
@@ -945,6 +945,7 @@ void Foam::fvMeshDistribute::addProcPatches
                         Pstream::myProcNo(),
                         nbrProc[bFaceI]
                     );
+
                     procPatchID[procI].insert
                     (
                         referPatchID[bFaceI],
@@ -952,9 +953,9 @@ void Foam::fvMeshDistribute::addProcPatches
                         (
                             mesh_,
                             pp,
-                            dictionary(),
+                            dictionary(),   // optional per field patchField
                             processorFvPatchField<scalar>::typeName,
-                            false       // not parallel sync
+                            false           // not parallel sync
                         )
                     );
                 }
@@ -985,6 +986,7 @@ void Foam::fvMeshDistribute::addProcPatches
                         nbrProc[bFaceI],
                         cycName
                     );
+
                     procPatchID[procI].insert
                     (
                         referPatchID[bFaceI],
diff --git a/src/dynamicMesh/fvMeshTools/fvMeshTools.C b/src/dynamicMesh/fvMeshTools/fvMeshTools.C
index 08d3cdc014b..682a96422e7 100644
--- a/src/dynamicMesh/fvMeshTools/fvMeshTools.C
+++ b/src/dynamicMesh/fvMeshTools/fvMeshTools.C
@@ -48,18 +48,22 @@ Foam::label Foam::fvMeshTools::addPatch
     }
 
 
+    // Append at end unless there are processor patches
     label insertPatchI = polyPatches.size();
     label startFaceI = mesh.nFaces();
 
-    forAll(polyPatches, patchI)
+    if (!isA<processorPolyPatch>(patch))
     {
-        const polyPatch& pp = polyPatches[patchI];
-
-        if (isA<processorPolyPatch>(pp))
+        forAll(polyPatches, patchI)
         {
-            insertPatchI = patchI;
-            startFaceI = pp.start();
-            break;
+            const polyPatch& pp = polyPatches[patchI];
+
+            if (isA<processorPolyPatch>(pp))
+            {
+                insertPatchI = patchI;
+                startFaceI = pp.start();
+                break;
+            }
         }
     }
 
diff --git a/src/dynamicMesh/fvMeshTools/fvMeshTools.H b/src/dynamicMesh/fvMeshTools/fvMeshTools.H
index a5d443fffda..0e7e132d9c1 100644
--- a/src/dynamicMesh/fvMeshTools/fvMeshTools.H
+++ b/src/dynamicMesh/fvMeshTools/fvMeshTools.H
@@ -36,7 +36,6 @@ SourceFiles
 #define fvMeshTools_H
 
 #include "fvMesh.H"
-//#include "HashSet.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -89,9 +88,10 @@ class fvMeshTools
 
 public:
 
-    //- Add patch. Supply per field the new patchField per field as a
+    //- Add patch. Inserts patch before all processor patches.
+    //  Supply per field the new patchField per field as a
     //  subdictionary or a default type. If validBoundary call is parallel
-    //  synced and all add the same patch with same settings
+    //  synced and all add the same patch with same settings.
     static label addPatch
     (
         fvMesh& mesh,
-- 
GitLab