initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / sammToFoam / calcPointCells.C
blobc94d7322344081907060b31a2ac0812d3079c823
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Description
26     Create intermediate mesh files from SAMM files
28 \*---------------------------------------------------------------------------*/
30 #include "sammMesh.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void sammMesh::calcPointCells() const
36     const static label UNIT_POINT_CELLS = 12;
38     if (pointCellsPtr_)
39     {
40         FatalErrorIn("sammMesh::calcPointCells()")
41             << "PointCells already calculated"
42             << abort(FatalError);
43     }
46     pointCellsPtr_ = new labelListList(points_.size());
48     labelListList& pc = *pointCellsPtr_;
50     forAll(pc, i)
51     {
52         pc[i].setSize(UNIT_POINT_CELLS);
53     }
55     // Initialise the list of labels which will hold the count the
56     // actual number of cells per point during the analysis
57     labelList cellCount(points_.size());
59     forAll(cellCount, i)
60     {
61         cellCount[i] = 0;
62     }
64     // Note. Unlike the standard point-cell algorithm, which asks the cell for
65     // the supporting point labels, we need to work based on the cell faces.
66     // This is because some of the faces for meshes with arbitrary interfaces
67     // do not come from the cell shape, but from the slaves of the coupled
68     // match. It is also adventageous to remove the duplicates from the
69     // point-cell addressing, because this removes a lot of waste later.
70     // 
72     // For each cell
73     forAll(cellShapes_, cellI)
74     {
75         const faceList& faces = cellFaces_[cellI];
77         forAll (faces, i)
78         {
79             // For each vertex
80             const labelList& labels = faces[i];
82             forAll(labels, j)
83             {
84                 // Set working point label
85                 label curPoint = labels[j];
86                 labelList& curPointCells = pc[curPoint];
87                 label curCount = cellCount[curPoint];
89                 // check if the cell has been added before
90                 bool found = false;
92                 for (label f = 0; f < curCount; f++)
93                 {
94                     if (curPointCells[f] == cellI)
95                     {
96                         found = true;
98                         break;
99                     }
100                 }
102                 if (!found)
103                 {
105                     // If the list of pointCells is not big enough, double it
106                     if (curPointCells.size() <= curCount)
107                     {
108                         curPointCells.setSize(curPointCells.size()*2);
109                     }
111                     // Enter the cell label in the point's cell list
112                     curPointCells[curCount] = cellI;
114                     // Increment the cell count for the point addressed
115                     cellCount[curPoint]++;
116                 }
117             }
118         }
119     }
121     // Finally, truncate the lists made to their active size
122     forAll(pc, i)
123     {
124         pc[i].setSize(cellCount[i]);
125     }
129 const labelListList& sammMesh::pointCells() const
131     if (!pointCellsPtr_)
132     {
133         calcPointCells();
134     }
136     return *pointCellsPtr_;
140 // ************************************************************************* //