blockVertex.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) 2016-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 "blockVertex.H"
27 #include "pointVertex.H"
28 #include "blockMeshTools.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(blockVertex, 0);
35  defineRunTimeSelectionTable(blockVertex, Istream);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 {}
43 
44 
46 {
48  return autoPtr<blockVertex>(nullptr);
49 }
50 
51 
53 (
54  const dictionary& dict,
55  const label index,
56  const searchableSurfaces& geometry,
57  Istream& is
58 )
59 {
60  if (debug)
61  {
62  InfoInFunction << "Constructing blockVertex" << endl;
63  }
64 
65  token firstToken(is);
66 
67  if (firstToken.isPunctuation() && firstToken.pToken() == token::BEGIN_LIST)
68  {
69  // Putback the opening bracket
70  is.putBack(firstToken);
71 
73  (
74  new blockVertices::pointVertex(dict, index, geometry, is)
75  );
76  }
77  else if (firstToken.isWord())
78  {
79  const word faceType(firstToken.wordToken());
80 
81  IstreamConstructorTable::iterator cstrIter =
82  IstreamConstructorTablePtr_->find(faceType);
83 
84  if (cstrIter == IstreamConstructorTablePtr_->end())
85  {
87  << "Unknown blockVertex type "
88  << faceType << nl << nl
89  << "Valid blockVertex types are" << endl
90  << IstreamConstructorTablePtr_->sortedToc()
91  << abort(FatalError);
92  }
93 
94  return autoPtr<blockVertex>(cstrIter()(dict, index, geometry, is));
95  }
96  else
97  {
99  << "incorrect first token, expected <word> or '(', found "
100  << firstToken.info()
101  << exit(FatalIOError);
102 
103  return autoPtr<blockVertex>(nullptr);
104  }
105 }
106 
107 
109 {
110  const dictionary* varDictPtr = dict.subDictPtr("namedVertices");
111  if (varDictPtr)
112  {
113  return blockMeshTools::read(is, *varDictPtr);
114  }
115  return readLabel(is);
116 }
117 
118 
120 (
121  Ostream& os,
122  const label val,
123  const dictionary& d
124 )
125 {
126  const dictionary* varDictPtr = d.subDictPtr("namedVertices");
127  if (varDictPtr)
128  {
129  blockMeshTools::write(os, val, *varDictPtr);
130  }
131  else
132  {
133  os << val;
134  }
135 }
136 
137 
138 // ************************************************************************* //
dictionary dict
bool isWord() const
Definition: tokenI.H:261
punctuationToken pToken() const
Definition: tokenI.H:248
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:306
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
const word & wordToken() const
Definition: tokenI.H:266
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static autoPtr< blockVertex > New(const dictionary &dict, const label index, const searchableSurfaces &geometry, Istream &)
New function which constructs and returns pointer to a blockVertex.
Definition: blockVertex.C:53
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
A class for handling words, derived from string.
Definition: word.H:59
Container for searchableSurfaces.
static label read(Istream &, const dictionary &)
Read vertex index with optional name lookup.
Definition: blockVertex.C:108
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label readLabel(Istream &is)
Definition: label.H:64
const dictionary * subDictPtr(const word &) const
Find and return a sub-dictionary pointer if present.
Definition: dictionary.C:972
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
blockVertex()
Construct null.
Definition: blockVertex.C:41
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
virtual autoPtr< blockVertex > clone() const
Clone function.
Definition: blockVertex.C:45
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
static void write(Ostream &, const label, const dictionary &)
Write vertex index with optional name backsubstitution.
Definition: blockVertex.C:120
bool isPunctuation() const
Definition: tokenI.H:243
Namespace for OpenFOAM.
IOerror FatalIOError
#define InfoInFunction
Report an information message using Foam::Info.