1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 void Foam::meshReader::calcPointCells() const
37 const static label UNIT_POINT_CELLS = 12;
41 FatalErrorIn("meshReader::calcPointCells() const")
42 << "pointCells already calculated"
46 label nPoints = points_.size();
48 pointCellsPtr_ = new labelListList(nPoints);
49 labelListList& ptCells = *pointCellsPtr_;
53 ptCells[i].setSize(UNIT_POINT_CELLS);
56 // Initialize the list of labels which will hold the count of the
57 // actual number of cells per point during the analysis
58 labelList cellCount(nPoints, 0);
60 // Note. Unlike the standard point-cell algorithm, which asks the cell for
61 // the supporting point labels, we need to work based on the cell faces.
62 // This is because some of the faces do not come from the cell shape.
63 // It is also advantageous to remove duplicates from the point-cell
64 // addressing, because this removes a lot of waste later.
66 faceListList& cFaces = cellFaces();
71 const faceList& faces = cFaces[cellI];
76 const labelList& labels = faces[i];
80 // Set working point label
81 label curPoint = labels[j];
82 labelList& curPointCells = ptCells[curPoint];
83 label curCount = cellCount[curPoint];
85 // check if the cell has been added before
88 for (label f = 0; f < curCount; f++)
90 if (curPointCells[f] == cellI)
99 // If the list of pointCells is not big enough, double it
100 if (curPointCells.size() <= curCount)
102 curPointCells.setSize(curPointCells.size()*2);
105 // Enter the cell label in the point's cell list
106 curPointCells[curCount] = cellI;
108 // Increment the cell count for the point addressed
109 cellCount[curPoint]++;
115 // report and remove unused points
116 // - adjust points, pointCells, and cellFaces accordingly
118 labelList oldToNew(nPoints, -1);
122 ptCells[i].setSize(cellCount[i]);
123 if (cellCount[i] > 0)
125 oldToNew[i] = pointI++;
129 // report unused points
130 if (nPoints > pointI)
132 Info<< "removing " << (nPoints - pointI) << " unused points" << endl;
136 // adjust points and truncate - bend const-ness
137 pointField& adjustedPoints = const_cast<pointField&>(points_);
139 inplaceReorder(oldToNew, adjustedPoints);
140 adjustedPoints.setSize(nPoints);
142 // adjust pointCells and truncate
143 inplaceReorder(oldToNew, ptCells);
144 ptCells.setSize(nPoints);
146 // adjust cellFaces - this could be faster
148 forAll(cFaces, cellI)
150 faceList& faces = cFaces[cellI];
155 inplaceRenumber(oldToNew, faces[i]);
162 const Foam::labelListList& Foam::meshReader::pointCells() const
169 return *pointCellsPtr_;
173 // ************************************************************************* //