1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
11 cfMesh is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
16 cfMesh is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
26 \*---------------------------------------------------------------------------*/
28 #include "voronoiMeshExtractor.H"
29 #include "demandDrivenData.H"
35 //#define DEBUGVoronoi
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 void voronoiMeshExtractor::createPoints()
46 const LongList<point>& tetPoints = tetCreator_.tetPoints();
47 const LongList<partTet>& tets = tetCreator_.tets();
49 pointFieldPMG& points = mesh_.points();
50 points.setSize(tets.size());
53 Info << "Number of tets " << tets.size() << endl;
57 # pragma omp parallel for schedule(dynamic, 100)
61 points[tetI] = tets[tetI].centroid(tetPoints);
64 Info << "Point " << tetI << " has coordinates "
65 << points[tetI] << endl;
66 Info << "Tet of origin " << tetI << " has nodes "
67 << tets[tetI] << endl;
72 void voronoiMeshExtractor::createPolyMesh()
74 const VRWGraph& pointEdges = this->pointEdges();
75 const VRWGraph& edgeTets = this->edgeTets();
76 const boolList& boundaryEdge = this->boundaryEdge();
77 const LongList<edge>& edges = this->edges();
79 polyMeshGenModifier meshModifier(mesh_);
80 faceListPMG& faces = meshModifier.facesAccess();
81 cellListPMG& cells = meshModifier.cellsAccess();
83 //- count the number of cells
85 labelList cellLabel(pointEdges.size(), -1);
87 forAll(pointEdges, pointI)
90 forAllRow(pointEdges, pointI, eI)
91 if( boundaryEdge[pointEdges(pointI, eI)] )
97 if( !create || (pointEdges.sizeOfRow(pointI) == 0) )
100 cellLabel[pointI] = nCells;
105 Info << "Number of cells " << nCells << endl;
108 //- count the number of faces
110 labelList faceLabel(edges.size(), -1);
112 forAll(boundaryEdge, edgeI)
114 if( boundaryEdge[edgeI] )
117 const edge& e = edges[edgeI];
118 if( cellLabel[e[0]] < 0 && cellLabel[e[1]] < 0 )
121 faceLabel[edgeI] = nFaces;
126 Info << "Number of mesh faces " << nFaces << endl;
130 Info << "Creating faces " << endl;
131 faces.setSize(nFaces);
132 labelList nFacesInCell(nCells, 0);
136 if( faceLabel[edgeI] < 0 )
139 const label faceI = faceLabel[edgeI];
141 face& f = faces[faceI];
142 f.setSize(edgeTets.sizeOfRow(edgeI));
144 //- fill the faces with the node labels
145 forAllRow(edgeTets, edgeI, pI)
146 f[pI] = edgeTets(edgeI, pI);
148 const edge& e = edges[edgeI];
149 const label cOwn = cellLabel[e[0]];
150 const label cNei = cellLabel[e[1]];
152 if( cOwn < 0 || ((cOwn > cNei) && (cNei != -1)) )
155 Info << "Reversing face " << cOwn << " " << cNei << endl;
162 ++nFacesInCell[cOwn];
164 ++nFacesInCell[cNei];
169 Info << "Setting cell sizes" << endl;
172 cells.setSize(nCells);
173 forAll(nFacesInCell, cellI)
175 cells[cellI].setSize(nFacesInCell[cellI]);
176 nFacesInCell[cellI] = 0;
180 Info << "Filling cells" << endl;
185 if( faceLabel[edgeI] < 0 )
188 const label faceI = faceLabel[edgeI];
189 const edge& e = edges[edgeI];
190 const label cOwn = cellLabel[e[0]];
191 const label cNei = cellLabel[e[1]];
194 cells[cOwn][nFacesInCell[cOwn]++] = faceI;
196 cells[cNei][nFacesInCell[cNei]++] = faceI;
200 Info << "Finished generating cells" << endl;
203 mesh_.clearAddressingData();
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 } // End namespace Foam
210 // ************************************************************************* //