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 \*---------------------------------------------------------------------------*/
28 #include "IOstreams.H"
29 #include "IOPosition.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 template<class ParticleType>
34 Foam::string Foam::Particle<ParticleType>::propHeader =
35 "(Px Py Pz) cellI origProc origId";
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 template<class ParticleType>
40 Foam::Particle<ParticleType>::Particle
42 const Cloud<ParticleType>& cloud,
50 origProc_(Pstream::myProcNo()),
54 // readFields : read additional data. Should be consistent with writeFields.
56 if (is.format() == IOstream::ASCII)
58 is >> position_ >> celli_;
61 is >> origProc_ >> origId_;
66 // In binary read all particle data - needed for parallel transfer
71 reinterpret_cast<char*>(&position_),
75 + sizeof(stepFraction_)
84 reinterpret_cast<char*>(&position_),
88 + sizeof(stepFraction_)
95 celli_ = cloud_.pMesh().findCell(position_);
98 // Check state of Istream
99 is.check("Particle<ParticleType>::Particle(Istream&)");
103 template<class ParticleType>
104 void Foam::Particle<ParticleType>::readFields
106 Cloud<ParticleType>& c
114 IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
116 if (procIO.headerOk())
118 IOField<label> origProcId(procIO);
119 c.checkFieldIOobject(c, origProcId);
120 IOField<label> origId(c.fieldIOobject("origId", IOobject::MUST_READ));
121 c.checkFieldIOobject(c, origId);
124 forAllIter(typename Cloud<ParticleType>, c, iter)
126 ParticleType& p = iter();
128 p.origProc_ = origProcId[i];
129 p.origId_ = origId[i];
136 template<class ParticleType>
137 void Foam::Particle<ParticleType>::writeFields
139 const Cloud<ParticleType>& c
142 // Write the cloud position file
143 IOPosition<ParticleType> ioP(c);
148 IOField<label> origProc
157 IOField<label> origId(c.fieldIOobject("origId", IOobject::NO_READ), np);
160 forAllConstIter(typename Cloud<ParticleType>, c, iter)
162 origProc[i] = iter().origProc_;
163 origId[i] = iter().origId_;
172 template<class ParticleType>
173 void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
175 if (os.format() == IOstream::ASCII)
179 // Write the additional entries
181 << token::SPACE << celli_
182 << token::SPACE << origProc_
183 << token::SPACE << origId_;
188 << token::SPACE << celli_;
193 // In binary write both celli_ and facei_, needed for parallel transfer
198 reinterpret_cast<const char*>(&position_),
202 + sizeof(stepFraction_)
211 reinterpret_cast<const char*>(&position_),
215 + sizeof(stepFraction_)
220 // Check state of Ostream
221 os.check("Particle<ParticleType>::write(Ostream& os, bool) const");
225 template<class ParticleType>
226 Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
235 // ************************************************************************* //