ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / meshTools / sets / topoSets / pointZoneSet.C
blob783cd78431a493443ba04888a06f314d35b34d0a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 "pointZoneSet.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(pointZoneSet, 0);
43 addToRunTimeSelectionTable(topoSet, pointZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, pointZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, pointZoneSet, set);
48 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
50 void pointZoneSet::updateSet()
52     labelList order;
53     sortedOrder(addressing_, order);
54     inplaceReorder(order, addressing_);
56     pointSet::clearStorage();
57     pointSet::resize(2*addressing_.size());
58     forAll(addressing_, i)
59     {
60         pointSet::insert(addressing_[i]);
61     }
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 pointZoneSet::pointZoneSet
69     const polyMesh& mesh,
70     const word& name,
71     readOption r,
72     writeOption w
75     pointSet(mesh, name, 1000),  // do not read pointSet
76     mesh_(mesh),
77     addressing_(0)
79     const pointZoneMesh& pointZones = mesh.pointZones();
80     label zoneID = pointZones.findZoneID(name);
82     if
83     (
84         r == IOobject::MUST_READ
85      || r == IOobject::MUST_READ_IF_MODIFIED
86      || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
87     )
88     {
89         const pointZone& fz = pointZones[zoneID];
90         addressing_ = fz;
91     }
93     updateSet();
95     check(mesh.nPoints());
99 pointZoneSet::pointZoneSet
101     const polyMesh& mesh,
102     const word& name,
103     const label size,
104     writeOption w
107     pointSet(mesh, name, size, w),
108     mesh_(mesh),
109     addressing_(0)
111     updateSet();
115 pointZoneSet::pointZoneSet
117     const polyMesh& mesh,
118     const word& name,
119     const topoSet& set,
120     writeOption w
123     pointSet(mesh, name, set.size(), w),
124     mesh_(mesh),
125     addressing_(refCast<const pointZoneSet>(set).addressing())
127     updateSet();
131 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
133 pointZoneSet::~pointZoneSet()
137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
139 void pointZoneSet::invert(const label maxLen)
141     label n = 0;
143     for (label pointI = 0; pointI < maxLen; pointI++)
144     {
145         if (!found(pointI))
146         {
147             addressing_[n] = pointI;
148             n++;
149         }
150     }
151     addressing_.setSize(n);
152     updateSet();
156 void pointZoneSet::subset(const topoSet& set)
158     DynamicList<label> newAddressing(addressing_.size());
160     const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
162     forAll(fSet.addressing(), i)
163     {
164         label pointI = fSet.addressing()[i];
166         if (found(pointI))
167         {
168             newAddressing.append(pointI);
169         }
170     }
172     addressing_.transfer(newAddressing);
173     updateSet();
177 void pointZoneSet::addSet(const topoSet& set)
179     DynamicList<label> newAddressing(addressing_);
181     const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
183     forAll(fSet.addressing(), i)
184     {
185         label pointI = fSet.addressing()[i];
187         if (!found(pointI))
188         {
189             newAddressing.append(pointI);
190         }
191     }
193     addressing_.transfer(newAddressing);
194     updateSet();
198 void pointZoneSet::deleteSet(const topoSet& set)
200     DynamicList<label> newAddressing(addressing_.size());
202     const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
204     forAll(addressing_, i)
205     {
206         label pointI = addressing_[i];
208         if (!fSet.found(pointI))
209         {
210             // Not found in fSet so add
211             newAddressing.append(pointI);
212         }
213     }
215     addressing_.transfer(newAddressing);
216     updateSet();
220 void pointZoneSet::sync(const polyMesh& mesh)
224 label pointZoneSet::maxSize(const polyMesh& mesh) const
226     return mesh.nPoints();
230 //- Write using given format, version and compression
231 bool pointZoneSet::writeObject
233     IOstream::streamFormat s,
234     IOstream::versionNumber v,
235     IOstream::compressionType c
236 ) const
238     // Write shadow pointSet
239     word oldTypeName = typeName;
240     const_cast<word&>(type()) = pointSet::typeName;
241     bool ok = pointSet::writeObject(s, v, c);
242     const_cast<word&>(type()) = oldTypeName;
244     // Modify pointZone
245     pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
246     label zoneID = pointZones.findZoneID(name());
248     if (zoneID == -1)
249     {
250         zoneID = pointZones.size();
252         pointZones.setSize(zoneID+1);
253         pointZones.set
254         (
255             zoneID,
256             new pointZone
257             (
258                 name(),
259                 addressing_,
260                 zoneID,
261                 pointZones
262             )
263         );
264     }
265     else
266     {
267         pointZones[zoneID] = addressing_;
268     }
269     pointZones.clearAddressing();
271     return ok && pointZones.write();
275 void pointZoneSet::updateMesh(const mapPolyMesh& morphMap)
277     // pointZone
278     labelList newAddressing(addressing_.size());
280     label n = 0;
281     forAll(addressing_, i)
282     {
283         label pointI = addressing_[i];
284         label newPointI = morphMap.reversePointMap()[pointI];
285         if (newPointI >= 0)
286         {
287             newAddressing[n] = newPointI;
288             n++;
289         }
290     }
291     newAddressing.setSize(n);
293     addressing_.transfer(newAddressing);
295     updateSet();
299 void pointZoneSet::writeDebug
301     Ostream& os,
302     const primitiveMesh& mesh,
303     const label maxLen
304 ) const
306     pointSet::writeDebug(os, mesh, maxLen);
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 } // End namespace Foam
314 // ************************************************************************* //