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-------------------------------------------------------------------------------
10License
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()
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()
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()
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
117template<>
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// ************************************************************************* //
A helper class for outputting values to Ostream.
Definition: InfoProxy.H:52
const T & t_
Definition: InfoProxy.H:55
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
InfoProxy< cellModel > info() const
Return info proxy.
Definition: cellModel.H:232
An analytical geometric cellShape.
Definition: cellShape.H:72
const cellModel & model() const
Model reference.
Definition: cellShapeI.H:126
A token holds an item read from Istream.
Definition: token.H:69
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
punctuationToken pToken() const
Return punctuation character.
Definition: tokenI.H:485
label labelToken() const
Return label value.
Definition: tokenI.H:513
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
const word & wordToken() const
Return const reference to the word contents.
Definition: tokenI.H:631
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE)
Definition: tokenI.H:609
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
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))
bool isNull(const T *ptr)
True if ptr is a pointer (of type T) to the nullObject.
Definition: nullObject.H:192
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
Istream & operator>>(Istream &, directionInfo &)
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333