PrimitivePatchEdgeLoops.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | foam-extend: Open Source CFD
4  \\ / O peration | Version: 3.2
5  \\ / A nd | Web: http://www.foam-extend.org
6  \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9  This file is part of foam-extend.
10 
11  foam-extend is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation, either version 3 of the License, or (at your
14  option) any later version.
15 
16  foam-extend is distributed in the hope that it will be useful, but
17  WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with foam-extend. 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 "PrimitivePatchTemplate.H"
31 
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 template
36 <
37  class Face,
38  template<class> class FaceList,
39  class PointField,
40  class PointType
41 >
42 void
45 {
46  if (debug)
47  {
48  Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
49  << "calcEdgeLoops() : "
50  << "calculating boundary edge loops"
51  << endl;
52  }
53 
54  if (edgeLoopsPtr_)
55  {
56  // it is considered an error to attempt to recalculate
57  // if already allocated
59  (
60  "PrimitivePatch<Face, FaceList, PointField, PointType>::"
61  "calcEdgeLoops()"
62  ) << "edge loops already calculated"
63  << abort(FatalError);
64  }
65 
66  const edgeList& patchEdges = edges();
67  label nIntEdges = nInternalEdges();
68  label nBdryEdges = patchEdges.size() - nIntEdges;
69 
70  if (nBdryEdges == 0)
71  {
72  edgeLoopsPtr_ = new labelListList(0);
73  return;
74  }
75 
76  const labelListList& patchPointEdges = pointEdges();
77 
78 
79  //
80  // Walk point-edge-point and assign loop number
81  //
82 
83  // Loop per (boundary) edge.
84  labelList loopNumber(nBdryEdges, -1);
85 
86  // Size return list plenty big
87  edgeLoopsPtr_ = new labelListList(nBdryEdges);
88  labelListList& edgeLoops = *edgeLoopsPtr_;
89 
90 
91  // Current loop number.
92  label loopI = 0;
93 
94  while (true)
95  {
96  // Find edge not yet given a loop number.
97  label currentEdgeI = -1;
98 
99  for (label edgeI = nIntEdges; edgeI < patchEdges.size(); edgeI++)
100  {
101  if (loopNumber[edgeI-nIntEdges] == -1)
102  {
103  currentEdgeI = edgeI;
104  break;
105  }
106  }
107 
108  if (currentEdgeI == -1)
109  {
110  // Did not find edge not yet assigned a loop number so done all.
111  break;
112  }
113 
114  // Temporary storage for vertices of current loop
115  dynamicLabelList loop(nBdryEdges);
116 
117  // Walk from first all the way round, assigning loops
118  label currentVertI = patchEdges[currentEdgeI].start();
119 
120  do
121  {
122  loop.append(currentVertI);
123 
124  loopNumber[currentEdgeI - nIntEdges] = loopI;
125 
126  // Step to next vertex
127  currentVertI = patchEdges[currentEdgeI].otherVertex(currentVertI);
128 
129  // Step to next (unmarked, boundary) edge.
130  const labelList& curEdges = patchPointEdges[currentVertI];
131 
132  currentEdgeI = -1;
133 
134  forAll(curEdges, pI)
135  {
136  label edgeI = curEdges[pI];
137 
138  if (edgeI >= nIntEdges && (loopNumber[edgeI - nIntEdges] == -1))
139  {
140  // Unassigned boundary edge.
141  currentEdgeI = edgeI;
142 
143  break;
144  }
145  }
146  }
147  while (currentEdgeI != -1);
148 
149  // Done all for current loop. Transfer to edgeLoops.
150  edgeLoops[loopI].transfer(loop);
151 
152  loopI++;
153  }
154 
155  edgeLoops.setSize(loopI);
156 
157  if (debug)
158  {
159  Info<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
160  << "calcEdgeLoops() : "
161  << "finished calculating boundary edge loops"
162  << endl;
163  }
164 }
165 
166 
167 template
168 <
169  class Face,
170  template<class> class FaceList,
171  class PointField,
172  class PointType
173 >
174 const Foam::labelListList&
176 edgeLoops() const
177 {
178  if (!edgeLoopsPtr_)
179  {
180  calcEdgeLoops();
181  }
182 
183  return *edgeLoopsPtr_;
184 }
185 
186 
187 // ************************************************************************* //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
PrimitivePatchTemplate.H
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:59
Foam::List::append
void append(const T &)
Append an element at the end of the list.
Foam::Info
messageStream Info
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
Foam::PrimitivePatch::edgeLoops
const labelListList & edgeLoops() const
Return list of closed loops of boundary vertices.
Definition: PrimitivePatchEdgeLoops.C:176
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::PrimitivePatch::calcEdgeLoops
void calcEdgeLoops() const
Calculate outside edge loops.
Definition: PrimitivePatchEdgeLoops.C:44
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.