BUG: pointHitSort: define operator<
[OpenFOAM-1.7.x.git] / src / meshTools / sets / topoSets / cellZoneSet.C
bloba6a18ea03318e8b1315b95d7eda28f4c918741d0
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.
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.
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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cellZoneSet.H"
27 #include "mapPolyMesh.H"
28 #include "polyMesh.H"
29 #include "processorPolyPatch.H"
30 #include "cyclicPolyPatch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(cellZoneSet, 0);
43 addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
48 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
50 void cellZoneSet::updateSet()
52     labelList order;
53     sortedOrder(addressing_, order);
54     inplaceReorder(order, addressing_);
56     cellSet::clearStorage();
57     cellSet::resize(2*addressing_.size());
58     forAll(addressing_, i)
59     {
60         cellSet::insert(addressing_[i]);
61     }
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 cellZoneSet::cellZoneSet
69     const polyMesh& mesh,
70     const word& name,
71     readOption r,
72     writeOption w
75     cellSet(mesh, name, 1000),  // do not read cellSet
76     mesh_(mesh),
77     addressing_(0)
79     const cellZoneMesh& cellZones = mesh.cellZones();
80     label zoneID = cellZones.findZoneID(name);
82     if
83     (
84         (r == IOobject::MUST_READ)
85      || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
86     )
87     {
88         const cellZone& fz = cellZones[zoneID];
89         addressing_ = fz;
90     }
92     updateSet();
94     check(mesh.nCells());
98 cellZoneSet::cellZoneSet
100     const polyMesh& mesh,
101     const word& name,
102     const label size,
103     writeOption w
106     cellSet(mesh, name, size, w),
107     mesh_(mesh),
108     addressing_(0)
110     updateSet();
114 cellZoneSet::cellZoneSet
116     const polyMesh& mesh,
117     const word& name,
118     const topoSet& set,
119     writeOption w
122     cellSet(mesh, name, set.size(), w),
123     mesh_(mesh),
124     addressing_(refCast<const cellZoneSet>(set).addressing())
126     updateSet();
130 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
132 cellZoneSet::~cellZoneSet()
136 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
138 void cellZoneSet::invert(const label maxLen)
140     label n = 0;
142     for (label cellI = 0; cellI < maxLen; cellI++)
143     {
144         if (!found(cellI))
145         {
146             addressing_[n] = cellI;
147             n++;
148         }
149     }
150     addressing_.setSize(n);
151     updateSet();
155 void cellZoneSet::subset(const topoSet& set)
157     DynamicList<label> newAddressing(addressing_.size());
159     const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
161     forAll(fSet.addressing(), i)
162     {
163         label cellI = fSet.addressing()[i];
165         if (found(cellI))
166         {
167             newAddressing.append(cellI);
168         }
169     }
171     addressing_.transfer(newAddressing);
172     updateSet();
176 void cellZoneSet::addSet(const topoSet& set)
178     DynamicList<label> newAddressing(addressing_);
180     const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
182     forAll(fSet.addressing(), i)
183     {
184         label cellI = fSet.addressing()[i];
186         if (!found(cellI))
187         {
188             newAddressing.append(cellI);
189         }
190     }
192     addressing_.transfer(newAddressing);
193     updateSet();
197 void cellZoneSet::deleteSet(const topoSet& set)
199     DynamicList<label> newAddressing(addressing_.size());
201     const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
203     forAll(addressing_, i)
204     {
205         label cellI = addressing_[i];
207         if (!fSet.found(cellI))
208         {
209             // Not found in fSet so add
210             newAddressing.append(cellI);
211         }
212     }
214     addressing_.transfer(newAddressing);
215     updateSet();
219 void cellZoneSet::sync(const polyMesh& mesh)
223 label cellZoneSet::maxSize(const polyMesh& mesh) const
225     return mesh.nCells();
229 //- Write using given format, version and compression
230 bool cellZoneSet::writeObject
232     IOstream::streamFormat s,
233     IOstream::versionNumber v,
234     IOstream::compressionType c
235 ) const
237     // Write shadow cellSet
238     word oldTypeName = typeName;
239     const_cast<word&>(type()) = cellSet::typeName;
240     bool ok = cellSet::writeObject(s, v, c);
241     const_cast<word&>(type()) = oldTypeName;
243     // Modify cellZone
244     cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
245     label zoneID = cellZones.findZoneID(name());
247     if (zoneID == -1)
248     {
249         zoneID = cellZones.size();
251         cellZones.setSize(zoneID+1);
252         cellZones.set
253         (
254             zoneID,
255             new cellZone
256             (
257                 name(),
258                 addressing_,
259                 zoneID,
260                 cellZones
261             )
262         );
263     }
264     else
265     {
266         cellZones[zoneID] = addressing_;
267     }
268     cellZones.clearAddressing();
270     return ok && cellZones.write();
274 void cellZoneSet::updateMesh(const mapPolyMesh& morphMap)
276     // cellZone
277     labelList newAddressing(addressing_.size());
279     label n = 0;
280     forAll(addressing_, i)
281     {
282         label cellI = addressing_[i];
283         label newCellI = morphMap.reverseCellMap()[cellI];
284         if (newCellI >= 0)
285         {
286             newAddressing[n] = newCellI;
287             n++;
288         }
289     }
290     newAddressing.setSize(n);
292     addressing_.transfer(newAddressing);
294     updateSet();
298 void cellZoneSet::writeDebug
300     Ostream& os,
301     const primitiveMesh& mesh,
302     const label maxLen
303 ) const
305     cellSet::writeDebug(os, mesh, maxLen);
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 } // End namespace Foam
313 // ************************************************************************* //