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 "tetMeshExtractorOctree.H"
29 #include "meshOctree.H"
30 #include "triSurface.H"
31 #include "polyMeshGenModifierAddCellByCell.H"
32 #include "demandDrivenData.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 void tetMeshExtractorOctree::createPoints()
49 polyMeshGenModifier meshModifier ( mesh_ );
50 pointFieldPMG& points = meshModifier.pointsAccess();
52 const LongList<point>& tetPoints = tetCreator_.tetPoints();
54 points.setSize(tetPoints.size());
57 # pragma omp parallel for
59 forAll(tetPoints, pointI)
60 points[pointI] = tetPoints[pointI];
63 void tetMeshExtractorOctree::createPolyMesh()
65 polyMeshGenModifier meshModifier ( mesh_ );
67 faceListPMG& faces = meshModifier.facesAccess();
68 cellListPMG& cells = meshModifier.cellsAccess();
69 meshModifier.boundariesAccess().setSize ( 0 );
70 meshModifier.procBoundariesAccess().setSize ( 0 );
72 const LongList<partTet>& tets = tetCreator_.tets();
75 pTets.reverseAddressing(mesh_.points().size(), tets);
77 //- set the number of cells
78 cells.setSize(tets.size());
80 //- all faces of tetrahedral cells
81 faces.setSize(4*tets.size());
82 boolList removeFace(faces.size());
85 # pragma omp parallel if( tets.size() > 1000 )
92 forAll(removeFace, faceI)
93 removeFace[faceI] = false;
95 //- set sizes of cells and create all faces
97 # pragma omp for schedule(dynamic, 20)
101 cells[elmtI].setSize(4);
103 const partTet& elmt = tets[elmtI];
105 label faceI = 4 * elmtI;
108 cells[elmtI][0] = faceI;
110 face& f0 = faces[faceI];
120 cells[elmtI][1] = faceI;
122 face& f1 = faces[faceI];
132 cells[elmtI][2] = faceI;
134 face& f2 = faces[faceI];
144 cells[elmtI][3] = faceI;
146 face& f3 = faces[faceI];
158 //- find duplicate faces
160 # pragma omp for schedule(dynamic, 20)
164 cell& c = cells[cellI];
168 const face& f = faces[c[fI]];
169 const label pointI = f[0];
171 forAllRow(pTets, pointI, ptI)
173 //- do not check cells with greater labels
174 //- they cannot be face owners
175 if( pTets(pointI, ptI) >= cellI )
178 const cell& otherTet = cells[pTets(pointI, ptI)];
180 //- check faces created from a tet
181 forAll(otherTet, ofI)
183 //- do not compare faces with greater labels
184 //- they shall not be removed here
185 if( otherTet[ofI] >= c[fI] )
188 //- check if the faces are equal
189 if( f == faces[otherTet[ofI]] )
191 removeFace[c[fI]] = true;
192 c[fI] = otherTet[ofI];
200 //- remove duplicate faces
202 labelLongList newFaceLabel(faces.size(), -1);
206 if( !removeFace[faceI] )
209 faces[nFaces].transfer(faces[faceI]);
211 newFaceLabel[faceI] = nFaces;
216 //- set the size of faces
217 faces.setSize(nFaces);
221 # pragma omp for schedule(dynamic, 40)
225 cell& c = cells[cellI];
231 if( newFaceLabel[c[fI]] != -1 )
232 newC.append(newFaceLabel[c[fI]]);
235 c.setSize(newC.size());
241 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
243 // Construct from octree and mesh data
244 tetMeshExtractorOctree::tetMeshExtractorOctree
246 const meshOctree& octree,
247 const IOdictionary& meshDict,
251 tetCreator_(octree, meshDict),
255 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
257 tetMeshExtractorOctree::~tetMeshExtractorOctree()
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 void tetMeshExtractorOctree::createMesh()
264 Info << "Extracting tetMesh" << endl;
266 //- copy tet points into the mesh
272 polyMeshGenModifier(mesh_).reorderBoundaryFaces();
273 polyMeshGenModifier(mesh_).removeUnusedVertices();
275 Info << "Mesh has :" << nl
276 << mesh_.points().size() << " vertices " << nl
277 << mesh_.faces().size() << " faces" << nl
278 << mesh_.cells().size() << " cells" << endl;
280 Info << "Finished extracting tetMesh" << endl;
283 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 } // End namespace Foam
287 // ************************************************************************* //