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 -------------------------------------------------------------------------------
10 License
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 
35 namespace Foam
36 {
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
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 )
64 :
65  topoBitSet(mesh, "cellBitSet", mesh.nCells(), std::move(bits))
66 {}
67 
68 
69 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70 
71 Foam::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
83 {
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  {
118  case topoSetSource::INVERT :
119  {
120  result.invert(mesh.nCells());
121  continue; // Handled
122  break;
123  }
124 
125  case topoSetSource::IGNORE :
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 
158  case topoSetSource::SUBSET :
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
static autoPtr< topoSetCellSource > New(const word &sourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected source type.
dictionary dict
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Cell-face mesh analysis engine.
Definition: primitiveMesh.H:75
Create a new set and ADD elements to it.
virtual void writeDebug(Ostream &os, const primitiveMesh &mesh, const label maxLen) const
Write maxLen items with label and coordinates.
Definition: cellBitSet.C:71
Add elements to current set.
void reset()
Set values to false, leaving the size untouched.
Definition: topoBitSet.H:141
Base for a special purpose topoSet using labels stored as a bitSet.
Definition: topoBitSet.H:47
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Invert the elements in the current set.
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.
A special purpose topoSet with the cell labels stored as a bitSet. It does not correspond to a cellSe...
Definition: cellBitSet.H:87
defineTypeName(manifoldCellsMeshObject)
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
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
dynamicFvMesh & mesh
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellBitSet.C:64
A class for handling words, derived from Foam::string.
Definition: word.H:63
Union of elements with current set.
const vectorField & cellCentres() const
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
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)
Subtract elements from current set.
cellBitSet(const polyMesh &mesh, const bool val=false)
Construct with nCells elements, all elements unset or initial value.
Definition: cellBitSet.C:36
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
const bitSet & addressing() const noexcept
Return the bitSet.
Definition: topoBitSet.H:125
label nCells() const noexcept
Number of mesh cells.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
"ignore" no-op action
static const Enum< setAction > combineNames
The setAction enum text when combining selections. Names: "use", "add", "subtract", "subset", "invert", "ignore".
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63