1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 template<class ParticleType>
32 Foam::word Foam::IOPosition<ParticleType>::particlePropertiesName
38 // * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
40 template<class ParticleType>
41 void Foam::IOPosition<ParticleType>::readParticleProperties()
43 IOobject propsDictHeader
45 particlePropertiesName,
46 cloud_.db().time().timeName(),
47 "uniform"/cloud::prefix/cloud_.name(),
54 if (propsDictHeader.headerOk())
56 const IOdictionary propsDict(propsDictHeader);
58 word procName("processor" + Foam::name(Pstream::myProcNo()));
59 if (propsDict.found(procName))
61 propsDict.subDict(procName).lookup("particleCount")
62 >> cloud_.particleCount_;
68 template<class ParticleType>
69 void Foam::IOPosition<ParticleType>::writeParticleProperties() const
71 IOdictionary propsDict
75 particlePropertiesName,
76 cloud_.db().time().timeName(),
77 "uniform"/cloud::prefix/cloud_.name(),
85 word procName("processor" + Foam::name(Pstream::myProcNo()));
86 propsDict.add(procName, dictionary());
87 propsDict.subDict(procName).add("particleCount", cloud_.particleCount_);
89 propsDict.regIOobject::write();
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 template<class ParticleType>
96 Foam::IOPosition<ParticleType>::IOPosition
98 const Cloud<ParticleType>& c
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
118 template<class ParticleType>
119 bool Foam::IOPosition<ParticleType>::write() const
123 return regIOobject::write();
132 template<class ParticleType>
133 bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
135 // Write global cloud data
136 writeParticleProperties();
138 os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
140 forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
142 // Prevent writing additional fields
143 static_cast<const Particle<ParticleType>&>(iter()).write
151 os<< token::END_LIST << endl;
157 template<class ParticleType>
158 void Foam::IOPosition<ParticleType>::readData
160 Cloud<ParticleType>& c,
164 // Read global cloud data. Resets count on cloud.
165 readParticleProperties();
167 Istream& is = readStream(checkClass ? typeName : "");
169 token firstToken(is);
171 if (firstToken.isLabel())
173 label s = firstToken.labelToken();
175 // Read beginning of contents
176 is.readBeginList("Cloud<ParticleType>");
178 for (label i=0; i<s; i++)
180 // Do not read any fields, position only
181 c.append(new ParticleType(c, is, false));
184 // Read end of contents
185 is.readEndList("Cloud<ParticleType>");
187 else if (firstToken.isPunctuation())
189 if (firstToken.pToken() != token::BEGIN_LIST)
193 "void IOPosition<ParticleType>::readData"
194 "(Cloud<ParticleType>&, bool)",
196 ) << "incorrect first token, '(', found "
198 << exit(FatalIOError);
205 lastToken.isPunctuation()
206 && lastToken.pToken() == token::END_LIST
210 is.putBack(lastToken);
211 // Do not read any fields, position only
212 c.append(new ParticleType(c, is, false));
220 "void IOPosition<ParticleType>::readData"
221 "(Cloud<ParticleType>&, bool)",
223 ) << "incorrect first token, expected <int> or '(', found "
225 << exit(FatalIOError);
228 // Check state of IOstream
231 "void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
236 // ************************************************************************* //