initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / PrimitivePatch / PrimitivePatchMeshEdges.C
blob79bac6f1c09db49c4dea705edd79e17c045b47b6
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "PrimitivePatch.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 template
36     class Face,
37     template<class> class FaceList,
38     class PointField,
39     class PointType
42 Foam::labelList
43 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
44 meshEdges
46     const edgeList& allEdges,
47     const labelListList& cellEdges,
48     const labelList& faceCells
49 ) const
51     if (debug)
52     {
53         Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
54             << "::meshEdges() : "
55             << "calculating labels of patch edges in mesh edge list"
56             << endl;
57     }
59     // get reference to the list of edges on the patch
60     const edgeList& PatchEdges = edges();
62     const labelListList& EdgeFaces = edgeFaces();
64     // create the storage
65     labelList meshEdges(PatchEdges.size());
67     register bool found = false;
69     // get reference to the points on the patch
70     const labelList& pp = meshPoints();
72     // WARNING: Remember that local edges address into local point list;
73     // local-to-global point label translation is necessary
74     forAll (PatchEdges, edgeI)
75     {
76         const edge curEdge
77             (pp[PatchEdges[edgeI].start()], pp[PatchEdges[edgeI].end()]);
79         found = false;
81         // get the patch faces sharing the edge
82         const labelList& curFaces = EdgeFaces[edgeI];
84         forAll (curFaces, faceI)
85         {
86             // get the cell next to the face
87             label curCell = faceCells[curFaces[faceI]];
89             // get reference to edges on the cell
90             const labelList& ce = cellEdges[curCell];
92             forAll (ce, cellEdgeI)
93             {
94                 if (allEdges[ce[cellEdgeI]] == curEdge)
95                 {
96                     found = true;
98                     meshEdges[edgeI] = ce[cellEdgeI];
100                     break;
101                 }
102             }
104             if (found) break;
105         }
106     }
108     return meshEdges;
112 template
114     class Face,
115     template<class> class FaceList,
116     class PointField,
117     class PointType
120 Foam::labelList
121 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
122 meshEdges
124     const edgeList& allEdges,
125     const labelListList& pointEdges
126 ) const
128     if (debug)
129     {
130         Info<< "labelList PrimitivePatch<Face, FaceList, PointField, PointType>"
131             << "::meshEdges() : "
132             << "calculating labels of patch edges in mesh edge list"
133             << endl;
134     }
136     // get reference to the list of edges on the patch
137     const edgeList& PatchEdges = edges();
139     // create the storage
140     labelList meshEdges(PatchEdges.size());
142     // get reference to the points on the patch
143     const labelList& pp = meshPoints();
145     // WARNING: Remember that local edges address into local point list;
146     // local-to-global point label translation is necessary
147     forAll (PatchEdges, edgeI)
148     {
149         const label globalPointI = pp[PatchEdges[edgeI].start()];
150         const edge curEdge(globalPointI, pp[PatchEdges[edgeI].end()]);
152         const labelList& pe = pointEdges[globalPointI];
154         forAll (pe, i)
155         {
156             if (allEdges[pe[i]] == curEdge)
157             {
158                 meshEdges[edgeI] = pe[i];
159                 break;
160             }
161         }
162     }
164     return meshEdges;
168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
170 template
172     class Face,
173     template<class> class FaceList,
174     class PointField,
175     class PointType
178 Foam::label
179 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
180 whichEdge
182     const edge& e
183 ) const
185     // Get pointEdges from the starting point and search all the candidates
186     const edgeList& Edges = edges();
188     if (e.start() > -1 && e.start() < nPoints())
189     {
190         const labelList& pe = pointEdges()[e.start()];
192         forAll (pe, peI)
193         {
194             if (e == Edges[pe[peI]])
195             {
196                 return pe[peI];
197             }
198         }
199     }
201     // Edge not found.  Return -1
202     return -1;
206 // ************************************************************************* //