Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / primitiveMesh / primitiveMeshCellCells.C
blobf03346e62798d9b6e160588a9612ec69c5f60a7d
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"
29 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
31 void Foam::primitiveMesh::calcCellCells() const
33     // Loop through faceCells and mark up neighbours
35     if (debug)
36     {
37         Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
38             << endl;
40         if (debug == -1)
41         {
42             // For checking calls:abort so we can quickly hunt down
43             // origin of call
44             FatalErrorIn("primitiveMesh::calcCellCells()")
45                 << abort(FatalError);
46         }
47     }
49     // It is an error to attempt to recalculate cellCells
50     // if the pointer is already set
51     if (ccPtr_)
52     {
53         FatalErrorIn("primitiveMesh::calcCellCells() const")
54             << "cellCells already calculated"
55             << abort(FatalError);
56     }
57     else
58     {
59         // 1. Count number of internal faces per cell
61         labelList ncc(nCells(), 0);
63         const labelList& own = faceOwner();
64         const labelList& nei = faceNeighbour();
66         forAll (nei, faceI)
67         {
68             ncc[own[faceI]]++;
69             ncc[nei[faceI]]++;
70         }
72         // Create the storage
73         ccPtr_ = new labelListList(ncc.size());
74         labelListList& cellCellAddr = *ccPtr_;
78         // 2. Size and fill cellCellAddr
80         forAll (cellCellAddr, cellI)
81         {
82             cellCellAddr[cellI].setSize(ncc[cellI]);
83         }
84         ncc = 0;
86         forAll (nei, faceI)
87         {
88             label ownCellI = own[faceI];
89             label neiCellI = nei[faceI];
91             cellCellAddr[ownCellI][ncc[ownCellI]++] = neiCellI;
92             cellCellAddr[neiCellI][ncc[neiCellI]++] = ownCellI;
93         }
94     }
98 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
100 const Foam::labelListList& Foam::primitiveMesh::cellCells() const
102     if (!ccPtr_)
103     {
104         calcCellCells();
105     }
107     return *ccPtr_;
111 const Foam::labelList& Foam::primitiveMesh::cellCells
113     const label cellI,
114     dynamicLabelList& storage
115 ) const
117     if (hasCellCells())
118     {
119         return cellCells()[cellI];
120     }
121     else
122     {
123         const labelList& own = faceOwner();
124         const labelList& nei = faceNeighbour();
125         const cell& cFaces = cells()[cellI];
127         storage.clear();
129         forAll(cFaces, i)
130         {
131             label faceI = cFaces[i];
133             if (faceI < nInternalFaces())
134             {
135                 if (own[faceI] == cellI)
136                 {
137                     storage.append(nei[faceI]);
138                 }
139                 else
140                 {
141                     storage.append(own[faceI]);
142                 }
143             }
144         }
146         return storage;
147     }
151 const Foam::labelList& Foam::primitiveMesh::cellCells(const label cellI) const
153     return cellCells(cellI, labels_);
157 // ************************************************************************* //