1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "IOPosition.H"
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 template<class ParticleType>
32 Foam::IOPosition<ParticleType>::IOPosition
34 const Cloud<ParticleType>& c
52 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 template<class ParticleType>
55 bool Foam::IOPosition<ParticleType>::write() const
59 return regIOobject::write();
68 template<class ParticleType>
69 bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
71 os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
73 forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
75 // Prevent writing additional fields
76 static_cast<const Particle<ParticleType>&>(iter()).write
84 os<< token::END_LIST << endl;
90 template<class ParticleType>
91 void Foam::IOPosition<ParticleType>::readData
93 Cloud<ParticleType>& c,
97 Istream& is = readStream(checkClass ? typeName : "");
101 if (firstToken.isLabel())
103 label s = firstToken.labelToken();
105 // Read beginning of contents
106 is.readBeginList("Cloud<ParticleType>");
108 for (label i=0; i<s; i++)
110 // Do not read any fields, position only
111 c.append(new ParticleType(c, is, false));
114 // Read end of contents
115 is.readEndList("Cloud<ParticleType>");
117 else if (firstToken.isPunctuation())
119 if (firstToken.pToken() != token::BEGIN_LIST)
123 "void IOPosition<ParticleType>::readData"
124 "(Cloud<ParticleType>&, bool)",
126 ) << "incorrect first token, '(', found "
128 << exit(FatalIOError);
135 lastToken.isPunctuation()
136 && lastToken.pToken() == token::END_LIST
140 is.putBack(lastToken);
141 // Do not read any fields, position only
142 c.append(new ParticleType(c, is, false));
150 "void IOPosition<ParticleType>::readData"
151 "(Cloud<ParticleType>&, bool)",
153 ) << "incorrect first token, expected <int> or '(', found "
155 << exit(FatalIOError);
158 // Check state of IOstream
161 "void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
166 // ************************************************************************* //