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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2015 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cellShape.H"
29 #include "token.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
34 {
35  bool readEndBracket = false;
36 
37  // Read the 'name' token for the symbol
38  token t(is);
39 
40  if (t.isPunctuation())
41  {
42  if (t.pToken() == token::BEGIN_LIST)
43  {
44  readEndBracket = true;
45 
46  is >> t;
47  }
48  else
49  {
51  << "incorrect first token, expected '(', found "
52  << t.info()
53  << exit(FatalIOError);
54  }
55  }
56 
57  // Model can be described by index or name
58  if (t.isLabel())
59  {
60  s.m = cellModel::ptr(t.labelToken());
61  }
62  else if (t.isWord())
63  {
64  s.m = cellModel::ptr(t.wordToken());
65  }
66  else
67  {
69  << "Bad type of token for cellShape symbol " << t.info()
70  << exit(FatalIOError);
71  return is;
72  }
73 
74  // Check that a model was found
75  if (s.m == nullptr)
76  {
78  << "CellShape has unknown model " << t.info()
79  << exit(FatalIOError);
80  return is;
81  }
82 
83  // Read the geometry labels
84  is >> static_cast<labelList&>(s);
85 
86  if (readEndBracket)
87  {
88  // Read end)
89  is.readEnd("cellShape");
90  }
91 
92  return is;
93 }
94 
95 
97 {
98  // Write beginning of record
99  os << token::BEGIN_LIST;
100 
101  // Write the list label for the symbol (ONE OR THE OTHER !!!)
102  os << (s.m)->index();
103 
104  // Write the model name instead of the label (ONE OR THE OTHER !!!)
105  // os << (s.m)->name();
106 
107  // Write the geometry
108  os << token::SPACE << static_cast<const labelList&>(s);
109 
110  // End of record
111  os << token::END_LIST;
112 
113  return os;
114 }
115 
116 
117 template<>
118 Foam::Ostream& Foam::operator<<(Ostream& os, const InfoProxy<cellShape>& ip)
119 {
120  const cellShape& cs = ip.t_;
121 
122  if (isNull(cs.model()))
123  {
124  os << " cellShape has no model!\n";
125  }
126  else
127  {
128  os << cs.model().info() << endl;
129  }
130 
131  os << "\tGeom:\tpoint\tlabel\txyz\n";
132 
133  forAll(cs, i)
134  {
135  os << "\t\t" << i << "\t" << cs[i] << endl;
136  }
137 
138  return os;
139 }
140 
141 
142 // ************************************************************************* //
token.H
Foam::token::labelToken
label labelToken() const
Return label value.
Definition: tokenI.H:513
Foam::token::isLabel
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
Foam::FatalIOError
IOerror FatalIOError
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::token
A token holds an item read from Istream.
Definition: token.H:68
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
Foam::token::pToken
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.H:485
Foam::token::isWord
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
Definition: tokenI.H:609
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::token::info
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::token::isPunctuation
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
os
OBJstream os(runTime.globalPath()/outputName)
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:69
Foam::token::wordToken
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:631
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::List< label >
cellShape.H
Foam::isNull
bool isNull(const T *ptr)
True if ptr is a pointer (of type T) to the nullObject.
Definition: nullObject.H:192
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56