Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / lagrangian / intermediate / parcels / Templates / ReactingMultiphaseParcel / ReactingMultiphaseParcelIO.C
blobe63eeaf2f99107cfbb26ff9b80d592b169169069
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  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     ReactingParcel<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 Cloud<ParcelType>& cloud,
45     Istream& is,
46     bool readFields
49     ReactingParcel<ParcelType>(cloud, is, readFields),
50     YGas_(0),
51     YLiquid_(0),
52     YSolid_(0),
53     canCombust_(false)
55     if (readFields)
56     {
57         const ReactingMultiphaseCloud<ParcelType>& cR =
58             dynamic_cast<const ReactingMultiphaseCloud<ParcelType>&>(cloud);
60         const label idGas = cR.composition().idGas();
61         const label nGas = cR.composition().componentNames(idGas).size();
62         const label idLiquid = cR.composition().idLiquid();
63         const label nLiquid = cR.composition().componentNames(idLiquid).size();
64         const label idSolid = cR.composition().idGas();
65         const label nSolid = cR.composition().componentNames(idSolid).size();
67         YGas_.setSize(nGas);
68         YLiquid_.setSize(nLiquid);
69         YSolid_.setSize(nSolid);
71         is >> YGas_ >> YLiquid_ >> YSolid_;
73         // scale the mass fractions
74         const scalarField& YMix = this->Y_;
75         YGas_ /= YMix[GAS] + ROOTVSMALL;
76         YLiquid_ /= YMix[LIQ] + ROOTVSMALL;
77         YSolid_ /= YMix[SLD] + ROOTVSMALL;
78     }
80     // Check state of Istream
81     is.check
82     (
83         "ReactingMultiphaseParcel<ParcelType>::ReactingMultiphaseParcel"
84         "("
85             "const Cloud<ParcelType>&, "
86             "Istream&, "
87             "bool"
88         ")"
89     );
93 template<class ParcelType>
94 void Foam::ReactingMultiphaseParcel<ParcelType>::readFields
96     Cloud<ParcelType>& cIn
99     if (!cIn.size())
100     {
101         return;
102     }
104     ReactingMultiphaseCloud<ParcelType>& c =
105         dynamic_cast<ReactingMultiphaseCloud<ParcelType>&>(cIn);
107     ReactingParcel<ParcelType>::readFields(c);
109     // Get names and sizes for each Y...
110     const label idGas = c.composition().idGas();
111     const wordList& gasNames = c.composition().componentNames(idGas);
112     const label idLiquid = c.composition().idLiquid();
113     const wordList& liquidNames = c.composition().componentNames(idLiquid);
114     const label idSolid = c.composition().idSolid();
115     const wordList& solidNames = c.composition().componentNames(idSolid);
116     const wordList& stateLabels = c.composition().stateLabels();
118     // Set storage for each Y... for each parcel
119     forAllIter(typename Cloud<ParcelType>, c, iter)
120     {
121         ReactingMultiphaseParcel<ParcelType>& p = iter();
122         p.YGas_.setSize(gasNames.size(), 0.0);
123         p.YLiquid_.setSize(liquidNames.size(), 0.0);
124         p.YSolid_.setSize(solidNames.size(), 0.0);
125     }
127     // Populate YGas for each parcel
128     forAll(gasNames, j)
129     {
130         IOField<scalar> YGas
131         (
132             c.fieldIOobject
133             (
134                 "Y" + gasNames[j] + stateLabels[idGas],
135                 IOobject::MUST_READ
136             )
137         );
139         label i = 0;
140         forAllIter(typename Cloud<ParcelType>, c, iter)
141         {
142             ReactingMultiphaseParcel<ParcelType>& p = iter();
143             p.YGas_[j] = YGas[i++]/(p.Y()[GAS] + ROOTVSMALL);
144         }
145     }
146     // Populate YLiquid for each parcel
147     forAll(liquidNames, j)
148     {
149         IOField<scalar> YLiquid
150         (
151             c.fieldIOobject
152             (
153                 "Y" + liquidNames[j] + stateLabels[idLiquid],
154                  IOobject::MUST_READ
155             )
156         );
158         label i = 0;
159         forAllIter(typename Cloud<ParcelType>, c, iter)
160         {
161             ReactingMultiphaseParcel<ParcelType>& p = iter();
162             p.YLiquid_[j] = YLiquid[i++]/(p.Y()[LIQ] + ROOTVSMALL);
163         }
164     }
165     // Populate YSolid for each parcel
166     forAll(solidNames, j)
167     {
168         IOField<scalar> YSolid
169         (
170             c.fieldIOobject
171             (
172                 "Y" + solidNames[j] + stateLabels[idSolid],
173                 IOobject::MUST_READ
174             )
175         );
177         label i = 0;
178         forAllIter(typename Cloud<ParcelType>, c, iter)
179         {
180             ReactingMultiphaseParcel<ParcelType>& p = iter();
181             p.YSolid_[j] = YSolid[i++]/(p.Y()[SLD] + ROOTVSMALL);
182         }
183     }
187 template<class ParcelType>
188 void Foam::ReactingMultiphaseParcel<ParcelType>::writeFields
190     const Cloud<ParcelType>& cIn
193     const ReactingMultiphaseCloud<ParcelType>& c =
194         dynamic_cast<const ReactingMultiphaseCloud<ParcelType>&>(cIn);
196     ReactingParcel<ParcelType>::writeFields(c);
198     label np =  c.size();
200     // Write the composition fractions
201     if (np > 0)
202     {
203         const wordList& stateLabels = c.composition().stateLabels();
205         const label idGas = c.composition().idGas();
206         const wordList& gasNames = c.composition().componentNames(idGas);
207         forAll(gasNames, j)
208         {
209             IOField<scalar> YGas
210             (
211                 c.fieldIOobject
212                 (
213                     "Y" + gasNames[j] + stateLabels[idGas],
214                     IOobject::NO_READ
215                 ),
216                 np
217             );
219             label i = 0;
220             forAllConstIter(typename Cloud<ParcelType>, c, iter)
221             {
222                 const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
223                 YGas[i++] = p0.YGas()[j]*p0.Y()[GAS];
224             }
226             YGas.write();
227         }
229         const label idLiquid = c.composition().idLiquid();
230         const wordList& liquidNames = c.composition().componentNames(idLiquid);
231         forAll(liquidNames, j)
232         {
233             IOField<scalar> YLiquid
234             (
235                 c.fieldIOobject
236                 (
237                     "Y" + liquidNames[j] + stateLabels[idLiquid],
238                     IOobject::NO_READ
239                 ),
240                 np
241             );
243             label i = 0;
244             forAllConstIter(typename Cloud<ParcelType>, c, iter)
245             {
246                 const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
247                 YLiquid[i++] = p0.YLiquid()[j]*p0.Y()[LIQ];
248             }
250             YLiquid.write();
251         }
253         const label idSolid = c.composition().idSolid();
254         const wordList& solidNames = c.composition().componentNames(idSolid);
255         forAll(solidNames, j)
256         {
257             IOField<scalar> YSolid
258             (
259                 c.fieldIOobject
260                 (
261                     "Y" + solidNames[j] + stateLabels[idSolid],
262                     IOobject::NO_READ
263                 ),
264                 np
265             );
267             label i = 0;
268             forAllConstIter(typename Cloud<ParcelType>, c, iter)
269             {
270                 const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
271                 YSolid[i++] = p0.YSolid()[j]*p0.Y()[SLD];
272             }
274             YSolid.write();
275         }
276     }
280 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
282 template<class ParcelType>
283 Foam::Ostream& Foam::operator<<
285     Ostream& os,
286     const ReactingMultiphaseParcel<ParcelType>& p
289     scalarField YGasLoc = p.YGas()*p.Y()[0];
290     scalarField YLiquidLoc = p.YLiquid()*p.Y()[1];
291     scalarField YSolidLoc = p.YSolid()*p.Y()[2];
292     if (os.format() == IOstream::ASCII)
293     {
294         os  << static_cast<const ReactingParcel<ParcelType>&>(p)
295             << token::SPACE << YGasLoc
296             << token::SPACE << YLiquidLoc
297             << token::SPACE << YSolidLoc;
298     }
299     else
300     {
301         os  << static_cast<const ReactingParcel<ParcelType>&>(p);
302         os  << YGasLoc << YLiquidLoc << YSolidLoc;
303     }
305     // Check state of Ostream
306     os.check
307     (
308         "Ostream& operator<<"
309         "("
310             "Ostream&, "
311             "const ReactingMultiphaseParcel<ParcelType>&"
312         ")"
313     );
315     return os;
319 // ************************************************************************* //