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-2021 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::SUBSET, "subset" },
57  { setAction::INVERT, "invert" },
58  { setAction::CLEAR, "clear" },
59  { setAction::NEW, "new" },
60  { setAction::REMOVE, "remove" },
61  { setAction::LIST, "list" },
62  { setAction::SUBTRACT, "delete" }, // Compat (1806)
63 });
64 
65 
67 (
68  "Illegal topoSetSource name"
69 );
70 
71 
72 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
73 
74 bool Foam::topoSetSource::check(labelList& list, const label maxLabel)
75 {
76  const label len = list.size();
77 
78  label nGood = 0;
79 
80  for (label i=0; i < len; ++i)
81  {
82  const label val = list[i];
83 
84  if (val >= 0 && val < maxLabel)
85  {
86  if (nGood != i)
87  {
88  list[nGood] = val;
89  }
90  ++nGood;
91  }
92  }
93 
94  const label nReject = (len - nGood);
95 
96  if (nReject)
97  {
98  list.resize(nGood);
99 
100  // Report?
101  }
102 
103  return !nReject;
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
110 (
111  const word& topoSetSourceType,
112  const polyMesh& mesh,
113  const dictionary& dict
114 )
115 {
116  auto* ctorPtr = wordConstructorTable(topoSetSourceType);
117 
118  if (!ctorPtr)
119  {
121  (
122  dict,
123  "topoSetSource",
124  topoSetSourceType,
125  *wordConstructorTablePtr_
126  ) << exit(FatalIOError);
127  }
128 
129  return autoPtr<topoSetSource>(ctorPtr(mesh, dict));
130 }
131 
132 
134 (
135  const word& topoSetSourceType,
136  const polyMesh& mesh,
137  Istream& is
138 )
139 {
140  auto* ctorPtr = istreamConstructorTable(topoSetSourceType);
141 
142  if (!ctorPtr)
143  {
145  (
146  "topoSetSource",
147  topoSetSourceType,
148  *istreamConstructorTablePtr_
149  ) << exit(FatalError);
150  }
151 
152  return autoPtr<topoSetSource>(ctorPtr(mesh, is));
153 }
154 
155 
157 {
158  if (!is.good() || is.eof())
159  {
161  << exit(FatalError);
162  }
163 
164  return is;
165 }
166 
167 
168 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
169 
171 (
172  topoSet& set,
173  const label id,
174  const bool add
175 ) const
176 {
177  if (add)
178  {
179  set.set(id);
180  }
181  else
182  {
183  set.unset(id);
184  }
185 }
186 
187 
189 (
190  topoSet& set,
191  const labelUList& labels,
192  const bool add
193 ) const
194 {
195  if (add)
196  {
197  set.set(labels);
198  }
199  else
200  {
201  set.unset(labels);
202  }
203 }
204 
205 
207 (
208  topoSet& set,
209  const bitSet& labels,
210  const bool add
211 ) const
212 {
213  if (add)
214  {
215  for (const label id : labels)
216  {
217  set.set(id);
218  }
219  }
220  else
221  {
222  for (const label id : labels)
223  {
224  set.unset(id);
225  }
226  }
227 }
228 
229 
230 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
231 
233 (
234  const polyMesh& mesh,
235  bool verbose
236 )
237 :
238  mesh_(mesh),
239  verbose_(verbose)
240 {}
241 
242 
244 (
245  const polyMesh& mesh,
246  const dictionary& dict
247 )
248 :
250 {
251  verbose(dict);
252 }
253 
254 
255 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
256 
258 {
259  bool flag(verbose_);
260 
261  if (dict.readIfPresent("verbose", flag))
262  {
263  verbose_ = flag;
264  }
265 }
266 
267 
268 // ************************************************************************* //
Foam::topoSetSource::usageTablePtr_
static HashTable< string > * usageTablePtr_
A table of usage strings.
Definition: topoSetSource.H:126
Foam::Enum
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
Definition: IOstreamOption.H:57
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
topoSet.H
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::FatalIOError
IOerror FatalIOError
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::topoSetSource::illegalSource_
static const string illegalSource_
Definition: topoSetSource.H:123
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:76
Foam::topoSetSource::verbose
bool verbose() const noexcept
Get output verbosity.
Definition: topoSetSource.H:348
polyMesh.H
bitSet.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOstream::eof
bool eof() const noexcept
True if end of input seen.
Definition: IOstream.H:239
Foam::topoSetSource::topoSetSource
topoSetSource(const topoSetSource &)=delete
No copy construct.
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::topoSetSource::check
static bool check(labelList &list, const label maxLabel)
Detect and remove any values less than 0 or ge maxLabel.
Definition: topoSetSource.C:74
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
FatalErrorInLookup
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:457
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::topoSetSource::New
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:110
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:67
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::HashTable< Foam::string >
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::List< label >
topoSetSource.H
Foam::topoSetSource::checkIs
static Istream & checkIs(Istream &is)
Check state of stream.
Definition: topoSetSource.C:156
Foam::UList< label >
dictionary.H
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:171
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405
Foam::topoSetSource::actionNames
static const Enum< setAction > actionNames
The setActions text representations.
Definition: topoSetSource.H:118