1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM 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 OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 calculate point cells - ie, the cells attached to each point
28 - remove unused points, adjust pointCells and cellFaces accordingly
29 \*---------------------------------------------------------------------------*/
31 #include "meshReader.H"
33 // for transition - in case someone really relied on the old behaviour
34 #undef LEAVE_UNUSED_POINTS
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 void Foam::meshReader::calcPointCells() const
40 const static label UNIT_POINT_CELLS = 12;
44 FatalErrorIn("meshReader::calcPointCells() const")
45 << "pointCells already calculated"
49 label nPoints = points().size();
51 pointCellsPtr_ = new labelListList(nPoints);
52 labelListList& ptCells = *pointCellsPtr_;
56 ptCells[i].setSize(UNIT_POINT_CELLS);
59 // Initialize the list of labels which will hold the count of the
60 // actual number of cells per point during the analysis
61 labelList cellCount(nPoints, 0);
63 // Note. Unlike the standard point-cell algorithm, which asks the cell for
64 // the supporting point labels, we need to work based on the cell faces.
65 // This is because some of the faces do not come from the cell shape.
66 // It is also advantageous to remove duplicates from the point-cell
67 // addressing, because this removes a lot of waste later.
69 faceListList& cFaces = cellFaces();
74 const faceList& faces = cFaces[cellI];
79 const labelList& labels = faces[i];
83 // Set working point label
84 label curPoint = labels[j];
85 labelList& curPointCells = ptCells[curPoint];
86 label curCount = cellCount[curPoint];
88 // check if the cell has been added before
91 for (label f = 0; f < curCount; f++)
93 if (curPointCells[f] == cellI)
102 // If the list of pointCells is not big enough, double it
103 if (curPointCells.size() <= curCount)
105 curPointCells.setSize(curPointCells.size()*2);
108 // Enter the cell label in the point's cell list
109 curPointCells[curCount] = cellI;
111 // Increment the cell count for the point addressed
112 cellCount[curPoint]++;
118 // report and remove unused points
119 // - adjust points, pointCells, and cellFaces accordingly
121 labelList oldToNew(nPoints, -1);
125 ptCells[i].setSize(cellCount[i]);
126 if (cellCount[i] > 0)
128 oldToNew[i] = pointI++;
132 // report unused points
133 if (nPoints > pointI)
135 #ifdef LEAVE_UNUSED_POINTS
136 FatalErrorIn("meshReader::calcPointCells() const")
137 << "mesh has " << (nPoints - pointI)
138 << " points that were declared but not used" << endl;
141 Info<< "removing " << (nPoints - pointI) << " unused points" << endl;
145 // adjust points and truncate
146 inplaceReorder(oldToNew, points());
147 points().setSize(nPoints);
149 // adjust pointCells and truncate
150 inplaceReorder(oldToNew, ptCells);
151 ptCells.setSize(nPoints);
153 // adjust cellFaces - this could be faster
155 forAll(cFaces, cellI)
157 faceList& faces = cFaces[cellI];
162 inplaceRenumber(oldToNew, faces[i]);
170 const Foam::labelListList& Foam::meshReader::pointCells() const
177 return *pointCellsPtr_;
181 // ************************************************************************* //