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 -------------------------------------------------------------------------------
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  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 
77 Foam::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  {
124  case topoSetSource::INVERT :
125  {
126  result.invert(mesh.nCells());
127  continue; // Handled
128  break;
129  }
130 
131  case topoSetSource::IGNORE :
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 
164  case topoSetSource::SUBSET :
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 // ************************************************************************* //
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:77
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
cellBitSet(const polyMesh &mesh)
Construct with nCells elements, all elements unset.
Definition: cellBitSet.C:36
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:204
dynamicFvMesh & mesh
virtual label maxSize(const polyMesh &mesh) const
Return max index+1.
Definition: cellBitSet.C:70
A class for handling words, derived from Foam::string.
Definition: word.H:63
void writeDebug(Ostream &os, const label maxElem, topoSet::const_iterator &iter, label &elemI) const
Write part of contents nicely formatted. Prints labels only.
Definition: topoSet.C:217
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:90
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual void subset(const topoSet &set)
Subset contents. Only elements present in both sets remain.
Definition: topoBitSet.C:211
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
Subtract elements from current set.
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:74
"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