From 0832014a493b8b067dfc18f1d6e774503fa56162 Mon Sep 17 00:00:00 2001
From: laurence <laurence>
Date: Wed, 12 Dec 2012 16:31:08 +0000
Subject: [PATCH] BUG: cvMesh: parallel redistribution

Redistribute reinserted feature points
Synchronise after distributing the background meshes in the constructor
---
 .../conformalVoronoiMesh.C                    | 115 ++++++++++--------
 .../conformalVoronoiMesh.H                    |   3 +
 .../conformalVoronoiMeshIO.C                  |   2 +-
 3 files changed, 69 insertions(+), 51 deletions(-)

diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C
index 8f229fdbc14..5c43329acfb 100644
--- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C
+++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C
@@ -47,6 +47,52 @@ const Foam::scalar Foam::conformalVoronoiMesh::tolParallel = 1e-3;
 
 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
 
+void Foam::conformalVoronoiMesh::cellSizeMeshOverlapsBackground() const
+{
+    const cellShapeControlMesh& cellSizeMesh =
+        cellShapeControl_.shapeControlMesh();
+
+    DynamicList<Foam::point> pts(number_of_vertices());
+
+    for
+    (
+        Delaunay::Finite_vertices_iterator vit = finite_vertices_begin();
+        vit != finite_vertices_end();
+        ++vit
+    )
+    {
+        if (vit->internalOrBoundaryPoint())
+        {
+            pts.append(topoint(vit->point()));
+        }
+    }
+
+    boundBox bb(pts);
+
+    boundBox cellSizeMeshBb = cellSizeMesh.bounds();
+
+    bool fullyContained = true;
+
+    if (!cellSizeMeshBb.contains(bb))
+    {
+        Pout<< "Triangulation not fully contained in cell size mesh."
+            << endl;
+
+        Pout<< "Cell Size Mesh Bounds = " << cellSizeMesh.bounds() << endl;
+        Pout<< "cvMesh Bounds         = " << bb << endl;
+
+        fullyContained = false;
+    }
+
+    reduce(fullyContained, andOp<unsigned int>());
+
+    Info<< "Triangulation is "
+        << (fullyContained ? "fully" : "not fully")
+        << " contained in the cell size mesh"
+        << endl;
+}
+
+
 Foam::scalar Foam::conformalVoronoiMesh::requiredSize
 (
     const Foam::point& pt
@@ -841,8 +887,6 @@ void Foam::conformalVoronoiMesh::buildCellSizeAndAlignmentMesh()
         label nAdded = cellShapeControl_.refineMesh(decomposition_);
         reduce(nAdded, sumOp<label>());
 
-//        label nRemoved = cellShapeControl_.shapeControlMesh().removePoints();
-
         if (Pstream::parRun())
         {
             cellSizeMesh.distribute(decomposition_);
@@ -1040,7 +1084,7 @@ void Foam::conformalVoronoiMesh::setVertexSizeAndAlignment()
                 vit->alignment()
             );
 
-//            vit->alignment() = tensor(1,0,0,0,1,0,0,0,1);
+            //vit->alignment() = tensor(1,0,0,0,1,0,0,0,1);
             //vit->alignment() = requiredAlignment(pt);
 
             //vit->targetCellSize() = cellShapeControls().cellSize(pt);
@@ -1068,7 +1112,11 @@ Foam::face Foam::conformalVoronoiMesh::buildDualFace
 
     do
     {
-        if (cc1->hasFarPoint() || cc2->hasFarPoint())
+        if
+        (
+            cc1->hasFarPoint() || cc2->hasFarPoint()
+         || is_infinite(cc1) || is_infinite(cc2)
+        )
         {
             Cell_handle c = eit->first;
             Vertex_handle vA = c->vertex(eit->second);
@@ -1352,51 +1400,7 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh
 
     setVertexSizeAndAlignment();
 
-    // Test for full containment
-    {
-        cellShapeControlMesh& cellSizeMesh =
-            cellShapeControl_.shapeControlMesh();
-
-        DynamicList<Foam::point> pts(number_of_vertices());
-
-        for
-        (
-            Delaunay::Finite_vertices_iterator vit = finite_vertices_begin();
-            vit != finite_vertices_end();
-            ++vit
-        )
-        {
-            if (vit->internalOrBoundaryPoint())
-            {
-                pts.append(topoint(vit->point()));
-            }
-        }
-
-        boundBox bb(pts);
-
-        boundBox cellSizeMeshBb = cellSizeMesh.bounds();
-
-        bool fullyContained = true;
-
-        if (!cellSizeMeshBb.contains(bb))
-        {
-            Pout<< "Triangulation not fully contained in cell size mesh."
-                << endl;
-
-            Pout<< "Cell Size Mesh Bounds = " << cellSizeMesh.bounds() << endl;
-            Pout<< "cvMesh Bounds         = " << bb << endl;
-
-            fullyContained = false;
-        }
-
-        reduce(fullyContained, andOp<unsigned int>());
-
-        Info<< "Triangulation is "
-            << (fullyContained ? "fully" : "not fully")
-            << " contained in the cell size mesh"
-            << endl;
-    }
-
+    cellSizeMeshOverlapsBackground();
 
     // Improve the guess that the backgroundMeshDecomposition makes with the
     // initial positions.  Use before building the surface conformation to
@@ -1409,6 +1413,11 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh
     // balance of vertices, distribute if necessary.
     distributeBackground();
 
+    if (Pstream::parRun())
+    {
+        sync(decomposition_().procBounds());
+    }
+
     // Do not store the surface conformation until after it has been
     // (potentially) redistributed.
     storeSurfaceConformation();
@@ -1421,6 +1430,8 @@ Foam::conformalVoronoiMesh::conformalVoronoiMesh
     // domain the processor they are on.
     // reportProcessorOccupancy();
 
+    cellSizeMeshOverlapsBackground();
+
     printVertexInfo();
 
     if (cvMeshControls().objOutput())
@@ -1656,6 +1667,10 @@ void Foam::conformalVoronoiMesh::move()
 
                     face dualFace = buildDualFace(eit);
 
+//                    Pout<< dualFace << endl;
+//                    Pout<< "    " << vA->info() << endl;
+//                    Pout<< "    " << vB->info() << endl;
+
                     const scalar faceArea = dualFace.mag(dualVertices);
 
                     // Update delta vector
@@ -1892,7 +1907,7 @@ void Foam::conformalVoronoiMesh::move()
 
     insertInternalPoints(pointsToInsert, true);
 
-    reinsertFeaturePoints(false);
+    reinsertFeaturePoints(true);
 
     // Remove internal points that have been inserted outside the surface.
 //    label internalPtIsOutside = 0;
diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H
index 7ff0e64170c..bf64f6196c4 100644
--- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H
+++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H
@@ -504,6 +504,9 @@ private:
         //  referred vertices, so the parallel interface may need rebuilt.
         bool distributeBackground();
 
+        // Test for full containment
+        void cellSizeMeshOverlapsBackground() const;
+
         //-
         void distribute();
 
diff --git a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C
index f21ef34adc6..e35a711148f 100644
--- a/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C
+++ b/applications/utilities/mesh/generation/cvMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C
@@ -414,7 +414,7 @@ void Foam::conformalVoronoiMesh::writeProcessorInterface
         ++cit
     )
     {
-        if (!cit->hasFarPoint())
+        if (!cit->hasFarPoint() && !is_infinite(cit))
         {
             points[cit->cellIndex()] = cit->dual();
         }
-- 
GitLab