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-2022 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);
44 }
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
49 {
50  labelList order(sortedOrder(addressing_));
51  inplaceReorder(order, addressing_);
52 
54  pointSet::reserve(addressing_.size());
55  pointSet::set(addressing_);
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const polyMesh& mesh,
64  const word& name,
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  (
79  || (IOobjectOption::isReadOptional(rOpt) && zoneID != -1)
80  )
81  {
82  const pointZone& fz = pointZones[zoneID];
83  addressing_ = fz;
84  }
85 
87 
88  check(mesh.nPoints());
89 }
90 
91 
93 (
94  const polyMesh& mesh,
95  const word& name,
96  const label size,
98 )
99 :
100  pointSet(mesh, name, size, wOpt),
101  mesh_(mesh),
102  addressing_()
103 {
104  updateSet();
105 }
106 
107 
109 (
110  const polyMesh& mesh,
111  const word& name,
112  const topoSet& set,
114 )
115 :
116  pointSet(mesh, name, set.size(), wOpt),
117  mesh_(mesh),
118  addressing_(refCast<const pointZoneSet>(set).addressing())
119 {
120  updateSet();
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
125 
126 void Foam::pointZoneSet::invert(const label maxLen)
127 {
128  // Count
129  label n = 0;
130 
131  for (label pointi = 0; pointi < maxLen; ++pointi)
132  {
133  if (!found(pointi))
134  {
135  ++n;
136  }
137  }
138 
139  // Fill
140  addressing_.setSize(n);
141  n = 0;
142 
143  for (label pointi = 0; pointi < maxLen; ++pointi)
144  {
145  if (!found(pointi))
146  {
147  addressing_[n] = pointi;
148  ++n;
149  }
150  }
151  updateSet();
152 }
153 
154 
155 void Foam::pointZoneSet::subset(const topoSet& set)
156 {
157  DynamicList<label> newAddressing(addressing_.size());
158 
159  const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
160 
161  for (const label pointi : zoneSet.addressing())
162  {
163  if (found(pointi))
164  {
165  newAddressing.append(pointi);
166  }
167  }
168 
169  addressing_.transfer(newAddressing);
170  updateSet();
171 }
172 
173 
174 void Foam::pointZoneSet::addSet(const topoSet& set)
175 {
176  DynamicList<label> newAddressing(addressing_);
177 
178  const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
179 
180  for (const label pointi : zoneSet.addressing())
181  {
182  if (!found(pointi))
183  {
184  newAddressing.append(pointi);
185  }
186  }
187 
188  addressing_.transfer(newAddressing);
189  updateSet();
190 }
191 
192 
193 void Foam::pointZoneSet::subtractSet(const topoSet& set)
194 {
195  DynamicList<label> newAddressing(addressing_.size());
196 
197  const pointZoneSet& zoneSet = refCast<const pointZoneSet>(set);
198 
199  for (label pointi : addressing_)
200  {
201  if (!zoneSet.found(pointi))
202  {
203  // Not found in zoneSet so add
204  newAddressing.append(pointi);
205  }
206  }
207 
208  addressing_.transfer(newAddressing);
209  updateSet();
210 }
211 
212 
213 void Foam::pointZoneSet::sync(const polyMesh& mesh)
214 {
217  // Take over contents of pointSet into addressing.
218  addressing_ = sortedToc();
219  updateSet();
220 }
221 
222 
223 Foam::label Foam::pointZoneSet::maxSize(const polyMesh& mesh) const
224 {
225  return mesh.nPoints();
226 }
227 
228 
230 (
231  IOstreamOption streamOpt,
232  const bool writeOnProc
233 ) const
234 {
235  // Write shadow pointSet
236  word oldTypeName = typeName;
237  const_cast<word&>(type()) = pointSet::typeName;
238  bool ok = pointSet::writeObject(streamOpt, writeOnProc);
239  const_cast<word&>(type()) = oldTypeName;
240 
241  // Modify pointZone
242  pointZoneMesh& pointZones = const_cast<polyMesh&>(mesh_).pointZones();
243  label zoneID = pointZones.findZoneID(name());
244 
245  if (zoneID == -1)
246  {
247  zoneID = pointZones.size();
248 
249  pointZones.emplace_back
250  (
251  name(),
252  addressing_,
253  zoneID,
254  pointZones
255  );
256  }
257  else
258  {
259  pointZones[zoneID] = addressing_;
260  }
261  pointZones.clearAddressing();
262 
263  return ok && pointZones.write(writeOnProc);
264 }
265 
266 
267 void Foam::pointZoneSet::updateMesh(const mapPolyMesh& morphMap)
268 {
269  // pointZone
270  labelList newAddressing(addressing_.size());
271 
272  label n = 0;
273  for (const label pointi : addressing_)
274  {
275  const label newPointi = morphMap.reversePointMap()[pointi];
276  if (newPointi >= 0)
277  {
278  newAddressing[n] = newPointi;
279  ++n;
280  }
281  }
282  newAddressing.resize(n);
283 
284  addressing_.transfer(newAddressing);
285 
286  updateSet();
287 }
288 
289 
291 (
292  Ostream& os,
293  const primitiveMesh& mesh,
294  const label maxLen
295 ) const
296 {
297  pointSet::writeDebug(os, mesh, maxLen);
298 }
299 
300 
301 // ************************************************************************* //
writeOption
Enumeration defining write preferences.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void clearAddressing()
Clear addressing.
Definition: ZoneMesh.C:815
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: pointZoneSet.C:148
A set of point labels.
Definition: pointSet.H:47
label nPoints() const noexcept
Number of mesh points.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
void inplaceReorder(const labelUList &oldToNew, ListType &input, const bool prune=false)
Inplace reorder the elements of a list.
virtual bool set(const label id)
Set an index.
Definition: topoSet.C:497
A simple container for options an IOstream can normally have.
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign &#39;true&#39;).
Definition: BitOps.C:30
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write using stream options.
void updateSet()
Sort addressing and make pointSet part consistent with addressing.
Definition: pointZoneSet.C:41
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointZoneSet.C:284
T & emplace_back(Args &&... args)
Construct and append an element to the end of the list, return reference to the new list element...
Definition: PtrListI.H:105
Macros for easy insertion into run-time selection tables.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
virtual void addSet(const topoSet &set)
Add elements present in set.
Definition: pointZoneSet.C:167
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:629
A class for handling words, derived from Foam::string.
Definition: word.H:63
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: pointZoneSet.C:216
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
virtual void subtractSet(const topoSet &set)
Subtract elements present in set.
Definition: pointZoneSet.C:186
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write pointZone using stream options.
Definition: pointZoneSet.C:223
A subset of mesh points.
Definition: pointZone.H:61
label newPointi
Definition: readKivaGrid.H:496
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: pointZoneSet.C:260
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
Definition: HashTable.C:712
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to &#39;true&#39; entries.
Definition: BitOps.C:195
virtual void invert(const label maxLen)
Invert contents.
Definition: pointZoneSet.C:119
label n
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
Definition: pointSet.C:123
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointSet.C:210
List< label > labelList
A List of labels.
Definition: List.H:62
virtual void check(const label maxSize)
Check limits on addressable range.
Definition: topoSet.C:196
bool found
virtual void sync(const polyMesh &mesh)
Sync pointZoneSet across coupled patches.
Definition: pointZoneSet.C:206
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
void clearStorage()
Remove all entries from table and the table itself.
Definition: HashTable.C:750
Like pointSet but -reads data from pointZone -updates pointZone when writing.
Definition: pointZoneSet.H:48
pointZoneSet(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE)
Construct from objectRegistry and name.
Definition: pointZoneSet.C:55
readOption
Enumeration defining read preferences.