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-2020 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);
43 }
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
48 {
49  labelList order(sortedOrder(addressing_));
50  inplaceReorder(order, addressing_);
51 
52  cellSet::clearStorage();
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 
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 
126 void Foam::cellZoneSet::invert(const label maxLen)
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 
156 void Foam::cellZoneSet::subset(const topoSet& set)
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 
175 void Foam::cellZoneSet::addSet(const topoSet& set)
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 
194 void Foam::cellZoneSet::subtractSet(const topoSet& set)
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 
214 void Foam::cellZoneSet::sync(const polyMesh& mesh)
215 {
217 
218  // Take over contents of cellSet into addressing.
219  addressing_ = sortedToc();
220  updateSet();
221 }
222 
223 
224 Foam::label Foam::cellZoneSet::maxSize(const polyMesh& mesh) const
225 {
226  return mesh.nCells();
227 }
228 
229 
231 (
232  IOstreamOption streamOpt,
233  const bool valid
234 ) const
235 {
236  // Write shadow cellSet
237  word oldTypeName = typeName;
238  const_cast<word&>(type()) = cellSet::typeName;
239  bool ok = cellSet::writeObject(streamOpt, valid);
240  const_cast<word&>(type()) = oldTypeName;
241 
242  // Modify cellZone
243  cellZoneMesh& cellZones = const_cast<polyMesh&>(mesh_).cellZones();
244  label zoneID = cellZones.findZoneID(name());
245 
246  if (zoneID == -1)
247  {
248  zoneID = cellZones.size();
249 
250  cellZones.setSize(zoneID+1);
251  cellZones.set
252  (
253  zoneID,
254  new cellZone
255  (
256  name(),
257  addressing_,
258  zoneID,
259  cellZones
260  )
261  );
262  }
263  else
264  {
265  cellZones[zoneID] = addressing_;
266  }
267  cellZones.clearAddressing();
268 
269  return ok && cellZones.write(valid);
270 }
271 
272 
273 void Foam::cellZoneSet::updateMesh(const mapPolyMesh& morphMap)
274 {
275  // cellZone
276  labelList newAddressing(addressing_.size());
277 
278  label n = 0;
279  for (const label celli : addressing_)
280  {
281  label newCelli = morphMap.reverseCellMap()[celli];
282  if (newCelli >= 0)
283  {
284  newAddressing[n] = newCelli;
285  ++n;
286  }
287  }
288  newAddressing.resize(n);
289 
290  addressing_.transfer(newAddressing);
291 
292  updateSet();
293 }
294 
295 
297 (
298  Ostream& os,
299  const primitiveMesh& mesh,
300  const label maxLen
301 ) const
302 {
303  cellSet::writeDebug(os, mesh, maxLen);
304 }
305 
306 
307 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:63
Foam::cellSet::sync
virtual void sync(const polyMesh &mesh)
Definition: cellSet.H:160
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Definition: BitOps.C:30
Foam::cellZoneSet::maxSize
virtual label maxSize(const polyMesh &mesh) const
Definition: cellZoneSet.C:217
Foam::cellZoneSet::subtractSet
virtual void subtractSet(const topoSet &set)
Definition: cellZoneSet.C:187
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::List::resize
void resize(const label len)
Definition: ListI.H:132
Foam::DynamicList< label >
mapPolyMesh.H
Foam::cellZoneSet::updateSet
void updateSet()
Definition: cellZoneSet.C:40
Foam::cellSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Definition: cellSet.C:229
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
Foam::cellZone
A subset of mesh cells.
Definition: cellZone.H:58
Foam::cellZoneSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Definition: cellZoneSet.C:290
Foam::cellZoneSet::addSet
virtual void addSet(const topoSet &set)
Definition: cellZoneSet.C:168
Foam::IOobject::writeOption
writeOption
Definition: IOobject.H:188
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::primitiveMesh::nCells
label nCells() const noexcept
Definition: primitiveMeshI.H:89
Foam::cellZoneSet::subset
virtual void subset(const topoSet &set)
Definition: cellZoneSet.C:149
Foam::topoSet::found
virtual bool found(const label id) const
Definition: topoSet.C:501
Foam::check
static void check(const int retVal, const char *what)
Definition: ptscotchDecomp.C:73
resize
patchWriters resize(patchIds.size())
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Definition: polyMesh.H:488
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Definition: DynamicListI.H:504
Foam::topoSet::set
virtual bool set(const label id)
Definition: topoSet.C:507
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: IOobject.H:183
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:59
Foam::ZoneMesh< cellZone, polyMesh >
Foam::cellZoneSet::invert
virtual void invert(const label maxLen)
Definition: cellZoneSet.C:119
Foam::cellZoneSet::addressing
const labelList & addressing() const
Definition: cellZoneSet.H:100
Foam::cellZoneSet
Like cellSet but -reads data from cellZone -updates cellZone when writing.
Definition: cellZoneSet.H:47
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
Foam::cellZoneSet::sync
virtual void sync(const polyMesh &mesh)
Definition: cellZoneSet.C:207
Foam::cellZoneSet::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Definition: cellZoneSet.C:224
os
OBJstream os(runTime.globalPath()/outputName)
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::regIOobject::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Definition: regIOobjectWrite.C:29
Foam
Definition: atmBoundaryLayer.C:26
Foam::cellSet
A collection of cell labels.
Definition: cellSet.H:47
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Definition: ZoneMesh.C:512
Foam::refCast
To & refCast(From &r)
Definition: typeInfo.H:136
Foam::cellZoneSet::cellZoneSet
cellZoneSet(const polyMesh &mesh, const word &name, readOption r=MUST_READ, writeOption w=NO_WRITE)
Definition: cellZoneSet.C:54
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::IOobject::name
const word & name() const noexcept
Definition: IOobjectI.H:58
Foam::mapPolyMesh::reverseCellMap
const labelList & reverseCellMap() const
Definition: mapPolyMesh.H:528
Foam::cellZoneSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Definition: cellZoneSet.C:266
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: BitOps.H:58
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Definition: POSIX.C:717
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:182
Foam::topoSet::check
virtual void check(const label maxSize)
Definition: topoSet.C:196
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::inplaceReorder
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Definition: ListOpsTemplates.C:117
Foam::sortedOrder
labelList sortedOrder(const UList< T > &input)
Foam::IOobject::readOption
readOption
Definition: IOobject.H:179
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::ZoneMesh::clearAddressing
void clearAddressing()
Definition: ZoneMesh.C:702
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:181
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:74