From ae41b74b57aad35c56c6d2f7bd2f4b91e9d1034b Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Mon, 18 Nov 2013 10:48:17 +0000
Subject: [PATCH] ENH: motionSmoother: encapsulate point calculation like
 motionSolver

---
 .../motionSmoother/motionSmoother.C           | 151 +++++++++++-------
 .../motionSmoother/motionSmoother.H           |  15 +-
 .../autoHexMeshDriver/autoLayerDriver.C       |   4 +-
 .../autoHexMeshDriver/autoLayerDriver.H       |   5 +-
 .../autoHexMeshDriver/autoLayerDriverShrink.C |  23 ++-
 5 files changed, 117 insertions(+), 81 deletions(-)

diff --git a/src/dynamicMesh/motionSmoother/motionSmoother.C b/src/dynamicMesh/motionSmoother/motionSmoother.C
index 3e87fbd7d51..1375099a4b8 100644
--- a/src/dynamicMesh/motionSmoother/motionSmoother.C
+++ b/src/dynamicMesh/motionSmoother/motionSmoother.C
@@ -872,10 +872,8 @@ void Foam::motionSmoother::correctBoundaryConditions
 }
 
 
-Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
-(
-    pointField& newPoints
-)
+
+void Foam::motionSmoother::modifyMotionPoints(pointField& newPoints) const
 {
     // Correct for 2-D motion
     if (twoDCorrector_.required())
@@ -892,8 +890,8 @@ Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
         const pointField& oldPoints = mesh_.points();
         const edgeList& edges = mesh_.edges();
 
-        const labelList& neIndices = twoDCorrector().normalEdgeIndices();
-        const vector& pn = twoDCorrector().planeNormal();
+        const labelList& neIndices = twoDCorrector_.normalEdgeIndices();
+        const vector& pn = twoDCorrector_.planeNormal();
 
         forAll(neIndices, i)
         {
@@ -915,19 +913,19 @@ Foam::tmp<Foam::scalarField> Foam::motionSmoother::movePoints
 
     if (debug)
     {
-        Pout<< "motionSmoother::movePoints : testing sync of newPoints."
+        Pout<< "motionSmoother::modifyMotionPoints : testing sync of newPoints."
             << endl;
         testSyncPositions(newPoints, 1e-6*mesh_.bounds().mag());
     }
+}
 
-    // Move actual mesh points. Make sure to delete tetBasePtIs so it
-    // gets rebuilt.
-    mesh_.clearAdditionalGeom();
-    tmp<scalarField> tsweptVol = mesh_.movePoints(newPoints);
 
+void Foam::motionSmoother::movePoints()
+{
+    // Make sure to clear out tetPtIs since used in checks (sometimes, should
+    // really check)
+    mesh_.clearAdditionalGeom();
     pp_.movePoints(mesh_.points());
-
-    return tsweptVol;
 }
 
 
@@ -983,6 +981,79 @@ bool Foam::motionSmoother::scaleMesh
 }
 
 
+Foam::tmp<Foam::pointField> Foam::motionSmoother::curPoints() const
+{
+    // Set newPoints as old + scale*displacement
+
+    // Create overall displacement with same b.c.s as displacement_
+    wordList actualPatchTypes;
+    {
+        const pointBoundaryMesh& pbm = displacement_.mesh().boundary();
+        actualPatchTypes.setSize(pbm.size());
+        forAll(pbm, patchI)
+        {
+            actualPatchTypes[patchI] = pbm[patchI].type();
+        }
+    }
+
+    wordList actualPatchFieldTypes;
+    {
+        const pointVectorField::GeometricBoundaryField& pfld =
+            displacement_.boundaryField();
+        actualPatchFieldTypes.setSize(pfld.size());
+        forAll(pfld, patchI)
+        {
+            if (isA<fixedValuePointPatchField<vector> >(pfld[patchI]))
+            {
+                // Get rid of funny
+                actualPatchFieldTypes[patchI] =
+                    fixedValuePointPatchField<vector>::typeName;
+            }
+            else
+            {
+                actualPatchFieldTypes[patchI] = pfld[patchI].type();
+            }
+        }
+    }
+
+    pointVectorField totalDisplacement
+    (
+        IOobject
+        (
+            "totalDisplacement",
+            mesh_.time().timeName(),
+            mesh_,
+            IOobject::NO_READ,
+            IOobject::NO_WRITE,
+            false
+        ),
+        scale_*displacement_,
+        actualPatchFieldTypes,
+        actualPatchTypes
+    );
+    correctBoundaryConditions(totalDisplacement);
+
+    if (debug)
+    {
+        Pout<< "scaleMesh : testing sync of totalDisplacement" << endl;
+        testSyncField
+        (
+            totalDisplacement,
+            maxMagEqOp(),
+            vector::zero,   // null value
+            1e-6*mesh_.bounds().mag()
+        );
+    }
+
+    tmp<pointField> tnewPoints(oldPoints_ + totalDisplacement.internalField());
+
+    // Correct for 2-D motion
+    modifyMotionPoints(tnewPoints());
+
+    return tnewPoints;
+}
+
+
 bool Foam::motionSmoother::scaleMesh
 (
     labelList& checkFaces,
@@ -1052,60 +1123,18 @@ bool Foam::motionSmoother::scaleMesh
         vector::zero    // null value
     );
 
