Loading...
Searching...
No Matches
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 {
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
96Foam::Ostream& Foam::operator<<(Ostream& os, const cellShape& s)
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
109
110 // End of record
112
113 return os;
114}
115
116
117template<>
118Foam::Ostream& Foam::operator<<
119(
120 Ostream& os,
121 const InfoProxy<cellShape>& iproxy
122)
123{
124 const auto& cs = *iproxy;
125
126 if (isNull(cs.model()))
127 {
128 os << " cellShape has no model!\n";
129 }
130 else
131 {
132 os << cs.model().info() << nl;
133 }
134
135 os << "\tGeom:\tpoint\tlabel\txyz\n";
136
137 forAll(cs, i)
138 {
139 os << "\t\t" << i << "\t" << cs[i] << endl;
140 }
141
142 return os;
143}
144
145
146// ************************************************************************* //
A helper class for outputting values to Ostream.
Definition InfoProxy.H:49
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition Istream.C:152
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
static const cellModel * ptr(const modelType model)
Look up pointer to cellModel by enumeration, or nullptr on failure.
Definition cellModels.C:113
An analytical geometric cellShape.
Definition cellShape.H:71
A token holds an item read from Istream.
Definition token.H:70
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition tokenI.H:650
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
punctuationToken pToken() const
Return punctuation character.
Definition tokenI.H:676
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
const word & wordToken() const
Return const reference to the word contents.
Definition tokenI.H:1022
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE).
Definition tokenI.H:1004
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
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))
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Istream & operator>>(Istream &, directionInfo &)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
bool isNull(const T *ptr) noexcept
True if ptr is a pointer (of type T) to the nullObject.
Definition nullObject.H:248
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299