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-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Description
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
37template<class FaceList, class PointField>
38void
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 const label nIntEdges = nInternalEdges();
53 const label nBdryEdges = patchEdges.size() - nIntEdges;
54
55 // Size return list plenty big
56 edgeLoopsPtr_.reset(new labelListList(nBdryEdges));
57 auto& edgeLoops = *edgeLoopsPtr_;
58
59 if (nBdryEdges == 0)
60 {
61 return;
62 }
63
64 const labelListList& patchPointEdges = pointEdges();
65
66
67 //
68 // Walk point-edge-point and assign loop number
69 //
70
71 // Loop per (boundary) edge.
72 labelList loopNumber(nBdryEdges, -1);
73
74 // Current loop number.
75 label loopI = 0;
76
77 while (true)
78 {
79 // Find edge not yet given a loop number.
80 label currentEdgeI = -1;
81
82 for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
83 {
84 if (loopNumber[edgeI-nIntEdges] == -1)
85 {
86 currentEdgeI = edgeI;
87 break;
88 }
89 }
90
91 if (currentEdgeI == -1)
92 {
93 // Did not find edge not yet assigned a loop number so done all.
94 break;
95 }
96
97 // Temporary storage for vertices of current loop
98 DynamicList<label> loop(nBdryEdges);
99
100 // Walk from first all the way round, assigning loops
101 label currentVertI = patchEdges[currentEdgeI].start();
102
103 do
104 {
105 loop.append(currentVertI);
106
107 loopNumber[currentEdgeI - nIntEdges] = loopI;
108
109 // Step to next vertex
110 currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
111
112 // Step to next (unmarked, boundary) edge.
113 const labelList& curEdges = patchPointEdges[currentVertI];
114
115 currentEdgeI = -1;
116
117 forAll(curEdges, pI)
118 {
119 label edgeI = curEdges[pI];
120
121 if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
122 {
123 // Unassigned boundary edge.
124 currentEdgeI = edgeI;
125
126 break;
127 }
128 }
129 }
130 while (currentEdgeI != -1);
131
132 // Done all for current loop. Transfer to edgeLoops.
133 edgeLoops[loopI].transfer(loop);
134
135 loopI++;
136 }
137
138 edgeLoops.setSize(loopI);
139
140 DebugInFunction << "Calculated boundary edge loops" << nl;
141}
142
143
144template<class FaceList, class PointField>
147{
148 if (!edgeLoopsPtr_)
149 {
150 calcEdgeLoops();
151 }
152
153 return *edgeLoopsPtr_;
154}
155
156
157// ************************************************************************* //
A list of faces which address into the list of points.
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const labelList nIntEdges(UPstream::listGatherValues< label >(aMesh.nInternalEdges()))
#define DebugInFunction
Report an information message using Foam::Info.
List< label > labelList
A List of labels.
Definition: List.H:66
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:144
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333