topoSetSource.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "topoSetSource.H"
27 #include "polyMesh.H"
28 #include "topoSet.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(topoSetSource, 0);
35  defineRunTimeSelectionTable(topoSetSource, word);
36  defineRunTimeSelectionTable(topoSetSource, istream);
37 
38  template<>
39  const char* Foam::NamedEnum
40  <
42  8
43  >::names[] =
44  {
45  "clear",
46  "new",
47  "invert",
48  "add",
49  "delete",
50  "subset",
51  "list",
52  "remove"
53  };
54 }
55 
56 
57 Foam::HashTable<Foam::string>* Foam::topoSetSource::usageTablePtr_ = nullptr;
58 
59 
61  Foam::topoSetSource::actionNames_;
62 
63 
64 const Foam::string Foam::topoSetSource::illegalSource_
65 (
66  "Illegal topoSetSource name"
67 );
68 
69 
70 
71 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 
74 (
75  const word& topoSetSourceType,
76  const polyMesh& mesh,
77  const dictionary& dict
78 )
79 {
80  wordConstructorTable::iterator cstrIter =
81  wordConstructorTablePtr_->find(topoSetSourceType);
82 
83  if (cstrIter == wordConstructorTablePtr_->end())
84  {
86  << "Unknown topoSetSource type " << topoSetSourceType
87  << endl << endl
88  << "Valid topoSetSource types : " << endl
89  << wordConstructorTablePtr_->sortedToc()
90  << exit(FatalError);
91  }
92 
93  return autoPtr<topoSetSource>(cstrIter()(mesh, dict));
94 }
95 
96 
98 (
99  const word& topoSetSourceType,
100  const polyMesh& mesh,
101  Istream& is
102 )
103 {
104  istreamConstructorTable::iterator cstrIter =
105  istreamConstructorTablePtr_->find(topoSetSourceType);
106 
107  if (cstrIter == istreamConstructorTablePtr_->end())
108  {
110  << "Unknown topoSetSource type " << topoSetSourceType
111  << endl << endl
112  << "Valid topoSetSource types : " << endl
113  << istreamConstructorTablePtr_->sortedToc()
114  << exit(FatalError);
115  }
116 
117  return autoPtr<topoSetSource>(cstrIter()(mesh, is));
118 }
119 
120 
122 {
123  if (is.good() && !is.eof())
124  {
125  return is;
126  }
127  else
128  {
130  << exit(FatalError);
131 
132  return is;
133  }
134 }
135 
136 
137 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
138 
140 (
141  topoSet& set,
142  const label celli,
143  const bool add
144 ) const
145 {
146  if (add)
147  {
148  set.insert(celli);
149  }
150  else
151  {
152  set.erase(celli);
153  }
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
158 
160 :
161  mesh_(mesh)
162 {}
163 
164 
165 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
166 
168 {}
169 
170 
171 // ************************************************************************* //
dictionary dict
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
topoSetSource(const polyMesh &mesh)
Construct from components.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static Istream & checkIs(Istream &is)
Check state of stream.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:336
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:74
virtual ~topoSetSource()
Destructor.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A class for handling character strings derived from std::string.
Definition: string.H:76
Namespace for OpenFOAM.