From 7f4582205548879332e6a224ee28a6be518550ef Mon Sep 17 00:00:00 2001
From: Franjo Juretic <franjo.juretic@c-fields.com>
Date: Thu, 24 Jul 2014 10:31:18 +0200
Subject: [PATCH] Added a utility and calculaion of planes

---
 meshLibrary/Make/files                        |   3 +
 .../symmetryPlaneOptimisation.C               | 147 ++++++++++++++++++
 .../symmetryPlaneOptimisation.H               |  99 ++++++++++++
 utilities/improveSymmetryPlanes/Make/files    |   3 +
 utilities/improveSymmetryPlanes/Make/options  |   8 +
 .../improveSymmetryPlanes.C                   |  55 +++++++
 6 files changed, 315 insertions(+)
 create mode 100644 meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.C
 create mode 100644 meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.H
 create mode 100644 utilities/improveSymmetryPlanes/Make/files
 create mode 100644 utilities/improveSymmetryPlanes/Make/options
 create mode 100644 utilities/improveSymmetryPlanes/improveSymmetryPlanes.C

diff --git a/meshLibrary/Make/files b/meshLibrary/Make/files
index 4bf848f7..0783a7ef 100644
--- a/meshLibrary/Make/files
+++ b/meshLibrary/Make/files
@@ -39,6 +39,7 @@ removeCellsInSelectedDomains = $(nonManifoldMeshing)/removeCellsInSelectedDomain
 
 meshOptimizer = utilities/smoothers/geometry/meshOptimizer
 tetMeshOptimisation = $(meshOptimizer)/tetMeshOptimisation
+symmetryPlaneOptimisation = $(meshOptimizer)/symmetryPlaneOptimisation
 simplexSmoother = $(tetMeshOptimisation)/advancedSmoothers/simplexSmoother
 knuppMetric = $(tetMeshOptimisation)/advancedSmoothers/knuppMetric
 meshUntangler = $(tetMeshOptimisation)/advancedSmoothers/meshUntangler
@@ -356,6 +357,8 @@ $(meshOptimizer)/optimizeMeshFV.C
 $(tetMeshOptimisation)/tetMeshOptimisation.C
 $(tetMeshOptimisation)/tetMeshOptimisationParallel.C
 
