1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-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 "faceZoneSet.H"
27 #include "mapPolyMesh.H"
30 #include "addToRunTimeSelectionTable.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(faceZoneSet, 0);
41 addToRunTimeSelectionTable(topoSet, faceZoneSet, word);
42 addToRunTimeSelectionTable(topoSet, faceZoneSet, size);
43 addToRunTimeSelectionTable(topoSet, faceZoneSet, set);
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 void faceZoneSet::updateSet()
51 sortedOrder(addressing_, order);
52 inplaceReorder(order, addressing_);
53 inplaceReorder(order, flipMap_);
55 faceSet::clearStorage();
56 faceSet::resize(2*addressing_.size());
57 forAll(addressing_, i)
59 faceSet::insert(addressing_[i]);
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 faceZoneSet::faceZoneSet
74 faceSet(mesh, name, 1000), // do not read faceSet
79 const faceZoneMesh& faceZones = mesh.faceZones();
80 label zoneID = faceZones.findZoneID(name);
84 (r == IOobject::MUST_READ)
85 || (r == IOobject::MUST_READ_IF_MODIFIED)
86 || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
89 const faceZone& fz = faceZones[zoneID];
91 flipMap_ = fz.flipMap();
100 faceZoneSet::faceZoneSet
102 const polyMesh& mesh,
108 faceSet(mesh, name, size, w),
117 faceZoneSet::faceZoneSet
119 const polyMesh& mesh,
125 faceSet(mesh, name, set.size(), w),
127 addressing_(refCast<const faceZoneSet>(set).addressing()),
128 flipMap_(refCast<const faceZoneSet>(set).flipMap())
134 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 faceZoneSet::~faceZoneSet()
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 void faceZoneSet::invert(const label maxLen)
146 for (label faceI = 0; faceI < maxLen; faceI++)
150 addressing_[n] = faceI;
151 flipMap_[n] = false; //? or true?
155 addressing_.setSize(n);
161 void faceZoneSet::subset(const topoSet& set)
165 DynamicList<label> newAddressing(addressing_.size());
166 DynamicList<bool> newFlipMap(flipMap_.size());
168 Map<label> faceToIndex(addressing_.size());
169 forAll(addressing_, i)
171 faceToIndex.insert(addressing_[i], i);
174 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
176 forAll(fSet.addressing(), i)
178 label faceI = fSet.addressing()[i];
180 Map<label>::const_iterator iter = faceToIndex.find(faceI);
182 if (iter != faceToIndex.end())
184 label index = iter();
186 if (fSet.flipMap()[i] != flipMap_[index])
190 newAddressing.append(faceI);
191 newFlipMap.append(flipMap_[index]);
197 WarningIn(" faceZoneSet::subset(const topoSet&)")
198 << "subset : there are " << nConflict
199 << " faces with different orientation in faceZonesSets "
200 << name() << " and " << set.name() << endl;
203 addressing_.transfer(newAddressing);
204 flipMap_.transfer(newFlipMap);
209 void faceZoneSet::addSet(const topoSet& set)
213 DynamicList<label> newAddressing(addressing_);
214 DynamicList<bool> newFlipMap(flipMap_);
216 Map<label> faceToIndex(addressing_.size());
217 forAll(addressing_, i)
219 faceToIndex.insert(addressing_[i], i);
222 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
224 forAll(fSet.addressing(), i)
226 label faceI = fSet.addressing()[i];
228 Map<label>::const_iterator iter = faceToIndex.find(faceI);
230 if (iter != faceToIndex.end())
232 label index = iter();
234 if (fSet.flipMap()[i] != flipMap_[index])
241 newAddressing.append(faceI);
242 newFlipMap.append(fSet.flipMap()[i]);
248 WarningIn("faceZoneSet::addSet(const topoSet&)")
249 << "addSet : there are " << nConflict
250 << " faces with different orientation in faceZonesSets "
251 << name() << " and " << set.name() << endl;
254 addressing_.transfer(newAddressing);
255 flipMap_.transfer(newFlipMap);
260 void faceZoneSet::deleteSet(const topoSet& set)
264 DynamicList<label> newAddressing(addressing_.size());
265 DynamicList<bool> newFlipMap(flipMap_.size());
267 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
269 Map<label> faceToIndex(fSet.addressing().size());
270 forAll(fSet.addressing(), i)
272 faceToIndex.insert(fSet.addressing()[i], i);
275 forAll(addressing_, i)
277 label faceI = addressing_[i];
279 Map<label>::const_iterator iter = faceToIndex.find(faceI);
281 if (iter != faceToIndex.end())
283 label index = iter();
285 if (fSet.flipMap()[index] != flipMap_[i])
292 // Not found in fSet so add
293 newAddressing.append(faceI);
294 newFlipMap.append(fSet.flipMap()[i]);
300 WarningIn("faceZoneSet::deleteSet(const topoSet&)")
301 << "deleteSet : there are " << nConflict
302 << " faces with different orientation in faceZonesSets "
303 << name() << " and " << set.name() << endl;
306 addressing_.transfer(newAddressing);
307 flipMap_.transfer(newFlipMap);
312 void faceZoneSet::sync(const polyMesh& mesh)
316 label faceZoneSet::maxSize(const polyMesh& mesh) const
318 return mesh.nFaces();
322 //- Write using given format, version and compression
323 bool faceZoneSet::writeObject
325 IOstream::streamFormat s,
326 IOstream::versionNumber v,
327 IOstream::compressionType c
330 // Write shadow faceSet
331 word oldTypeName = typeName;
332 const_cast<word&>(type()) = faceSet::typeName;
333 bool ok = faceSet::writeObject(s, v, c);
334 const_cast<word&>(type()) = oldTypeName;
337 faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh_).faceZones();
338 label zoneID = faceZones.findZoneID(name());
342 zoneID = faceZones.size();
344 faceZones.setSize(zoneID+1);
360 faceZones[zoneID].resetAddressing(addressing_, flipMap_);
362 faceZones.clearAddressing();
364 return ok && faceZones.write();
368 void faceZoneSet::updateMesh(const mapPolyMesh& morphMap)
371 labelList newAddressing(addressing_.size());
372 boolList newFlipMap(flipMap_.size());
375 forAll(addressing_, i)
377 label faceI = addressing_[i];
378 label newFaceI = morphMap.reverseFaceMap()[faceI];
381 newAddressing[n] = newFaceI;
382 newFlipMap[n] = flipMap_[i];
386 newAddressing.setSize(n);
387 newFlipMap.setSize(n);
389 addressing_.transfer(newAddressing);
390 flipMap_.transfer(newFlipMap);
396 void faceZoneSet::writeDebug
399 const primitiveMesh& mesh,
403 faceSet::writeDebug(os, mesh, maxLen);
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
409 } // End namespace Foam
411 // ************************************************************************* //