Loading...
Searching...
No Matches
cellSet.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 OpenFOAM Foundation
9 Copyright (C) 2016-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "cellSet.H"
30#include "mapPolyMesh.H"
31#include "polyMesh.H"
32#include "Time.H"
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
46
47// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49Foam::cellSet::cellSet(const IOobject& io)
50:
52{}
53
55Foam::cellSet::cellSet(const IOobject& io, const Foam::zero)
56:
57 topoSet(io, Foam::zero{})
58{}
59
60
61Foam::cellSet::cellSet
62(
63 const polyMesh& mesh,
64 const word& name,
68)
70 topoSet(mesh, typeName, name, rOpt, wOpt, reg)
71{
72 check(mesh.nCells()); // Valid range?
73}
74
75
76Foam::cellSet::cellSet
77(
78 const polyMesh& mesh,
79 const word& name,
80 const label initialCapacity,
82)
83:
84 topoSet(mesh, name, initialCapacity, wOpt)
85{}
86
87
88Foam::cellSet::cellSet
89(
90 const polyMesh& mesh,
91 const word& name,
92 const topoSet& set,
94)
95:
96 topoSet(mesh, name, set, wOpt)
97{}
98
99
100Foam::cellSet::cellSet
101(
102 const polyMesh& mesh,
103 const word& name,
104 const labelHashSet& labels,
106)
107:
108 topoSet(mesh, name, labels, wOpt)
109{}
110
111
112Foam::cellSet::cellSet
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
124Foam::cellSet::cellSet
125(
126 const polyMesh& mesh,
127 const word& name,
128 const labelUList& labels,
131:
132 topoSet(mesh, name, labels, wOpt)
133{}
134
135
136// Database constructors (for when no mesh available)
137Foam::cellSet::cellSet
138(
139 const Time& runTime,
140 const word& name,
143)
144:
145 topoSet
147 findIOobject(runTime, name, rOpt, wOpt),
149 )
150{}
151
152
153Foam::cellSet::cellSet
154(
155 const Time& runTime,
156 const word& name,
157 const label initialCapacity,
159)
160:
161 topoSet
164 initialCapacity
165 )
166{}
167
168
169Foam::cellSet::cellSet
170(
171 const Time& runTime,
172 const word& name,
173 const labelHashSet& labels,
175)
176:
177 topoSet
178 (
179 findIOobject(runTime, name, IOobject::NO_READ, wOpt),
180 labels
181 )
182{}
183
184
185// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
186
188(
189 const polyMesh& mesh,
190 const word& name
191)
192{
193 cellSet reader
194 (
196 Foam::zero{}
197 );
198
199 labelHashSet labels;
200 reader.readIOcontents(typeName, labels);
201 reader.checkLabels(labels, mesh.nCells()); // Valid range?
203 return labels;
204}
205
206
207// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
209Foam::label Foam::cellSet::maxSize(const polyMesh& mesh) const
210{
211 return mesh.nCells();
212}
213
215void Foam::cellSet::updateMesh(const mapPolyMesh& morphMap)
216{
217 updateLabels(morphMap.reverseCellMap());
218}
219
220
222{
223 labelHashSet& labels = *this;
224
225 boolList contents(map.nOldCells(), false);
226
227 for (const label celli : labels)
228 {
229 contents.set(celli);
230 }
231
232 map.distributeCellData(contents);
233
234 // The new length
235 const label len = contents.size();
236
237 // Count
238 label n = 0;
239 for (label i=0; i < len; ++i)
240 {
241 if (contents.test(i))
242 {
243 ++n;
244 }
245 }
246
247 // Update labelHashSet
248
249 labels.clear();
250 labels.reserve(n);
251
252 for (label i=0; i < len; ++i)
253 {
254 if (contents.test(i))
256 labels.set(i);
257 }
258 }
259}
260
261
263(
264 Ostream& os,
265 const primitiveMesh& mesh,
266 const label maxLen
267) const
268{
270}
271
272
273// ************************************************************************* //
label n
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
bool set(const Key &key)
Same as insert (no value to overwrite).
Definition HashSet.H:237
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
Definition HashTable.C:729
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
void clear()
Remove all entries from table.
Definition HashTable.C:742
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
@ NO_REGISTER
Do not request registration (bool: false).
readOption
Enumeration defining read preferences.
@ NO_READ
Nothing to be read.
writeOption
Enumeration defining write preferences.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
bool set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition List.H:469
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
bool test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition UList.H:852
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A collection of cell labels.
Definition cellSet.H:50
virtual void distribute(const mapDistributePolyMesh &map)
Update any stored data for mesh redistribution.
Definition cellSet.C:214
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition cellSet.C:202
static labelHashSet readContents(const polyMesh &mesh, const word &name)
Read and return contents. Intermediate IOobject is not registered.
Definition cellSet.C:181
virtual void writeDebug(Ostream &os, const primitiveMesh &, const label maxLen) const
Write maxLen items with label and coordinates.
Definition cellSet.C:256
virtual void updateMesh(const mapPolyMesh &morphMap)
Update any stored data for new labels.
Definition cellSet.C:208
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
void distributeCellData(List< T > &values) const
Distribute list of cell data.
label nOldCells() const noexcept
Number of cells in mesh before distribution.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reverseCellMap() const noexcept
Reverse cell map.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Cell-face mesh analysis engine.
const vectorField & cellCentres() const
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
topoSet(const topoSet &)=delete
No copy construct.
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 writeDebug(Ostream &os, const label maxElem, labelHashSet::const_iterator &iter) const
Write part of contents nicely formatted.
Definition topoSet.C:260
virtual void updateLabels(const labelUList &map)
Update map from map.
Definition topoSet.C:164
virtual bool set(const label id)
Set an index.
Definition topoSet.C:545
virtual void check(const label maxSize)
Check limits on addressable range.
Definition topoSet.C:252
A class for handling words, derived from Foam::string.
Definition word.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
dynamicFvMesh & mesh
engineTime & runTime
OBJstream os(runTime.globalPath()/outputName)
const auto & io
Namespace for OpenFOAM.
HashSet< label, Hash< label > > labelHashSet
A HashSet of labels, uses label hasher.
Definition HashSet.H:85
static void check(const int retVal, const char *what)
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
List< bool > boolList
A List of bools.
Definition List.H:60
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
UList< label > labelUList
A UList of labels.
Definition UList.H:75