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 | 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 "pointZoneSet.H"
30 #include "mapPolyMesh.H"
31 #include "polyMesh.H"
32 #include "processorPolyPatch.H"
33 #include "cyclicPolyPatch.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(pointZoneSet, 0);
41  addToRunTimeSelectionTable(topoSet, pointZoneSet, word);
42  addToRunTimeSelectionTable(topoSet, pointZoneSet, size);
43  addToRunTimeSelectionTable(topoSet, pointZoneSet, set);
44 }
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 {
50  labelList order(sortedOrder(addressing_));
51  inplaceReorder(order, addressing_);
52 
53  pointSet::clearStorage();
54  pointSet::resize(2*addressing_.size());
55  pointSet::set(addressing_);
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const polyMesh& mesh,
64  const word& name,
65  readOption r,
66  writeOption w
67 )
68 :
69  pointSet(mesh, name, 1024), // do not read pointSet
70  mesh_(mesh),
71  addressing_()
72 {
73  const pointZoneMesh& pointZones = mesh.pointZones();
74  label zoneID = pointZones.findZoneID(name);
75 
76  if
77  (
80  || (r == IOobject::READ_IF_PRESENT && zoneID != -1)
81  )
82  {
83  const pointZone& fz = pointZones[zoneID];
84  addressing_ = fz;
85  }
86 
87  updateSet();
88 
89  check(mesh.nPoints());
90 }
91 
92 
94 (
95  const polyMesh& mesh,
96  const word& name,
97  const label size,
98  writeOption w
99 )
100 :
101  pointSet(mesh, name, size, w),
102  mesh_(mesh),
103  addressing_()
104 {
105  updateSet();
106 }
107 
108 
110 (
111  const polyMesh& mesh,
112  const word& name,
113  const topoSet& set,
114  writeOption w
115 )
116 :
117  pointSet(mesh, name, set.size(), w),
118  mesh_(mesh),
119  addressing_(refCast<const pointZoneSet>(set).addressing())
120 {
121  updateSet();
122 }
123 
124 
125 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
126 
127 void Foam::pointZoneSet::invert(const label maxLen)
128 {
129  // Count
130  label n = 0;
131 
132  for (label pointi = 0; pointi < maxLen; ++pointi)
133  {
134  if (!found(pointi))
135  {
136  ++n;
137  }
138  }
139 
140  // Fill
141  addressing_.setSize(n);
142  n = 0;
143 
144  for (label pointi = 0; pointi < maxLen; ++pointi)
145  {
146  if (!found(pointi))
147  {
148  addressing_[n] = pointi;
149  ++n;
150  }
151  }
152  updateSet();
153 }
154 
155 
157 {
158  DynamicList<label> newAddressing(addressing_.size());
159 
160  const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
161 
162  for (const label pointi : zoneSet.addressing())
163  {
164  if (found(pointi))
165  {
166  newAddressing.append(pointi);
167  }
168  }
169 
170  addressing_.transfer(newAddressing);
171  updateSet();
172 }
173 
174 
176 {
177  DynamicList<label> newAddressing(addressing_);
178 
179  const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
180 
181  for (const label pointi : zoneSet.addressing())
182  {
183  if (!found(pointi))
184  {
185  newAddressing.append(pointi);
186  }
187  }
188 
189  addressing_.transfer(newAddressing);
190  updateSet();
191 }
192 
193 
195 {
196  DynamicList<label> newAddressing(addressing_.size());
197 
198  const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
199 
200  for (label pointi : addressing_)
201  {
202  if (!zoneSet.found(pointi))
203  {
204  // Not found in zoneSet so add
205  newAddressing.append(pointi);
206  }
207  }
208 
209  addressing_.transfer(newAddressing);
210  updateSet();
211 }
212 
213 
215 {
217 
218  // Take over contents of pointSet into addressing.
219  addressing_ = sortedToc();
220  updateSet();
221 }
222 
223 
224 Foam::label Foam::pointZoneSet::maxSize(const polyMesh& mesh) const
225 {
226  return mesh.nPoints();
227 }
228 
229 
231 (
232  IOstreamOption streamOpt,
233  const bool valid
234 ) const
235 {
236  // Write shadow pointSet
237  word oldTypeName = typeName;
238  const_cast<word&>(type()) = pointSet::typeName;
239  bool ok = pointSet::writeObject(streamOpt, valid);
240  const_cast<word&>(type()) = oldTypeName;
241 
242  // Modify pointZone
243  pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
244  label zoneID = pointZones.findZoneID(name());
245 
246  if (zoneID == -1)
247  {
248  zoneID = pointZones.size();
249 
250  pointZones.setSize(zoneID+1);
251  pointZones.set
252  (
253  zoneID,
254  new pointZone
255  (
256  name(),
257  addressing_,
258  zoneID,
259  pointZones
260  )
261  );
262  }
263  else
264  {
265  pointZones[zoneID] = addressing_;
266  }
267  pointZones.clearAddressing();
268 
269  return ok && pointZones.write(valid);
270 }
271 
272 
274 {
275  // pointZone
276  labelList newAddressing(addressing_.size());
277 
278  label n = 0;
279  for (const label pointi : addressing_)
280  {
281  const label newPointi = morphMap.reversePointMap()[pointi];
282  if (newPointi >= 0)
283  {
284  newAddressing[n] = newPointi;
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  pointSet::writeDebug(os, mesh, maxLen);
304 }
305 
306 
307 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointZoneSet
Like pointSet but -reads data from pointZone -updates pointZone when writing.
Definition: pointZoneSet.H:52
Foam::pointZoneSet::updateMesh
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: pointZoneSet.C:273
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
cyclicPolyPatch.H
Foam::DynamicList< label >
mapPolyMesh.H
Foam::pointZone
A subset of mesh points.
Definition: pointZone.H:65
Foam::pointSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointSet.C:217
Foam::pointZoneSet::maxSize
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: pointZoneSet.C:224
Foam::pointZoneSet::invert
virtual void invert(const label maxLen)
Invert contents.
Definition: pointZoneSet.C:127
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
Foam::IOobject::writeOption
writeOption
Enumeration defining the write options.
Definition: IOobject.H:192
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::check
static void check(const int retVal, const char *what)
Definition: ptscotchDecomp.C:80
resize
patchWriters resize(patchIds.size())
Foam::pointZoneSet::sync
virtual void sync(const polyMesh &mesh)
Sync pointZoneSet across coupled patches.
Definition: pointZoneSet.C:214
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::topoSet::set
virtual bool set(const label id)
Set an index.
Definition: topoSet.C:514
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::ZoneMesh< pointZone, polyMesh >
Foam::pointZoneSet::writeDebug
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointZoneSet.C:297
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::pointSet::sync
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
Definition: pointSet.C:130
newPointi
label newPointi
Definition: readKivaGrid.H:496
processorPolyPatch.H
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
Write using stream options.
Definition: regIOobjectWrite.C:36
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:519
Foam::pointZoneSet::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write pointZone using stream options.
Definition: pointZoneSet.C:231
Foam::pointZoneSet::addSet
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: pointZoneSet.C:175
Foam::pointZoneSet::subset
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: pointZoneSet.C:156
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::pointSet
A set of point labels.
Definition: pointSet.H:51
Foam::mapPolyMesh::reversePointMap
const labelList & reversePointMap() const
Reverse point map.
Definition: mapPolyMesh.H:469
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::polyMesh::pointZones
const pointZoneMesh & pointZones() const noexcept
Return point zone mesh.
Definition: polyMesh.H:480
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
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:183
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:709
Foam::pointZoneSet::subtractSet
virtual void subtractSet(const topoSet &set)
Subtract elements present in set.
Definition: pointZoneSet.C:194
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:62
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::pointZoneSet::addressing
const labelList & addressing() const
Definition: pointZoneSet.H:105
Foam::pointZoneSet::updateSet
void updateSet()
Sort addressing and make pointSet part consistent with addressing.
Definition: pointZoneSet.C:48
pointZoneSet.H
Foam::IOobject::MUST_READ
Definition: IOobject.H:185
Foam::primitiveMesh
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:78