topoSetSource.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-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2022 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 "topoSetSource.H"
30#include "dictionary.H"
31#include "polyMesh.H"
32#include "bitSet.H"
33#include "topoSet.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
42}
43
44
46
47
48const Foam::Enum
49<
51>
53({
54 { setAction::ADD, "add" },
55 { setAction::SUBTRACT, "subtract" },
56 { setAction::NEW, "new" },
57 { setAction::SUBSET, "subset" },
58 { setAction::INVERT, "invert" },
59 { setAction::CLEAR, "clear" },
60 { setAction::REMOVE, "remove" },
61 { setAction::LIST, "list" },
62 { setAction::IGNORE, "ignore" },
63 { setAction::SUBTRACT, "delete" }, // Compat (1806)
64});
65
66
67const Foam::Enum
68<
70>
72({
73 { setAction::NEW, "use" }, // "use" specified selection
74 { setAction::ADD, "add" },
75 { setAction::SUBTRACT, "subtract" },
76 { setAction::SUBSET, "subset" },
77 { setAction::INVERT, "invert" },
78 { setAction::IGNORE, "ignore" },
79});
80
81
83(
84 "Illegal topoSetSource name"
85);
86
87
88// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
89
90bool Foam::topoSetSource::check(labelList& list, const label maxLabel)
91{
92 const label len = list.size();
93
94 label nGood = 0;
95
96 for (label i=0; i < len; ++i)
97 {
98 const label val = list[i];
99
100 if (val >= 0 && val < maxLabel)
101 {
102 if (nGood != i)
103 {
104 list[nGood] = val;
105 }
106 ++nGood;
107 }
108 }
109
110 const label nReject = (len - nGood);
111
112 if (nReject)
113 {
114 list.resize(nGood);
115
116 // Report?
117 }
118
119 return !nReject;
120}
121
122
123// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124
126(
127 const word& topoSetSourceType,
128 const polyMesh& mesh,
129 const dictionary& dict
130)
131{
132 auto* ctorPtr = wordConstructorTable(topoSetSourceType);
133
134 if (!ctorPtr)
135 {
137 (
138 dict,
139 "topoSetSource",
140 topoSetSourceType,
141 *wordConstructorTablePtr_
142 ) << exit(FatalIOError);
143 }
144
145 return autoPtr<topoSetSource>(ctorPtr(mesh, dict));
146}
147
148
150(
151 const word& topoSetSourceType,
152 const polyMesh& mesh,
153 Istream& is
154)
155{
156 auto* ctorPtr = istreamConstructorTable(topoSetSourceType);
157
158 if (!ctorPtr)
159 {
161 (
162 "topoSetSource",
163 topoSetSourceType,
164 *istreamConstructorTablePtr_
165 ) << exit(FatalError);
166 }
167
168 return autoPtr<topoSetSource>(ctorPtr(mesh, is));
169}
170
171
173{
174 if (!is.good() || is.eof())
175 {
177 << exit(FatalError);
178 }
179
180 return is;
181}
182
183
184// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
185
187(
188 topoSet& set,
189 const label id,
190 const bool add
191) const
192{
193 if (add)
194 {
195 set.set(id);
196 }
197 else
198 {
199 set.unset(id);
200 }
201}
202
203
205(
206 topoSet& set,
207 const labelUList& labels,
208 const bool add
209) const
210{
211 if (add)
212 {
213 set.set(labels);
214 }
215 else
216 {
217 set.unset(labels);
218 }
219}
220
221
223(
224 topoSet& set,
225 const bitSet& labels,
226 const bool add
227) const
228{
229 if (add)
230 {
231 for (const label id : labels)
232 {
233 set.set(id);
234 }
235 }
236 else
237 {
238 for (const label id : labels)
239 {
240 set.unset(id);
241 }
242 }
243}
244
245
246// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
247
249(
250 const polyMesh& mesh,
251 bool verbose
252)
253:
254 mesh_(mesh),
255 verbose_(verbose)
256{}
257
258
260(
261 const polyMesh& mesh,
262 const dictionary& dict
263)
264:
266{
267 verbose(dict);
268}
269
270
271// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
272
274{
275 bool flag(verbose_);
276
277 if (dict.readIfPresent("verbose", flag))
278 {
279 verbose_ = flag;
280 }
281}
282
283
284// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: Enum.H:61
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:239
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
A class for handling character strings derived from std::string.
Definition: string.H:79
Base class of a source for a topoSet.
Definition: topoSetSource.H:68
static const string illegalSource_
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:90
setAction
Enumeration defining various actions.
static HashTable< string > * usageTablePtr_
A table of usage strings.
bool verbose() const noexcept
Get output verbosity.
static Istream & checkIs(Istream &is)
Check state of stream.
static const Enum< setAction > actionNames
static const Enum< setAction > combineNames
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:67
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
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:457
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
IOerror FatalIOError
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dictionary dict