cellBitSet.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) 2018-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "cellBitSet.H"
29#include "dictionary.H"
30#include "polyMesh.H"
31#include "topoSetCellSource.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38}
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
44:
45 cellBitSet(mesh, false)
46{}
47
48
50:
51 topoBitSet(mesh, "cellBitSet", mesh.nCells(), val)
52{}
53
54
56(
57 const polyMesh& mesh,
58 const bitSet& bits
59)
60:
61 topoBitSet(mesh, "cellBitSet", mesh.nCells(), bits)
62{}
63
64
66(
67 const polyMesh& mesh,
68 bitSet&& bits
69)
70:
71 topoBitSet(mesh, "cellBitSet", mesh.nCells(), std::move(bits))
72{}
73
74
75// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76
77Foam::label Foam::cellBitSet::maxSize(const polyMesh& mesh) const
78{
79 return mesh.nCells();
80}
81
82
84(
85 Ostream& os,
86 const primitiveMesh& mesh,
87 const label maxLen
88) const
89{
91}
92
93
94// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
95
97(
98 const polyMesh& mesh,
99 const dictionary& dict,
100 const bool verbosity
101)
102{
103 // Start with all cells unselected
104 cellBitSet result(mesh);
105
106 // Execute all actions
107 for (const entry& dEntry : dict)
108 {
109 if (!dEntry.isDict())
110 {
112 << "Ignoring non-dictionary entry "
113 << dEntry << endl;
114 continue;
115 }
116
117 const dictionary& dict = dEntry.dict();
118
119 const auto action = topoSetSource::combineNames.get("action", dict);
120
121 // These ones we do directly
122 switch (action)
123 {
125 {
126 result.invert(mesh.nCells());
127 continue; // Handled
128 break;
129 }
130
132 continue; // Nothing to do
133 break;
134
135 default:
136 break;
137 }
138
139 auto source = topoSetCellSource::New
140 (
141 dict.get<word>("source"),
142 mesh,
143 dict.optionalSubDict("sourceInfo")
144 );
145 source->verbose(verbosity);
146
147 switch (action)
148 {
149 case topoSetSource::NEW : // ie, "use"
150 case topoSetSource::ADD :
152 {
153 if (topoSetSource::NEW == action)
154 {
155 // "use": only use this selection (CLEAR + ADD)
156 // NEW is handled like ADD in applyToSet()
157 result.reset();
158 }
159 source->applyToSet(action, result);
160
161 break;
162 }
163
165 {
166 cellBitSet other(mesh);
167 source->applyToSet(topoSetSource::NEW, other);
168
169 result.subset(other);
170
171 break;
172 }
173
174 default:
175 // Should already have been caught
177 << "Ignoring unhandled action: "
178 << topoSetSource::combineNames[action] << endl;
179 }
180 }
181
182 bitSet addr(std::move(result.addressing()));
183
184 return addr;
185}
186
187
188// ************************************************************************* //
label maxSize() const
The max row length used.
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition: Enum.C:75
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A special purpose topoSet with the cell labels stored as a bitSet. It does not correspond to a cellSe...
Definition: cellBitSet.H:94
static bitSet select(const polyMesh &mesh, const dictionary &dict, const bool verbosity=false)
Definition: cellBitSet.C:97
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:577
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:79
const vectorField & cellCentres() const
label nCells() const noexcept
Number of mesh cells.
void writeDebug() const
Debug write.
Base for a special purpose topoSet using labels stored as a bitSet.
Definition: topoBitSet.H:54
virtual void invert(const label maxLen)
Invert contents.
Definition: topoBitSet.C:211
const bitSet & addressing() const noexcept
Return the bitSet.
Definition: topoBitSet.H:112
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoBitSet.C:218
void reset()
Set values to false, leaving the size untouched.
Definition: topoBitSet.H:124
@ SUBSET
Union of elements with current set.
@ IGNORE
"ignore" no-op action
@ SUBTRACT
Subtract elements from current set.
@ INVERT
Invert the elements in the current set.
@ ADD
Add elements to current set.
@ NEW
Create a new set and ADD elements to it.
static const Enum< setAction > combineNames
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dictionary dict