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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cellZoneSet.H"
30 #include "mapPolyMesh.H"
31 #include "polyMesh.H"
32 
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(cellZoneSet, 0);
40  addToRunTimeSelectionTable(topoSet, cellZoneSet, word);
41  addToRunTimeSelectionTable(topoSet, cellZoneSet, size);
42  addToRunTimeSelectionTable(topoSet, cellZoneSet, set);
43 }
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
48 {
49  labelList order(sortedOrder(addressing_));
50  inplaceReorder(order, addressing_);
51 
53  cellSet::resize(2*addressing_.size());
54  cellSet::set(addressing_);
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 (
62  const polyMesh& mesh,
63  const word& name,
64  readOption r,
65  writeOption w
66 )
67 :
68  cellSet(mesh, name, 1024), // do not read cellSet
69  mesh_(mesh),
70  addressing_()
71 {
72  const cellZoneMesh& cellZones = mesh.cellZones();
73  label zoneID = cellZones.findZoneID(name);
74 
75  if
76  (
77  (r == IOobject::MUST_READ)
79  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
80  )
81  {
82  const cellZone& fz = cellZones[zoneID];
83  addressing_ = fz;
84  }
85 
86  updateSet();
87 
88  check(mesh.nCells());
89 }
90 
91 
93 (
94  const polyMesh& mesh,
95  const word& name,
96  const label size,
97  writeOption w
98 )
99 :
100  cellSet(mesh, name, size, w),
101  mesh_(mesh),
102  addressing_()
103 {
104  updateSet();
105 }
106 
107 
109 (
110  const polyMesh& mesh,
111  const word& name,
112  const topoSet& set,
113  writeOption w
114 )
115 :
116  cellSet(mesh, name, set.size(), w),
117  mesh_(mesh),
118  addressing_(refCast<const cellZoneSet>(set).addressing())
119 {
120  updateSet();
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
127 {
128  // Count
129  label n = 0;
130 
131  for (label celli = 0; celli < maxLen; ++celli)
132  {
133  if (!found(celli))
134  {
135  ++n;
136  }
137  }
138 
139  // Fill
140  addressing_.setSize(n);
141  n = 0;
142 
143  for (label celli = 0; celli < maxLen; ++celli)
144  {
145  if (!found(celli))
146  {
147  addressing_[n] = celli;
148  ++n;
149  }
150  }
151 
152  updateSet();
153 }
154 
155 
157 {
158  DynamicList<label> newAddressing(addressing_.size());
159 
160  const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set);
161 
162  for (const label celli : zoneSet.addressing())
163  {
164  if (found(celli))
165  {
166  newAddressing.append(celli);
167  }
168  }
169 
170  addressing_.transfer(newAddressing);
171  updateSet();
172 }
173 
174 
176 {
177  DynamicList<label> newAddressing(addressing_);
178 
179  const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set);
180 
181  for (const label celli : zoneSet.addressing())
182  {
183  if (!found(celli))
184  {
185  newAddressing.append(celli);
186  }
187  }
188 
189  addressing_.transfer(newAddressing);
190  updateSet();
191 }
192 
193 
195 {
196  DynamicList<label> newAddressing(addressing_.size());
197 
198  const cellZoneSet& zoneSet = refCast<const cellZoneSet>(set);
199 
200  for (const label celli : addressing_)
201  {
202  if (!zoneSet.found(celli))
203  {
204  // Not found in zoneSet so add
205  newAddressing.append(celli);
206  }
207  }
208 
209  addressing_.transfer(newAddressing);
210  updateSet();
211 }
212 
213 
215 {
217 
218  // Take over contents of cellSet into addressing.
219  addressing_ = sortedToc();
220  updateSet();
221 }
222 
223 
225 {
226  return mesh.nCells();
227 }
228 
229 
231 (
235  const bool valid
236 ) const
237 {
238  // Write shadow cellSet
239  word oldTypeName = typeName;
240  const_cast<word&>(type()) = cellSet::typeName;
241  bool ok = cellSet::writeObject(s, v, c, valid);
242  const_cast<word&>(type()) = oldTypeName;
243 
244  // Modify cellZone
245  cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
246  label zoneID = cellZones.findZoneID(name());
247 
248  if (zoneID == -1)
249  {
250  zoneID = cellZones.size();
251 
252  cellZones.setSize(zoneID+1);
253  cellZones.set
254  (
255  zoneID,
256  new cellZone
257  (
258  name(),
259  addressing_,
260  zoneID,
261  cellZones
262  )
263  );
264  }
265  else
266  {
267  cellZones[zoneID] = addressing_;
268  }
269  cellZones.clearAddressing();
270 
271  return ok && cellZones.write(valid);
272 }
273 
274 
276 {
277  // cellZone
278  labelList newAddressing(addressing_.size());
279 
280  label n = 0;
281  for (const label celli : addressing_)
282  {
283  label newCelli = morphMap.reverseCellMap()[celli];
284  if (newCelli >= 0)
285  {
286  newAddressing[n] = newCelli;
287  ++n;
288  }
289  }
290  newAddressing.resize(n);
291 
292  addressing_.transfer(newAddressing);
293 
294  updateSet();
295 }
296 
297 
299 (
300  Ostream& os,
301  const primitiveMesh& mesh,
302  const label maxLen
303 ) const
304 {
305  cellSet::writeDebug(os, mesh, maxLen);
306 }
307 
308 
309 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::HashTable::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::regIOobject::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool valid) const
Write using given format, version and compression.
Definition: regIOobjectWrite.C:39
Foam::cellSet::sync
virtual void sync(const polyMesh &mesh)
Sync cellSet across coupled patches.
Definition: cellSet.H:164
Foam::cellZoneSet::maxSize
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellZoneSet.C:224
Foam::cellZoneSet::subtractSet
virtual void subtractSet(const topoSet &set)
Subtract elements present in set.
Definition: cellZoneSet.C:194
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
Foam::DynamicList< label >
mapPolyMesh.H
Foam::cellZoneSet::updateSet
void updateSet()
Sort addressing and make cellSet part consistent with addressing.
Definition: cellZoneSet.C:47
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const
Return cell zone mesh.
Definition: polyMesh.H:483
Foam::cellSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellSet.C:236
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:62
Foam::cellZoneSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellZoneSet.C:299
Foam::cellZoneSet::addSet
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: cellZoneSet.C:175
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:127
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::cellZoneSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: cellZoneSet.C:156
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
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:62
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:472
Foam::topoSet::set
virtual bool set(const label id)
Set an index.
Definition: topoSet.C:517
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:122
Foam::HashTable< zero::null, label, Hash< label > >::resize
void resize(const label sz)
Resize the hash table for efficiency.
Definition: HashTable.C:553
Foam::ZoneMesh< cellZone, polyMesh >
Foam::cellZoneSet::invert
virtual void invert(const label maxLen)
Invert contents.
Definition: cellZoneSet.C:126
Foam::cellZoneSet::addressing
const labelList & addressing() const
Definition: cellZoneSet.H:104
Foam::cellZoneSet
Like cellSet but -reads data from cellZone -updates cellZone when writing.
Definition: cellZoneSet.H:51
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
Foam::cellZoneSet::sync
virtual void sync(const polyMesh &mesh)
Sync cellSet across coupled patches; update cellZone from cellSet.
Definition: cellZoneSet.C:214
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:51
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index given a name, return -1 if not found.
Definition: ZoneMesh.C:484
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:61
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::mapPolyMesh::reverseCellMap
const labelList & reverseCellMap() const
Reverse cell map.
Definition: mapPolyMesh.H:531
Foam::HashTable< zero::null, label, Hash< label > >::clearStorage
void clearStorage()
Clear the table entries and the table itself.
Definition: HashTable.C:649
Foam::cellZoneSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: cellZoneSet.C:275
cellZoneSet.H
Foam::List< label >
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::cellZoneSet::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType, const bool valid) const
Write cellZone.
Definition: cellZoneSet.C:231
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:160
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:71
Foam::inplaceReorder
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
Definition: ListOpsTemplates.C:124
Foam::sortedOrder
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
Foam::IOobject::readOption
readOption
Enumeration defining the read options.
Definition: IOobject.H:118
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:621
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:120
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78