initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveMesh / primitivePatch / patchZones.C
blobef48f93ba0e26528c578980a691907ac7e9e68c7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "patchZones.H"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::patchZones, 0);
37 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
39 // Gets labels of changed faces and propagates them to the edges. Returns
40 // labels of edges changed.
41 Foam::labelList Foam::patchZones::faceToEdge
43     const labelList& changedFaces,
44     labelList& edgeRegion
47     labelList changedEdges(pp_.nEdges(), -1);
48     label changedI = 0;
50     forAll(changedFaces, i)
51     {
52         label faceI = changedFaces[i];
54         const labelList& fEdges = pp_.faceEdges()[faceI];
56         forAll(fEdges, fEdgeI)
57         {
58             label edgeI = fEdges[fEdgeI];
60             if (!borderEdge_[edgeI] && (edgeRegion[edgeI] == -1))
61             {
62                 edgeRegion[edgeI] = nZones_;
64                 changedEdges[changedI++] = edgeI;
65             }
66         }
67     }
69     changedEdges.setSize(changedI);
71     return changedEdges;
75 // Reverse of faceToEdge: gets edges and returns faces
76 Foam::labelList Foam::patchZones::edgeToFace(const labelList& changedEdges)
78     labelList changedFaces(pp_.size(), -1);
79     label changedI = 0;
81     forAll(changedEdges, i)
82     {
83         label edgeI = changedEdges[i];
85         const labelList& eFaces = pp_.edgeFaces()[edgeI];
87         forAll(eFaces, eFaceI)
88         {
89             label faceI = eFaces[eFaceI];
91             if (operator[](faceI) == -1)
92             {
93                 operator[](faceI) = nZones_;
95                 changedFaces[changedI++] = faceI;
96             }
97         }
98     }
100     changedFaces.setSize(changedI);
102     return changedFaces;
106 // Finds area, starting at faceI, delimited by borderEdge
107 void Foam::patchZones::markZone(label faceI)
109     // List of faces whose faceZone has been set.
110     labelList changedFaces(1, faceI);
111     // List of edges whose faceZone has been set.
112     labelList changedEdges;
114     // Zones on all edges.
115     labelList edgeZone(pp_.nEdges(), -1);
117     while(1)
118     {
119         changedEdges = faceToEdge(changedFaces, edgeZone);
121         if (debug)
122         {
123             Info<< "From changedFaces:" << changedFaces.size()
124                 << " to changedEdges:" << changedEdges.size()
125                 << endl;
126         }
128         if (changedEdges.empty())
129         {
130             break;
131         }
133         changedFaces = edgeToFace(changedEdges);
135         if (debug)
136         {
137             Info<< "From changedEdges:" << changedEdges.size()
138                 << " to changedFaces:" << changedFaces.size()
139                 << endl;
140         }
142         if (changedEdges.empty())
143         {
144             break;
145         }
146     }
150 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
152 // Construct from components
153 Foam::patchZones::patchZones
155     const primitivePatch& pp,
156     const boolList& borderEdge
159     labelList(pp.size(), -1),
160     pp_(pp),
161     borderEdge_(borderEdge),
162     nZones_(0)
164     // Finds areas delimited by borderEdge (or 'real' edges).
165     // Fills *this with zone number accordingly.
167     if (borderEdge.size() != pp_.nEdges())
168     {
169         FatalErrorIn
170         (
171             "patchZones::patchZones(const primitivePatch&, const boolList&)"
172         )   << "borderEdge boolList not same size as number of edges" << endl
173             << "borderEdge:" << borderEdge.size() << endl
174             << "nEdges    :" << pp_.nEdges()
175             << abort(FatalError);
176     }
178     label faceI = 0;
180     while (true)
181     {
182         // Find first non-visited face
183         for (; faceI < pp_.size(); faceI++)
184         {
185             if (operator[](faceI) == -1)
186             {
187                 operator[](faceI) = nZones_;
189                 markZone(faceI);
191                 break;
192             }
193         }
195         if (faceI == pp_.size())
196         {
197             // Finished.
198             break;
199         }
201         nZones_++;
202     }
206 // ************************************************************************* //