1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 calculate point cells - ie, the cells attached to each point
27 - remove unused points, adjust pointCells and cellFaces accordingly
28 \*---------------------------------------------------------------------------*/
30 #include "meshReader.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void Foam::meshReader::calcPointCells() const
36 static const label UNIT_POINT_CELLS = 12;
40 FatalErrorIn("meshReader::calcPointCells() const")
41 << "pointCells already calculated"
45 label nPoints = points_.size();
47 pointCellsPtr_ = new labelListList(nPoints);
48 labelListList& ptCells = *pointCellsPtr_;
52 ptCells[i].setSize(UNIT_POINT_CELLS);
55 // Initialize the list of labels which will hold the count of the
56 // actual number of cells per point during the analysis
57 labelList cellCount(nPoints, 0);
59 // Note. Unlike the standard point-cell algorithm, which asks the cell for
60 // the supporting point labels, we need to work based on the cell faces.
61 // This is because some of the faces do not come from the cell shape.
62 // It is also advantageous to remove duplicates from the point-cell
63 // addressing, because this removes a lot of waste later.
65 faceListList& cFaces = cellFaces();
70 const faceList& faces = cFaces[cellI];
75 const labelList& labels = faces[i];
79 // Set working point label
80 label curPoint = labels[j];
81 labelList& curPointCells = ptCells[curPoint];
82 label curCount = cellCount[curPoint];
84 // check if the cell has been added before
87 for (label f = 0; f < curCount; f++)
89 if (curPointCells[f] == cellI)
98 // If the list of pointCells is not big enough, double it
99 if (curPointCells.size() <= curCount)
101 curPointCells.setSize(curPointCells.size()*2);
104 // Enter the cell label in the point's cell list
105 curPointCells[curCount] = cellI;
107 // Increment the cell count for the point addressed
108 cellCount[curPoint]++;
114 // report and remove unused points
115 // - adjust points, pointCells, and cellFaces accordingly
117 labelList oldToNew(nPoints, -1);
121 ptCells[i].setSize(cellCount[i]);
122 if (cellCount[i] > 0)
124 oldToNew[i] = pointI++;
128 // report unused points
129 if (nPoints > pointI)
131 Info<< "removing " << (nPoints - pointI) << " unused points" << endl;
135 // adjust points and truncate - bend const-ness
136 pointField& adjustedPoints = const_cast<pointField&>(points_);
138 inplaceReorder(oldToNew, adjustedPoints);
139 adjustedPoints.setSize(nPoints);
141 // adjust pointCells and truncate
142 inplaceReorder(oldToNew, ptCells);
143 ptCells.setSize(nPoints);
145 // adjust cellFaces - this could be faster
147 forAll(cFaces, cellI)
149 faceList& faces = cFaces[cellI];
154 inplaceRenumber(oldToNew, faces[i]);
161 const Foam::labelListList& Foam::meshReader::pointCells() const
168 return *pointCellsPtr_;
172 // ************************************************************************* //