cellZoneSet.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 "cellZoneSet.H"
27 #include "mapPolyMesh.H"
28 #include "polyMesh.H"
29 
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 defineTypeNameAndDebug(cellZoneSet, 0);
40 
41 addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
42 addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
43 addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 {
50  labelList order;
51  sortedOrder(addressing_, order);
53 
57  {
59  }
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
64 
66 (
67  const polyMesh& mesh,
68  const word& name,
69  readOption r,
71 )
72 :
73  cellSet(mesh, name, 1000), // do not read cellSet
74  mesh_(mesh),
75  addressing_(0)
76 {
77  const cellZoneMesh& cellZones = mesh.cellZones();
78  label zoneID = cellZones.findZoneID(name);
79 
80  if
81  (
82  (r == IOobject::MUST_READ)
84  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
85  )
86  {
87  const cellZone& fz = cellZones[zoneID];
88  addressing_ = fz;
89  }
90 
91  updateSet();
92 
93  check(mesh.nCells());
94 }
95 
96 
98 (
99  const polyMesh& mesh,
100  const word& name,
101  const label size,
102  writeOption w
103 )
104 :
105  cellSet(mesh, name, size, w),
106  mesh_(mesh),
107  addressing_(0)
108 {
109  updateSet();
110 }
111 
112 
114 (
115  const polyMesh& mesh,
116  const word& name,
117  const topoSet& set,
118  writeOption w
119 )
120 :
121  cellSet(mesh, name, set.size(), w),
122  mesh_(mesh),
123  addressing_(refCast<const cellZoneSet>(set).addressing())
124 {
125  updateSet();
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
130 
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
137 void cellZoneSet::invert(const label maxLen)
138 {
139  // Count
140  label n = 0;
141 
142  for (label cellI = 0; cellI < maxLen; cellI++)
143  {
144  if (!found(cellI))
145  {
146  n++;
147  }
148  }
149 
150  // Fill
152  n = 0;
153 
154  for (label cellI = 0; cellI < maxLen; cellI++)
155  {
156  if (!found(cellI))
157  {
158  addressing_[n] = cellI;
159  n++;
160  }
161  }
162 
163  updateSet();
164 }
165 
166 
167 void cellZoneSet::subset(const topoSet& set)
168 {
169  DynamicList<label> newAddressing(addressing_.size());
170 
171  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
172 
173  forAll(fSet.addressing(), i)
174  {
175  label cellI = fSet.addressing()[i];
176 
177  if (found(cellI))
178  {
179  newAddressing.append(cellI);
180  }
181  }
182 
183  addressing_.transfer(newAddressing);
184  updateSet();
185 }
186 
187 
188 void cellZoneSet::addSet(const topoSet& set)
189 {
190  DynamicList<label> newAddressing(addressing_);
191 
192  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
193 
194  forAll(fSet.addressing(), i)
195  {
196  label cellI = fSet.addressing()[i];
197 
198  if (!found(cellI))
199  {
200  newAddressing.append(cellI);
201  }
202  }
203 
204  addressing_.transfer(newAddressing);
205  updateSet();
206 }
207 
208 
210 {
211  DynamicList<label> newAddressing(addressing_.size());
212 
213  const cellZoneSet& fSet = refCast<const cellZoneSet>(set);
214 
215  forAll(addressing_, i)
216  {
217  label cellI = addressing_[i];
218 
219  if (!fSet.found(cellI))
220  {
221  // Not found in fSet so add
222  newAddressing.append(cellI);
223  }
224  }
225 
226  addressing_.transfer(newAddressing);
227  updateSet();
228 }
229 
230 
232 {}
233 
234 
236 {
237  return mesh.nCells();
238 }
239 
240 
241 //- Write using given format, version and compression
243 (
247 ) const
248 {
249  // Write shadow cellSet
250  word oldTypeName = typeName;
251  const_cast<word&>(type()) = cellSet::typeName;
252  bool ok = cellSet::writeObject(s, v, c);
253  const_cast<word&>(type()) = oldTypeName;
254 
255  // Modify cellZone
256  cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
257  label zoneID = cellZones.findZoneID(name());
258 
259  if (zoneID == -1)
260  {
261  zoneID = cellZones.size();
262 
263  cellZones.setSize(zoneID+1);
264  cellZones.set
265  (
266  zoneID,
267  new cellZone
268  (
269  name(),
270  addressing_,
271  zoneID,
272  cellZones
273  )
274  );
275  }
276  else
277  {
278  cellZones[zoneID] = addressing_;
279  }
280  cellZones.clearAddressing();
281 
282  return ok && cellZones.write();
283 }
284 
285 
287 {
288  // cellZone
289  labelList newAddressing(addressing_.size());
290 
291  label n = 0;
292  forAll(addressing_, i)
293  {
294  label cellI = addressing_[i];
295  label newCellI = morphMap.reverseCellMap()[cellI];
296  if (newCellI >= 0)
297  {
298  newAddressing[n] = newCellI;
299  n++;
300  }
301  }
302  newAddressing.setSize(n);
303 
304  addressing_.transfer(newAddressing);
305 
306  updateSet();
307 }
308 
309 
311 (
312  Ostream& os,
313  const primitiveMesh& mesh,
314  const label maxLen
315 ) const
316 {
317  cellSet::writeDebug(os, mesh, maxLen);
318 }
319 
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 } // End namespace Foam
324 
325 // ************************************************************************* //
Foam::cellZoneSet::deleteSet
virtual void deleteSet(const topoSet &set)
Delete elements present in set.
Definition: cellZoneSet.C:209
Foam::cellZoneSet::maxSize
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellZoneSet.C:235
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::cellZoneSet::addressing_
labelList addressing_
Definition: cellZoneSet.H:57
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::cellZoneSet::updateSet
void updateSet()
Sort addressing and make cellSet part consistent with addressing.
Definition: cellZoneSet.C:48
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:469
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::cellSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellSet.C:232
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:61
Foam::cellZoneSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellZoneSet.C:311
Foam::cellZoneSet::~cellZoneSet
virtual ~cellZoneSet()
Destructor.
Definition: cellZoneSet.C:131
Foam::primitiveMesh::nCells
label nCells() const
Definition: primitiveMeshI.H:64
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::cellZoneSet::addSet
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: cellZoneSet.C:188
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::cellZoneSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: cellZoneSet.C:167
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::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:115
Foam::ZoneMesh< cellZone, polyMesh >
Foam::cellZoneSet::invert
virtual void invert(const label maxLen)
Invert contents. (insert all members 0..maxLen-1 which were not in.
Definition: cellZoneSet.C:137
Foam::cellZoneSet::addressing
const labelList & addressing() const
Definition: cellZoneSet.H:102
Foam::cellZoneSet
Like cellSet but updates cellZone when writing.
Definition: cellZoneSet.H:49
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Foam::cellZoneSet::sync
virtual void sync(const polyMesh &mesh)
Sync cellZoneSet across coupled patches.
Definition: cellZoneSet.C:231
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::cellSet
A collection of cell labels.
Definition: cellSet.H:48
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::cellZoneSet::cellZoneSet
cellZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Construct from objectRegistry and name.
Definition: cellZoneSet.C:66
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::mapPolyMesh::reverseCellMap
const labelList & reverseCellMap() const
Reverse cell map.
Definition: mapPolyMesh.H:528
Foam::HashTable< nil, word, string::hash >::clearStorage
void clearStorage()
Clear the table entries and the table itself.
Definition: HashTable.C:497
Foam::cellZoneSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: cellZoneSet.C:286
cellZoneSet.H
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::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::cellZoneSet::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write cellZone.
Definition: cellZoneSet.C:243
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:110
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::HashSet::set
bool set(const Key &key)
Same as insert (cannot overwrite nil content)
Definition: HashSet.H:126
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