Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMeshCellCells.C
blobba3f644e8508372acdf845a0adfbf902d774318c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, 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 cellFaceAddr
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     DynamicList<label>& 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 // ************************************************************************* //