faceSet.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 "faceSet.H"
30 #include "polyMesh.H"
31 #include "mapPolyMesh.H"
32 #include "syncTools.H"
33 #include "mapDistributePolyMesh.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeName(faceSet);
44 }
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 :
50  topoSet(io, typeName)
51 {}
52 
53 
55 :
56  topoSet(io, Foam::zero{})
57 {}
58 
59 
61 (
62  const polyMesh& mesh,
63  const word& name,
67 )
68 :
69  topoSet(mesh, typeName, name, rOpt, wOpt, reg)
70 {
71  check(mesh.nFaces()); // Valid range?
72 }
73 
74 
76 (
77  const polyMesh& mesh,
78  const word& name,
79  const label initialCapacity,
81 )
82 :
83  topoSet(mesh, name, initialCapacity, wOpt)
84 {}
85 
86 
88 (
89  const polyMesh& mesh,
90  const word& name,
91  const topoSet& set,
93 )
94 :
95  topoSet(mesh, name, set, wOpt)
96 {}
97 
98 
100 (
101  const polyMesh& mesh,
102  const word& name,
103  const labelHashSet& labels,
105 )
106 :
107  topoSet(mesh, name, labels, wOpt)
108 {}
109 
110 
112 (
113  const polyMesh& mesh,
114  const word& name,
115  labelHashSet&& labels,
117 )
118 :
119  topoSet(mesh, name, std::move(labels), wOpt)
120 {}
121 
122 
124 (
125  const polyMesh& mesh,
126  const word& name,
127  const labelUList& labels,
129 )
130 :
131  topoSet(mesh, name, labels, wOpt)
132 {}
133 
134 
135 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
136 
138 (
139  const polyMesh& mesh,
140  const word& name
141 )
142 {
143  faceSet reader
144  (
146  Foam::zero{}
147  );
148 
149  labelHashSet labels;
150  reader.readIOcontents(typeName, labels);
151  reader.checkLabels(labels, mesh.nFaces()); // Valid range?
153  return labels;
154 }
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
159 void Foam::faceSet::sync(const polyMesh& mesh)
160 {
161  labelHashSet& labels = *this;
162 
163  // Convert to boolList
164  // TBD: could change to using bitSet for the synchronization
165 
166  const label len = mesh.nFaces();
167 
168  boolList contents(len, false);
169 
170  for (const label facei : labels)
171  {
172  contents.set(facei);
173  }
174 
175  syncTools::syncFaceList(mesh, contents, orEqOp<bool>());
176 
177 
178  // Update labelHashSet
179 
180  for (label i=0; i < len; ++i)
181  {
182  if (contents.test(i))
183  {
184  labels.set(i);
185  }
186  }
187 }
188 
190 Foam::label Foam::faceSet::maxSize(const polyMesh& mesh) const
191 {
192  return mesh.nFaces();
193 }
194 
196 void Foam::faceSet::updateMesh(const mapPolyMesh& morphMap)
197 {
198  updateLabels(morphMap.reverseFaceMap());
199 }
200 
201 
203 {
204  labelHashSet& labels = *this;
205 
206  boolList contents(map.nOldFaces(), false);
207 
208  for (const label facei : labels)
209  {
210  contents.set(facei);
211  }
212 
213  map.distributeFaceData(contents);
214 
215  // The new length
216  const label len = contents.size();
217 
218  // Count - as per BitOps::count(contents)
219  label n = 0;
220  for (label i=0; i < len; ++i)
221  {
222  if (contents.test(i))
223  {
224  ++n;
225  }
226  }
227 
228  // Update labelHashSet
229 
230  labels.clear();
231  labels.reserve(n);
232 
233  for (label i=0; i < len; ++i)
234  {
235  if (contents.test(i))
236  {
237  labels.set(i);
238  }
239  }
240 }
241 
242 
244 (
245  Ostream& os,
246  const primitiveMesh& mesh,
247  const label maxLen
248 ) const
249 {
251 }
252 
253 
254 // ************************************************************************* //
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: faceSet.C:183
writeOption
Enumeration defining write preferences.
static void syncFaceList(const polyMesh &mesh, UList< T > &faceValues, const CombineOp &cop, const bool parRun=UPstream::parRun())
Synchronize values on all mesh faces.
Definition: syncTools.H:465
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A list of face labels.
Definition: faceSet.H:47
virtual void distribute(const mapDistributePolyMesh &map)
Update any stored data for mesh redistribution.
Definition: faceSet.C:195
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
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
label nFaces() const noexcept
Number of mesh faces.
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 void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: faceSet.C:237
const labelList & reverseFaceMap() const noexcept
Reverse face map.
Definition: mapPolyMesh.H:620
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition: HashSet.H:85
defineTypeName(manifoldCellsMeshObject)
void distributeFaceData(List< T > &values) const
Distribute list of face data.
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
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
label nOldFaces() const noexcept
Number of faces in mesh before distribution.
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
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)
const vectorField & faceCentres() const
static labelHashSet readContents(const polyMesh &mesh, const word &name)
Read and return contents. Intermediate IOobject is not registered.
Definition: faceSet.C:131
faceSet(const IOobject &io)
Construct from IOobject. No checking.
Definition: faceSet.C:41
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 faceSet across coupled patches.
Definition: faceSet.C:152
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
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition: faceSet.C:189
Do not request registration (bool: false)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
readOption
Enumeration defining read preferences.