PrimitivePatchEdgeLoops.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Create the list of loops of outside vertices. Goes wrong on multiply
26  connected edges (loops will be unclosed).
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "PrimitivePatch.H"
31 
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template
36 <
37  class Face,
38  template<class> class FaceList,
39  class PointField,
40  class PointType
41 >
42 void
44 calcEdgeLoops() const
45 {
46  if (debug)
47  {
48  Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
49  << "calcEdgeLoops() : "
50  << "calculating boundary edge loops"
51  << endl;
52  }
53 
54  if (edgeLoopsPtr_)
55  {
56  // it is considered an error to attempt to recalculate
57  // if already allocated
59  (
60  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
61  "calcIntBdryEdges()"
62  ) << "edge loops already calculated"
63  << abort(FatalError);
64  }
65 
66  const edgeList& patchEdges = edges();
67  label nIntEdges = nInternalEdges();
68  label nBdryEdges = patchEdges.size() - nIntEdges;
69 
70  if (nBdryEdges == 0)
71  {
72  edgeLoopsPtr_ = new labelListList(0);
73  return;
74  }
75 
76  const labelListList& patchPointEdges = pointEdges();
77 
78 
79  //
80  // Walk point-edge-point and assign loop number
81  //
82 
83  // Loop per (boundary) edge.
84  labelList loopNumber(nBdryEdges, -1);
85 
86  // Size return list plenty big
87  edgeLoopsPtr_ = new labelListList(nBdryEdges);
88  labelListList& edgeLoops = *edgeLoopsPtr_;
89 
90 
91  // Current loop number.
92  label loopI = 0;
93 
94  while (true)
95  {
96  // Find edge not yet given a loop number.
97  label currentEdgeI = -1;
98 
99  for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
100  {
101  if (loopNumber[edgeI-nIntEdges] == -1)
102  {
103  currentEdgeI = edgeI;
104  break;
105  }
106  }
107 
108  if (currentEdgeI == -1)
109  {
110  // Did not find edge not yet assigned a loop number so done all.
111  break;
112  }
113 
114  // Temporary storage for vertices of current loop
115  DynamicList<label> loop(nBdryEdges);
116 
117  // Walk from first all the way round, assigning loops
118  label currentVertI = patchEdges[currentEdgeI].start();
119 
120  do
121  {
122  loop.append(currentVertI);
123 
124  loopNumber[currentEdgeI - nIntEdges] = loopI;
125 
126  // Step to next vertex
127  currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
128 
129  // Step to next (unmarked, boundary) edge.
130  const labelList& curEdges = patchPointEdges[currentVertI];
131 
132  currentEdgeI = -1;
133 
134  forAll(curEdges, pI)
135  {
136  label edgeI = curEdges[pI];
137 
138  if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
139  {
140  // Unassigned boundary edge.
141  currentEdgeI = edgeI;
142 
143  break;
144  }
145  }
146  }
147  while (currentEdgeI != -1);
148 
149  // Done all for current loop. Transfer to edgeLoops.
150  edgeLoops[loopI].transfer(loop);
151 
152  loopI++;
153  }
154 
155  edgeLoops.setSize(loopI);
156 
157  if (debug)
158  {
159  Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
160  << "calcEdgeLoops() : "
161  << "finished calculating boundary edge loops"
162  << endl;
163  }
164 }
165 
166 
167 template
168 <
169  class Face,
170  template<class> class FaceList,
171  class PointField,
172  class PointType
173 >
174 const Foam::labelListList&
176 edgeLoops() const
177 {
178  if (!edgeLoopsPtr_)
179  {
180  calcEdgeLoops();
181  }
182 
183  return *edgeLoopsPtr_;
184 }
185 
186 
187 // ************************************************************************* //
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
messageStream Info
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
List< edge > edgeList
Definition: edgeList.H:38
A list of faces which address into the list of points.
error FatalError
List< label > labelList
A List of labels.
Definition: labelList.H:56
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57