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 | Copyright (C) 2011 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_ = NULL;
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  (
87  "topoSetSource::New(const word&, "
88  "const polyMesh&, const dictionary&)"
89  ) << "Unknown topoSetSource type " << topoSetSourceType
90  << endl << endl
91  << "Valid topoSetSource types : " << endl
92  << wordConstructorTablePtr_->sortedToc()
93  << exit(FatalError);
94  }
95 
96  return autoPtr<topoSetSource>(cstrIter()(mesh, dict));
97 }
98 
99 
101 (
102  const word& topoSetSourceType,
103  const polyMesh& mesh,
104  Istream& is
105 )
106 {
107  istreamConstructorTable::iterator cstrIter =
108  istreamConstructorTablePtr_->find(topoSetSourceType);
109 
110  if (cstrIter == istreamConstructorTablePtr_->end())
111  {
113  (
114  "topoSetSource::New(const word&, "
115  "const polyMesh&, Istream&)"
116  ) << "Unknown topoSetSource type " << topoSetSourceType
117  << endl << endl
118  << "Valid topoSetSource types : " << endl
119  << istreamConstructorTablePtr_->sortedToc()
120  << exit(FatalError);
121  }
122 
123  return autoPtr<topoSetSource>(cstrIter()(mesh, is));
124 }
125 
126 
128 {
129  if (is.good() && !is.eof())
130  {
131  return is;
132  }
133  else
134  {
135  FatalErrorIn("cellToFace::cellToFace") << "Istream not good"
136  << exit(FatalError);
137 
138  return is;
139  }
140 }
141 
142 
143 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
144 
146 (
147  topoSet& set,
148  const label cellI,
149  const bool add
150 ) const
151 {
152  if (add)
153  {
154  set.insert(cellI);
155  }
156  else
157  {
158  set.erase(cellI);
159  }
160 }
161 
162 
163 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
164 
165 Foam::topoSetSource::topoSetSource(const polyMesh& mesh)
166 :
167  mesh_(mesh)
168 {}
169 
170 
171 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
172 
174 {}
175 
176 
177 // ************************************************************************* //
static autoPtr< topoSetSource > New(const word &topoSetSourceType, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected topoSetSource.
Definition: topoSetSource.C:74
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A class for handling words, derived from string.
Definition: word.H:59
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
A class for handling character strings derived from std::string.
Definition: string.H:74
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
bool eof() const
Return true if end of input seen.
Definition: IOstream.H:339
dictionary dict
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
static Istream & checkIs(Istream &is)
Check state of stream.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
error FatalError
virtual ~topoSetSource()
Destructor.
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
defineTypeNameAndDebug(combustionModel, 0)