1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-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 "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(DsmcCloud<ParcelType>& c)
84 IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
85 c.checkFieldIOobject(c, U);
87 IOField<scalar> Ei(c.fieldIOobject("Ei", IOobject::MUST_READ));
88 c.checkFieldIOobject(c, Ei);
90 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
91 c.checkFieldIOobject(c, typeId);
94 forAllIter(typename Cloud<ParcelType>, c, iter)
96 ParcelType& p = iter();
100 p.typeId_ = typeId[i];
106 template<class ParcelType>
107 void Foam::DsmcParcel<ParcelType>::writeFields(const DsmcCloud<ParcelType>& c)
109 Particle<ParcelType>::writeFields(c);
113 IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
114 IOField<scalar> Ei(c.fieldIOobject("Ei", IOobject::NO_READ), np);
115 IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
118 forAllConstIter(typename Cloud<ParcelType>, c, iter)
120 const DsmcParcel<ParcelType>& p = iter();
124 typeId[i] = p.typeId();
134 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
136 template<class ParcelType>
137 Foam::Ostream& Foam::operator<<
140 const DsmcParcel<ParcelType>& p
143 if (os.format() == IOstream::ASCII)
145 os << static_cast<const Particle<ParcelType>& >(p)
146 << token::SPACE << p.U()
147 << token::SPACE << p.Ei()
148 << token::SPACE << p.typeId();
152 os << static_cast<const Particle<ParcelType>& >(p);
155 reinterpret_cast<const char*>(&p.U_),
162 // Check state of Ostream
165 "Ostream& operator<<(Ostream&, const DsmcParcel<ParcelType>&)"
172 // ************************************************************************* //