patchZones.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 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "patchZones.H"
29 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
34 
35 
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 
38 // Gets labels of changed faces and propagates them to the edges. Returns
39 // labels of edges changed.
41 (
42  const labelList& changedFaces,
43  labelList& edgeRegion
44 )
45 {
46  labelList changedEdges(pp_.nEdges(), -1);
47  label changedI = 0;
48 
49  forAll(changedFaces, i)
50  {
51  label faceI = changedFaces[i];
52 
53  const labelList& fEdges = pp_.faceEdges()[faceI];
54 
55  forAll(fEdges, fEdgeI)
56  {
57  label edgeI = fEdges[fEdgeI];
58 
59  if (!borderEdge_[edgeI] && (edgeRegion[edgeI] == -1))
60  {
61  edgeRegion[edgeI] = nZones_;
62 
63  changedEdges[changedI++] = edgeI;
64  }
65  }
66  }
67 
68  changedEdges.setSize(changedI);
69 
70  return changedEdges;
71 }
72 
73 
74 // Reverse of faceToEdge: gets edges and returns faces
76 {
77  labelList changedFaces(pp_.size(), -1);
78  label changedI = 0;
79 
80  forAll(changedEdges, i)
81  {
82  label edgeI = changedEdges[i];
83 
84  const labelList& eFaces = pp_.edgeFaces()[edgeI];
85 
86  forAll(eFaces, eFaceI)
87  {
88  label faceI = eFaces[eFaceI];
89 
90  if (operator[](faceI) == -1)
91  {
92  operator[](faceI) = nZones_;
93 
94  changedFaces[changedI++] = faceI;
95  }
96  }
97  }
98 
99  changedFaces.setSize(changedI);
100 
101  return changedFaces;
102 }
103 
104 
105 // Finds area, starting at faceI, delimited by borderEdge
107 {
108  // List of faces whose faceZone has been set.
109  labelList changedFaces(1, faceI);
110  // List of edges whose faceZone has been set.
111  labelList changedEdges;
112 
113  // Zones on all edges.
114  labelList edgeZone(pp_.nEdges(), -1);
115 
116  while(1)
117  {
118  changedEdges = faceToEdge(changedFaces, edgeZone);
119 
120  if (debug)
121  {
122  Info<< "From changedFaces:" << changedFaces.size()
123  << " to changedEdges:" << changedEdges.size()
124  << endl;
125  }
126 
127  if (changedEdges.empty())
128  {
129  break;
130  }
131 
132  changedFaces = edgeToFace(changedEdges);
133 
134  if (debug)
135  {
136  Info<< "From changedEdges:" << changedEdges.size()
137  << " to changedFaces:" << changedFaces.size()
138  << endl;
139  }
140 
141  if (changedEdges.empty())
142  {
143  break;
144  }
145  }
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
150 
151 // Construct from components
153 (
154  const primitivePatch& pp,
155  const boolList& borderEdge
156 )
157 :
158  labelList(pp.size(), -1),
159  pp_(pp),
160  borderEdge_(borderEdge),
161  nZones_(0)
162 {
163  // Finds areas delimited by borderEdge (or 'real' edges).
164  // Fills *this with zone number accordingly.
165 
166  if (borderEdge.size() != pp_.nEdges())
167  {
169  (
170  "patchZones::patchZones(const primitivePatch&, const boolList&)"
171  ) << "borderEdge boolList not same size as number of edges" << endl
172  << "borderEdge:" << borderEdge.size() << endl
173  << "nEdges :" << pp_.nEdges()
174  << abort(FatalError);
175  }
176 
177  label faceI = 0;
178 
179  while (true)
180  {
181  // Find first non-visited face
182  for (; faceI < pp_.size(); faceI++)
183  {
184  if (operator[](faceI) == -1)
185  {
186  operator[](faceI) = nZones_;
187 
188  markZone(faceI);
189 
190  break;
191  }
192  }
193 
194  if (faceI == pp_.size())
195  {
196  // Finished.
197  break;
198  }
199 
200  nZones_++;
201  }
202 }
203 
204 
205 // ************************************************************************* //
patchZones.H
Foam::PrimitivePatch::edgeFaces
const labelListList & edgeFaces() const
Return edge-face addressing.
Definition: PrimitivePatchTemplate.C:292
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
defineTypeNameAndDebug
defineTypeNameAndDebug(Foam::patchZones, 0)
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::patchZones::markZone
void markZone(label faceI)
Fill *this with current zone for every face reachable.
Definition: patchZones.C:106
Foam::patchZones::patchZones
patchZones(const primitivePatch &pp, const boolList &borderEdge)
Fills *this with zone of face. Zone is area.
Definition: patchZones.C:153
Foam::patchZones::pp_
const primitivePatch & pp_
Reference to patch.
Definition: patchZones.H:60
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::patchZones
Calculates zone number for every face of patch.
Definition: patchZones.H:53
Foam::patchZones::nZones_
label nZones_
Max number of zones.
Definition: patchZones.H:66
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::Info
messageStream Info
Foam::patchZones::faceToEdge
labelList faceToEdge(const labelList &changedFaces, labelList &edgeRegion)
Gets labels of changed faces and propagates them to the edges.
Definition: patchZones.C:41
Foam::FatalError
error FatalError
Foam::patchZones::edgeToFace
labelList edgeToFace(const labelList &changedEdges)
Reverse of faceToEdge: gets edges and returns faces.
Definition: patchZones.C:75
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
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::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88