Added faceCentres member function.
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / PrimitivePatch / PrimitivePatchEdgeLoops.C
blob80e36f166dba6209014e79ab20c1ed67daf1a25c
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
26     Create the list of loops of outside vertices. Goes wrong on multiply
27     connected edges (loops will be unclosed).
29 \*---------------------------------------------------------------------------*/
31 #include "PrimitivePatch.H"
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 template
38     class Face,
39     template<class> class FaceList,
40     class PointField,
41     class PointType
43 void
44 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
45 calcEdgeLoops() const
47     if (debug)
48     {
49         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
50             << "calcEdgeLoops() : "
51             << "calculating boundary edge loops"
52             << endl;
53     }
55     if (edgeLoopsPtr_)
56     {
57         // it is considered an error to attempt to recalculate
58         // if already allocated
59         FatalErrorIn
60         (
61             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
62             "calcIntBdryEdges()"
63         )   << "edge loops already calculated"
64             << abort(FatalError);
65     }
67     const edgeList& patchEdges = edges();
68     label nIntEdges = nInternalEdges();
69     label nBdryEdges = patchEdges.size() - nIntEdges;
71     if (nBdryEdges == 0)
72     {
73         edgeLoopsPtr_ = new labelListList(0);
74         return;
75     }
77     const labelListList& patchPointEdges = pointEdges();
80     //
81     // Walk point-edge-point and assign loop number
82     //
84     // Loop per (boundary) edge.
85     labelList loopNumber(nBdryEdges, -1);
87     // Size return list plenty big
88     edgeLoopsPtr_ = new labelListList(nBdryEdges);
89     labelListList& edgeLoops = *edgeLoopsPtr_;
92     // Current loop number.
93     label loopI = 0;
95     while (true)
96     {
97         // Find edge not yet given a loop number.
98         label currentEdgeI = -1;
100         for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
101         {
102             if (loopNumber[edgeI-nIntEdges] == -1)
103             {
104                 currentEdgeI = edgeI;
105                 break;
106             }
107         }
109         if (currentEdgeI == -1)
110         {
111             // Did not find edge not yet assigned a loop number so done all.
112             break;
113         }
115         // Temporary storage for vertices of current loop
116         DynamicList<label> loop(nBdryEdges);
118         // Walk from first all the way round, assigning loops
119         label currentVertI = patchEdges[currentEdgeI].start();
121         do
122         {
123             loop.append(currentVertI);
125             loopNumber[currentEdgeI - nIntEdges] = loopI;
127             // Step to next vertex
128             currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
130             // Step to next (unmarked, boundary) edge.
131             const labelList& curEdges = patchPointEdges[currentVertI];
133             currentEdgeI = -1;
135             forAll(curEdges, pI)
136             {
137                 label edgeI = curEdges[pI];
139                 if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
140                 {
141                     // Unassigned boundary edge.
142                     currentEdgeI = edgeI;
144                     break;
145                 }
146             }
147         }
148         while (currentEdgeI != -1);
150         // Done all for current loop. Transfer to edgeLoops.
151         edgeLoops[loopI].transfer(loop);
153         loopI++;
154     }
156     edgeLoops.setSize(loopI);
158     if (debug)
159     {
160         Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
161             << "calcEdgeLoops() : "
162             << "finished calculating boundary edge loops"
163             << endl;
164     }
168 template
170     class Face,
171     template<class> class FaceList,
172     class PointField,
173     class PointType
175 const Foam::labelListList&
176 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
177 edgeLoops() const
179     if (!edgeLoopsPtr_)
180     {
181         calcEdgeLoops();
182     }
184     return *edgeLoopsPtr_;
188 // ************************************************************************* //