pointZoneSet.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "pointZoneSet.H"
27 #include "mapPolyMesh.H"
28 #include "polyMesh.H"
29 #include "processorPolyPatch.H"
30 #include "cyclicPolyPatch.H"
31 
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 
41 defineTypeNameAndDebug(pointZoneSet, 0);
42 
43 addToRunTimeSelectionTable(topoSet, pointZoneSet, word);
44 addToRunTimeSelectionTable(topoSet, pointZoneSet, size);
45 addToRunTimeSelectionTable(topoSet, pointZoneSet, set);
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 {
52  labelList order;
53  sortedOrder(addressing_, order);
55 
59  {
61  }
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
68 (
69  const polyMesh& mesh,
70  const word& name,
71  readOption r,
73 )
74 :
75  pointSet(mesh, name, 1000), // do not read pointSet
76  mesh_(mesh),
77  addressing_(0)
78 {
79  const pointZoneMesh& pointZones = mesh.pointZones();
80  label zoneID = pointZones.findZoneID(name);
81 
82  if
83  (
86  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
87  )
88  {
89  const pointZone& fz = pointZones[zoneID];
90  addressing_ = fz;
91  }
92 
93  updateSet();
94 
95  check(mesh.nPoints());
96 }
97 
98 
100 (
101  const polyMesh& mesh,
102  const word& name,
103  const label size,
104  writeOption w
105 )
106 :
107  pointSet(mesh, name, size, w),
108  mesh_(mesh),
109  addressing_(0)
110 {
111  updateSet();
112 }
113 
114 
116 (
117  const polyMesh& mesh,
118  const word& name,
119  const topoSet& set,
120  writeOption w
121 )
122 :
123  pointSet(mesh, name, set.size(), w),
124  mesh_(mesh),
125  addressing_(refCast<const pointZoneSet>(set).addressing())
126 {
127  updateSet();
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
139 void pointZoneSet::invert(const label maxLen)
140 {
141  // Count
142  label n = 0;
143 
144  for (label pointI = 0; pointI < maxLen; pointI++)
145  {
146  if (!found(pointI))
147  {
148  n++;
149  }
150  }
151 
152  // Fill
154  n = 0;
155 
156  for (label pointI = 0; pointI < maxLen; pointI++)
157  {
158  if (!found(pointI))
159  {
160  addressing_[n] = pointI;
161  n++;
162  }
163  }
164  updateSet();
165 }
166 
167 
169 {
170  DynamicList<label> newAddressing(addressing_.size());
171 
172  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
173 
174  forAll(fSet.addressing(), i)
175  {
176  label pointI = fSet.addressing()[i];
177 
178  if (found(pointI))
179  {
180  newAddressing.append(pointI);
181  }
182  }
183 
184  addressing_.transfer(newAddressing);
185  updateSet();
186 }
187 
188 
190 {
191  DynamicList<label> newAddressing(addressing_);
192 
193  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
194 
195  forAll(fSet.addressing(), i)
196  {
197  label pointI = fSet.addressing()[i];
198 
199  if (!found(pointI))
200  {
201  newAddressing.append(pointI);
202  }
203  }
204 
205  addressing_.transfer(newAddressing);
206  updateSet();
207 }
208 
209 
211 {
212  DynamicList<label> newAddressing(addressing_.size());
213 
214  const pointZoneSet& fSet = refCast<const pointZoneSet>(set);
215 
216  forAll(addressing_, i)
217  {
218  label pointI = addressing_[i];
219 
220  if (!fSet.found(pointI))
221  {
222  // Not found in fSet so add
223  newAddressing.append(pointI);
224  }
225  }
226 
227  addressing_.transfer(newAddressing);
228  updateSet();
229 }
230 
231 
233 {}
234 
235 
237 {
238  return mesh.nPoints();
239 }
240 
241 
242 //- Write using given format, version and compression
244 (
248 ) const
249 {
250  // Write shadow pointSet
251  word oldTypeName = typeName;
252  const_cast<word&>(type()) = pointSet::typeName;
253  bool ok = pointSet::writeObject(s, v, c);
254  const_cast<word&>(type()) = oldTypeName;
255 
256  // Modify pointZone
257  pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
258  label zoneID = pointZones.findZoneID(name());
259 
260  if (zoneID == -1)
261  {
262  zoneID = pointZones.size();
263 
264  pointZones.setSize(zoneID+1);
265  pointZones.set
266  (
267  zoneID,
268  new pointZone
269  (
270  name(),
271  addressing_,
272  zoneID,
273  pointZones
274  )
275  );
276  }
277  else
278  {
279  pointZones[zoneID] = addressing_;
280  }
281  pointZones.clearAddressing();
282 
283  return ok && pointZones.write();
284 }
285 
286 
288 {
289  // pointZone
290  labelList newAddressing(addressing_.size());
291 
292  label n = 0;
293  forAll(addressing_, i)
294  {
295  label pointI = addressing_[i];
296  label newPointI = morphMap.reversePointMap()[pointI];
297  if (newPointI >= 0)
298  {
299  newAddressing[n] = newPointI;
300  n++;
301  }
302  }
303  newAddressing.setSize(n);
304 
305  addressing_.transfer(newAddressing);
306 
307  updateSet();
308 }
309 
310 
312 (
313  Ostream& os,
314  const primitiveMesh& mesh,
315  const label maxLen
316 ) const
317 {
318  pointSet::writeDebug(os, mesh, maxLen);
319 }
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 } // End namespace Foam
325 
326 // ************************************************************************* //
Foam::pointZoneSet
Like pointSet but updates pointZone when writing.
Definition: pointZoneSet.H:49
Foam::pointZoneSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: pointZoneSet.C:287
w
volScalarField w(IOobject("w", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE), mesh, dimensionedScalar("w", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0))
Foam::regIOobject::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write using given format, version and compression.
Definition: regIOobjectWrite.C:37
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::HashTable< nil, word, string::hash >::resize
void resize(const label newSize)
Resize the hash table for efficiency.
Definition: HashTable.C:436
cyclicPolyPatch.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::IOstream::compressionType
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
mapPolyMesh.H
Foam::pointZone
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list.
Definition: pointZone.H:62
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::pointSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Update any stored data for new labels.
Definition: pointSet.C:160
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::pointZoneSet::invert
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: pointZoneSet.C:139
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::IOstream::versionNumber
Version number type.
Definition: IOstream.H:96
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:109
Foam::pointZoneSet::maxSize
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: pointZoneSet.C:236
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::sortedOrder
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
Definition: ListOpsTemplates.C:179
Foam::primitiveMesh::nPoints
label nPoints() const
Definition: primitiveMeshI.H:35
Foam::inplaceReorder
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
Definition: ListOpsTemplates.C:102
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::pointZoneSet::sync
virtual void sync(const polyMesh &mesh)
Sync pointZoneSet across coupled patches.
Definition: pointZoneSet.C:232
Foam::polyMesh::pointZones
const pointZoneMesh & pointZones() const
Return point zone mesh.
Definition: polyMesh.H:457
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
Foam::ZoneMesh
A list of mesh zones.
Definition: cellZoneMeshFwd.H:39
Foam::pointZoneSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointZoneSet.C:312
Foam::pointZoneSet::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write pointZone.
Definition: pointZoneSet.C:244
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
processorPolyPatch.H
Foam::HashTable::size
label size() const
Return number of elements in table.
Definition: HashTableI.H:65
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::HashTable< nil, word, string::hash >::found
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:109
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name.
Definition: ZoneMesh.C:348
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::pointZoneSet::addSet
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: pointZoneSet.C:189
Foam::pointZoneSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: pointZoneSet.C:168
Foam::pointZoneSet::deleteSet
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: pointZoneSet.C:210
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::HashTable< nil, word, string::hash >::clearStorage
void clearStorage()
Clear the table entries and the table itself.
Definition: HashTable.C:497
Foam::pointSet
A set of point labels.
Definition: pointSet.H:48
Foam::pointZoneSet::~pointZoneSet
virtual ~pointZoneSet()
Destructor.
Definition: pointZoneSet.C:133
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:465
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::HashSet::insert
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:106
Foam::pointZoneSet::addressing_
labelList addressing_
Definition: pointZoneSet.H:57
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:394
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::pointZoneSet::pointZoneSet
pointZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: pointZoneSet.C:68
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::pointZoneSet::addressing
const labelList & addressing() const
Definition: pointZoneSet.H:105
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::pointZoneSet::updateSet
void updateSet()
Sort addressing and make pointSet part consistent with addressing.
Definition: pointZoneSet.C:50
Foam::HashSet::set
bool set(const Key &key)
Same as insert (cannot overwrite nil content)
Definition: HashSet.H:126
pointZoneSet.H
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79