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