initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitiveMeshCellCells.C
blob191ee7f5e86631f648b3bbe81554fdd8965e9ca8
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"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 void Foam::primitiveMesh::calcCellCells() const
34     // Loop through faceCells and mark up neighbours
36     if (debug)
37     {
38         Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
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::calcCellCells()")
46                 << abort(FatalError);
47         }
48     }
50     // It is an error to attempt to recalculate cellCells
51     // if the pointer is already set
52     if (ccPtr_)
53     {
54         FatalErrorIn("primitiveMesh::calcCellCells() const")
55             << "cellCells already calculated"
56             << abort(FatalError);
57     }
58     else
59     {
60         // 1. Count number of internal faces per cell
62         labelList ncc(nCells(), 0);
64         const labelList& own = faceOwner();
65         const labelList& nei = faceNeighbour();
67         forAll (nei, faceI)
68         {
69             ncc[own[faceI]]++;
70             ncc[nei[faceI]]++;
71         }
73         // Create the storage
74         ccPtr_ = new labelListList(ncc.size());
75         labelListList& cellCellAddr = *ccPtr_;
79         // 2. Size and fill cellFaceAddr
81         forAll (cellCellAddr, cellI)
82         {
83             cellCellAddr[cellI].setSize(ncc[cellI]);
84         }
85         ncc = 0;
87         forAll (nei, faceI)
88         {
89             label ownCellI = own[faceI];
90             label neiCellI = nei[faceI];
92             cellCellAddr[ownCellI][ncc[ownCellI]++] = neiCellI;
93             cellCellAddr[neiCellI][ncc[neiCellI]++] = ownCellI;
94         }
95     }
99 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
101 const Foam::labelListList& Foam::primitiveMesh::cellCells() const
103     if (!ccPtr_)
104     {
105         calcCellCells();
106     }
108     return *ccPtr_;
112 const Foam::labelList& Foam::primitiveMesh::cellCells
114     const label cellI,
115     DynamicList<label>& storage
116 ) const
118     if (hasCellCells())
119     {
120         return cellCells()[cellI];
121     }
122     else
123     {
124         const labelList& own = faceOwner();
125         const labelList& nei = faceNeighbour();
126         const cell& cFaces = cells()[cellI];
128         storage.clear();
130         forAll(cFaces, i)
131         {
132             label faceI = cFaces[i];
134             if (faceI < nInternalFaces())
135             {
136                 if (own[faceI] == cellI)
137                 {
138                     storage.append(nei[faceI]);
139                 }
140                 else
141                 {
142                     storage.append(own[faceI]);
143                 }
144             }
145         }
147         return storage;
148     }
152 const Foam::labelList& Foam::primitiveMesh::cellCells(const label cellI) const
154     return cellCells(cellI, labels_);
158 // ************************************************************************* //