patchZones.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "patchZones.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(patchZones, 0);
33 }
34 
35 
36 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
37 
38 Foam::labelList Foam::patchZones::faceToEdge
39 (
40  const labelList& changedFaces,
41  labelList& edgeRegion
42 )
43 {
44  labelList changedEdges(pp_.nEdges(), -1);
45  label changedI = 0;
46 
47  forAll(changedFaces, i)
48  {
49  label facei = changedFaces[i];
50 
51  const labelList& fEdges = pp_.faceEdges()[facei];
52 
53  forAll(fEdges, fEdgeI)
54  {
55  label edgeI = fEdges[fEdgeI];
56 
57  if (!borderEdge_[edgeI] && (edgeRegion[edgeI] == -1))
58  {
59  edgeRegion[edgeI] = nZones_;
60 
61  changedEdges[changedI++] = edgeI;
62  }
63  }
64  }
65 
66  changedEdges.setSize(changedI);
67 
68  return changedEdges;
69 }
70 
71 
72 Foam::labelList Foam::patchZones::edgeToFace(const labelList& changedEdges)
73 {
74  labelList changedFaces(pp_.size(), -1);
75  label changedI = 0;
76 
77  forAll(changedEdges, i)
78  {
79  label edgeI = changedEdges[i];
80 
81  const labelList& eFaces = pp_.edgeFaces()[edgeI];
82 
83  forAll(eFaces, eFacei)
84  {
85  label facei = eFaces[eFacei];
86 
87  if (operator[](facei) == -1)
88  {
89  operator[](facei) = nZones_;
90 
91  changedFaces[changedI++] = facei;
92  }
93  }
94  }
95 
96  changedFaces.setSize(changedI);
97 
98  return changedFaces;
99 }
100 
101 
102 void Foam::patchZones::markZone(label facei)
103 {
104  // List of faces whose faceZone has been set.
105  labelList changedFaces(1, facei);
106  // List of edges whose faceZone has been set.
107  labelList changedEdges;
108 
109  // Zones on all edges.
110  labelList edgeZone(pp_.nEdges(), -1);
111 
112  while (true)
113  {
114  changedEdges = faceToEdge(changedFaces, edgeZone);
115 
116  if (debug)
117  {
118  Info<< "From changedFaces:" << changedFaces.size()
119  << " to changedEdges:" << changedEdges.size()
120  << endl;
121  }
122 
123  if (changedEdges.empty())
124  {
125  break;
126  }
127 
128  changedFaces = edgeToFace(changedEdges);
129 
130  if (debug)
131  {
132  Info<< "From changedEdges:" << changedEdges.size()
133  << " to changedFaces:" << changedFaces.size()
134  << endl;
135  }
136 
137  if (changedEdges.empty())
138  {
139  break;
140  }
141  }
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
146 
148 (
149  const primitivePatch& pp,
150  const boolList& borderEdge
151 )
152 :
153  labelList(pp.size(), -1),
154  pp_(pp),
155  borderEdge_(borderEdge),
156  nZones_(0)
157 {
158  // Finds areas delimited by borderEdge (or 'real' edges).
159  // Fills *this with zone number accordingly.
160 
161  if (borderEdge.size() != pp_.nEdges())
162  {
164  << "borderEdge boolList not same size as number of edges" << endl
165  << "borderEdge:" << borderEdge.size() << endl
166  << "nEdges :" << pp_.nEdges()
167  << abort(FatalError);
168  }
169 
170  label facei = 0;
171 
172  while (true)
173  {
174  // Find first non-visited face
175  for (; facei < pp_.size(); facei++)
176  {
177  if (operator[](facei) == -1)
178  {
179  operator[](facei) = nZones_;
180 
181  markZone(facei);
182 
183  break;
184  }
185  }
186 
187  if (facei == pp_.size())
188  {
189  // Finished.
190  break;
191  }
192 
193  nZones_++;
194  }
195 }
196 
197 
198 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A list of faces which address into the list of points.
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
defineTypeNameAndDebug(combustionModel, 0)
messageStream Info
patchZones(const primitivePatch &pp, const boolList &borderEdge)
Fills *this with zone of face. Zone is area.
Definition: patchZones.C:148
Namespace for OpenFOAM.