cellShapeIO.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-2015 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 "cellShape.H"
27 #include "token.H"
28 #include "cellModeller.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
33 {
34  bool readEndBracket = false;
35 
36  // Read the 'name' token for the symbol
37  token t(is);
38 
39  if (t.isPunctuation())
40  {
41  if (t.pToken() == token::BEGIN_LIST)
42  {
43  readEndBracket = true;
44 
45  is >> t;
46  }
47  else
48  {
50  << "incorrect first token, expected '(', found "
51  << t.info()
52  << exit(FatalIOError);
53  }
54  }
55 
56  // it is allowed to have either a word or a number describing the model
57  if (t.isLabel())
58  {
59  s.m = cellModeller::lookup(int(t.labelToken()));
60  }
61  else if (t.isWord())
62  {
64  }
65  else
66  {
68  << "Bad type of token for cellShape symbol " << t.info()
69  << exit(FatalIOError);
70  return is;
71  }
72 
73  // Check that a model was found
74  if (!s.m)
75  {
77  << "CellShape has unknown model " << t.info()
78  << exit(FatalIOError);
79  return is;
80  }
81 
82  // Read the geometry labels
83  is >> static_cast<labelList&>(s);
84 
85  if (readEndBracket)
86  {
87  // Read end)
88  is.readEnd("cellShape");
89  }
90 
91  return is;
92 }
93 
94 
96 {
97  // Write beginning of record
98  os << token::BEGIN_LIST;
99 
100  // Write the list label for the symbol (ONE OR THE OTHER !!!)
101  os << (s.m)->index() << token::SPACE;
102 
103  // Write the model name instead of the label (ONE OR THE OTHER !!!)
104  // os << (s.m)->name() << token::SPACE;
105 
106  // Write the geometry
107  os << static_cast<const labelList&>(s);
108 
109  // End of record
110  os << token::END_LIST;
111 
112  return os;
113 }
114 
115 
116 template<>
117 Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<cellShape>& ip)
118 {
119  const cellShape& cs = ip.t_;
120 
121  if (isNull(cs.model()))
122  {
123  os << " cellShape has no model!\n";
124  }
125  else
126  {
127  os << cs.model().info() << endl;
128  }
129 
130  os << "\tGeom:\tpoint\tlabel\txyz\n";
131 
132  forAll(cs, i)
133  {
134  os << "\t\t" << i << "\t" << cs[i] << endl;
135  }
136 
137  return os;
138 }
139 
140 
141 // ************************************************************************* //
const cellModel & model() const
Model reference.
Definition: cellShapeI.H:88
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
InfoProxy< cellModel > info() const
Return info proxy.
Definition: cellModel.H:149
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
label labelToken() const
Definition: tokenI.H:259
An analytical geometric cellShape.
Definition: cellShape.H:69
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:69
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
stressControl lookup("compactNormalStress") >> compactNormalStress
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:40
bool isWord() const
Definition: tokenI.H:213
punctuationToken pToken() const
Definition: tokenI.H:200
Istream & operator>>(Istream &, directionInfo &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool isLabel() const
Definition: tokenI.H:254
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:331
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:374
Ostream & operator<<(Ostream &, const ensightPart &)
const word & wordToken() const
Definition: tokenI.H:218
bool isPunctuation() const
Definition: tokenI.H:195
IOerror FatalIOError