PrimitivePatchEdgeLoops.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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<class FaceList, class PointField>
37 {
38  if (debug)
39  {
40  InfoInFunction << "Calculating boundary edge loops" << endl;
41  }
42 
43  if (edgeLoopsPtr_)
44  {
45  // it is considered an error to attempt to recalculate
46  // if already allocated
48  << "edge loops already calculated"
49  << abort(FatalError);
50  }
51 
52  const edgeList& patchEdges = edges();
53  label nIntEdges = nInternalEdges();
54  label nBdryEdges = patchEdges.size() - nIntEdges;
55 
56  if (nBdryEdges == 0)
57  {
58  edgeLoopsPtr_ = new labelListList(0);
59  return;
60  }
61 
62  const labelListList& patchPointEdges = pointEdges();
63 
64 
65  //
66  // Walk point-edge-point and assign loop number
67  //
68 
69  // Loop per (boundary) edge.
70  labelList loopNumber(nBdryEdges, -1);
71 
72  // Size return list plenty big
73  edgeLoopsPtr_ = new labelListList(nBdryEdges);
74  labelListList& edgeLoops = *edgeLoopsPtr_;
75 
76 
77  // Current loop number.
78  label loopI = 0;
79 
80  while (true)
81  {
82  // Find edge not yet given a loop number.
83  label currentEdgeI = -1;
84 
85  for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
86  {
87  if (loopNumber[edgeI-nIntEdges] == -1)
88  {
89  currentEdgeI = edgeI;
90  break;
91  }
92  }
93 
94  if (currentEdgeI == -1)
95  {
96  // Did not find edge not yet assigned a loop number so done all.
97  break;
98  }
99 
100  // Temporary storage for vertices of current loop
101  DynamicList<label> loop(nBdryEdges);
102 
103  // Walk from first all the way round, assigning loops
104  label currentVertI = patchEdges[currentEdgeI].start();
105 
106  do
107  {
108  loop.append(currentVertI);
109 
110  loopNumber[currentEdgeI - nIntEdges] = loopI;
111 
112  // Step to next vertex
113  currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
114 
115  // Step to next (unmarked, boundary) edge.
116  const labelList& curEdges = patchPointEdges[currentVertI];
117 
118  currentEdgeI = -1;
119 
120  forAll(curEdges, pI)
121  {
122  label edgeI = curEdges[pI];
123 
124  if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
125  {
126  // Unassigned boundary edge.
127  currentEdgeI = edgeI;
128 
129  break;
130  }
131  }
132  }
133  while (currentEdgeI != -1);
134 
135  // Done all for current loop. Transfer to edgeLoops.
136  edgeLoops[loopI].transfer(loop);
137 
138  loopI++;
139  }
140 
141  edgeLoops.setSize(loopI);
142 
143  if (debug)
144  {
145  Info<< " Finished." << endl;
146  }
147 }
148 
149 
150 template<class FaceList, class PointField>
151 const Foam::labelListList&
153 {
154  if (!edgeLoopsPtr_)
155  {
156  calcEdgeLoops();
157  }
158 
159  return *edgeLoopsPtr_;
160 }
161 
162 
163 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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.