-    // Set newPoints as old + scale*displacement
-    pointField newPoints;
-    {
-        // Create overall displacement with same b.c.s as displacement_
-        wordList actualPatchTypes;
-        {
-            const pointBoundaryMesh& pbm = displacement_.mesh().boundary();
-            actualPatchTypes.setSize(pbm.size());
-            forAll(pbm, patchI)
-            {
-                actualPatchTypes[patchI] = pbm[patchI].type();
-            }
-        }
-
-        pointVectorField totalDisplacement
-        (
-            IOobject
-            (
-                "totalDisplacement",
-                mesh_.time().timeName(),
-                mesh_,
-                IOobject::NO_READ,
-                IOobject::NO_WRITE,
-                false
-            ),
-            scale_*displacement_,
-            displacement_.boundaryField().types(),
-            actualPatchTypes
-        );
-        correctBoundaryConditions(totalDisplacement);
-
-        if (debug)
-        {
-            Pout<< "scaleMesh : testing sync of totalDisplacement" << endl;
-            testSyncField
-            (
-                totalDisplacement,
-                maxMagEqOp(),
-                vector::zero,   // null value
-                1e-6*mesh_.bounds().mag()
-            );
-        }
-
-        newPoints = oldPoints_ + totalDisplacement.internalField();
-    }
-
     Info<< "Moving mesh using displacement scaling :"
         << " min:" << gMin(scale_.internalField())
         << "  max:" << gMax(scale_.internalField())
         << endl;
 
+    // Get points using current displacement and scale. Optionally 2D corrected.
+    pointField newPoints(curPoints());
+
+    // Move. No need to do 2D correction since curPoints already done that.
+    mesh_.movePoints(newPoints);
+    movePoints();
 
-    // Move
-    movePoints(newPoints);
 
     // Check. Returns parallel number of incorrect faces.
     faceSet wrongFaces(mesh_, "wrongFaces", mesh_.nFaces()/100+100);
diff --git a/src/dynamicMesh/motionSmoother/motionSmoother.H b/src/dynamicMesh/motionSmoother/motionSmoother.H
index fff07c4b94a..33bb2835e21 100644
--- a/src/dynamicMesh/motionSmoother/motionSmoother.H
+++ b/src/dynamicMesh/motionSmoother/motionSmoother.H
@@ -403,9 +403,11 @@ public:
             //  bc's.
             void correctBoundaryConditions(pointVectorField&) const;
 
-            //- Move mesh. Does 2D correction (modifies passed pointField) and
-            //  polyMesh::movePoints. Returns swept volumes.
-            tmp<scalarField> movePoints(pointField&);
+            //- Apply optional point constraint (2d correction)
+            void modifyMotionPoints(pointField& newPoints) const;
+
+            //- Get the current points (oldPoints+scale*displacement)
+            tmp<pointField> curPoints() const;
 
             //- Set the errorReduction (by how much to scale the displacement
             //  at error locations) parameter. Returns the old value.
@@ -446,9 +448,14 @@ public:
                 const label nAllow = 0
             );
 
-            //- Update topology
+
+            //- Update for new mesh geometry
+            void movePoints();
+
+            //- Update for new mesh topology
             void updateMesh();
 
+
             //- Check mesh with mesh settings in dict. Collects incorrect faces
             //  in set. Returns true if one or more faces in error.
             //  Parallel ok.
diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C
index 316d376defd..1dcafdec3ee 100644
--- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C
+++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C
@@ -3522,7 +3522,9 @@ void Foam::autoLayerDriver::addLayers
         }
 
         // Reset mesh points and start again
-        meshMover().movePoints(oldPoints);
+        mesh.movePoints(oldPoints);
+        // Update meshmover for change of mesh geometry
+        meshMover().movePoints();
         meshMover().correct();
 
 
diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H
index 58464ad4954..72c62020a0a 100644
--- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H
+++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.H
@@ -58,7 +58,9 @@ class layerParameters;
 
 class autoLayerDriver
 {
-    // Static data members
+public:
+
+    // Public data types
 
         //- Extrusion controls
         enum extrudeMode
@@ -69,6 +71,7 @@ class autoLayerDriver
                             /*!< faces locally */
         };
 
+private:
 
     // Private classes
 
diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C
index 328b4fd86a1..3349a5f8b6b 100644
--- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C
+++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriverShrink.C
@@ -1756,19 +1756,10 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance
         Info<< "Writing wanted-displacement mesh (possibly illegal) to "
             << meshRefiner_.timeName() << endl;
         pointField oldPoints(mesh.points());
-        vectorField totalDisp
-        (
-            meshMover.scale().internalField()
-          * displacement.internalField()
-        );
-        syncTools::syncPointList
-        (
-            mesh,
-            totalDisp,
-            minMagSqrEqOp<point>(),
-            vector(GREAT, GREAT, GREAT)
-        );
-        meshMover.movePoints((mesh.points()+totalDisp)());
+
+        meshRefiner_.mesh().movePoints(meshMover.curPoints());
+        // Warn meshMover for changed geometry
+        meshMover.movePoints();
 
         // Above move will have changed the instance only on the points (which
         // is correct).
@@ -1791,7 +1782,11 @@ void Foam::autoLayerDriver::shrinkMeshMedialDistance
         dispVec.write();
         medialDist.write();
         medialRatio.write();
-        meshMover.movePoints(oldPoints);
+
+        // Move mesh back
+        meshRefiner_.mesh().movePoints(oldPoints);
+        // Warn meshMover for changed geometry
+        meshMover.movePoints();
     }
 
 
-- 
GitLab