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 -------------------------------------------------------------------------------
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 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(topoSetSource, 0);
40  defineRunTimeSelectionTable(topoSetSource, word);
41  defineRunTimeSelectionTable(topoSetSource, istream);
42 }
43 
44 
46 
47 
48 const 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 
67 const 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 
90 bool 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_
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 // ************************************************************************* //
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".
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:160
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:598
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static Istream & checkIs(Istream &is)
Check state of stream.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:605
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
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
dynamicFvMesh & mesh
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.
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.
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.
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:83
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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:635
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 ...