Loading...
Searching...
No Matches
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-2024 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
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43Foam::cellBitSet::cellBitSet(const polyMesh& mesh, const bool val)
44:
45 topoBitSet(mesh, "cellBitSet", mesh.nCells(), val)
46{}
47
48
50(
51 const polyMesh& mesh,
52 const bitSet& bits
53)
54:
55 topoBitSet(mesh, "cellBitSet", mesh.nCells(), bits)
56{}
57
58
60(
61 const polyMesh& mesh,
62 bitSet&& bits
63)
65 topoBitSet(mesh, "cellBitSet", mesh.nCells(), std::move(bits))
66{}
67
68
69// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71Foam::label Foam::cellBitSet::maxSize(const polyMesh& mesh) const
72{
73 return mesh.nCells();
74}
75
76
78(
79 Ostream& os,
80 const primitiveMesh& mesh,
81 const label maxLen
82) const
84 topoSet::writeDebug(os, mesh.cellCentres(), maxLen);
85}
86
87
88// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
89
91(
92 const polyMesh& mesh,
93 const dictionary& dict,
94 const bool verbosity
95)
96{
97 // Start with all cells unselected
98 cellBitSet result(mesh);
99
100 // Execute all actions
101 for (const entry& dEntry : dict)
102 {
103 if (!dEntry.isDict())
104 {
106 << "Ignoring non-dictionary entry "
107 << dEntry << endl;
108 continue;
109 }
110
111 const dictionary& dict = dEntry.dict();
112
113 const auto action = topoSetSource::combineNames.get("action", dict);
114
115 // These ones we do directly
116 switch (action)
117 {
119 {
120 result.invert(mesh.nCells());
121 continue; // Handled
122 break;
123 }
124
126 continue; // Nothing to do
127 break;
128
129 default:
130 break;
131 }
132
133 auto source = topoSetCellSource::New
134 (
135 dict.get<word>("source"),
136 mesh,
137 dict.optionalSubDict("sourceInfo")
138 );
139 source->verbose(verbosity);
140
141 switch (action)
142 {
143 case topoSetSource::NEW : // ie, "use"
144 case topoSetSource::ADD :
146 {
147 if (topoSetSource::NEW == action)
148 {
149 // "use": only use this selection (CLEAR + ADD)
150 // NEW is handled like ADD in applyToSet()
151 result.reset();
152 }
153 source->applyToSet(action, result);
154
155 break;
156 }
157
159 {
160 cellBitSet other(mesh);
161 source->applyToSet(topoSetSource::NEW, other);
162
163 result.subset(other);
164
165 break;
166 }
167
168 default:
169 // Should already have been caught
171 << "Ignoring unhandled action: "
172 << topoSetSource::combineNames[action] << endl;
173 }
174 }
175
176 bitSet addr(std::move(result.addressing()));
177
178 return addr;
179}
180
181
182// ************************************************************************* //
EnumType get(const word &enumName) const
The enumeration corresponding to the given name.
Definition Enum.C:68
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A special purpose topoSet with the cell labels stored as a bitSet. It does not correspond to a cellSe...
Definition cellBitSet.H:90
cellBitSet(const polyMesh &mesh, const bool val=false)
Construct with nCells elements, all elements unset or initial value.
Definition cellBitSet.C:36
virtual void writeDebug(Ostream &os, const primitiveMesh &mesh, const label maxLen) const
Write maxLen items with label and coordinates.
Definition cellBitSet.C:71
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition cellBitSet.C:64
static bitSet select(const polyMesh &mesh, const dictionary &dict, const bool verbosity=false)
Return a cell selection according to the dictionary specification of actions.
Definition cellBitSet.C:84
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
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:560
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Cell-face mesh analysis engine.
virtual void invert(const label maxLen)
Invert contents.
Definition topoBitSet.C:209
virtual void subset(const labelUList &elems)
Subset contents. Only elements present in both sets remain.
Definition topoBitSet.C:243
topoBitSet(const polyMesh &mesh, const word &setName)
Construct (no-read) with empty selection.
Definition topoBitSet.C:106
const bitSet & addressing() const noexcept
Return the bitSet.
Definition topoBitSet.H:125
void reset()
Set values to false, leaving the size untouched.
Definition topoBitSet.H:141
static autoPtr< topoSetCellSource > New(const word &sourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected source type.
@ 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
The setAction enum text when combining selections. Names: "use", "add", "subtract",...
label writeDebug(Ostream &os, const label maxElem, labelHashSet::const_iterator &iter) const
Write part of contents nicely formatted.
Definition topoSet.C:260
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeName(Type)
Define the typeName.
Definition className.H:113
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:519
dictionary dict