pointSet.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-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2024 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 "pointSet.H"
30 #include "mapPolyMesh.H"
31 #include "polyMesh.H"
32 #include "syncTools.H"
33 #include "mapDistributePolyMesh.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeName(pointSet);
41  addToRunTimeSelectionTable(topoSet, pointSet, word);
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 :
51  topoSet(io, typeName)
52 {}
53 
54 
56 :
57  topoSet(io, Foam::zero{})
58 {}
59 
60 
62 (
63  const polyMesh& mesh,
64  const word& name,
68 )
69 :
70  topoSet(mesh, typeName, name, rOpt, wOpt, reg)
71 {
72  check(mesh.nPoints()); // Valid range?
73 }
74 
75 
77 (
78  const polyMesh& mesh,
79  const word& name,
80  const label initialCapacity,
82 )
83 :
84  topoSet(mesh, name, initialCapacity, wOpt)
85 {}
86 
87 
89 (
90  const polyMesh& mesh,
91  const word& name,
92  const topoSet& set,
94 )
95 :
96  topoSet(mesh, name, set, wOpt)
97 {}
98 
99 
101 (
102  const polyMesh& mesh,
103  const word& name,
104  const labelHashSet& labels,
106 )
107 :
108  topoSet(mesh, name, labels, wOpt)
109 {}
110 
111 
113 (
114  const polyMesh& mesh,
115  const word& name,
116  labelHashSet&& labels,
118 )
119 :
120  topoSet(mesh, name, std::move(labels), wOpt)
121 {}
122 
123 
125 (
126  const polyMesh& mesh,
127  const word& name,
128  const labelUList& labels,
130 )
131 :
132  topoSet(mesh, name, labels, wOpt)
133 {}
134 
135 
136 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
137 
139 (
140  const polyMesh& mesh,
141  const word& name
142 )
143 {
144  pointSet reader
145  (
147  Foam::zero{}
148  );
149 
150  labelHashSet labels;
151  reader.readIOcontents(typeName, labels);
152  reader.checkLabels(labels, mesh.nPoints()); // Valid range?
154  return labels;
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
161 {
162  labelHashSet& labels = *this;
163 
164  // Convert to boolList
165  // TBD: could change to using bitSet for the synchronization
166 
167  const label len = mesh.nPoints();
168 
169  boolList contents(len, false);
170 
171  for (const label pointi : labels)
172  {
173  contents.set(pointi);
174  }
175 
176  // The nullValue = 'false'
177  syncTools::syncPointList(mesh, contents, orEqOp<bool>(), false);
178 
179 
180  // Update labelHashSet
181 
182  for (label pointi=0; pointi < len; ++pointi)
183  {
184  if (contents.test(pointi))
185  {
186  labels.set(pointi);
187  }
188  }
189 }
190 
192 Foam::label Foam::pointSet::maxSize(const polyMesh& mesh) const
193 {
194  return mesh.nPoints();
195 }
196 
198 void Foam::pointSet::updateMesh(const mapPolyMesh& morphMap)
199 {
200  updateLabels(morphMap.reversePointMap());
201 }
202 
203 
205 {
206  labelHashSet& labels = *this;
207 
208  boolList contents(map.nOldPoints(), false);
209 
210  for (const label pointi : labels)
211  {
212  contents.set(pointi);
213  }
214 
215  map.distributePointData(contents);
216 
217  // The new length
218  const label len = contents.size();
219 
220  // Count - as per BitOps::count(contents)
221  label n = 0;
222  for (label i=0; i < len; ++i)
223  {
224  if (contents.test(i))
225  {
226  ++n;
227  }
228  }
229 
230 
231  // Update labelHashSet
232 
233  labels.clear();
234  labels.reserve(n);
235 
236  for (label i=0; i < len; ++i)
237  {
238  if (contents.test(i))
239  {
240  labels.set(i);
241  }
242  }
243 }
244 
245 
247 (
248  Ostream& os,
249  const primitiveMesh& mesh,
250  const label maxLen
251 ) const
252 {
253  topoSet::writeDebug(os, mesh.points(), maxLen);
254 }
255 
256 
257 // ************************************************************************* //
writeOption
Enumeration defining write preferences.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: pointSet.C:185
A set of point labels.
Definition: pointSet.H:47
label nPoints() const noexcept
Number of mesh points.
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition: List.H:493
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: pointSet.C:191
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign &#39;true&#39;).
Definition: BitOps.C:30
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
Macros for easy insertion into run-time selection tables.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1078
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
defineTypeName(manifoldCellsMeshObject)
static IOobject findIOobject(const polyMesh &mesh, const word &name, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, IOobjectOption::writeOption wOpt=IOobjectOption::NO_WRITE, IOobjectOption::registerOption reg=IOobjectOption::LEGACY_REGISTER)
Find IOobject in the polyMesh/sets/ (used as constructor helper)
Definition: topoSet.C:352
label nOldPoints() const noexcept
Number of points in mesh before distribution.
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
const labelList & reversePointMap() const noexcept
Reverse point map.
Definition: mapPolyMesh.H:582
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
label writeDebug(Ostream &os, const label maxElem, labelHashSet::const_iterator &iter) const
Write part of contents nicely formatted.
Definition: topoSet.C:260
OBJstream os(runTime.globalPath()/outputName)
static void check(const int retVal, const char *what)
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition: UList.H:778
virtual void distribute(const mapDistributePolyMesh &)
Update any stored data for mesh redistribution.
Definition: pointSet.C:197
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
void distributePointData(List< T > &values) const
Distribute list of point data.
static labelHashSet readContents(const polyMesh &mesh, const word &name)
Read and return contents. Intermediate IOobject is not registered.
Definition: pointSet.C:132
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
label n
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
virtual void sync(const polyMesh &mesh)
Sync set across coupled patches. Adds coupled points to set.
Definition: pointSet.C:153
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: pointSet.C:240
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Do not request registration (bool: false)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
pointSet(const IOobject &io)
Construct from IOobject.
Definition: pointSet.C:42
readOption
Enumeration defining read preferences.