Forward compatibility: flex
[foam-extend-3.2.git] / src / foam / meshes / primitiveMesh / primitiveMeshEdgeCells.C
blob0863700daf8dab51a97c5251cb2457f3f9dca81d
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 "ListOps.H"
30 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
32 const Foam::labelListList& Foam::primitiveMesh::edgeCells() const
34     if (!ecPtr_)
35     {
36         if (debug)
37         {
38             Pout<< "primitiveMesh::edgeCells() : calculating edgeCells"
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::edgeCells()")
46                     << abort(FatalError);
47             }
48         }
49         // Invert cellEdges
50         ecPtr_ = new labelListList(nEdges());
51         invertManyToMany(nEdges(), cellEdges(), *ecPtr_);
52     }
54     return *ecPtr_;
58 const Foam::labelList& Foam::primitiveMesh::edgeCells
60     const label edgeI,
61     dynamicLabelList& storage
62 ) const
64     if (hasEdgeCells())
65     {
66         return edgeCells()[edgeI];
67     }
68     else
69     {
70         const labelList& own = faceOwner();
71         const labelList& nei = faceNeighbour();
73         // Construct edgeFaces
74         dynamicLabelList eFacesStorage;
75         const labelList& eFaces = edgeFaces(edgeI, eFacesStorage);
77         storage.clear();
79         // Do quadratic insertion.
80         forAll(eFaces, i)
81         {
82             label faceI = eFaces[i];
84             {
85                 label ownCellI = own[faceI];
87                 // Check if not already in storage
88                 forAll(storage, j)
89                 {
90                     if (storage[j] == ownCellI)
91                     {
92                         ownCellI = -1;
93                         break;
94                     }
95                 }
97                 if (ownCellI != -1)
98                 {
99                     storage.append(ownCellI);
100                 }
101             }
103             if (isInternalFace(faceI))
104             {
105                 label neiCellI = nei[faceI];
107                 forAll(storage, j)
108                 {
109                     if (storage[j] == neiCellI)
110                     {
111                         neiCellI = -1;
112                         break;
113                     }
114                 }
116                 if (neiCellI != -1)
117                 {
118                     storage.append(neiCellI);
119                 }
120             }
121         }
123         return storage;
124     }
128 const Foam::labelList& Foam::primitiveMesh::edgeCells(const label edgeI) const
130     return edgeCells(edgeI, labels_);
134 // ************************************************************************* //