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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Description
27  Create the list of loops of outside vertices. Goes wrong on multiply
28  connected edges (loops will be unclosed).
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "PrimitivePatch.H"
33 
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
37 template
38 <
39  class Face,
40  template<class> class FaceList,
41  class PointField,
42  class PointType
43 >
44 void
46 calcEdgeLoops() const
47 {
48  if (debug)
49  {
50  InfoInFunction << "Calculating boundary edge loops" << endl;
51  }
52 
53  if (edgeLoopsPtr_)
54  {
55  // An error to recalculate if already allocated
57  << "edge loops already calculated"
58  << abort(FatalError);
59  }
60 
61  const edgeList& patchEdges = edges();
62  label nIntEdges = nInternalEdges();
63  label nBdryEdges = patchEdges.size() - nIntEdges;
64 
65  if (nBdryEdges == 0)
66  {
67  edgeLoopsPtr_ = new labelListList(0);
68  return;
69  }
70 
71  const labelListList& patchPointEdges = pointEdges();
72 
73 
74  //
75  // Walk point-edge-point and assign loop number
76  //
77 
78  // Loop per (boundary) edge.
79  labelList loopNumber(nBdryEdges, -1);
80 
81  // Size return list plenty big
82  edgeLoopsPtr_ = new labelListList(nBdryEdges);
83  labelListList& edgeLoops = *edgeLoopsPtr_;
84 
85 
86  // Current loop number.
87  label loopI = 0;
88 
89  while (true)
90  {
91  // Find edge not yet given a loop number.
92  label currentEdgeI = -1;
93 
94  for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
95  {
96  if (loopNumber[edgeI-nIntEdges] == -1)
97  {
98  currentEdgeI = edgeI;
99  break;
100  }
101  }
102 
103  if (currentEdgeI == -1)
104  {
105  // Did not find edge not yet assigned a loop number so done all.
106  break;
107  }
108 
109  // Temporary storage for vertices of current loop
110  DynamicList<label> loop(nBdryEdges);
111 
112  // Walk from first all the way round, assigning loops
113  label currentVertI = patchEdges[currentEdgeI].start();
114 
115  do
116  {
117  loop.append(currentVertI);
118 
119  loopNumber[currentEdgeI - nIntEdges] = loopI;
120 
121  // Step to next vertex
122  currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
123 
124  // Step to next (unmarked, boundary) edge.
125  const labelList& curEdges = patchPointEdges[currentVertI];
126 
127  currentEdgeI = -1;
128 
129  forAll(curEdges, pI)
130  {
131  label edgeI = curEdges[pI];
132 
133  if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
134  {
135  // Unassigned boundary edge.
136  currentEdgeI = edgeI;
137 
138  break;
139  }
140  }
141  }
142  while (currentEdgeI != -1);
143 
144  // Done all for current loop. Transfer to edgeLoops.
145  edgeLoops[loopI].transfer(loop);
146 
147  loopI++;
148  }
149 
150  edgeLoops.setSize(loopI);
151 
152  if (debug)
153  {
154  Info<< " Finished." << endl;
155  }
156 }
157 
158 
159 template
160 <
161  class Face,
162  template<class> class FaceList,
163  class PointField,
164  class PointType
165 >
166 const Foam::labelListList&
168 edgeLoops() const
169 {
170  if (!edgeLoopsPtr_)
171  {
172  calcEdgeLoops();
173  }
174 
175  return *edgeLoopsPtr_;
176 }
177 
178 
179 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:316
Foam::edgeList
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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:62
PrimitivePatch.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::PrimitivePatch::edgeLoops
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
Definition: PrimitivePatchEdgeLoops.C:168
Foam::List< labelList >
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90