initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / surfMesh / MeshedSurface / MeshedSurfaceZones.C
bloba31e8d6314ee75d921e8a340a04a0836b8596fc8
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 \*---------------------------------------------------------------------------*/
27 #include "MeshedSurface.H"
29 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
31 template<class Face>
32 void Foam::MeshedSurface<Face>::checkZones()
34     // extra safety, ensure we have at some zones
35     // and they cover all the faces - fix start silently
36     surfZoneList& zones = this->storedZones();
37     if (zones.size())
38     {
39         label count = 0;
40         forAll(zones, zoneI)
41         {
42             zones[zoneI].start() = count;
43             count += zones[zoneI].size();
44         }
46         if (count < this->size())
47         {
48             WarningIn
49             (
50                 "MeshedSurface::checkZones()\n"
51             )
52                 << "more faces " << this->size() << " than zones " << count
53                 << " ... extending final zone"
54                 << endl;
56             zones[zones.size()-1].size() += count - this->size();
57         }
58         else if (count > this->size())
59         {
60             FatalErrorIn
61             (
62                 "MeshedSurface::checkZones()\n"
63             )
64                 << "more zones " << count << " than faces " << this->size()
65                 << exit(FatalError);
66         }
67     }
71 template<class Face>
72 void Foam::MeshedSurface<Face>::sortFacesAndStore
74     const Xfer< List<Face> >& unsortedFaces,
75     const Xfer< List<label> >& zoneIds,
76     const bool sorted
79     List<Face>  oldFaces(unsortedFaces);
80     List<label> zones(zoneIds);
82     if (sorted)
83     {
84         // already sorted - simply transfer faces
85         this->storedFaces().transfer(oldFaces);
86     }
87     else
88     {
89         // unsorted - determine the sorted order:
90         // avoid SortableList since we discard the main list anyhow
91         List<label> faceMap;
92         sortedOrder(zones, faceMap);
93         zones.clear();
95         // sorted faces
96         List<Face> newFaces(faceMap.size());
97         forAll(faceMap, faceI)
98         {
99             // use transfer to recover memory where possible
100             newFaces[faceI].transfer(oldFaces[faceMap[faceI]]);
101         }
102         this->storedFaces().transfer(newFaces);
103     }
104     zones.clear();
108 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
110 template<class Face>
111 void Foam::MeshedSurface<Face>::addZones
113     const UList<surfZone>& srfZones,
114     const bool cullEmpty
117     label nZone = 0;
119     surfZoneList& zones = this->storedZones();
120     zones.setSize(zones.size());
121     forAll(zones, zoneI)
122     {
123         if (srfZones[zoneI].size() || !cullEmpty)
124         {
125             zones[nZone] = surfZone(srfZones[zoneI], nZone);
126             nZone++;
127         }
128     }
129     zones.setSize(nZone);
133 template<class Face>
134 void Foam::MeshedSurface<Face>::addZones
136     const UList<label>& sizes,
137     const UList<word>& names,
138     const bool cullEmpty
141     label start   = 0;
142     label nZone = 0;
144     surfZoneList& zones = this->storedZones();
145     zones.setSize(sizes.size());
146     forAll(zones, zoneI)
147     {
148         if (sizes[zoneI] || !cullEmpty)
149         {
150             zones[nZone] = surfZone
151             (
152                 names[zoneI],
153                 sizes[zoneI],
154                 start,
155                 nZone
156             );
157             start += sizes[zoneI];
158             nZone++;
159         }
160     }
161     zones.setSize(nZone);
165 template<class Face>
166 void Foam::MeshedSurface<Face>::addZones
168     const UList<label>& sizes,
169     const bool cullEmpty
172     label start   = 0;
173     label nZone = 0;
175     surfZoneList& zones = this->storedZones();
176     zones.setSize(sizes.size());
177     forAll(zones, zoneI)
178     {
179         if (sizes[zoneI] || !cullEmpty)
180         {
181             zones[nZone] = surfZone
182             (
183                 word("zone") + ::Foam::name(nZone),
184                 sizes[zoneI],
185                 start,
186                 nZone
187             );
188             start += sizes[zoneI];
189             nZone++;
190         }
191     }
192     zones.setSize(nZone);
196 template<class Face>
197 void Foam::MeshedSurface<Face>::removeZones()
199     this->storedZones().clear();
203 // ************************************************************************* //