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 "faceZoneSet.H"
27 #include "mapPolyMesh.H"
29 #include "processorPolyPatch.H"
30 #include "cyclicPolyPatch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
41 defineTypeNameAndDebug(faceZoneSet, 0);
43 addToRunTimeSelectionTable(topoSet, faceZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, faceZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, faceZoneSet, set);
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 void faceZoneSet::updateSet()
53 sortedOrder(addressing_, order);
54 inplaceReorder(order, addressing_);
55 inplaceReorder(order, flipMap_);
57 faceSet::clearStorage();
58 faceSet::resize(2*addressing_.size());
59 forAll(addressing_, i)
61 faceSet::insert(addressing_[i]);
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 faceZoneSet::faceZoneSet
76 faceSet(mesh, name, 1000), // do not read faceSet
81 const faceZoneMesh& faceZones = mesh.faceZones();
82 label zoneID = faceZones.findZoneID(name);
86 (r == IOobject::MUST_READ)
87 || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
90 const faceZone& fz = faceZones[zoneID];
92 flipMap_ = fz.flipMap();
101 faceZoneSet::faceZoneSet
103 const polyMesh& mesh,
109 faceSet(mesh, name, size, w),
118 faceZoneSet::faceZoneSet
120 const polyMesh& mesh,
126 faceSet(mesh, name, set.size(), w),
128 addressing_(refCast<const faceZoneSet>(set).addressing()),
129 flipMap_(refCast<const faceZoneSet>(set).flipMap())
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
137 faceZoneSet::~faceZoneSet()
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
143 void faceZoneSet::invert(const label maxLen)
147 for (label faceI = 0; faceI < maxLen; faceI++)
151 addressing_[n] = faceI;
152 flipMap_[n] = false; //? or true?
156 addressing_.setSize(n);
162 void faceZoneSet::subset(const topoSet& set)
166 DynamicList<label> newAddressing(addressing_.size());
167 DynamicList<bool> newFlipMap(flipMap_.size());
169 Map<label> faceToIndex(addressing_.size());
170 forAll(addressing_, i)
172 faceToIndex.insert(addressing_[i], i);
175 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
177 forAll(fSet.addressing(), i)
179 label faceI = fSet.addressing()[i];
181 Map<label>::const_iterator iter = faceToIndex.find(faceI);
183 if (iter != faceToIndex.end())
185 label index = iter();
187 if (fSet.flipMap()[i] != flipMap_[index])
191 newAddressing.append(faceI);
192 newFlipMap.append(flipMap_[index]);
198 WarningIn(" faceZoneSet::subset(const topoSet&)")
199 << "subset : there are " << nConflict
200 << " faces with different orientation in faceZonesSets "
201 << name() << " and " << set.name() << endl;
204 addressing_.transfer(newAddressing);
205 flipMap_.transfer(newFlipMap);
210 void faceZoneSet::addSet(const topoSet& set)
214 DynamicList<label> newAddressing(addressing_);
215 DynamicList<bool> newFlipMap(flipMap_);
217 Map<label> faceToIndex(addressing_.size());
218 forAll(addressing_, i)
220 faceToIndex.insert(addressing_[i], i);
223 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
225 forAll(fSet.addressing(), i)
227 label faceI = fSet.addressing()[i];
229 Map<label>::const_iterator iter = faceToIndex.find(faceI);
231 if (iter != faceToIndex.end())
233 label index = iter();
235 if (fSet.flipMap()[i] != flipMap_[index])
242 newAddressing.append(faceI);
243 newFlipMap.append(fSet.flipMap()[i]);
249 WarningIn("faceZoneSet::addSet(const topoSet&)")
250 << "addSet : there are " << nConflict
251 << " faces with different orientation in faceZonesSets "
252 << name() << " and " << set.name() << endl;
255 addressing_.transfer(newAddressing);
256 flipMap_.transfer(newFlipMap);
261 void faceZoneSet::deleteSet(const topoSet& set)
265 DynamicList<label> newAddressing(addressing_.size());
266 DynamicList<bool> newFlipMap(flipMap_.size());
268 const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
270 Map<label> faceToIndex(fSet.addressing().size());
271 forAll(fSet.addressing(), i)
273 faceToIndex.insert(fSet.addressing()[i], i);
276 forAll(addressing_, i)
278 label faceI = addressing_[i];
280 Map<label>::const_iterator iter = faceToIndex.find(faceI);
282 if (iter != faceToIndex.end())
284 label index = iter();
286 if (fSet.flipMap()[index] != flipMap_[i])
293 // Not found in fSet so add
294 newAddressing.append(faceI);
295 newFlipMap.append(fSet.flipMap()[i]);
301 WarningIn("faceZoneSet::deleteSet(const topoSet&)")
302 << "deleteSet : there are " << nConflict
303 << " faces with different orientation in faceZonesSets "
304 << name() << " and " << set.name() << endl;
307 addressing_.transfer(newAddressing);
308 flipMap_.transfer(newFlipMap);
313 void faceZoneSet::sync(const polyMesh& mesh)
317 label faceZoneSet::maxSize(const polyMesh& mesh) const
319 return mesh.nFaces();
323 //- Write using given format, version and compression
324 bool faceZoneSet::writeObject
326 IOstream::streamFormat s,
327 IOstream::versionNumber v,
328 IOstream::compressionType c
331 // Write shadow faceSet
332 word oldTypeName = typeName;
333 const_cast<word&>(type()) = faceSet::typeName;
334 bool ok = faceSet::writeObject(s, v, c);
335 const_cast<word&>(type()) = oldTypeName;
338 faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh_).faceZones();
339 label zoneID = faceZones.findZoneID(name());
343 zoneID = faceZones.size();
345 faceZones.setSize(zoneID+1);
361 faceZones[zoneID].resetAddressing(addressing_, flipMap_);
363 faceZones.clearAddressing();
365 return ok && faceZones.write();
369 void faceZoneSet::updateMesh(const mapPolyMesh& morphMap)
372 labelList newAddressing(addressing_.size());
373 boolList newFlipMap(flipMap_.size());
376 forAll(addressing_, i)
378 label faceI = addressing_[i];
379 label newFaceI = morphMap.reverseFaceMap()[faceI];
382 newAddressing[n] = newFaceI;
383 newFlipMap[n] = flipMap_[i];
387 newAddressing.setSize(n);
388 newFlipMap.setSize(n);
390 addressing_.transfer(newAddressing);
391 flipMap_.transfer(newFlipMap);
397 void faceZoneSet::writeDebug
400 const primitiveMesh& mesh,
404 faceSet::writeDebug(os, mesh, maxLen);
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 } // End namespace Foam
412 // ************************************************************************* //