From f97f715f667d14e6c99e7094935999cbe26f0a6e Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Wed, 17 Jul 2024 09:14:02 +0100
Subject: [PATCH] ENH: shm: parallel consistency. See #2331

---
 .../polyTopoChange/hexRef8/hexRef8.C          | 47 +++++++++++++------
 .../meshRefinement/meshRefinement.C           | 39 ++-------------
 2 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C
index cd1b62ad59f..73501db8cf9 100644
--- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C
+++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C
@@ -2443,26 +2443,45 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement
     // Seed all boundary faces with owner value. This is to make sure that
     // they are visited (probably only important for coupled faces since
     // these need to be visited from both sides)
+    List<refinementData> nbrCellInfo;
+    syncTools::swapBoundaryCellList(mesh_, allCellInfo, nbrCellInfo);
+
     for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); facei++)
     {
         // Check if face already handled in loop above
         if (!allFaceInfo[facei].valid(dummyTrackData))
         {
-            label own = faceOwner[facei];
+            const label own = faceOwner[facei];
+            const auto& nbrInfo = nbrCellInfo[facei-mesh_.nInternalFaces()];
 
-            // Seed face with transported data from owner.
-            refinementData faceData;
-            faceData.updateFace
-            (
-                mesh_,
-                facei,
-                own,
-                allCellInfo[own],
-                FaceCellWave<refinementData, int>::propagationTol(),
-                dummyTrackData
-            );
-            seedFaces.append(facei);
-            seedFacesInfo.append(faceData);
+            if (allCellInfo[own].count() > nbrInfo.count())
+            {
+                allFaceInfo[facei].updateFace
+                (
+                    mesh_,
+                    facei,
+                    own,
+                    allCellInfo[own],
+                    FaceCellWave<refinementData, int>::propagationTol(),
+                    dummyTrackData
+                );
+                seedFaces.append(facei);
+                seedFacesInfo.append(allFaceInfo[facei]);
+            }
+            else if (allCellInfo[own].count() < nbrInfo.count())
+            {
+                allFaceInfo[facei].updateFace
+                (
+                    mesh_,
+                    facei,
+                    -1,         // Lucky! neighbCelli not used!
+                    nbrInfo,
+                    FaceCellWave<refinementData, int>::propagationTol(),
+                    dummyTrackData
+                );
+                seedFaces.append(facei);
+                seedFacesInfo.append(allFaceInfo[facei]);
+            }
         }
     }
 
diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
index 130845c1961..6838f904db6 100644
--- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
+++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C
@@ -2054,7 +2054,6 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
 
     // Mark all points on faces that will become baffles
     bitSet isBoundaryPoint(mesh_.nPoints());
-    label nBoundaryPoints = 0;
 
     const labelList& surfIndex = surfaceIndex();
 
@@ -2062,15 +2061,7 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
     {
         if (surfIndex[facei] != -1)
         {
-            const face& f = faces[facei];
-
-            forAll(f, fp)
-            {
-                if (isBoundaryPoint.set(f[fp]))
-                {
-                    nBoundaryPoints++;
-                }
-            }
+            isBoundaryPoint.set(faces[facei]);
         }
     }
 
@@ -2083,37 +2074,17 @@ Foam::labelList Foam::meshRefinement::intersectedPoints() const
     //    if (patchi != -1)
     //    {
     //        const polyPatch& pp = mesh_.boundaryMesh()[patchi];
-    //
-    //        label facei = pp.start();
-    //
     //        forAll(pp, i)
     //        {
-    //            const face& f = faces[facei];
-    //
-    //            forAll(f, fp)
-    //            {
-    //                if (isBoundaryPoint.set(f[fp]))
-    //                    nBoundaryPoints++;
-    //                }
-    //            }
-    //            facei++;
+    //            isBoundaryPoint.set(faces[pp.start()+i]);
     //        }
     //    }
     //}
 
+    // Make sure all processors have the same data
+    syncTools::syncPointList(mesh_, isBoundaryPoint, orEqOp<unsigned int>(), 0);
 
-    // Pack
-    labelList boundaryPoints(nBoundaryPoints);
-    nBoundaryPoints = 0;
-    forAll(isBoundaryPoint, pointi)
-    {
-        if (isBoundaryPoint.test(pointi))
-        {
-            boundaryPoints[nBoundaryPoints++] = pointi;
-        }
-    }
-
-    return boundaryPoints;
+    return isBoundaryPoint.sortedToc();
 }
 
 
-- 
GitLab