+$(symmetryPlaneOptimisation)/symmetryPlaneOptimisation.C
+
 $(simplexSmoother)/simplexSmoother.C
 
 $(knuppMetric)/knuppMetric.C
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.C b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.C
new file mode 100644
index 00000000..48bd9f59
--- /dev/null
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.C
@@ -0,0 +1,147 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | cfMesh: A library for mesh generation
+   \\    /   O peration     |
+    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
+     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of cfMesh.
+
+    cfMesh is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 3 of the License, or (at your
+    option) any later version.
+
+    cfMesh is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+
+\*---------------------------------------------------------------------------*/
+
+#include "demandDrivenData.H"
+#include "symmetryPlaneOptimisation.H"
+#include "partTetMesh.H"
+#include "meshSurfaceEngine.H"
+#include "meshSurfaceEngineModifier.H"
+
+#include "partTetMeshSimplex.H"
+#include "meshUntangler.H"
+#include "volumeOptimizer.H"
+#include "knuppMetric.H"
+
+#include <map>
+
+# ifdef USE_OMP
+#include <omp.h>
+# endif
+
+// #define DEBUGSearch
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+void symmetryPlaneOptimisation::detectSymmetryPlanes()
+{
+    const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
+    const pointFieldPMG& points = mesh_.points();
+    const faceListPMG& faces = mesh_.faces();
+
+    symmetryPlanes_.clear();
+
+    typedef std::map<label, std::pair<vector, label> > mapType;
+    mapType centreSum, normalSum;
+
+    forAll(boundaries, patchI)
+    {
+        if( boundaries[patchI].type() == "symmetryPlane" )
+        {
+            std::pair<vector, label>& cs = centreSum[patchI];
+            cs = std::pair<vector, label>(vector::zero, 0);
+
+            std::pair<vector, label>& ns = normalSum[patchI];
+            ns = std::pair<vector, label>(vector::zero, 0);
+
+            const label start = boundaries[patchI].patchStart();
+            const label end = start + boundaries[patchI].patchSize();
+            for(label faceI=start;faceI<end;++faceI)
+            {
+                cs.first += faces[faceI].centre(points);
+                ns.first += faces[faceI].normal(points);
+            }
+
+            cs.second = ns.second = boundaries[patchI].patchSize();
+        }
+    }
+
+    if( Pstream::parRun() )
+    {
+        //- sum up all normals and centres of all processors
+        //- every symmetry plane patch must be present on all processors
+        forAllIter(mapType, centreSum, pIter)
+        {
+            std::pair<vector, label>& cs = pIter->second;
+            reduce(cs.second, sumOp<label>());
+            reduce(cs.first, sumOp<vector>());
+
+            std::pair<vector, label>& ns = normalSum[pIter->first];
+            reduce(ns.first, sumOp<vector>());
+            ns.second = cs.second;
+        }
+    }
+
+    //- create planes corresponding to each symmetry plane
+    forAllConstIter(mapType, centreSum, it)
+    {
+        const point c = it->second.first / it->second.second;
+
+        const std::pair<vector, label>& ns = normalSum[it->first];
+        const point n = ns.first / ns.second;
+
+        const word pName = boundaries[it->first].patchName();
+        symmetryPlanes_.insert(std::make_pair(pName, plane(c, n)));
+    }
+}
+
+void symmetryPlaneOptimisation::pointInPlanes(VRWGraph&) const
+{
+
+}
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+// Construct from mesh
+symmetryPlaneOptimisation::symmetryPlaneOptimisation(polyMeshGen& mesh)
+:
+    mesh_(mesh)
+{
+    detectSymmetryPlanes();
+}
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+symmetryPlaneOptimisation::~symmetryPlaneOptimisation()
+{}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+void symmetryPlaneOptimisation::optimizeSymmetryPlanes()
+{
+
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.H b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.H
new file mode 100644
index 00000000..d306a202
--- /dev/null
+++ b/meshLibrary/utilities/smoothers/geometry/meshOptimizer/symmetryPlaneOptimisation/symmetryPlaneOptimisation.H
@@ -0,0 +1,99 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | cfMesh: A library for mesh generation
+   \\    /   O peration     |
+    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
+     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of cfMesh.
+
+    cfMesh is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 3 of the License, or (at your
+    option) any later version.
+
+    cfMesh is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
+
+Class
+    symmetryPlaneOptimisation
+
+Description
+    Smoothing of symmetry planes in the mesh such that all points
+    are in the plane.
+
+SourceFiles
+    symmetryPlaneOptimisation.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef symmetryPlaneOptimisation_H
+#define symmetryPlaneOptimisation_H
+
+#include "DynList.H"
+#include "polyMeshGenModifier.H"
+#include "boundBox.H"
+#include "labelLongList.H"
+#include "boolList.H"
+#include "plane.H"
+
+#include <map>
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+                Class symmetryPlaneOptimisation Declaration
+\*---------------------------------------------------------------------------*/
+
+class symmetryPlaneOptimisation
+{
+    // Private data
+        //- reference to the mesh
+        polyMeshGen& mesh_;
+
+        //- symmetry planes in the mesh
+        std::map<word, plane> symmetryPlanes_;
+
+    // Private member functions
+        //- detect symmetry planes
+        void detectSymmetryPlanes();
+
+        //- point-planes addressing
+        void pointInPlanes(VRWGraph&) const;
+
+public:
+
+    // Constructors
+
+        //- Construct from mesh
+        symmetryPlaneOptimisation(polyMeshGen& mesh);
+
+
+    // Destructor
+
+        ~symmetryPlaneOptimisation();
+
+    // Member Functions
+        //- move vertices to the symmetry planes
+        void optimizeSymmetryPlanes();
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/utilities/improveSymmetryPlanes/Make/files b/utilities/improveSymmetryPlanes/Make/files
new file mode 100644
index 00000000..432077c9
--- /dev/null
+++ b/utilities/improveSymmetryPlanes/Make/files
@@ -0,0 +1,3 @@
+improveSymmetryPlanes.C
+
+EXE = $(FOAM_USER_APPBIN)/improveSymmetryPlanes
diff --git a/utilities/improveSymmetryPlanes/Make/options b/utilities/improveSymmetryPlanes/Make/options
new file mode 100644
index 00000000..e0ad8cce
--- /dev/null
+++ b/utilities/improveSymmetryPlanes/Make/options
@@ -0,0 +1,8 @@
+EXE_INC = \
+    -I../../meshLibrary/lnInclude \
+    -I$(LIB_SRC)/meshTools/lnInclude
+
+EXE_LIBS = \
+    -L$(FOAM_USER_LIBBIN) \
+    -lmeshLibrary \
+    -lmeshTools
diff --git a/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C b/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C
new file mode 100644
index 00000000..6fa67590
--- /dev/null
+++ b/utilities/improveSymmetryPlanes/improveSymmetryPlanes.C
@@ -0,0 +1,55 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | cfMesh: A library for mesh generation
+   \\    /   O peration     |
+    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
+     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
+-------------------------------------------------------------------------------
+License
+    This file is part of cfMesh.
+
+    cfMesh is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 3 of the License, or (at your
+    option) any later version.
+
+    cfMesh is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with cfMesh.  If not, see <http://www.gnu.org/licenses/>.
+
+Description
+    Ensures that all mesh points belonging to a symmetryPlane are
+    in a plane.
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+#include "Time.H"
+#include "polyMeshGenModifier.H"
+#include "symmetryPlaneOptimisation.H"
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+int main(int argc, char *argv[])
+{
+#   include "setRootCase.H"
+#   include "createTime.H"
+
+    polyMeshGen pmg(runTime);
+    pmg.read();
+
+    symmetryPlaneOptimisation(pmg).optimizeSymmetryPlanes();
+
+    pmg.write();
+
+    Info << "End\n" << endl;
+    return 0;
+}
+
+// ************************************************************************* //
-- 
GitLab