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-2015 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  << "edge loops already calculated"
60  << abort(FatalError);
61  }
62 
63  const edgeList& patchEdges = edges();
64  label nIntEdges = nInternalEdges();
65  label nBdryEdges = patchEdges.size() - nIntEdges;
66 
67  if (nBdryEdges == 0)
68  {
69  edgeLoopsPtr_ = new labelListList(0);
70  return;
71  }
72 
73  const labelListList& patchPointEdges = pointEdges();
74 
75 
76  //
77  // Walk point-edge-point and assign loop number
78  //
79 
80  // Loop per (boundary) edge.
81  labelList loopNumber(nBdryEdges, -1);
82 
83  // Size return list plenty big
84  edgeLoopsPtr_ = new labelListList(nBdryEdges);
85  labelListList& edgeLoops = *edgeLoopsPtr_;
86 
87 
88  // Current loop number.
89  label loopI = 0;
90 
91  while (true)
92  {
93  // Find edge not yet given a loop number.
94  label currentEdgeI = -1;
95 
96  for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
97  {
98  if (loopNumber[edgeI-nIntEdges] == -1)
99  {
100  currentEdgeI = edgeI;
101  break;
102  }
103  }
104 
105  if (currentEdgeI == -1)
106  {
107  // Did not find edge not yet assigned a loop number so done all.
108  break;
109  }
110 
111  // Temporary storage for vertices of current loop
112  DynamicList<label> loop(nBdryEdges);
113 
114  // Walk from first all the way round, assigning loops
115  label currentVertI = patchEdges[currentEdgeI].start();
116 
117  do
118  {
119  loop.append(currentVertI);
120 
121  loopNumber[currentEdgeI - nIntEdges] = loopI;
122 
123  // Step to next vertex
124  currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
125 
126  // Step to next (unmarked, boundary) edge.
127  const labelList& curEdges = patchPointEdges[currentVertI];
128 
129  currentEdgeI = -1;
130 
131  forAll(curEdges, pI)
132  {
133  label edgeI = curEdges[pI];
134 
135  if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
136  {
137  // Unassigned boundary edge.
138  currentEdgeI = edgeI;
139 
140  break;
141  }
142  }
143  }
144  while (currentEdgeI != -1);
145 
146  // Done all for current loop. Transfer to edgeLoops.
147  edgeLoops[loopI].transfer(loop);
148 
149  loopI++;
150  }
151 
152  edgeLoops.setSize(loopI);
153 
154  if (debug)
155  {
156  Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
157  << "calcEdgeLoops() : "
158  << "finished calculating boundary edge loops"
159  << endl;
160  }
161 }
162 
163 
164 template
165 <
166  class Face,
167  template<class> class FaceList,
168  class PointField,
169  class PointType
170 >
171 const Foam::labelListList&
173 edgeLoops() const
174 {
175  if (!edgeLoopsPtr_)
176  {
177  calcEdgeLoops();
178  }
179 
180  return *edgeLoopsPtr_;
181 }
182 
183 
184 // ************************************************************************* //
Foam::edgeList
List< edge > edgeList
Definition: edgeList.H:38
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::label
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
PrimitivePatch.H
Foam::Info
messageStream Info
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::PrimitivePatch::edgeLoops
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
Definition: PrimitivePatchEdgeLoops.C:176
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::PrimitivePatch::calcEdgeLoops
void calcEdgeLoops() const
Calculate outside edge loops.
Definition: PrimitivePatchEdgeLoops.C:44