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 "DsmcParcel.H"
28 #include "IOstreams.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 template <class ParcelType>
35 Foam::DsmcParcel<ParcelType>::DsmcParcel
37 const Cloud<ParcelType>& cloud,
42 Particle<ParcelType>(cloud, is, readFields),
49 if (is.format() == IOstream::ASCII)
53 typeId_ = readLabel(is);
59 reinterpret_cast<char*>(&U_),
67 // Check state of Istream
70 "DsmcParcel<ParcelType>::DsmcParcel"
71 "(const Cloud<ParcelType>&, Istream&, bool)"
76 template<class ParcelType>
77 void Foam::DsmcParcel<ParcelType>::readFields(Cloud<ParcelType>& c)
84 Particle<ParcelType>::readFields(c);
86 IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
87 c.checkFieldIOobject(c, U);
89 IOField<scalar> Ei(c.fieldIOobject("Ei", IOobject::MUST_READ));
90 c.checkFieldIOobject(c, Ei);
92 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
93 c.checkFieldIOobject(c, typeId);
96 forAllIter(typename Cloud<ParcelType>, c, iter)
98 ParcelType& p = iter();
102 p.typeId_ = typeId[i];
108 template<class ParcelType>
109 void Foam::DsmcParcel<ParcelType>::writeFields(const Cloud<ParcelType>& c)
111 Particle<ParcelType>::writeFields(c);
115 IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
116 IOField<scalar> Ei(c.fieldIOobject("Ei", IOobject::NO_READ), np);
117 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
120 forAllConstIter(typename Cloud<ParcelType>, c, iter)
122 const DsmcParcel<ParcelType>& p = iter();
126 typeId[i] = p.typeId();
136 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
138 template<class ParcelType>
139 Foam::Ostream& Foam::operator<<
142 const DsmcParcel<ParcelType>& p
145 if (os.format() == IOstream::ASCII)
147 os << static_cast<const Particle<ParcelType>& >(p)
148 << token::SPACE << p.U()
149 << token::SPACE << p.Ei()
150 << token::SPACE << p.typeId();
154 os << static_cast<const Particle<ParcelType>& >(p);
157 reinterpret_cast<const char*>(&p.U_),
164 // Check state of Ostream
167 "Ostream& operator<<(Ostream&, const DsmcParcel<ParcelType>&)"
174 // ************************************************************************* //