Added faceCentres member function.
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / PrimitivePatch / PrimitivePatchMeshEdges.C
blobfe65b515ecf517232cfdf4ba8cd179d1fd45a255
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 "PrimitivePatch.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 template
34     class Face,
35     template<class> class FaceList,
36     class PointField,
37     class PointType
39 Foam::labelList
40 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
41 meshEdges
43     const edgeList& allEdges,
44     const labelListList& cellEdges,
45     const labelList& faceCells
46 ) const
48     if (debug)
49     {
50         Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
51             << "::meshEdges() : "
52             << "calculating labels of patch edges in mesh edge list"
53             << endl;
54     }
56     // get reference to the list of edges on the patch
57     const edgeList& PatchEdges = edges();
59     const labelListList& EdgeFaces = edgeFaces();
61     // create the storage
62     labelList meshEdges(PatchEdges.size());
64     register bool found = false;
66     // get reference to the points on the patch
67     const labelList& pp = meshPoints();
69     // WARNING: Remember that local edges address into local point list;
70     // local-to-global point label translation is necessary
71     forAll (PatchEdges, edgeI)
72     {
73         const edge curEdge
74             (pp[PatchEdges[edgeI].start()], pp[PatchEdges[edgeI].end()]);
76         found = false;
78         // get the patch faces sharing the edge
79         const labelList& curFaces = EdgeFaces[edgeI];
81         forAll (curFaces, faceI)
82         {
83             // get the cell next to the face
84             label curCell = faceCells[curFaces[faceI]];
86             // get reference to edges on the cell
87             const labelList& ce = cellEdges[curCell];
89             forAll (ce, cellEdgeI)
90             {
91                 if (allEdges[ce[cellEdgeI]] == curEdge)
92                 {
93                     found = true;
95                     meshEdges[edgeI] = ce[cellEdgeI];
97                     break;
98                 }
99             }
101             if (found) break;
102         }
103     }
105     return meshEdges;
109 template
111     class Face,
112     template<class> class FaceList,
113     class PointField,
114     class PointType
116 Foam::labelList
117 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
118 meshEdges
120     const edgeList& allEdges,
121     const labelListList& pointEdges
122 ) const
124     if (debug)
125     {
126         Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
127             << "::meshEdges() : "
128             << "calculating labels of patch edges in mesh edge list"
129             << endl;
130     }
132     // get reference to the list of edges on the patch
133     const edgeList& PatchEdges = edges();
135     // create the storage
136     labelList meshEdges(PatchEdges.size());
138     // get reference to the points on the patch
139     const labelList& pp = meshPoints();
141     // WARNING: Remember that local edges address into local point list;
142     // local-to-global point label translation is necessary
143     forAll (PatchEdges, edgeI)
144     {
145         const label globalPointI = pp[PatchEdges[edgeI].start()];
146         const edge curEdge(globalPointI, pp[PatchEdges[edgeI].end()]);
148         const labelList& pe = pointEdges[globalPointI];
150         forAll (pe, i)
151         {
152             if (allEdges[pe[i]] == curEdge)
153             {
154                 meshEdges[edgeI] = pe[i];
155                 break;
156             }
157         }
158     }
160     return meshEdges;
164 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
166 template
168     class Face,
169     template<class> class FaceList,
170     class PointField,
171     class PointType
173 Foam::label
174 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
175 whichEdge
177     const edge& e
178 ) const
180     // Get pointEdges from the starting point and search all the candidates
181     const edgeList& Edges = edges();
183     if (e.start() > -1 && e.start() < nPoints())
184     {
185         const labelList& pe = pointEdges()[e.start()];
187         forAll (pe, peI)
188         {
189             if (e == Edges[pe[peI]])
190             {
191                 return pe[peI];
192             }
193         }
194     }
196     // Edge not found.  Return -1
197     return -1;
201 // ************************************************************************* //