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) 2011-2016 OpenFOAM Foundation
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 "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<class ParcelType>
32 Foam::string Foam::ReactingMultiphaseParcel<ParcelType>::propertyList_ =
34 
35 template<class ParcelType>
37 (
38  0
39 );
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 template<class ParcelType>
46 (
47  const polyMesh& mesh,
48  Istream& is,
49  bool readFields
50 )
51 :
52  ParcelType(mesh, is, readFields),
53  YGas_(0),
54  YLiquid_(0),
55  YSolid_(0),
56  canCombust_(0)
57 {
58  if (readFields)
59  {
63 
64  is >> Yg >> Yl >> Ys;
65 
66  YGas_.transfer(Yg);
67  YLiquid_.transfer(Yl);
68  YSolid_.transfer(Ys);
69 
70  // scale the mass fractions
71  const scalarField& YMix = this->Y_;
72  YGas_ /= YMix[GAS] + ROOTVSMALL;
73  YLiquid_ /= YMix[LIQ] + ROOTVSMALL;
74  YSolid_ /= YMix[SLD] + ROOTVSMALL;
75  }
76 
77  // Check state of Istream
78  is.check
79  (
80  "ReactingMultiphaseParcel<ParcelType>::ReactingMultiphaseParcel"
81  "("
82  "const polyMesh&, "
83  "Istream&, "
84  "bool"
85  ")"
86  );
87 }
88 
89 
90 template<class ParcelType>
91 template<class CloudType>
93 {
94  if (!c.size())
95  {
96  return;
97  }
98 
100 }
101 
102 
103 template<class ParcelType>
104 template<class CloudType, class CompositionType>
106 (
107  CloudType& c,
108  const CompositionType& compModel
109 )
110 {
111  if (!c.size())
112  {
113  return;
114  }
115 
116  ParcelType::readFields(c, compModel);
117 
118  // Get names and sizes for each Y...
119  const label idGas = compModel.idGas();
120  const wordList& gasNames = compModel.componentNames(idGas);
121  const label idLiquid = compModel.idLiquid();
122  const wordList& liquidNames = compModel.componentNames(idLiquid);
123  const label idSolid = compModel.idSolid();
124  const wordList& solidNames = compModel.componentNames(idSolid);
125  const wordList& stateLabels = compModel.stateLabels();
126 
127  // Set storage for each Y... for each parcel
129  {
131  p.YGas_.setSize(gasNames.size(), 0.0);
132  p.YLiquid_.setSize(liquidNames.size(), 0.0);
133  p.YSolid_.setSize(solidNames.size(), 0.0);
134  }
135 
136  // Populate YGas for each parcel
137  forAll(gasNames, j)
138  {
139  IOField<scalar> YGas
140  (
141  c.fieldIOobject
142  (
143  "Y" + gasNames[j] + stateLabels[idGas],
144  IOobject::MUST_READ
145  )
146  );
147 
148  label i = 0;
149  forAllIter
150  (
152  c,
153  iter
154  )
155  {
157  p.YGas_[j] = YGas[i++]/(p.Y()[GAS] + ROOTVSMALL);
158  }
159  }
160  // Populate YLiquid for each parcel
161  forAll(liquidNames, j)
162  {
163  IOField<scalar> YLiquid
164  (
165  c.fieldIOobject
166  (
167  "Y" + liquidNames[j] + stateLabels[idLiquid],
168  IOobject::MUST_READ
169  )
170  );
171 
172  label i = 0;
173  forAllIter
174  (
176  c,
177  iter
178  )
179  {
181  p.YLiquid_[j] = YLiquid[i++]/(p.Y()[LIQ] + ROOTVSMALL);
182  }
183  }
184  // Populate YSolid for each parcel
185  forAll(solidNames, j)
186  {
187  IOField<scalar> YSolid
188  (
189  c.fieldIOobject
190  (
191  "Y" + solidNames[j] + stateLabels[idSolid],
192  IOobject::MUST_READ
193  )
194  );
195 
196  label i = 0;
197  forAllIter
198  (
200  c,
201  iter
202  )
203  {
205  p.YSolid_[j] = YSolid[i++]/(p.Y()[SLD] + ROOTVSMALL);
206  }
207  }
208 }
209 
210 
211 template<class ParcelType>
212 template<class CloudType>
214 {
215  ParcelType::writeFields(c);
216 }
217 
218 
219 template<class ParcelType>
220 template<class CloudType, class CompositionType>
222 (
223  const CloudType& c,
224  const CompositionType& compModel
225 )
226 {
227  ParcelType::writeFields(c, compModel);
228 
229  label np = c.size();
230 
231  // Write the composition fractions
232  if (np > 0)
233  {
234  const wordList& stateLabels = compModel.stateLabels();
235 
236  const label idGas = compModel.idGas();
237  const wordList& gasNames = compModel.componentNames(idGas);
238  forAll(gasNames, j)
239  {
240  IOField<scalar> YGas
241  (
242  c.fieldIOobject
243  (
244  "Y" + gasNames[j] + stateLabels[idGas],
245  IOobject::NO_READ
246  ),
247  np
248  );
249 
250  label i = 0;
252  (
254  c,
255  iter
256  )
257  {
258  const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
259  YGas[i++] = p0.YGas()[j]*p0.Y()[GAS];
260  }
261 
262  YGas.write();
263  }
264 
265  const label idLiquid = compModel.idLiquid();
266  const wordList& liquidNames = compModel.componentNames(idLiquid);
267  forAll(liquidNames, j)
268  {
269  IOField<scalar> YLiquid
270  (
271  c.fieldIOobject
272  (
273  "Y" + liquidNames[j] + stateLabels[idLiquid],
274  IOobject::NO_READ
275  ),
276  np
277  );
278 
279  label i = 0;
281  (
283  c,
284  iter
285  )
286  {
287  const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
288  YLiquid[i++] = p0.YLiquid()[j]*p0.Y()[LIQ];
289  }
290 
291  YLiquid.write();
292  }
293 
294  const label idSolid = compModel.idSolid();
295  const wordList& solidNames = compModel.componentNames(idSolid);
296  forAll(solidNames, j)
297  {
298  IOField<scalar> YSolid
299  (
300  c.fieldIOobject
301  (
302  "Y" + solidNames[j] + stateLabels[idSolid],
303  IOobject::NO_READ
304  ),
305  np
306  );
307 
308  label i = 0;
310  (
312  c,
313  iter
314  )
315  {
316  const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
317  YSolid[i++] = p0.YSolid()[j]*p0.Y()[SLD];
318  }
319 
320  YSolid.write();
321  }
322  }
323 }
324 
325 
326 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
327 
328 template<class ParcelType>
329 Foam::Ostream& Foam::operator<<
330 (
331  Ostream& os,
333 )
334 {
335  scalarField YGasLoc(p.YGas()*p.Y()[0]);
336  scalarField YLiquidLoc(p.YLiquid()*p.Y()[1]);
337  scalarField YSolidLoc(p.YSolid()*p.Y()[2]);
338  if (os.format() == IOstream::ASCII)
339  {
340  os << static_cast<const ParcelType&>(p)
341  << token::SPACE << YGasLoc
342  << token::SPACE << YLiquidLoc
343  << token::SPACE << YSolidLoc;
344  }
345  else
346  {
347  os << static_cast<const ParcelType&>(p);
348  os << YGasLoc << YLiquidLoc << YSolidLoc;
349  }
350 
351  // Check state of Ostream
352  os.check
353  (
354  "Ostream& operator<<"
355  "("
356  "Ostream&, "
357  "const ReactingMultiphaseParcel<ParcelType>&"
358  ")"
359  );
360 
361  return os;
362 }
363 
364 
365 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
static void writeFields(const CloudType &c, const CompositionType &compModel)
Write.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:453
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static void readFields(CloudType &c, const CompositionType &compModel)
Read.
scalarField YGas_
Mass fractions of gases [].
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
ReactingMultiphaseParcel(const polyMesh &mesh, const vector &position, const label celli, const label tetFacei, const label tetPtI)
Construct from owner, position, and cloud owner.
const scalarField & YLiquid() const
Return const access to mass fractions of liquids.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Base cloud calls templated on particle type.
Definition: Cloud.H:52
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const scalarField & YGas() const
Return const access to mass fractions of gases.
scalarField YSolid_
Mass fractions of solids [].
label size() const
Definition: Cloud.H:175
scalarField YLiquid_
Mass fractions of liquids [].
const scalarField & YSolid() const
Return const access to mass fractions of solids.
Multiphase variant of the reacting parcel class with one/two-way coupling with the continuous phase...
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:195
volScalarField & p
void transfer(List< T > &)
Transfer contents of the argument List into this.
Definition: DynamicListI.H:259
A class for handling character strings derived from std::string.
Definition: string.H:74
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50