BUG: pointHitSort: define operator<
[OpenFOAM-1.7.x.git] / src / meshTools / sets / topoSets / faceZoneSet.C
blob87a4befd602b25b03eeea828f9fb1dbb541c5594
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 "faceZoneSet.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(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()
52     labelList order;
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)
60     {
61         faceSet::insert(addressing_[i]);
62     }
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 faceZoneSet::faceZoneSet
70     const polyMesh& mesh,
71     const word& name,
72     readOption r,
73     writeOption w
76     faceSet(mesh, name, 1000),  // do not read faceSet
77     mesh_(mesh),
78     addressing_(0),
79     flipMap_(0)
81     const faceZoneMesh& faceZones = mesh.faceZones();
82     label zoneID = faceZones.findZoneID(name);
84     if
85     (
86         (r == IOobject::MUST_READ)
87      || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
88     )
89     {
90         const faceZone& fz = faceZones[zoneID];
91         addressing_ = fz;
92         flipMap_ = fz.flipMap();
93     }
95     updateSet();
97     check(mesh.nFaces());
101 faceZoneSet::faceZoneSet
103     const polyMesh& mesh,
104     const word& name,
105     const label size,
106     writeOption w
109     faceSet(mesh, name, size, w),
110     mesh_(mesh),
111     addressing_(0),
112     flipMap_(0)
114     updateSet();
118 faceZoneSet::faceZoneSet
120     const polyMesh& mesh,
121     const word& name,
122     const topoSet& set,
123     writeOption w
126     faceSet(mesh, name, set.size(), w),
127     mesh_(mesh),
128     addressing_(refCast<const faceZoneSet>(set).addressing()),
129     flipMap_(refCast<const faceZoneSet>(set).flipMap())
131     updateSet();
135 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
137 faceZoneSet::~faceZoneSet()
141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
143 void faceZoneSet::invert(const label maxLen)
145     label n = 0;
147     for (label faceI = 0; faceI < maxLen; faceI++)
148     {
149         if (!found(faceI))
150         {
151             addressing_[n] = faceI;
152             flipMap_[n] = false;         //? or true?
153             n++;
154         }
155     }
156     addressing_.setSize(n);
157     flipMap_.setSize(n);
158     updateSet();
162 void faceZoneSet::subset(const topoSet& set)
164     label nConflict = 0;
166     DynamicList<label> newAddressing(addressing_.size());
167     DynamicList<bool> newFlipMap(flipMap_.size());
169     Map<label> faceToIndex(addressing_.size());
170     forAll(addressing_, i)
171     {
172         faceToIndex.insert(addressing_[i], i);
173     }
175     const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
177     forAll(fSet.addressing(), i)
178     {
179         label faceI = fSet.addressing()[i];
181         Map<label>::const_iterator iter = faceToIndex.find(faceI);
183         if (iter != faceToIndex.end())
184         {
185             label index = iter();
187             if (fSet.flipMap()[i] != flipMap_[index])
188             {
189                 nConflict++;
190             }
191             newAddressing.append(faceI);
192             newFlipMap.append(flipMap_[index]);
193         }
194     }
196     if (nConflict > 0)
197     {
198         WarningIn(" faceZoneSet::subset(const topoSet&)")
199             << "subset : there are " << nConflict
200             << " faces with different orientation in faceZonesSets "
201             << name() << " and " << set.name() << endl;
202     }
204     addressing_.transfer(newAddressing);
205     flipMap_.transfer(newFlipMap);
206     updateSet();
210 void faceZoneSet::addSet(const topoSet& set)
212     label nConflict = 0;
214     DynamicList<label> newAddressing(addressing_);
215     DynamicList<bool> newFlipMap(flipMap_);
217     Map<label> faceToIndex(addressing_.size());
218     forAll(addressing_, i)
219     {
220         faceToIndex.insert(addressing_[i], i);
221     }
223     const faceZoneSet& fSet = refCast<const faceZoneSet>(set);
225     forAll(fSet.addressing(), i)
226     {
227         label faceI = fSet.addressing()[i];
229         Map<label>::const_iterator iter = faceToIndex.find(faceI);
231         if (iter != faceToIndex.end())
232         {
233             label index = iter();
235             if (fSet.flipMap()[i] != flipMap_[index])
236             {
237                 nConflict++;
238             }
239         }
240         else
241         {
242             newAddressing.append(faceI);
243             newFlipMap.append(fSet.flipMap()[i]);
244         }
245     }
247     if (nConflict > 0)
248     {
249         WarningIn("faceZoneSet::addSet(const topoSet&)")
250             << "addSet : there are " << nConflict
251             << " faces with different orientation in faceZonesSets "
252             << name() << " and " << set.name() << endl;
253     }
255     addressing_.transfer(newAddressing);
256     flipMap_.transfer(newFlipMap);
257     updateSet();
261 void faceZoneSet::deleteSet(const topoSet& set)
263     label nConflict = 0;
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)
272     {
273         faceToIndex.insert(fSet.addressing()[i], i);
274     }
276     forAll(addressing_, i)
277     {
278         label faceI = addressing_[i];
280         Map<label>::const_iterator iter = faceToIndex.find(faceI);
282         if (iter != faceToIndex.end())
283         {
284             label index = iter();
286             if (fSet.flipMap()[index] != flipMap_[i])
287             {
288                 nConflict++;
289             }
290         }
291         else
292         {
293             // Not found in fSet so add
294             newAddressing.append(faceI);
295             newFlipMap.append(fSet.flipMap()[i]);
296         }
297     }
299     if (nConflict > 0)
300     {
301         WarningIn("faceZoneSet::deleteSet(const topoSet&)")
302             << "deleteSet : there are " << nConflict
303             << " faces with different orientation in faceZonesSets "
304             << name() << " and " << set.name() << endl;
305     }
307     addressing_.transfer(newAddressing);
308     flipMap_.transfer(newFlipMap);
309     updateSet();
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
329 ) const
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;
337     // Modify faceZone
338     faceZoneMesh& faceZones = const_cast<polyMesh&>(mesh_).faceZones();
339     label zoneID = faceZones.findZoneID(name());
341     if (zoneID == -1)
342     {
343         zoneID = faceZones.size();
345         faceZones.setSize(zoneID+1);
346         faceZones.set
347         (
348             zoneID,
349             new faceZone
350             (
351                 name(),
352                 addressing_,
353                 flipMap_,
354                 zoneID,
355                 faceZones
356             )
357         );
358     }
359     else
360     {
361         faceZones[zoneID].resetAddressing(addressing_, flipMap_);
362     }
363     faceZones.clearAddressing();
365     return ok && faceZones.write();
369 void faceZoneSet::updateMesh(const mapPolyMesh& morphMap)
371     // faceZone
372     labelList newAddressing(addressing_.size());
373     boolList newFlipMap(flipMap_.size());
375     label n = 0;
376     forAll(addressing_, i)
377     {
378         label faceI = addressing_[i];
379         label newFaceI = morphMap.reverseFaceMap()[faceI];
380         if (newFaceI >= 0)
381         {
382             newAddressing[n] = newFaceI;
383             newFlipMap[n] = flipMap_[i];
384             n++;
385         }
386     }
387     newAddressing.setSize(n);
388     newFlipMap.setSize(n);
390     addressing_.transfer(newAddressing);
391     flipMap_.transfer(newFlipMap);
393     updateSet();
397 void faceZoneSet::writeDebug
399     Ostream& os,
400     const primitiveMesh& mesh,
401     const label maxLen
402 ) const
404     faceSet::writeDebug(os, mesh, maxLen);
408 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
410 } // End namespace Foam
412 // ************************************************************************* //