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-2019 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 "polyMesh.H"
31 #include "bitSet.H"
32 #include "topoSet.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(topoSetSource, 0);
39  defineRunTimeSelectionTable(topoSetSource, word);
40  defineRunTimeSelectionTable(topoSetSource, istream);
41 }
42 
43 
45 
46 
47 const Foam::Enum
48 <
50 >
52 ({
53  { setAction::ADD, "add" },
54  { setAction::SUBTRACT, "subtract" },
55  { setAction::SUBSET, "subset" },
56  { setAction::INVERT, "invert" },
57  { setAction::CLEAR, "clear" },
58  { setAction::NEW, "new" },
59  { setAction::REMOVE, "remove" },
60  { setAction::LIST, "list" },
61  { setAction::SUBTRACT, "delete" }, // Compat (1806)
62 });
63 
64 
66 (
67  "Illegal topoSetSource name"
68 );
69 
70 
71 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
72 
73 bool Foam::topoSetSource::check(labelList& list, const label maxLabel)
74 {
75  const label len = list.size();
76 
77  label nGood = 0;
78 
79  for (label i=0; i < len; ++i)
80  {
81  const label val = list[i];
82 
83  if (val >= 0 && val < maxLabel)
84  {
85  if (nGood != i)
86  {
87  list[nGood] = val;
88  }
89  ++nGood;
90  }
91  }
92 
93  const label nReject = (len - nGood);
94 
95  if (nReject)
96  {
97  list.resize(nGood);
98 
99  // Report?
100  }
101 
102  return !nReject;
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
107 
109 (
110  const word& topoSetSourceType,
111  const polyMesh& mesh,
112  const dictionary& dict
113 )
114 {
115  auto cstrIter = wordConstructorTablePtr_->cfind(topoSetSourceType);
116 
117  if (!cstrIter.found())
118  {
120  (
121  dict,
122  "topoSetSource",
123  topoSetSourceType,
124  *wordConstructorTablePtr_
125  ) << exit(FatalIOError);
126  }
127 
128  return autoPtr<topoSetSource>(cstrIter()(mesh, dict));
129 }
130 
131 
133 (
134  const word& topoSetSourceType,
135  const polyMesh& mesh,
136  Istream& is
137 )
138 {
139  auto cstrIter = istreamConstructorTablePtr_->cfind(topoSetSourceType);
140 
141  if (!cstrIter.found())
142  {
144  (
145  "topoSetSource",
146  topoSetSourceType,
147  *istreamConstructorTablePtr_
148  ) << exit(FatalError);
149  }
150 
151  return autoPtr<topoSetSource>(cstrIter()(mesh, is));
152 }
153 
154 
156 {
157  if (!is.good() || is.eof())
158  {
160  << exit(FatalError);
161  }
162 
163  return is;
164 }
165 
166 
167 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
168 
170 (
171  topoSet& set,
172  const label id,
173  const bool add
174 ) const
175 {
176  if (add)
177  {
178  set.set(id);
179  }
180  else
181  {
182  set.unset(id);
183  }
184 }
185 
186 
188 (
189  topoSet& set,
190  const labelUList& labels,
191  const bool add
192 ) const
193 {
194  if (add)
195  {
196  set.set(labels);
197  }
198  else
199  {
200  set.unset(labels);
201  }
202 }
203 
204 
206 (
207  topoSet& set,
208  const bitSet& labels,
209  const bool add
210 ) const
211 {
212  if (add)
213  {
214  for (const label id : labels)
215  {
216  set.set(id);
217  }
218  }
219  else
220  {
221  for (const label id : labels)
222  {
223  set.unset(id);
224  }
225  }
226 }
227 
228 
229 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
230 
232 :
233  mesh_(mesh),
234  verbose_(true)
235 {}
236 
237 
238 // ************************************************************************* //
Foam::topoSetSource::usageTablePtr_
static HashTable< string > * usageTablePtr_
A table of usage strings.
Definition: topoSetSource.H:121
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:62
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
topoSet.H
Foam::IOstream::eof
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:230
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::FatalIOError
IOerror FatalIOError
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::illegalSource_
static const string illegalSource_
Definition: topoSetSource.H:118
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:73
polyMesh.H
bitSet.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:406
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
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:73
Foam::List::resize
void resize(const label newSize)
Adjust allocated size of list.
Definition: ListI.H:139
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:121
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:385
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:109
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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:381
Foam::List< label >
topoSetSource.H
Foam::topoSetSource::checkIs
static Istream & checkIs(Istream &is)
Check state of stream.
Definition: topoSetSource.C:155
Foam::UList< label >
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:170
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::topoSetSource::actionNames
static const Enum< setAction > actionNames
The setActions text representations.
Definition: topoSetSource.H:113