1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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"
29 #include "processorPolyPatch.H"
30 #include "cyclicPolyPatch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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()
53 sortedOrder(addressing_, order);
54 inplaceReorder(order, addressing_);
56 cellSet::clearStorage();
57 cellSet::resize(2*addressing_.size());
58 forAll(addressing_, i)
60 cellSet::insert(addressing_[i]);
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 cellZoneSet::cellZoneSet
75 cellSet(mesh, name, 1000), // do not read cellSet
79 const cellZoneMesh& cellZones = mesh.cellZones();
80 label zoneID = cellZones.findZoneID(name);
84 (r == IOobject::MUST_READ)
85 || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
88 const cellZone& fz = cellZones[zoneID];
98 cellZoneSet::cellZoneSet
100 const polyMesh& mesh,
106 cellSet(mesh, name, size, w),
114 cellZoneSet::cellZoneSet
116 const polyMesh& mesh,
122 cellSet(mesh, name, set.size(), w),
124 addressing_(refCast<const cellZoneSet>(set).addressing())
130 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 cellZoneSet::~cellZoneSet()
136 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 void cellZoneSet::invert(const label maxLen)
142 for (label cellI = 0; cellI < maxLen; cellI++)
146 addressing_[n] = cellI;
150 addressing_.setSize(n);
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)
163 label cellI = fSet.addressing()[i];
167 newAddressing.append(cellI);
171 addressing_.transfer(newAddressing);
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)
184 label cellI = fSet.addressing()[i];
188 newAddressing.append(cellI);
192 addressing_.transfer(newAddressing);
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)
205 label cellI = addressing_[i];
207 if (!fSet.found(cellI))
209 // Not found in fSet so add
210 newAddressing.append(cellI);
214 addressing_.transfer(newAddressing);
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
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;
244 cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
245 label zoneID = cellZones.findZoneID(name());
249 zoneID = cellZones.size();
251 cellZones.setSize(zoneID+1);
266 cellZones[zoneID] = addressing_;
268 cellZones.clearAddressing();
270 return ok && cellZones.write();
274 void cellZoneSet::updateMesh(const mapPolyMesh& morphMap)
277 labelList newAddressing(addressing_.size());
280 forAll(addressing_, i)
282 label cellI = addressing_[i];
283 label newCellI = morphMap.reverseCellMap()[cellI];
286 newAddressing[n] = newCellI;
290 newAddressing.setSize(n);
292 addressing_.transfer(newAddressing);
298 void cellZoneSet::writeDebug
301 const primitiveMesh& mesh,
305 cellSet::writeDebug(os, mesh, maxLen);
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 } // End namespace Foam
313 // ************************************************************************* //