Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / primitiveMesh / primitiveMeshPointCells.C
blobe4df335ca13683158ea00b7cd76d660c40d2843f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "primitiveMesh.H"
27 #include "cell.H"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 void Foam::primitiveMesh::calcPointCells() const
33     // Loop through cells and mark up points
35     if (debug)
36     {
37         Pout<< "primitiveMesh::calcPointCells() : "
38             << "calculating pointCells"
39             << endl;
41         if (debug == -1)
42         {
43             // For checking calls:abort so we can quickly hunt down
44             // origin of call
45             FatalErrorIn("primitiveMesh::calcPointCells()")
46                 << abort(FatalError);
47         }
48     }
50     // It is an error to attempt to recalculate pointCells
51     // if the pointer is already set
52     if (pcPtr_)
53     {
54         FatalErrorIn("primitiveMesh::calcPointCells() const")
55             << "pointCells already calculated"
56             << abort(FatalError);
57     }
58     else
59     {
60         const cellList& cf = cells();
62         // Count number of cells per point
64         labelList npc(nPoints(), 0);
66         forAll (cf, cellI)
67         {
68             const labelList curPoints = cf[cellI].labels(faces());
70             forAll (curPoints, pointI)
71             {
72                 label ptI = curPoints[pointI];
74                 npc[ptI]++;
75             }
76         }
79         // Size and fill cells per point
81         pcPtr_ = new labelListList(npc.size());
82         labelListList& pointCellAddr = *pcPtr_;
84         forAll (pointCellAddr, pointI)
85         {
86             pointCellAddr[pointI].setSize(npc[pointI]);
87         }
88         npc = 0;
91         forAll (cf, cellI)
92         {
93             const labelList curPoints = cf[cellI].labels(faces());
95             forAll (curPoints, pointI)
96             {
97                 label ptI = curPoints[pointI];
99                 pointCellAddr[ptI][npc[ptI]++] = cellI;
100             }
101         }
102     }
106 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
108 const Foam::labelListList& Foam::primitiveMesh::pointCells() const
110     if (!pcPtr_)
111     {
112         calcPointCells();
113     }
115     return *pcPtr_;
119 const Foam::labelList& Foam::primitiveMesh::pointCells
121     const label pointI,
122     dynamicLabelList& storage
123 ) const
125     if (hasPointCells())
126     {
127         return pointCells()[pointI];
128     }
129     else
130     {
131         const labelList& own = faceOwner();
132         const labelList& nei = faceNeighbour();
133         const labelList& pFaces = pointFaces()[pointI];
135         storage.clear();
137         forAll(pFaces, i)
138         {
139             const label faceI = pFaces[i];
141             // Append owner
142             storage.append(own[faceI]);
144             // Append neighbour
145             if (faceI < nInternalFaces())
146             {
147                 storage.append(nei[faceI]);
148             }
149         }
151         // Filter duplicates
152         if (storage.size() > 1)
153         {
154             sort(storage);
156             label n = 1;
157             for (label i = 1; i < storage.size(); i++)
158             {
159                 if (storage[i-1] != storage[i])
160                 {
161                     storage[n++] = storage[i];
162                 }
163             }
165             // truncate addressed list
166             storage.setSize(n);
167         }
169         return storage;
170     }
174 const Foam::labelList& Foam::primitiveMesh::pointCells(const label pointI) const
176     return pointCells(pointI, labels_);
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 // ************************************************************************* //