ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / lagrangian / intermediate / parcels / Templates / ReactingMultiphaseParcel / ReactingMultiphaseParcelIO.C
blob66d6095ae45fa05a02747120bcb099c1550e6d94
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 "ReactingMultiphaseParcel.H"
27 #include "IOstreams.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 template<class ParcelType>
32 Foam::string Foam::ReactingMultiphaseParcel<ParcelType>::propHeader =
33     ParcelType::propHeader
34   + " nGas(Y1..YN)"
35   + " nLiquid(Y1..YN)"
36   + " nSolid(Y1..YN)";
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 template<class ParcelType>
42 Foam::ReactingMultiphaseParcel<ParcelType>::ReactingMultiphaseParcel
44     const polyMesh& mesh,
45     Istream& is,
46     bool readFields
49     ParcelType(mesh, is, readFields),
50     YGas_(0),
51     YLiquid_(0),
52     YSolid_(0),
53     canCombust_(false)
55     if (readFields)
56     {
57         DynamicList<scalar> Yg;
58         DynamicList<scalar> Yl;
59         DynamicList<scalar> Ys;
61         is >> Yg >> Yl >> Ys;
63         YGas_.transfer(Yg);
64         YLiquid_.transfer(Yl);
65         YSolid_.transfer(Ys);
67         // scale the mass fractions
68         const scalarField& YMix = this->Y_;
69         YGas_ /= YMix[GAS] + ROOTVSMALL;
70         YLiquid_ /= YMix[LIQ] + ROOTVSMALL;
71         YSolid_ /= YMix[SLD] + ROOTVSMALL;
72     }
74     // Check state of Istream
75     is.check
76     (
77         "ReactingMultiphaseParcel<ParcelType>::ReactingMultiphaseParcel"
78         "("
79             "const polyMesh&, "
80             "Istream&, "
81             "bool"
82         ")"
83     );
87 template<class ParcelType>
88 template<class CloudType>
89 void Foam::ReactingMultiphaseParcel<ParcelType>::readFields(CloudType& c)
91     if (!c.size())
92     {
93         return;
94     }
96     ParcelType::readFields(c);
100 template<class ParcelType>
101 template<class CloudType, class CompositionType>
102 void Foam::ReactingMultiphaseParcel<ParcelType>::readFields
104     CloudType& c,
105     const CompositionType& compModel
108     if (!c.size())
109     {
110         return;
111     }
113     ParcelType::readFields(c, compModel);
115     // Get names and sizes for each Y...
116     const label idGas = compModel.idGas();
117     const wordList& gasNames = compModel.componentNames(idGas);
118     const label idLiquid = compModel.idLiquid();
119     const wordList& liquidNames = compModel.componentNames(idLiquid);
120     const label idSolid = compModel.idSolid();
121     const wordList& solidNames = compModel.componentNames(idSolid);
122     const wordList& stateLabels = compModel.stateLabels();
124     // Set storage for each Y... for each parcel
125     forAllIter(typename Cloud<ReactingMultiphaseParcel<ParcelType> >, c, iter)
126     {
127         ReactingMultiphaseParcel<ParcelType>& p = iter();
128         p.YGas_.setSize(gasNames.size(), 0.0);
129         p.YLiquid_.setSize(liquidNames.size(), 0.0);
130         p.YSolid_.setSize(solidNames.size(), 0.0);
131     }
133     // Populate YGas for each parcel
134     forAll(gasNames, j)
135     {
136         IOField<scalar> YGas
137         (
138             c.fieldIOobject
139             (
140                 "Y" + gasNames[j] + stateLabels[idGas],
141                 IOobject::MUST_READ
142             )
143         );
145         label i = 0;
146         forAllIter
147         (
148             typename Cloud<ReactingMultiphaseParcel<ParcelType> >,
149             c,
150             iter
151         )
152         {
153             ReactingMultiphaseParcel<ParcelType>& p = iter();
154             p.YGas_[j] = YGas[i++]/(p.Y()[GAS] + ROOTVSMALL);
155         }
156     }
157     // Populate YLiquid for each parcel
158     forAll(liquidNames, j)
159     {
160         IOField<scalar> YLiquid
161         (
162             c.fieldIOobject
163             (
164                 "Y" + liquidNames[j] + stateLabels[idLiquid],
165                  IOobject::MUST_READ
166             )
167         );
169         label i = 0;
170         forAllIter
171         (
172             typename Cloud<ReactingMultiphaseParcel<ParcelType> >,
173             c,
174             iter
175         )
176         {
177             ReactingMultiphaseParcel<ParcelType>& p = iter();
178             p.YLiquid_[j] = YLiquid[i++]/(p.Y()[LIQ] + ROOTVSMALL);
179         }
180     }
181     // Populate YSolid for each parcel
182     forAll(solidNames, j)
183     {
184         IOField<scalar> YSolid
185         (
186             c.fieldIOobject
187             (
188                 "Y" + solidNames[j] + stateLabels[idSolid],
189                 IOobject::MUST_READ
190             )
191         );
193         label i = 0;
194         forAllIter
195         (
196             typename Cloud<ReactingMultiphaseParcel<ParcelType> >,
197             c,
198             iter
199         )
200         {
201             ReactingMultiphaseParcel<ParcelType>& p = iter();
202             p.YSolid_[j] = YSolid[i++]/(p.Y()[SLD] + ROOTVSMALL);
203         }
204     }
208 template<class ParcelType>
209 template<class CloudType>
210 void Foam::ReactingMultiphaseParcel<ParcelType>::writeFields(const CloudType& c)
212     ParcelType::writeFields(c);
216 template<class ParcelType>
217 template<class CloudType, class CompositionType>
218 void Foam::ReactingMultiphaseParcel<ParcelType>::writeFields
220     const CloudType& c,
221     const CompositionType& compModel
224     ParcelType::writeFields(c, compModel);
226     label np = c.size();
228     // Write the composition fractions
229     if (np > 0)
230     {
231         const wordList& stateLabels = compModel.stateLabels();
233         const label idGas = compModel.idGas();
234         const wordList& gasNames = compModel.componentNames(idGas);
235         forAll(gasNames, j)
236         {
237             IOField<scalar> YGas
238             (
239                 c.fieldIOobject
240                 (
241                     "Y" + gasNames[j] + stateLabels[idGas],
242                     IOobject::NO_READ
243                 ),
244                 np
245             );
247             label i = 0;
248             forAllConstIter
249             (
250                 typename Cloud<ReactingMultiphaseParcel<ParcelType> >,
251                 c,
252                 iter
253             )
254             {
255                 const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
256                 YGas[i++] = p0.YGas()[j]*p0.Y()[GAS];
257             }
259             YGas.write();
260         }
262         const label idLiquid = compModel.idLiquid();
263         const wordList& liquidNames = compModel.componentNames(idLiquid);
264         forAll(liquidNames, j)
265         {
266             IOField<scalar> YLiquid
267             (
268                 c.fieldIOobject
269                 (
270                     "Y" + liquidNames[j] + stateLabels[idLiquid],
271                     IOobject::NO_READ
272                 ),
273                 np
274             );
276             label i = 0;
277             forAllConstIter
278             (
279                 typename Cloud<ReactingMultiphaseParcel<ParcelType> >,
280                 c,
281                 iter
282             )
283             {
284                 const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
285                 YLiquid[i++] = p0.YLiquid()[j]*p0.Y()[LIQ];
286             }
288             YLiquid.write();
289         }
291         const label idSolid = compModel.idSolid();
292         const wordList& solidNames = compModel.componentNames(idSolid);
293         forAll(solidNames, j)
294         {
295             IOField<scalar> YSolid
296             (
297                 c.fieldIOobject
298                 (
299                     "Y" + solidNames[j] + stateLabels[idSolid],
300                     IOobject::NO_READ
301                 ),
302                 np
303             );
305             label i = 0;
306             forAllConstIter
307             (
308                 typename Cloud<ReactingMultiphaseParcel<ParcelType> >,
309                 c,
310                 iter
311             )
312             {
313                 const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
314                 YSolid[i++] = p0.YSolid()[j]*p0.Y()[SLD];
315             }
317             YSolid.write();
318         }
319     }
323 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
325 template<class ParcelType>
326 Foam::Ostream& Foam::operator<<
328     Ostream& os,
329     const ReactingMultiphaseParcel<ParcelType>& p
332     scalarField YGasLoc(p.YGas()*p.Y()[0]);
333     scalarField YLiquidLoc(p.YLiquid()*p.Y()[1]);
334     scalarField YSolidLoc(p.YSolid()*p.Y()[2]);
335     if (os.format() == IOstream::ASCII)
336     {
337         os  << static_cast<const ParcelType&>(p)
338             << token::SPACE << YGasLoc
339             << token::SPACE << YLiquidLoc
340             << token::SPACE << YSolidLoc;
341     }
342     else
343     {
344         os  << static_cast<const ParcelType&>(p);
345         os  << YGasLoc << YLiquidLoc << YSolidLoc;
346     }
348     // Check state of Ostream
349     os.check
350     (
351         "Ostream& operator<<"
352         "("
353             "Ostream&, "
354             "const ReactingMultiphaseParcel<ParcelType>&"
355         ")"
356     );
358     return os;
362 // ************************************************************************* //