1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
27 #include "IOstreams.H"
28 #include "IOPosition.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 template<class ParticleType>
33 Foam::string Foam::Particle<ParticleType>::propHeader =
34 "(Px Py Pz) cellI origProc origId";
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 template<class ParticleType>
39 Foam::Particle<ParticleType>::Particle
41 const Cloud<ParticleType>& cloud,
49 origProc_(Pstream::myProcNo()),
53 // readFields : read additional data. Should be consistent with writeFields.
55 if (is.format() == IOstream::ASCII)
57 is >> position_ >> celli_;
60 is >> origProc_ >> origId_;
65 // In binary read all particle data - needed for parallel transfer
70 reinterpret_cast<char*>(&position_),
74 + sizeof(stepFraction_)
83 reinterpret_cast<char*>(&position_),
87 + sizeof(stepFraction_)
94 celli_ = cloud_.pMesh().findCell(position_);
97 // Check state of Istream
98 is.check("Particle<ParticleType>::Particle(Istream&)");
102 template<class ParticleType>
103 void Foam::Particle<ParticleType>::readFields
105 Cloud<ParticleType>& c
113 IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
115 if (procIO.headerOk())
117 IOField<label> origProcId(procIO);
118 c.checkFieldIOobject(c, origProcId);
119 IOField<label> origId(c.fieldIOobject("origId", IOobject::MUST_READ));
120 c.checkFieldIOobject(c, origId);
123 forAllIter(typename Cloud<ParticleType>, c, iter)
125 ParticleType& p = iter();
127 p.origProc_ = origProcId[i];
128 p.origId_ = origId[i];
135 template<class ParticleType>
136 void Foam::Particle<ParticleType>::writeFields
138 const Cloud<ParticleType>& c
141 // Write the cloud position file
142 IOPosition<ParticleType> ioP(c);
147 IOField<label> origProc
156 IOField<label> origId(c.fieldIOobject("origId", IOobject::NO_READ), np);
159 forAllConstIter(typename Cloud<ParticleType>, c, iter)
161 origProc[i] = iter().origProc_;
162 origId[i] = iter().origId_;
171 template<class ParticleType>
172 void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
174 if (os.format() == IOstream::ASCII)
178 // Write the additional entries
180 << token::SPACE << celli_
181 << token::SPACE << origProc_
182 << token::SPACE << origId_;
187 << token::SPACE << celli_;
192 // In binary write both celli_ and facei_, needed for parallel transfer
197 reinterpret_cast<const char*>(&position_),
201 + sizeof(stepFraction_)
210 reinterpret_cast<const char*>(&position_),
214 + sizeof(stepFraction_)
219 // Check state of Ostream
220 os.check("Particle<ParticleType>::write(Ostream& os, bool) const");
224 template<class ParticleType>
225 Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
234 // ************************************************************************* //