initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMeshPointCells.C
blob3666defa09992338be0ee46071bf502b4b87b5c7
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 \*---------------------------------------------------------------------------*/
27 #include "primitiveMesh.H"
28 #include "cell.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 void Foam::primitiveMesh::calcPointCells() const
34     // Loop through cells and mark up points
36     if (debug)
37     {
38         Pout<< "primitiveMesh::calcPointCells() : "
39             << "calculating pointCells"
40             << endl;
42         if (debug == -1)
43         {
44             // For checking calls:abort so we can quickly hunt down
45             // origin of call
46             FatalErrorIn("primitiveMesh::calcPointCells()")
47                 << abort(FatalError);
48         }
49     }
51     // It is an error to attempt to recalculate pointCells
52     // if the pointer is already set
53     if (pcPtr_)
54     {
55         FatalErrorIn("primitiveMesh::calcPointCells() const")
56             << "pointCells already calculated"
57             << abort(FatalError);
58     }
59     else
60     {
61         const cellList& cf = cells();
63         // Count number of cells per point
65         labelList npc(nPoints(), 0);
67         forAll (cf, cellI)
68         {
69             const labelList curPoints = cf[cellI].labels(faces());
71             forAll (curPoints, pointI)
72             {
73                 label ptI = curPoints[pointI];
75                 npc[ptI]++;
76             }
77         }
80         // Size and fill cells per point
82         pcPtr_ = new labelListList(npc.size());
83         labelListList& pointCellAddr = *pcPtr_;
85         forAll (pointCellAddr, pointI)
86         {
87             pointCellAddr[pointI].setSize(npc[pointI]);
88         }
89         npc = 0;
92         forAll (cf, cellI)
93         {
94             const labelList curPoints = cf[cellI].labels(faces());
96             forAll (curPoints, pointI)
97             {
98                 label ptI = curPoints[pointI];
100                 pointCellAddr[ptI][npc[ptI]++] = cellI;
101             }
102         }
103     }
107 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
109 const Foam::labelListList& Foam::primitiveMesh::pointCells() const
111     if (!pcPtr_)
112     {
113         calcPointCells();
114     }
116     return *pcPtr_;
120 const Foam::labelList& Foam::primitiveMesh::pointCells
122     const label pointI,
123     DynamicList<label>& storage
124 ) const
126     if (hasPointCells())
127     {
128         return pointCells()[pointI];
129     }
130     else
131     {
132         const labelList& own = faceOwner();
133         const labelList& nei = faceNeighbour();
134         const labelList& pFaces = pointFaces()[pointI];
136         storage.clear();
138         forAll(pFaces, i)
139         {
140             const label faceI = pFaces[i];
142             // Append owner
143             storage.append(own[faceI]);
145             // Append neighbour
146             if (faceI < nInternalFaces())
147             {
148                 storage.append(nei[faceI]);
149             }
150         }
152         // Filter duplicates
153         if (storage.size() > 1)
154         {
155             sort(storage);
157             label n = 1;
158             for (label i = 1; i < storage.size(); i++)
159             {
160                 if (storage[i-1] != storage[i])
161                 {
162                     storage[n++] = storage[i];
163                 }
164             }
166             // truncate addressed list
167             storage.setSize(n);
168         }
170         return storage;
171     }
175 const Foam::labelList& Foam::primitiveMesh::pointCells(const label pointI) const
177     return pointCells(pointI, labels_);
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 // ************************************************************************* //