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-2023 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  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  // Temporary storage for vertices of current loop
72  DynamicList<label> loop(nBdryEdges);
73 
74  // In a loop? - per boundary edge
75  boolList unvisited(nBdryEdges, true);
76 
77  // Current loop number
78  label numLoops = 0;
79 
80  // Walk all boundary edges not yet in a loop
81  for
82  (
83  label bndEdgei = -1;
84  (bndEdgei = unvisited.find(true)) >= 0;
85  /*nil*/
86  )
87  {
88  label currentEdgei = (bndEdgei + nIntEdges);
89 
90  // Walk from first all the way round, assigning loops
91  label currentVerti = patchEdges[currentEdgei].first();
92 
93  loop.clear();
94 
95  do
96  {
97  loop.push_back(currentVerti);
98 
99  unvisited[currentEdgei - nIntEdges] = false;
100 
101  // Step to next vertex
102  currentVerti = patchEdges[currentEdgei].otherVertex(currentVerti);
103 
104  // Step to next (unmarked, boundary) edge.
105  currentEdgei = -1;
106 
107  for (const label edgei : patchPointEdges[currentVerti])
108  {
109  if (edgei >= nIntEdges && unvisited[edgei - nIntEdges])
110  {
111  // Unvisited boundary edge
112  currentEdgei = edgei;
113  break;
114  }
115  }
116  }
117  while (currentEdgei != -1);
118 
119  // Done all for current loop - copy to edgeLoops
120  edgeLoops[numLoops] = loop;
121 
122  ++numLoops;
123  }
124 
125  edgeLoops.resize(numLoops);
126 
127  DebugInFunction << "Calculated boundary edge loops" << nl;
128 }
129 
130 
131 template<class FaceList, class PointField>
132 const Foam::labelListList&
134 {
135  if (!edgeLoopsPtr_)
136  {
137  calcEdgeLoops();
138  }
139 
140  return *edgeLoopsPtr_;
141 }
142 
143 
144 // ************************************************************************* //
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
List< edge > edgeList
List of edge.
Definition: edgeList.H:32
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
A list of faces which address into the list of points.
#define DebugInFunction
Report an information message using Foam::Info.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
List< bool > boolList
A List of bools.
Definition: List.H:60