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