1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2011 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "ReactingParcel.H"
27 #include "IOstreams.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 template<class ParcelType>
32 Foam::string Foam::ReactingParcel<ParcelType>::propHeader =
33 ParcelType::propHeader
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 template<class ParcelType>
41 Foam::ReactingParcel<ParcelType>::ReactingParcel
48 ParcelType(mesh, is, readFields),
55 DynamicList<scalar> Ymix;
57 if (is.format() == IOstream::ASCII)
65 reinterpret_cast<char*>(&mass0_),
74 // Check state of Istream
77 "ReactingParcel<ParcelType>::ReactingParcel"
87 template<class ParcelType>
88 template<class CloudType>
89 void Foam::ReactingParcel<ParcelType>::readFields(CloudType& c)
96 ParcelType::readFields(c);
100 template<class ParcelType>
101 template<class CloudType, class CompositionType>
102 void Foam::ReactingParcel<ParcelType>::readFields
105 const CompositionType& compModel
113 ParcelType::readFields(c);
115 IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::MUST_READ));
116 c.checkFieldIOobject(c, mass0);
119 forAllIter(typename Cloud<ReactingParcel<ParcelType> >, c, iter)
121 ReactingParcel<ParcelType>& p = iter();
122 p.mass0_ = mass0[i++];
125 // Get names and sizes for each Y...
126 const wordList& phaseTypes = compModel.phaseTypes();
127 const label nPhases = phaseTypes.size();
128 wordList stateLabels(nPhases, "");
129 if (compModel.nPhase() == 1)
131 stateLabels = compModel.stateLabels();
135 // Set storage for each Y... for each parcel
136 forAllIter(typename Cloud<ReactingParcel<ParcelType> >, c, iter)
138 ReactingParcel<ParcelType>& p = iter();
139 p.Y_.setSize(nPhases, 0.0);
142 // Populate Y for each parcel
143 forAll(phaseTypes, j)
149 "Y" + phaseTypes[j] + stateLabels[j],
155 forAllIter(typename Cloud<ReactingParcel<ParcelType> >, c, iter)
157 ReactingParcel<ParcelType>& p = iter();
164 template<class ParcelType>
165 template<class CloudType>
166 void Foam::ReactingParcel<ParcelType>::writeFields(const CloudType& c)
168 ParcelType::writeFields(c);
172 template<class ParcelType>
173 template<class CloudType, class CompositionType>
174 void Foam::ReactingParcel<ParcelType>::writeFields
177 const CompositionType& compModel
180 ParcelType::writeFields(c);
182 const label np = c.size();
186 IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);
189 forAllConstIter(typename Cloud<ReactingParcel<ParcelType> >, c, iter)
191 const ReactingParcel<ParcelType>& p = iter();
192 mass0[i++] = p.mass0_;
196 // Write the composition fractions
197 const wordList& phaseTypes = compModel.phaseTypes();
198 wordList stateLabels(phaseTypes.size(), "");
199 if (compModel.nPhase() == 1)
201 stateLabels = compModel.stateLabels();
204 forAll(phaseTypes, j)
210 "Y" + phaseTypes[j] + stateLabels[j],
218 typename Cloud<ReactingParcel<ParcelType> >,
223 const ReactingParcel<ParcelType>& p = iter();
233 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
235 template<class ParcelType>
236 Foam::Ostream& Foam::operator<<
239 const ReactingParcel<ParcelType>& p
242 if (os.format() == IOstream::ASCII)
244 os << static_cast<const ParcelType&>(p)
245 << token::SPACE << p.mass0()
246 << token::SPACE << p.Y();
250 os << static_cast<const ParcelType&>(p);
253 reinterpret_cast<const char*>(&p.mass0_),
259 // Check state of Ostream
262 "Ostream& operator<<(Ostream&, const ReactingParcel<ParcelType>&)"
269 // ************************************************************************* //