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 "ReactingParcel.H"
28 #include "IOstreams.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 template <class ParcelType>
33 Foam::string Foam::ReactingParcel<ParcelType>::propHeader =
34 ThermoParcel<ParcelType>::propHeader
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 template<class ParcelType>
42 Foam::ReactingParcel<ParcelType>::ReactingParcel
44 const Cloud<ParcelType>& cloud,
49 ThermoParcel<ParcelType>(cloud, is, readFields),
56 const ReactingCloud<ParcelType>& cR =
57 dynamic_cast<const ReactingCloud<ParcelType>&>(cloud);
59 const label nMixture = cR.composition().phaseTypes().size();
62 if (is.format() == IOstream::ASCII)
70 reinterpret_cast<char*>(&mass0_),
77 // Check state of Istream
80 "ReactingParcel<ParcelType>::ReactingParcel"
82 "const Cloud<ParcelType>&, "
90 template<class ParcelType>
91 void Foam::ReactingParcel<ParcelType>::readFields(Cloud<ParcelType>& cIn)
98 ReactingCloud<ParcelType>& c =
99 dynamic_cast<ReactingCloud<ParcelType>&>(cIn);
101 ThermoParcel<ParcelType>::readFields(c);
103 IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::MUST_READ));
104 c.checkFieldIOobject(c, mass0);
107 forAllIter(typename Cloud<ParcelType>, c, iter)
109 ReactingParcel<ParcelType>& p = iter();
110 p.mass0_ = mass0[i++];
113 // Get names and sizes for each Y...
114 const wordList& phaseTypes = c.composition().phaseTypes();
115 const label nPhases = phaseTypes.size();
116 wordList stateLabels(nPhases, "");
117 if (c.composition().nPhase() == 1)
119 stateLabels = c.composition().stateLabels();
123 // Set storage for each Y... for each parcel
124 forAllIter(typename Cloud<ParcelType>, c, iter)
126 ReactingParcel<ParcelType>& p = iter();
127 p.Y_.setSize(nPhases, 0.0);
130 // Populate Y for each parcel
131 forAll(phaseTypes, j)
137 "Y" + phaseTypes[j] + stateLabels[j],
143 forAllIter(typename Cloud<ParcelType>, c, iter)
145 ReactingParcel<ParcelType>& p = iter();
152 template<class ParcelType>
153 void Foam::ReactingParcel<ParcelType>::writeFields
155 const Cloud<ParcelType>& cIn
158 const ReactingCloud<ParcelType>& c =
159 dynamic_cast<const ReactingCloud<ParcelType>&>(cIn);
161 ThermoParcel<ParcelType>::writeFields(c);
163 const label np = c.size();
167 IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);
170 forAllConstIter(typename Cloud<ParcelType>, c, iter)
172 const ReactingParcel<ParcelType>& p = iter();
173 mass0[i++] = p.mass0_;
177 // Write the composition fractions
178 const wordList& phaseTypes = c.composition().phaseTypes();
179 wordList stateLabels(phaseTypes.size(), "");
180 if (c.composition().nPhase() == 1)
182 stateLabels = c.composition().stateLabels();
185 forAll(phaseTypes, j)
191 "Y" + phaseTypes[j] + stateLabels[j],
198 forAllConstIter(typename Cloud<ParcelType>, c, iter)
200 const ReactingParcel<ParcelType>& p0 = iter();
210 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
212 template<class ParcelType>
213 Foam::Ostream& Foam::operator<<
216 const ReactingParcel<ParcelType>& p
219 if (os.format() == IOstream::ASCII)
221 os << static_cast<const ThermoParcel<ParcelType>&>(p)
222 << token::SPACE << p.mass0()
223 << token::SPACE << p.Y();
227 os << static_cast<const ThermoParcel<ParcelType>&>(p);
230 reinterpret_cast<const char*>(&p.mass0_),
236 // Check state of Ostream
239 "Ostream& operator<<(Ostream&, const ReactingParcel<ParcelType>&)"
246 // ************************************************************************* //