FreeFOAM The Cross-Platform CFD Toolkit
ReactingMultiphaseParcelIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include <OpenFOAM/IOstreams.H>
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template <class ParcelType>
33  ReactingParcel<ParcelType>::propHeader
34  + " nGas(Y1..YN)"
35  + " nLiquid(Y1..YN)"
36  + " nSolid(Y1..YN)";
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
41 template<class ParcelType>
43 (
44  const Cloud<ParcelType>& cloud,
45  Istream& is,
46  bool readFields
47 )
48 :
50  YGas_(0),
51  YLiquid_(0),
52  YSolid_(0),
53  canCombust_(false)
54 {
55  if (readFields)
56  {
58  dynamic_cast<const ReactingMultiphaseCloud<ParcelType>&>(cloud);
59 
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();
66 
67  YGas_.setSize(nGas);
68  YLiquid_.setSize(nLiquid);
69  YSolid_.setSize(nSolid);
70 
71  is >> YGas_ >> YLiquid_ >> YSolid_;
72 
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  }
79 
80  // Check state of Istream
81  is.check
82  (
83  "ReactingMultiphaseParcel<ParcelType>::ReactingMultiphaseParcel"
84  "("
85  "const Cloud<ParcelType>&, "
86  "Istream&, "
87  "bool"
88  ")"
89  );
90 }
91 
92 
93 template<class ParcelType>
95 (
97 )
98 {
99  if (!cIn.size())
100  {
101  return;
102  }
103 
105  dynamic_cast<ReactingMultiphaseCloud<ParcelType>&>(cIn);
106 
108 
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();
117 
118  // Set storage for each Y... for each parcel
119  forAllIter(typename Cloud<ParcelType>, c, iter)
120  {
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  }
126 
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  );
138 
139  label i = 0;
140  forAllIter(typename Cloud<ParcelType>, c, iter)
141  {
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  );
157 
158  label i = 0;
159  forAllIter(typename Cloud<ParcelType>, c, iter)
160  {
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  );
176 
177  label i = 0;
178  forAllIter(typename Cloud<ParcelType>, c, iter)
179  {
181  p.YSolid_[j] = YSolid[i++]/(p.Y()[SLD] + ROOTVSMALL);
182  }
183  }
184 }
185 
186 
187 template<class ParcelType>
189 (
190  const Cloud<ParcelType>& cIn
191 )
192 {
194  dynamic_cast<const ReactingMultiphaseCloud<ParcelType>&>(cIn);
195 
197 
198  label np = c.size();
199 
200  // Write the composition fractions
201  if (np > 0)
202  {
203  const wordList& stateLabels = c.composition().stateLabels();
204 
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  );
218 
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  }
225 
226  YGas.write();
227  }
228 
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  );
242 
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  }
249 
250  YLiquid.write();
251  }
252 
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  );
266 
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  }
273 
274  YSolid.write();
275  }
276  }
277 }
278 
279 
280 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
281 
282 template<class ParcelType>
283 Foam::Ostream& Foam::operator<<
284 (
285  Ostream& os,
287 )
288 {
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  }
304 
305  // Check state of Ostream
306  os.check
307  (
308  "Ostream& operator<<"
309  "("
310  "Ostream&, "
311  "const ReactingMultiphaseParcel<ParcelType>&"
312  ")"
313  );
314 
315  return os;
316 }
317 
318 
319 // ************************ vim: set sw=4 sts=4 et: ************************ //