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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "patchZones.H"
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32namespace Foam
33{
35}
36
37
38// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
39
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
75{
76 labelList changedFaces(pp_.size(), -1);
77 label changedI = 0;
78
79 forAll(changedEdges, i)
80 {
81 label edgeI = changedEdges[i];
82
83 const labelList& eFaces = pp_.edgeFaces()[edgeI];
84
85 forAll(eFaces, eFacei)
86 {
87 label facei = eFaces[eFacei];
88
89 if (operator[](facei) == -1)
90 {
91 operator[](facei) = nZones_;
92
93 changedFaces[changedI++] = facei;
94 }
95 }
96 }
97
98 changedFaces.setSize(changedI);
99
100 return changedFaces;
101}
102
103
104void Foam::patchZones::markZone(label facei)
105{
106 // List of faces whose faceZone has been set.
107 labelList changedFaces(1, facei);
108 // List of edges whose faceZone has been set.
109 labelList changedEdges;
110
111 // Zones on all edges.
112 labelList edgeZone(pp_.nEdges(), -1);
113
114 while (true)
115 {
116 changedEdges = faceToEdge(changedFaces, edgeZone);
117
118 if (debug)
119 {
120 Info<< "From changedFaces:" << changedFaces.size()
121 << " to changedEdges:" << changedEdges.size()
122 << endl;
123 }
124
125 if (changedEdges.empty())
126 {
127 break;
128 }
129
130 changedFaces = edgeToFace(changedEdges);
131
132 if (debug)
133 {
134 Info<< "From changedEdges:" << changedEdges.size()
135 << " to changedFaces:" << changedFaces.size()
136 << endl;
137 }
138
139 if (changedEdges.empty())
140 {
141 break;
142 }
143 }
144}
145
146
147// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
148
150(
151 const primitivePatch& pp,
152 const boolList& borderEdge
153)
154:
155 labelList(pp.size(), -1),
156 pp_(pp),
157 borderEdge_(borderEdge),
158 nZones_(0)
159{
160 // Finds areas delimited by borderEdge (or 'real' edges).
161 // Fills *this with zone number accordingly.
162
163 if (borderEdge.size() != pp_.nEdges())
164 {
166 << "borderEdge boolList not same size as number of edges" << endl
167 << "borderEdge:" << borderEdge.size() << endl
168 << "nEdges :" << pp_.nEdges()
169 << abort(FatalError);
170 }
171
172 label facei = 0;
173
174 while (true)
175 {
176 // Find first non-visited face
177 for (; facei < pp_.size(); facei++)
178 {
179 if (operator[](facei) == -1)
180 {
181 operator[](facei) = nZones_;
182
183 markZone(facei);
184
185 break;
186 }
187 }
188
189 if (facei == pp_.size())
190 {
191 // Finished.
192 break;
193 }
194
195 nZones_++;
196 }
197}
198
199
200// ************************************************************************* //
label edgeToFace()
Propagate from edge to face.
label faceToEdge()
Propagate from face to edge.
A list of faces which address into the list of points.
label nEdges() const
Number of edges in patch.
const labelListList & faceEdges() const
Return face-edge addressing.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:299
Calculates zone number for every face of patch.
Definition: patchZones.H:58
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333