From c1a77b102e5f728f9e2729e38e9d3d99d46eac81 Mon Sep 17 00:00:00 2001 From: laurence Date: Mon, 29 Jul 2013 15:02:59 +0100 Subject: [PATCH 01/33] COMP: foamyHexMesh: Add missing includes --- .../utilities/mesh/generation/foamyHexMesh/foamyHexMesh.C | 3 +++ 1 file changed, 3 insertions(+) diff --git a/applications/utilities/mesh/generation/foamyHexMesh/foamyHexMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/foamyHexMesh.C index f71a17cfcb..d636a7e9e9 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/foamyHexMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/foamyHexMesh.C @@ -30,6 +30,9 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" +#include "Time.H" +#include "IOdictionary.H" +#include "searchableSurfaces.H" #include "conformalVoronoiMesh.H" #include "vtkSetWriter.H" From 2bfe5c8864cba7e3f151f4af0da4e14030e7a640 Mon Sep 17 00:00:00 2001 From: laurence Date: Mon, 29 Jul 2013 15:16:37 +0100 Subject: [PATCH 02/33] ENH: foamyHexMesh: Move writing functions to a new namespace --- .../DelaunayMeshTools/DelaunayMeshTools.C | 110 +++++++ .../DelaunayMeshTools/DelaunayMeshTools.H | 152 +++++++++ .../DelaunayMeshToolsTemplates.C | 305 ++++++++++++++++++ .../conformalVoronoiMesh/Make/files | 2 + .../conformalVoronoiMesh.C | 38 ++- .../conformalVoronoiMesh.H | 137 +++----- .../conformalVoronoiMeshCalcDualMesh.C | 38 +-- .../conformalVoronoiMeshFeaturePoints.C | 1 + .../conformalVoronoiMeshIO.C | 305 +----------------- 9 files changed, 654 insertions(+), 434 deletions(-) create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.C create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.H create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.C new file mode 100644 index 0000000000..c37e1fad9b --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.C @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "DelaunayMeshTools.H" +#include "meshTools.H" +#include "OFstream.H" +#include "pointConversion.H" + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +void Foam::DelaunayMeshTools::writeOBJ +( + const fileName& fName, + const List& points +) +{ + if (points.size()) + { + OFstream str(fName); + + Pout<< nl + << "Writing " << points.size() << " points from pointList to " + << str.name() << endl; + + forAll(points, p) + { + meshTools::writeOBJ(str, points[p]); + } + } +} + + +void Foam::DelaunayMeshTools::writeOBJ +( + const fileName& fName, + const List& points +) +{ + if (points.size()) + { + OFstream str(fName); + + Pout<< nl + << "Writing " << points.size() << " points from pointList to " + << str.name() << endl; + + forAll(points, p) + { + meshTools::writeOBJ(str, topoint(points[p].point())); + } + } +} + + +void Foam::DelaunayMeshTools::writeObjMesh +( + const fileName& fName, + const pointField& points, + const faceList& faces +) +{ + OFstream str(fName); + + Pout<< nl + << "Writing points and faces to " << str.name() << endl; + + forAll(points, p) + { + meshTools::writeOBJ(str, points[p]); + } + + forAll(faces, f) + { + str<< 'f'; + + const face& fP = faces[f]; + + forAll(fP, p) + { + str<< ' ' << fP[p] + 1; + } + + str<< nl; + } +} + + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.H new file mode 100644 index 0000000000..5e517d27fe --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshTools.H @@ -0,0 +1,152 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +Class + Foam::DelaunayMeshTools + +Description + Collection of functions for operating on a Delaunay mesh. Includes: + + - Functions for writing to an OBJ file + - Functions for extracting fields from the Delaunay triangulation + +SourceFiles + DelaunayMeshToolsI.H + DelaunayMeshTools.C + +\*---------------------------------------------------------------------------*/ + +#ifndef DelaunayMeshTools_H +#define DelaunayMeshTools_H + +#include "fileName.H" +#include "List.H" +#include "point.H" +#include "CGALTriangulation3Ddefs.H" +#include "indexedVertexEnum.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Namespace DelaunayMeshTools Declaration +\*---------------------------------------------------------------------------*/ + +namespace DelaunayMeshTools +{ + +// OBJ writing + + //- Write list of points to file + void writeOBJ(const fileName& fName, const List& points); + + //- Write list of points to file + void writeOBJ(const fileName& fName, const List& points); + + //- Write an OBJ mesh consisting of points and faces + void writeObjMesh + ( + const fileName& fName, + const pointField& points, + const faceList& faces + ); + + //- Write Delaunay points in the range between (and including) + // type startPointType and endPointType to an OBJ file + template + void writeOBJ + ( + const fileName& fName, + const Triangulation& t, + const indexedVertexEnum::vertexType startPointType, + const indexedVertexEnum::vertexType endPointType + ); + + //- Write Delaunay points of type pointType to .obj file + template + void writeOBJ + ( + const fileName& fName, + const Triangulation& t, + const indexedVertexEnum::vertexType pointType + ); + + //- Write the fixed Delaunay points to an OBJ file + template + void writeFixedPoints(const fileName& fName, const Triangulation& t); + + //- Write the boundary Delaunay points to an OBJ file + template + void writeBoundaryPoints(const fileName& fName, const Triangulation& t); + + //- Write the processor interface to an OBJ file + template + void writeProcessorInterface + ( + const fileName& fName, + const Triangulation& t, + const faceList& faces + ); + + //- Write the internal Delaunay vertices of the tessellation as a + // pointField that may be used to restart the meshing process + template + void writeInternalDelaunayVertices + ( + const fileName& instance, + const Triangulation& t + ); + + //- Draws a tet cell to an output stream. The offset is supplied as the tet + // number to be drawn. + template + void drawDelaunayCell(Ostream& os, const CellHandle& c, label offset = 0); + + +// Field extraction + + //- Extract all points in vertex-index order + template + tmp allPoints(const Triangulation& t); + + +} // End namespace DelaunayMeshTools + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "DelaunayMeshToolsTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C new file mode 100644 index 0000000000..551380c6e2 --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMeshTools/DelaunayMeshToolsTemplates.C @@ -0,0 +1,305 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "DelaunayMeshTools.H" +#include "meshTools.H" +#include "OFstream.H" +#include "pointConversion.H" +#include "pointIOField.H" +#include "indexedVertexOps.H" + +// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // + +template +void Foam::DelaunayMeshTools::writeOBJ +( + const fileName& fName, + const Triangulation& t, + const indexedVertexEnum::vertexType startPointType, + const indexedVertexEnum::vertexType endPointType +) +{ + OFstream str(fName); + + Pout<< nl + << "Writing points of types:" << nl; + + forAllConstIter + ( + HashTable, + indexedVertexEnum::vertexTypeNames_, + iter + ) + { + if (iter() >= startPointType && iter() <= endPointType) + { + Pout<< " " << iter.key() << nl; + } + } + + Pout<< "to " << str.name() << endl; + + for + ( + typename Triangulation::Finite_vertices_iterator vit = + t.finite_vertices_begin(); + vit != t.finite_vertices_end(); + ++vit + ) + { + if (vit->type() >= startPointType && vit->type() <= endPointType) + { + meshTools::writeOBJ(str, topoint(vit->point())); + } + } +} + + +template +void Foam::DelaunayMeshTools::writeOBJ +( + const fileName& fName, + const Triangulation& t, + const indexedVertexEnum::vertexType pointType +) +{ + writeOBJ(fName, t, pointType, pointType); +} + + +template +void Foam::DelaunayMeshTools::writeFixedPoints +( + const fileName& fName, + const Triangulation& t +) +{ + OFstream str(fName); + + Pout<< nl + << "Writing fixed points to " << str.name() << endl; + + for + ( + typename Triangulation::Finite_vertices_iterator vit = + t.finite_vertices_begin(); + vit != t.finite_vertices_end(); + ++vit + ) + { + if (vit->fixed()) + { + meshTools::writeOBJ(str, topoint(vit->point())); + } + } +} + + +template +void Foam::DelaunayMeshTools::writeBoundaryPoints +( + const fileName& fName, + const Triangulation& t +) +{ + OFstream str(fName); + + Pout<< nl + << "Writing boundary points to " << str.name() << endl; + + for + ( + typename Triangulation::Finite_vertices_iterator vit = + t.finite_vertices_begin(); + vit != t.finite_vertices_end(); + ++vit + ) + { + if (!vit->internalPoint()) + { + meshTools::writeOBJ(str, topoint(vit->point())); + } + } +} + + +template +void Foam::DelaunayMeshTools::writeProcessorInterface +( + const fileName& fName, + const Triangulation& t, + const faceList& faces +) +{ + OFstream str(fName); + + pointField points(t.number_of_finite_cells(), point::max); + + for + ( + typename Triangulation::Finite_cells_iterator cit = + t.finite_cells_begin(); + cit != t.finite_cells_end(); + ++cit + ) + { + if (!cit->hasFarPoint() && !t.is_infinite(cit)) + { + points[cit->cellIndex()] = cit->dual(); + } + } + + meshTools::writeOBJ(str, faces, points); +} + + +template +void Foam::DelaunayMeshTools::writeInternalDelaunayVertices +( + const fileName& instance, + const Triangulation& t +) +{ + pointField internalDelaunayVertices(t.number_of_vertices()); + + label vertI = 0; + + for + ( + typename Triangulation::Finite_vertices_iterator vit = + t.finite_vertices_begin(); + vit != t.finite_vertices_end(); + ++vit + ) + { + if (vit->internalPoint()) + { + internalDelaunayVertices[vertI++] = topoint(vit->point()); + } + } + + internalDelaunayVertices.setSize(vertI); + + pointIOField internalDVs + ( + IOobject + ( + "internalDelaunayVertices", + instance, + t.time(), + IOobject::NO_READ, + IOobject::AUTO_WRITE + ), + internalDelaunayVertices + ); + + Info<< nl + << "Writing " << internalDVs.name() + << " to " << internalDVs.instance() + << endl; + + internalDVs.write(); +} + + +template +void Foam::DelaunayMeshTools::drawDelaunayCell +( + Ostream& os, + const CellHandle& c, + label offset +) +{ + // Supply offset as tet number + offset *= 4; + + os << "# cell index: " << label(c->cellIndex()) + << " INT_MIN = " << INT_MIN + << endl; + + os << "# circumradius " + << mag(c->dual() - topoint(c->vertex(0)->point())) + << endl; + + for (int i = 0; i < 4; i++) + { + os << "# index / type / procIndex: " + << label(c->vertex(i)->index()) << " " + << label(c->vertex(i)->type()) << " " + << label(c->vertex(i)->procIndex()) + << + ( + CGAL::indexedVertexOps::uninitialised(c->vertex(i)) + ? " # This vertex is uninitialised!" + : "" + ) + << endl; + + meshTools::writeOBJ(os, topoint(c->vertex(i)->point())); + } + + os << "f " << 1 + offset << " " << 3 + offset << " " << 2 + offset << nl + << "f " << 2 + offset << " " << 3 + offset << " " << 4 + offset << nl + << "f " << 1 + offset << " " << 4 + offset << " " << 3 + offset << nl + << "f " << 1 + offset << " " << 2 + offset << " " << 4 + offset << endl; + +// os << "# cicumcentre " << endl; + +// meshTools::writeOBJ(os, c->dual()); + +// os << "l " << 1 + offset << " " << 5 + offset << endl; +} + + +template +Foam::tmp Foam::DelaunayMeshTools::allPoints +( + const Triangulation& t +) +{ + tmp tpts(new pointField(t.number_of_vertices(), point::max)); + pointField& pts = tpts(); + + label nVert = 0; + + for + ( + typename Triangulation::Finite_vertices_iterator vit = + t.finite_vertices_begin(); + vit != t.finite_vertices_end(); + ++vit + ) + { + if (vit->internalOrBoundaryPoint()) + { + pts[nVert++] = topoint(vit->point()); + } + } + + return tpts; +} + + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files index ca374fb5f4..eec581bf10 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files @@ -1,5 +1,7 @@ #include CGAL_FILES +DelaunayMeshTools/DelaunayMeshTools.C + conformalVoronoiMesh/indexedVertex/indexedVertexEnum.C conformalVoronoiMesh/indexedCell/indexedCellEnum.C diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index 3ba5b8c9e7..70cb8face6 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -34,6 +34,7 @@ License #include "controlMeshRefinement.H" #include "smoothAlignmentSolver.H" #include "OBJstream.H" +#include "DelaunayMeshTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -288,7 +289,7 @@ void Foam::conformalVoronoiMesh::insertSurfacePointPairs if (foamyHexMeshControls().objOutput() && fName != fileName::null) { - writePoints(fName, pts); + DelaunayMeshTools::writeOBJ(time().path()/fName, pts); } } @@ -328,7 +329,7 @@ void Foam::conformalVoronoiMesh::insertEdgePointGroups if (foamyHexMeshControls().objOutput() && fName != fileName::null) { - writePoints(fName, pts); + DelaunayMeshTools::writeOBJ(time().path()/fName, pts); } } @@ -381,9 +382,10 @@ void Foam::conformalVoronoiMesh::insertInitialPoints() if (foamyHexMeshControls().objOutput()) { - writePoints + DelaunayMeshTools::writeOBJ ( - "initialPoints.obj", + time().path()/"initialPoints.obj", + *this, Foam::indexedVertexEnum::vtInternal ); } @@ -625,8 +627,8 @@ Foam::face Foam::conformalVoronoiMesh::buildDualFace Vertex_handle vA = c->vertex(eit->second); Vertex_handle vB = c->vertex(eit->third); - drawDelaunayCell(Pout, cc1); - drawDelaunayCell(Pout, cc2); + DelaunayMeshTools::drawDelaunayCell(Pout, cc1); + DelaunayMeshTools::drawDelaunayCell(Pout, cc2); FatalErrorIn("Foam::conformalVoronoiMesh::buildDualFace") << "Dual face uses circumcenter defined by a " @@ -953,9 +955,10 @@ void Foam::conformalVoronoiMesh::initialiseForMotion() if (foamyHexMeshControls().objOutput()) { - writePoints + DelaunayMeshTools::writeOBJ ( - "internalPoints_" + runTime_.timeName() + ".obj", + time().path()/"internalPoints_" + time().timeName() + ".obj", + *this, Foam::indexedVertexEnum::vtUnassigned, Foam::indexedVertexEnum::vtExternalFeaturePoint ); @@ -1614,16 +1617,21 @@ void Foam::conformalVoronoiMesh::move() if (foamyHexMeshControls().objOutput()) { - writePoints + DelaunayMeshTools::writeOBJ ( - "internalPoints_" + time().timeName() + ".obj", + time().path()/"internalPoints_" + time().timeName() + ".obj", + *this, Foam::indexedVertexEnum::vtInternal ); - } - if (foamyHexMeshControls().objOutput() && time().outputTime()) - { - writeBoundaryPoints("boundaryPoints_" + time().timeName() + ".obj"); + if (reconformToSurface()) + { + DelaunayMeshTools::writeBoundaryPoints + ( + time().path()/"boundaryPoints_" + time().timeName() + ".obj", + *this + ); + } } timeCheck("After conformToSurface"); @@ -1776,7 +1784,7 @@ void Foam::conformalVoronoiMesh::checkCoPlanarCells() const << " quality = " << quality << nl << " dual = " << topoint(cit->dual()) << endl; - drawDelaunayCell(str, cit, badCells++); + DelaunayMeshTools::drawDelaunayCell(str, cit, badCells++); FixedList cellVerticesExact(PointExact(0,0,0)); forAll(cellVerticesExact, vI) diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index 777f277d58..4ebc3f70e2 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -228,36 +228,6 @@ private: const Delaunay::Finite_facets_iterator& fit ) const; - //- Return the local point pair separation at the given location - inline scalar pointPairDistance(const Foam::point& pt) const; - - //- Return the local mixed feature point placement distance - inline scalar mixedFeaturePointDistance(const Foam::point& pt) const; - - //- Return the square of the local feature point exclusion distance - inline scalar featurePointExclusionDistanceSqr - ( - const Foam::point& pt - ) const; - - //- Return the square of the local feature edge exclusion distance - inline scalar featureEdgeExclusionDistanceSqr - ( - const Foam::point& pt - ) const; - - //- Return the square of the local surface point exclusion distance - inline scalar surfacePtExclusionDistanceSqr - ( - const Foam::point& pt - ) const; - - //- Return the square of the local surface search distance - inline scalar surfaceSearchDistanceSqr(const Foam::point& pt) const; - - //- Return the local maximum surface protrusion distance - inline scalar maxSurfaceProtrusion(const Foam::point& pt) const; - //- Insert Delaunay vertices using the CGAL range insertion method, // optionally check processor occupancy and distribute to other // processors @@ -850,9 +820,6 @@ private: //- Create the cell centres to use for the mesh void createCellCentres(pointField& cellCentres) const; - //- Extract all points in vertex-index order - tmp allPoints() const; - //- Sort the faces, owner and neighbour lists into // upper-triangular order. For internal faces only, use // before adding patch faces @@ -1022,6 +989,49 @@ public: inline const cvControls& foamyHexMeshControls() const; + // Query + + //- Return the local point pair separation at the given location + inline scalar pointPairDistance(const Foam::point& pt) const; + + //- Return the local mixed feature point placement distance + inline scalar mixedFeaturePointDistance + ( + const Foam::point& pt + ) const; + + //- Return the square of the local feature point exclusion distance + inline scalar featurePointExclusionDistanceSqr + ( + const Foam::point& pt + ) const; + + //- Return the square of the local feature edge exclusion distance + inline scalar featureEdgeExclusionDistanceSqr + ( + const Foam::point& pt + ) const; + + //- Return the square of the local surface point exclusion distance + inline scalar surfacePtExclusionDistanceSqr + ( + const Foam::point& pt + ) const; + + //- Return the square of the local surface search distance + inline scalar surfaceSearchDistanceSqr(const Foam::point& pt) const; + + //- Return the local maximum surface protrusion distance + inline scalar maxSurfaceProtrusion(const Foam::point& pt) const; + + //- Call the appropriate function to conform to an edge + void createEdgePointGroup + ( + const extendedFeatureEdgeMesh& feMesh, + const pointIndexHit& edHit, + DynamicList& pts + ) const; + // Write //- Write the elapsedCpuTime and memory usage, with an optional @@ -1038,53 +1048,6 @@ public: const string& description = string::null ) const; - //- Write the Delaunay cell - void drawDelaunayCell - ( - Ostream& os, - const Cell_handle& c, - label offset = 0 - ) const; - - //- Write Delaunay points in the range between (and including) - // type startPointType and endPointType to .obj file - void writePoints - ( - const fileName& fName, - const Foam::indexedVertexEnum::vertexType startPointType, - const Foam::indexedVertexEnum::vertexType endPointType - ) const; - - //- Write Delaunay points of type pointType to .obj file - void writePoints - ( - const fileName& fName, - const Foam::indexedVertexEnum::vertexType pointType - ) const; - - void writeFixedPoints(const fileName& fName) const; - - //- Write the boundary Delaunay points to .obj file - void writeBoundaryPoints(const fileName& fName) const; - - //- Write list of points to file - void writePoints - ( - const fileName& fName, - const List& points - ) const; - - //- Write list of points to file - void writePoints - ( - const fileName& fName, - const List& points - ) const; - - //- Write the internal Delaunay vertices of the tessellation as a - // pointField that may be used to restart the meshing process - void writeInternalDelaunayVertices(const fileName& instance) const; - //- Prepare data and call writeMesh for polyMesh and // tetDualMesh void writeMesh(const fileName& instance); @@ -1105,14 +1068,6 @@ public: const PackedBoolList& boundaryFacesToRemove ) const; - //- Write points and faces as .obj file - void writeObjMesh - ( - const pointField& points, - const faceList& faces, - const fileName& fName - ) const; - //- Calculate and write a field of the target cell size, // target cell volume, actual cell volume and equivalent // actual cell size (cbrt(actual cell volume)). @@ -1126,12 +1081,6 @@ public: //- Find the cellSet of the boundary cells which have points that // protrude out of the surface beyond a tolerance. labelHashSet findRemainingProtrusionSet(const polyMesh& mesh) const; - - void writeProcessorInterface - ( - const fileName& fName, - const faceList& faces - ) const; }; diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C index 5a45b8ab4f..2b938021a4 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C @@ -29,6 +29,7 @@ License #include "polyMeshGeometry.H" #include "indexedCellChecks.H" #include "OBJstream.H" +#include "DelaunayMeshTools.H" #include "CGAL/Exact_predicates_exact_constructions_kernel.h" #include "CGAL/Gmpq.h" @@ -598,7 +599,7 @@ void Foam::conformalVoronoiMesh::calcDualMesh // deferredCollapseFaceSet(owner, neighbour, deferredCollapseFaces); - cellCentres = allPoints(); + cellCentres = DelaunayMeshTools::allPoints(*this); cellToDelaunayVertex = removeUnusedCells(owner, neighbour); @@ -1227,7 +1228,7 @@ Foam::conformalVoronoiMesh::createPolyMeshFromPoints ); //createCellCentres(cellCentres); - cellCentres = allPoints(); + cellCentres = DelaunayMeshTools::allPoints(*this); labelList cellToDelaunayVertex(removeUnusedCells(owner, neighbour)); cellCentres = pointField(cellCentres, cellToDelaunayVertex); @@ -2443,7 +2444,7 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches && vc2->neighbor(cI)->hasConstrainedPoint() ) { - drawDelaunayCell + DelaunayMeshTools::drawDelaunayCell ( cellStr, vc2->neighbor(cI), @@ -2837,7 +2838,12 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches + name(neighbour) + "_interface.obj"; - writeProcessorInterface(fName, procPatchFaces); + DelaunayMeshTools::writeProcessorInterface + ( + time().path()/fName, + *this, + procPatchFaces + ); } } } @@ -2871,30 +2877,6 @@ void Foam::conformalVoronoiMesh::createCellCentres } -Foam::tmp Foam::conformalVoronoiMesh::allPoints() const -{ - tmp tpts(new pointField(number_of_vertices(), point::max)); - pointField& pts = tpts(); - - label nVert = 0; - - for - ( - Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); - vit != finite_vertices_end(); - ++vit - ) - { - if (vit->internalOrBoundaryPoint()) - { - pts[nVert++] = topoint(vit->point()); - } - } - - return tpts; -} - - void Foam::conformalVoronoiMesh::sortFaces ( faceList& faces, diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C index ac17397ad2..612709e140 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshFeaturePoints.C @@ -28,6 +28,7 @@ License #include "triangle.H" #include "tetrahedron.H" #include "const_circulator.H" +#include "DelaunayMeshTools.H" using namespace Foam::vectorTools; diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index 4c584fd4b5..172d21444f 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -33,6 +33,7 @@ License #include "polyTopoChange.H" #include "PrintTable.H" #include "pointMesh.H" +#include "DelaunayMeshTools.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -91,272 +92,9 @@ void Foam::conformalVoronoiMesh::timeCheck } -void Foam::conformalVoronoiMesh::drawDelaunayCell -( - Ostream& os, - const Cell_handle& c, - label offset -) const -{ - // Supply offset as tet number - offset *= 4; - - os << "# cell index: " << label(c->cellIndex()) - << " INT_MIN = " << INT_MIN - << endl; - - os << "# circumradius " - << mag(c->dual() - topoint(c->vertex(0)->point())) - << endl; - - for (int i = 0; i < 4; i++) - { - os << "# index / type / procIndex: " - << label(c->vertex(i)->index()) << " " - << label(c->vertex(i)->type()) << " " - << label(c->vertex(i)->procIndex()) - << (is_infinite(c->vertex(i)) ? " # This vertex is infinite!" : "") - << - ( - c->vertex(i)->uninitialised() - ? " # This vertex is uninitialised!" - : "" - ) - << endl; - - meshTools::writeOBJ(os, topoint(c->vertex(i)->point())); - } - - os << "f " << 1 + offset << " " << 3 + offset << " " << 2 + offset << nl - << "f " << 2 + offset << " " << 3 + offset << " " << 4 + offset << nl - << "f " << 1 + offset << " " << 4 + offset << " " << 3 + offset << nl - << "f " << 1 + offset << " " << 2 + offset << " " << 4 + offset << endl; - -// os << "# cicumcentre " << endl; - -// meshTools::writeOBJ(os, c->dual()); - -// os << "l " << 1 + offset << " " << 5 + offset << endl; -} - - -void Foam::conformalVoronoiMesh::writePoints -( - const fileName& fName, - const Foam::indexedVertexEnum::vertexType startPointType, - const Foam::indexedVertexEnum::vertexType endPointType -) const -{ - OFstream str(runTime_.path()/fName); - - Pout<< nl << "Writing points of types:" << nl; - - forAllConstIter - ( - HashTable, - Foam::indexedVertexEnum::vertexTypeNames_, - iter - ) - { - if (iter() >= startPointType && iter() <= endPointType) - { - Pout<< " " << iter.key() << nl; - } - } - - Pout<< "to " << str.name() << endl; - - for - ( - Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); - vit != finite_vertices_end(); - ++vit - ) - { - if (vit->type() >= startPointType && vit->type() <= endPointType) - { - meshTools::writeOBJ(str, topoint(vit->point())); - } - } -} - - -void Foam::conformalVoronoiMesh::writePoints -( - const fileName& fName, - const Foam::indexedVertexEnum::vertexType pointType -) const -{ - writePoints(fName, pointType, pointType); -} - - -void Foam::conformalVoronoiMesh::writeFixedPoints -( - const fileName& fName -) const -{ - OFstream str(runTime_.path()/fName); - - Pout<< nl << "Writing fixed points to " << str.name() << endl; - - for - ( - Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); - vit != finite_vertices_end(); - ++vit - ) - { - if (vit->fixed()) - { - meshTools::writeOBJ(str, topoint(vit->point())); - } - } -} - - -void Foam::conformalVoronoiMesh::writeBoundaryPoints -( - const fileName& fName -) const -{ - OFstream str(runTime_.path()/fName); - - Pout<< nl << "Writing boundary points to " << str.name() << endl; - - for - ( - Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); - vit != finite_vertices_end(); - ++vit - ) - { - if (!vit->internalPoint()) - { - meshTools::writeOBJ(str, topoint(vit->point())); - } - } -} - - -void Foam::conformalVoronoiMesh::writePoints -( - const fileName& fName, - const List& points -) const -{ - if (points.size()) - { - OFstream str(runTime_.path()/fName); - - Pout<< nl << "Writing " << points.size() << " points from pointList to " - << str.name() << endl; - - forAll(points, p) - { - meshTools::writeOBJ(str, points[p]); - } - } -} - - -void Foam::conformalVoronoiMesh::writePoints -( - const fileName& fName, - const List& points -) const -{ - if (points.size()) - { - OFstream str(runTime_.path()/fName); - - Pout<< nl << "Writing " << points.size() << " points from pointList to " - << str.name() << endl; - - forAll(points, p) - { - meshTools::writeOBJ(str, topoint(points[p].point())); - } - } -} - - -void Foam::conformalVoronoiMesh::writeProcessorInterface -( - const fileName& fName, - const faceList& faces -) const -{ - OFstream str(runTime_.path()/fName); - - pointField points(number_of_finite_cells(), point::max); - - for - ( - Delaunay::Finite_cells_iterator cit = finite_cells_begin(); - cit != finite_cells_end(); - ++cit - ) - { - if (!cit->hasFarPoint() && !is_infinite(cit)) - { - points[cit->cellIndex()] = cit->dual(); - } - } - - meshTools::writeOBJ(str, faces, points); -} - - -void Foam::conformalVoronoiMesh::writeInternalDelaunayVertices -( - const fileName& instance -) const -{ - pointField internalDelaunayVertices(number_of_vertices()); - - label vertI = 0; - - for - ( - Delaunay::Finite_vertices_iterator vit = finite_vertices_begin(); - vit != finite_vertices_end(); - ++vit - ) - { - if (vit->internalPoint()) - { - internalDelaunayVertices[vertI++] = topoint(vit->point()); - } - } - - internalDelaunayVertices.setSize(vertI); - - pointIOField internalDVs - ( - IOobject - ( - "internalDelaunayVertices", - instance, - runTime_, - IOobject::NO_READ, - IOobject::AUTO_WRITE - ), - internalDelaunayVertices - ); - - Info<< nl - << "Writing " << internalDVs.name() - << " to " << internalDVs.instance() - << endl; - - internalDVs.write(); -} - - void Foam::conformalVoronoiMesh::writeMesh(const fileName& instance) { - writeInternalDelaunayVertices(instance); + DelaunayMeshTools::writeInternalDelaunayVertices(instance, *this); // Per cell the Delaunay vertex labelList cellToDelaunayVertex; @@ -1049,7 +787,12 @@ void Foam::conformalVoronoiMesh::writeMesh { if (foamyHexMeshControls().objOutput()) { - writeObjMesh(points, faces, word(meshName + ".obj")); + DelaunayMeshTools::writeObjMesh + ( + time().path()/word(meshName + ".obj"), + points, + faces + ); } const label nInternalFaces = readLabel(patchDicts[0].lookup("startFace")); @@ -1404,38 +1147,6 @@ void Foam::conformalVoronoiMesh::writeMesh } -void Foam::conformalVoronoiMesh::writeObjMesh -( - const pointField& points, - const faceList& faces, - const fileName& fName -) const -{ - OFstream str(runTime_.path()/fName); - - Pout<< nl << "Writing points and faces to " << str.name() << endl; - - forAll(points, p) - { - meshTools::writeOBJ(str, points[p]); - } - - forAll(faces, f) - { - str<< 'f'; - - const face& fP = faces[f]; - - forAll(fP, p) - { - str<< ' ' << fP[p] + 1; - } - - str<< nl; - } -} - - void Foam::conformalVoronoiMesh::writeCellSizes ( const fvMesh& mesh From 60764c3941ed973654c5c6cf7086eae3e5c07980 Mon Sep 17 00:00:00 2001 From: laurence Date: Mon, 29 Jul 2013 15:35:12 +0100 Subject: [PATCH 03/33] ENH: foamyHexMesh: Move some functions to new namespaces - Added indexedVertexOps namespace - Added indexedCellOps namespace --- .../cellShapeControl/cellShapeControl.C | 5 +- .../conformalVoronoiMesh.C | 8 +- .../conformalVoronoiMesh.H | 8 -- .../conformalVoronoiMeshCalcDualMesh.C | 1 + .../conformalVoronoiMeshI.H | 28 ++----- .../conformalVoronoiMeshIO.C | 1 + .../indexedCell/indexedCell.H | 5 -- .../indexedCell/indexedCellI.H | 54 ------------ .../indexedCell/indexedCellOps.H | 76 +++++++++++++++++ .../indexedCell/indexedCellOpsTemplates.C | 82 +++++++++++++++++++ .../indexedVertex/indexedVertex.H | 4 +- .../indexedVertex/indexedVertexI.H | 7 -- .../indexedVertex/indexedVertexOps.H | 77 +++++++++++++++++ .../indexedVertex/indexedVertexOpsTemplates.C | 57 +++++++++++++ 14 files changed, 309 insertions(+), 104 deletions(-) create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOps.H create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOpsTemplates.C create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOps.H create mode 100644 applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOpsTemplates.C diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/cellShapeControl/cellShapeControl/cellShapeControl.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/cellShapeControl/cellShapeControl/cellShapeControl.C index 58ed8eb34c..1dd0f4ca81 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/cellShapeControl/cellShapeControl/cellShapeControl.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/cellShapeControl/cellShapeControl/cellShapeControl.C @@ -30,6 +30,7 @@ License #include "cellSizeAndAlignmentControl.H" #include "searchableSurfaceControl.H" #include "cellSizeFunction.H" +#include "indexedVertexOps.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -152,7 +153,7 @@ Foam::scalar Foam::cellShapeControl::cellSize(const point& pt) const { for (label pI = 0; pI < 4; ++pI) { - if (!ch->vertex(pI)->uninitialised()) + if (!CGAL::indexedVertexOps::uninitialised(ch->vertex(pI))) { size = ch->vertex(pI)->targetCellSize(); return size; @@ -276,7 +277,7 @@ void Foam::cellShapeControl::cellSizeAndAlignment { for (label pI = 0; pI < 4; ++pI) { - if (!ch->vertex(pI)->uninitialised()) + if (!CGAL::indexedVertexOps::uninitialised(ch->vertex(pI))) { size = ch->vertex(pI)->targetCellSize(); alignment = ch->vertex(pI)->alignment(); diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index 70cb8face6..f97eb553a3 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -34,6 +34,7 @@ License #include "controlMeshRefinement.H" #include "smoothAlignmentSolver.H" #include "OBJstream.H" +#include "indexedVertexOps.H" #include "DelaunayMeshTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -153,7 +154,7 @@ void Foam::conformalVoronoiMesh::insertInternalPoints ++vit ) { - if (vit->uninitialised()) + if (CGAL::indexedVertexOps::uninitialised(vit)) { vit->index() = getNewVertexIndex(); vit->type() = Vb::vtInternal; @@ -1206,7 +1207,8 @@ void Foam::conformalVoronoiMesh::move() > foamyHexMeshControls().cosAlignmentAcceptanceAngle() ) { - scalar targetCellSize = averageCellSize(vA, vB); + scalar targetCellSize = + CGAL::indexedVertexOps::averageCellSize(vA, vB); scalar targetFaceArea = sqr(targetCellSize); @@ -1538,7 +1540,7 @@ void Foam::conformalVoronoiMesh::move() //&& !vit->referred() ) { - const Foam::point& pt = topoint(vit->point()); + const pointFromPoint pt = topoint(vit->point()); bool inside = geometryToConformTo_.inside(pt); diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index 4ebc3f70e2..4133b1f554 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -203,14 +203,6 @@ private: // to be on a surface. inline scalar targetCellSize(const Foam::point& pt) const; - //- Return the target cell size from that stored on a pair of - // Delaunay vertices, using a mean function. - inline scalar averageCellSize - ( - const Vertex_handle& vA, - const Vertex_handle& vB - ) const; - //- Return the target cell size from that stored on a pair of // Delaunay vertices, including the possibility that one of // them is not an internalOrBoundaryPoint, and so will not diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C index 2b938021a4..86892c28d9 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshCalcDualMesh.C @@ -29,6 +29,7 @@ License #include "polyMeshGeometry.H" #include "indexedCellChecks.H" #include "OBJstream.H" +#include "indexedCellOps.H" #include "DelaunayMeshTools.H" #include "CGAL/Exact_predicates_exact_constructions_kernel.h" diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H index 9fa34b82d3..ff73cd79bd 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshI.H @@ -23,6 +23,9 @@ License \*---------------------------------------------------------------------------*/ +#include "indexedVertexOps.H" +#include "indexedCellOps.H" + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // inline Foam::scalar Foam::conformalVoronoiMesh::defaultCellSize() const @@ -40,25 +43,6 @@ inline Foam::scalar Foam::conformalVoronoiMesh::targetCellSize } -inline Foam::scalar Foam::conformalVoronoiMesh::averageCellSize -( - const Vertex_handle& vA, - const Vertex_handle& vB -) const -{ - // Arithmetic mean - // return 0.5*(vA->targetCellSize() + vB->targetCellSize()); - - // Geometric mean - return sqrt(vA->targetCellSize()*vB->targetCellSize()); - - // Harmonic mean - // return - // 2.0*(vA->targetCellSize()*vB->targetCellSize()) - // /(vA->targetCellSize() + vB->targetCellSize()); -} - - inline Foam::scalar Foam::conformalVoronoiMesh::averageAnyCellSize ( const Vertex_handle& vA, @@ -90,7 +74,7 @@ inline Foam::scalar Foam::conformalVoronoiMesh::averageAnyCellSize return vB->targetCellSize(); } - return averageCellSize(vA, vB); + return CGAL::indexedVertexOps::averageCellSize(vA, vB); } @@ -507,9 +491,9 @@ inline Foam::List Foam::conformalVoronoiMesh::processorsAttached const int oppositeVertex = fit->second; const Cell_handle c2(c1->neighbor(oppositeVertex)); - FixedList c1Procs(c1->processorsAttached()); + FixedList c1Procs(CGAL::indexedCellOps::processorsAttached(c1)); - FixedList c2Procs(c2->processorsAttached()); + FixedList c2Procs(CGAL::indexedCellOps::processorsAttached(c2)); forAll(c1Procs, aPI) { diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index 172d21444f..9c33e9f5ab 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -33,6 +33,7 @@ License #include "polyTopoChange.H" #include "PrintTable.H" #include "pointMesh.H" +#include "indexedVertexOps.H" #include "DelaunayMeshTools.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCell.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCell.H index c53cd38857..7a95b036a9 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCell.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCell.H @@ -189,11 +189,6 @@ public: //- Does the Dual vertex form part of a processor patch inline bool parallelDualVertex() const; - //- Does the Dual vertex form part of a processor patch - inline Foam::label dualVertexMasterProc() const; - - inline Foam::FixedList processorsAttached() const; - //- Using the globalIndex object, return a list of four (sorted) global // Delaunay vertex indices that uniquely identify this tet in parallel inline Foam::tetCell vertexGlobalIndices diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H index a812fe4664..8e035dbc7b 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellI.H @@ -265,60 +265,6 @@ inline bool CGAL::indexedCell::parallelDualVertex() const } -template -inline Foam::label CGAL::indexedCell::dualVertexMasterProc() const -{ - if (!parallelDualVertex()) - { - return -1; - } - - // The master processor is the lowest numbered of the four on this tet. - - int masterProc = Foam::Pstream::nProcs() + 1; - - for (int i = 0; i < 4; i++) - { - if (this->vertex(i)->referred()) - { - masterProc = min(masterProc, this->vertex(i)->procIndex()); - } - else - { - masterProc = min(masterProc, Foam::Pstream::myProcNo()); - } - } - - return masterProc; -} - - -template -inline Foam::FixedList -CGAL::indexedCell::processorsAttached() const -{ - if (!parallelDualVertex()) - { - return Foam::FixedList(Foam::Pstream::myProcNo()); - } - - Foam::FixedList procsAttached - ( - Foam::Pstream::myProcNo() - ); - - for (int i = 0; i < 4; i++) - { - if (this->vertex(i)->referred()) - { - procsAttached[i] = this->vertex(i)->procIndex(); - } - } - - return procsAttached; -} - - template inline Foam::tetCell CGAL::indexedCell::vertexGlobalIndices ( diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOps.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOps.H new file mode 100644 index 0000000000..4284c2d41b --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOps.H @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +Class + indexedCellOps + +Description + +SourceFiles + indexedCellOpsTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef indexedCellOps_H +#define indexedCellOps_H + +#include "label.H" +#include "FixedList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace CGAL +{ + +/*---------------------------------------------------------------------------*\ + Namespace indexedCellOps Declaration +\*---------------------------------------------------------------------------*/ + +namespace indexedCellOps +{ + +//- Does the Dual vertex form part of a processor patch +template +Foam::label dualVertexMasterProc(const CellType& c); + +template +Foam::FixedList processorsAttached(const CellType& c); + +} // End namespace indexedCellOps + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace CGAL + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "indexedCellOpsTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOpsTemplates.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOpsTemplates.C new file mode 100644 index 0000000000..f5fb7f2f22 --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedCell/indexedCellOpsTemplates.C @@ -0,0 +1,82 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "indexedCellOps.H" +#include "Pstream.H" + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +template +Foam::label CGAL::indexedCellOps::dualVertexMasterProc(const CellType& c) +{ + if (!c->parallelDualVertex()) + { + return -1; + } + + // The master processor is the lowest numbered of the four on this tet. + + int masterProc = Foam::Pstream::nProcs() + 1; + + for (Foam::label vI = 0; vI < 4; ++vI) + { + if (c->vertex(vI)->referred()) + { + masterProc = min(masterProc, c->vertex(vI)->procIndex()); + } + else + { + masterProc = min(masterProc, Foam::Pstream::myProcNo()); + } + } + + return masterProc; +} + + +template +Foam::FixedList +CGAL::indexedCellOps::processorsAttached(const CellType& c) +{ + Foam::FixedList procsAttached(Foam::Pstream::myProcNo()); + + if (!c->parallelDualVertex()) + { + return procsAttached; + } + + for (Foam::label vI = 0; vI < 4; ++vI) + { + if (c->vertex(vI)->referred()) + { + procsAttached[vI] = c->vertex(vI)->procIndex(); + } + } + + return procsAttached; +} + + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertex.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertex.H index 73efceccd7..b556be66cc 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertex.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertex.H @@ -95,7 +95,7 @@ namespace CGAL { /*---------------------------------------------------------------------------*\ - Class indexedVertex Declaration + Class indexedVertex Declaration \*---------------------------------------------------------------------------*/ template > @@ -190,8 +190,6 @@ public: inline Foam::scalar targetCellSize() const; - inline bool uninitialised() const; - //- Is point a far-point inline bool farPoint() const; diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexI.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexI.H index 78029d1265..76a77da47d 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexI.H +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexI.H @@ -211,13 +211,6 @@ inline Foam::scalar CGAL::indexedVertex::targetCellSize() const } -template -inline bool CGAL::indexedVertex::uninitialised() const -{ - return type_ == vtUnassigned; -} - - template inline bool CGAL::indexedVertex::farPoint() const { diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOps.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOps.H new file mode 100644 index 0000000000..233cac8d21 --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOps.H @@ -0,0 +1,77 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +Class + indexedVertexOps + +Description + +SourceFiles + indexedVertexOpsTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef indexedVertexOps_H +#define indexedVertexOps_H + +#include "scalar.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace CGAL +{ + +/*---------------------------------------------------------------------------*\ + Namespace indexedVertexOps Declaration +\*---------------------------------------------------------------------------*/ + +namespace indexedVertexOps +{ + +//- Return the target cell size from that stored on a pair of Delaunay vertices, +// using a mean function. +template +Foam::scalar averageCellSize(const VertexType& vA, const VertexType& vB); + + +template +inline bool uninitialised(const VertexType& v); + +} // End namespace indexedVertexOps + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace CGAL + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "indexedVertexOpsTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOpsTemplates.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOpsTemplates.C new file mode 100644 index 0000000000..55adb7cebf --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/indexedVertex/indexedVertexOpsTemplates.C @@ -0,0 +1,57 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "indexedVertexOps.H" + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +template +Foam::scalar CGAL::indexedVertexOps::averageCellSize +( + const VertexType& vA, + const VertexType& vB +) +{ + // Arithmetic mean + // return 0.5*(vA->targetCellSize() + vB->targetCellSize()); + + // Geometric mean + return sqrt(vA->targetCellSize()*vB->targetCellSize()); + + // Harmonic mean + // return + // 2.0*(vA->targetCellSize()*vB->targetCellSize()) + // /(vA->targetCellSize() + vB->targetCellSize()); +} + + +template +inline bool CGAL::indexedVertexOps::uninitialised(const VertexType& v) +{ + return v->type() == Foam::indexedVertexEnum::vtUnassigned; +} + + +// ************************************************************************* // From 56421096d13b823b89dad121930d13e52248a50b Mon Sep 17 00:00:00 2001 From: laurence Date: Mon, 29 Jul 2013 15:38:30 +0100 Subject: [PATCH 04/33] ENH: foamyHexMesh: Shift calculateLoadBalance to DistributedDelaunayMesh --- .../DelaunayMesh/DistributedDelaunayMesh.C | 38 ++++++++++++++++ .../DelaunayMesh/DistributedDelaunayMesh.H | 2 + .../conformalVoronoiMesh.H | 4 -- .../conformalVoronoiMeshTemplates.C | 43 +------------------ 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C index 4f7a07fab9..809de99d8a 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C @@ -747,6 +747,44 @@ void Foam::DistributedDelaunayMesh::sync // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // +template +Foam::scalar +Foam::DistributedDelaunayMesh::calculateLoadUnbalance() const +{ + label nRealVertices = 0; + + for + ( + Finite_vertices_iterator vit = Triangulation::finite_vertices_begin(); + vit != Triangulation::finite_vertices_end(); + ++vit + ) + { + // Only store real vertices that are not feature vertices + if (vit->real() && !vit->featurePoint()) + { + nRealVertices++; + } + } + + scalar globalNRealVertices = returnReduce + ( + nRealVertices, + sumOp