Loading...
Searching...
No Matches
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-2024 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"
36// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37
38namespace Foam
39{
43}
44
45
47
48
49const Foam::Enum
50<
52>
54({
55 { setAction::ADD, "add" },
56 { setAction::SUBTRACT, "subtract" },
57 { setAction::NEW, "new" },
58 { setAction::SUBSET, "subset" },
59 { setAction::INVERT, "invert" },
60 { setAction::CLEAR, "clear" },
61 { setAction::REMOVE, "remove" },
62 { setAction::LIST, "list" },
63 { setAction::IGNORE, "ignore" },
64 { setAction::SUBTRACT, "delete" }, // Compat (1806)
65});
66
67
68const Foam::Enum
69<
71>
73({
74 { setAction::NEW, "use" }, // "use" specified selection
75 { setAction::ADD, "add" },
76 { setAction::SUBTRACT, "subtract" },
77 { setAction::SUBSET, "subset" },
78 { setAction::INVERT, "invert" },
79 { setAction::IGNORE, "ignore" },
80});
81
82
85 "Illegal topoSetSource name"
86);
87
88
89// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
90
91bool Foam::topoSetSource::check(labelList& list, const label maxLabel)
92{
93 const label len = list.size();
94
95 label nGood = 0;
96
97 for (label i=0; i < len; ++i)
98 {
99 const label val = list[i];
100
101 if (val >= 0 && val < maxLabel)
102 {
103 if (nGood != i)
104 {
105 list[nGood] = val;
106 }
107 ++nGood;
108 }
109 }
110
111 const label nReject = (len - nGood);
112
113 if (nReject)
114 {
115 list.resize(nGood);
116
117 // Report?
118 }
120 return !nReject;
121}
122
123
124// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125
127(
128 const word& topoSetSourceType,
129 const polyMesh& mesh,
130 const dictionary& dict
131)
132{
133 auto* ctorPtr = wordConstructorTable(topoSetSourceType);
134
135 if (!ctorPtr)
136 {
138 (
139 dict,
140 "topoSetSource",
141 topoSetSourceType,
142 *wordConstructorTablePtr_
144 }
145
146 return autoPtr<topoSetSource>(ctorPtr(mesh, dict));
147}
148
149
151(
152 const word& topoSetSourceType,
153 const polyMesh& mesh,
154 Istream& is
155)
156{
157 auto* ctorPtr = istreamConstructorTable(topoSetSourceType);
158
159 if (!ctorPtr)
160 {
162 (
163 "topoSetSource",
164 topoSetSourceType,
165 *istreamConstructorTablePtr_
167 }
168
169 return autoPtr<topoSetSource>(ctorPtr(mesh, is));
170}
171
172
174{
175 if (!is.good() || is.eof())
176 {
178 << exit(FatalError);
179 }
181 return is;
182}
183
184
185// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
186
188(
189 topoSet& set,
190 const label id,
191 const bool add
192) const
193{
194 if (add)
195 {
196 set.set(id);
197 }
198 else
199 {
200 set.unset(id);
201 }
202}
203
204
206(
207 topoSet& set,
208 const labelUList& labels,
209 const bool add
210) const
211{
212 if (add)
213 {
214 set.set(labels);
215 }
216 else
217 {
218 set.unset(labels);
219 }
220}
221
222
224(
225 topoSet& set,
226 const bitSet& labels,
227 const bool add
228) const
229{
230 if (add)
231 {
232 for (const label id : labels)
233 {
234 set.set(id);
235 }
236 }
237 else
238 {
239 for (const label id : labels)
240 {
241 set.unset(id);
243 }
244}
245
246
247// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
248
250(
251 const polyMesh& mesh,
252 bool verbose
253)
255 mesh_(mesh),
257 transformPtr_(nullptr)
258{}
259
260
262(
263 const polyMesh& mesh,
264 const dictionary& dict
265)
266:
267 mesh_(mesh),
268 verbose_(dict.getOrDefault<bool>("verbose", true)),
269 transformPtr_
270 (
271 // Uses "solidBodyMotionFunction" if present
272 solidBodyMotionFunction::NewIfPresent(dict, mesh.time())
273 )
274{}
275
276
277// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
278
280{
281 bool flag(verbose_);
282
283 if (dict.readIfPresent("verbose", flag, keyType::LITERAL))
284 {
285 verbose_ = flag;
286 }
287}
288
289
291(
292 const pointField& points
293) const
294{
295 if (transformPtr_)
296 {
297 return transformPoints(transformPtr_->transformation(), points);
298 }
299 else
301 // No transform - return reference to input points
302 return points;
303 }
304}
305
306
308(
309 const dictionary& dict,
311)
312{
313 bool isZone = false;
314
315 // priority
316 // 1. 'sets'
317 // 2. 'zones'
318 // 3. 'set'
319 // 4. 'zone'
320
321 if (dict.readIfPresent("sets", names, keyType::LITERAL))
322 {
323 // -> isZone = false;
324 }
325 else if (dict.readIfPresent("zones", names, keyType::LITERAL))
326 {
327 isZone = true;
328 }
329 else
330 {
331 // Ensure error messsages make sense if nothing was provided
332 names.resize(1);
333
334 if (dict.readIfPresent("zone", names.front(), keyType::LITERAL))
335 {
336 // Had 'zone', so 'set' is optional...
337 isZone = true;
338 if (dict.readIfPresent("set", names.front(), keyType::LITERAL))
339 {
340 isZone = false;
341 }
342 }
343 else
344 {
345 // No 'zone', so 'set' is mandatory...
346 dict.readEntry("set", names.front(), keyType::LITERAL);
347 // -> isZone = false;
348 }
349 }
350
351 return isZone;
352}
353
354
355// ************************************************************************* //
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition Enum.H:57
A HashTable similar to std::unordered_map.
Definition HashTable.H:124
bool good() const noexcept
True if next operation might succeed.
Definition IOstream.H:281
bool eof() const noexcept
True if end of input seen.
Definition IOstream.H:289
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, IOobjectOption::readOption readOpt=IOobjectOption::MUST_READ) const
Find entry and assign to T val. FatalIOError if it is found and the number of tokens is incorrect,...
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
@ LITERAL
String literal.
Definition keyType.H:82
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Base class for defining solid-body motions.
A class for handling character strings derived from std::string.
Definition string.H:76
A class for managing temporary objects.
Definition tmp.H:75
Base class of a source for a topoSet.
static const string illegalSource_
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
static bool readNames(const dictionary &dict, wordList &names)
Helper: extract wordList of patches/zones from dictionary. Returns.
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.
topoSetSource(const topoSetSource &)=delete
No copy construct.
autoPtr< solidBodyMotionFunction > transformPtr_
Optional transformation for geometric data.
setAction
Enumeration defining various actions.
static HashTable< string > * usageTablePtr_
A table of usage strings.
bool verbose_
Output verbosity (default: true).
bool verbose() const noexcept
Get output verbosity.
const polyMesh & mesh() const noexcept
Reference to the mesh.
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
const polyMesh & mesh_
Reference to the mesh.
static Istream & checkIs(Istream &is)
Check state of stream.
static const Enum< setAction > actionNames
The setActions enum text. Names: "new", add", "subtract", "subset", "invert","clear",...
static const Enum< setAction > combineNames
The setAction enum text when combining selections. Names: "use", "add", "subtract",...
General set of labels of mesh quantity (points, cells, faces).
Definition topoSet.H:63
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition error.H:607
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition error.H:637
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
auto & names
const pointField & points
void set(List< bool > &bools, const labelUList &locations)
Set the listed locations (assign 'true').
Definition BitOps.C:35
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
void add(DimensionedField< scalar, GeoMesh > &result, const dimensioned< scalar > &dt1, const DimensionedField< scalar, GeoMesh > &f2)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
void transformPoints(vectorField &, const septernion &, const vectorField &)
Transform given vectorField of coordinates with the given septernion.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
UList< label > labelUList
A UList of labels.
Definition UList.H:75
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
dict add("bounds", meshBb)
dictionary dict
Spatial transformation functions for primitive fields.