FreeFOAM The Cross-Platform CFD Toolkit
patchZones.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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 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.
40 Foam::labelList Foam::patchZones::faceToEdge
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
75 Foam::labelList Foam::patchZones::edgeToFace(const labelList& changedEdges)
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
106 void Foam::patchZones::markZone(label faceI)
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 // ************************ vim: set sw=4 sts=4 et: ************************ //