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 -------------------------------------------------------------------------------
11 License
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 #include "transformField.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(topoSetSource, 0);
41  defineRunTimeSelectionTable(topoSetSource, word);
42  defineRunTimeSelectionTable(topoSetSource, istream);
43 }
44 
45 
47 
48 
49 const 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 
68 const 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 
84 (
85  "Illegal topoSetSource name"
86 );
87 
88 
89 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
90 
91 bool 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  }
119 
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_
143  ) << exit(FatalIOError);
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  }
180 
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);
242  }
243  }
244 }
245 
246 
247 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
248 
250 (
251  const polyMesh& mesh,
252  bool verbose
253 )
254 :
255  mesh_(mesh),
256  verbose_(verbose),
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
300  {
301  // No transform - return reference to input points
302  return points;
303  }
304 }
305 
306 
308 (
309  const dictionary& dict,
310  wordList& names
311 )
312 {
313  bool isZone = false;
314 
315  // priority
316  // 1. 'sets'
317  // 2. 'zones'
318  // 3. 'set'
319  // 4. 'zone'
320 
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 
335  {
336  // Had 'zone', so 'set' is optional...
337  isZone = true;
339  {
340  isZone = false;
341  }
342  }
343  else
344  {
345  // No 'zone', so 'set' is mandatory...
347  // -> isZone = false;
348  }
349  }
350 
351  return isZone;
352 }
353 
354 
355 // ************************************************************************* //
topoSetSource(const topoSetSource &)=delete
No copy construct.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
static const Enum< setAction > actionNames
The setActions enum text. Names: "new", add", "subtract", "subset", "invert", "clear", "remove", "list", "ignore".
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:153
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
void transformPoints(vectorField &, const septernion &, const vectorField &)
Transform given vectorField of coordinates with the given septernion.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
T & front()
Access first element of the list, position [0].
Definition: UListI.H:230
static Istream & checkIs(Istream &is)
Check state of stream.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:615
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when &#39;add&#39; is true.
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
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...
Spatial transformation functions for primitive fields.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
dynamicFvMesh & mesh
const pointField & points
Base class for defining solid-body motions.
A class for handling words, derived from Foam::string.
Definition: word.H:63
setAction
Enumeration defining various actions.
static const string illegalSource_
bool verbose() const noexcept
Get output verbosity.
String literal.
Definition: keyType.H:82
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
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...
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:59
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
List< word > wordList
List of word.
Definition: fileName.H:59
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: error.H:64
static HashTable< string > * usageTablePtr_
A table of usage strings.
tmp< pointField > transform(const pointField &points) const
Coordinate transform (optionally) coordinates. Returns reference to input data if no transform is act...
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:84
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
static bool readNames(const dictionary &dict, wordList &names)
Helper: extract wordList of patches/zones from dictionary. Returns.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A class for handling character strings derived from std::string.
Definition: string.H:72
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:645
static const Enum< setAction > combineNames
The setAction enum text when combining selections. Names: "use", "add", "subtract", "subset", "invert", "ignore".
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...