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-2015 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>
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  {
60  DynamicList<scalar> Yg;
61  DynamicList<scalar> Yl;
62  DynamicList<scalar> Ys;
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],
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],
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],
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],
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],
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],
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 // ************************************************************************* //
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:48
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
p
p
Definition: pEqn.H:62
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::ReactingMultiphaseParcel::writeFields
static void writeFields(const CloudType &c, const CompositionType &compModel)
Write.
Definition: ReactingMultiphaseParcelIO.C:222
Foam::ReactingMultiphaseParcel::YGas
const scalarField & YGas() const
Return const access to mass fractions of gases.
Definition: ReactingMultiphaseParcelI.H:173
Foam::ReactingMultiphaseParcel::SLD
static const label SLD
Definition: ReactingMultiphaseParcel.H:80
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::ReactingMultiphaseParcel::readFields
static void readFields(CloudType &c, const CompositionType &compModel)
Read.
Definition: ReactingMultiphaseParcelIO.C:106
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::IOstream::ASCII
@ ASCII
Definition: IOstream.H:88
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::ReactingMultiphaseParcel
Multiphase variant of the reacting parcel class with one/two-way coupling with the continuous phase.
Definition: ReactingMultiphaseParcel.H:50
ReactingMultiphaseParcel.H
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
Foam::ReactingMultiphaseParcel::sizeofFields_
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: ReactingMultiphaseParcel.H:71
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::ReactingMultiphaseParcel::YLiquid
const scalarField & YLiquid() const
Return const access to mass fractions of liquids.
Definition: ReactingMultiphaseParcelI.H:181
Foam::ReactingMultiphaseParcel::LIQ
static const label LIQ
Definition: ReactingMultiphaseParcel.H:79
Foam::ReactingMultiphaseParcel::GAS
static const label GAS
Definition: ReactingMultiphaseParcel.H:78
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
readFields
void readFields(const boolList &haveMesh, const fvMesh &mesh, const autoPtr< fvMeshSubset > &subsetterPtr, IOobjectList &allObjects, PtrList< GeoField > &fields)
Definition: redistributePar.C:589
Foam::ReactingMultiphaseParcel::YLiquid_
scalarField YLiquid_
Mass fractions of liquids [].
Definition: ReactingMultiphaseParcel.H:189
Foam::ReactingMultiphaseParcel::YSolid
const scalarField & YSolid() const
Return const access to mass fractions of solids.
Definition: ReactingMultiphaseParcelI.H:189
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:52
Foam::ReactingMultiphaseParcel::YGas_
scalarField YGas_
Mass fractions of gases [].
Definition: ReactingMultiphaseParcel.H:186
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::ReactingMultiphaseParcel::ReactingMultiphaseParcel
ReactingMultiphaseParcel(const polyMesh &mesh, const vector &position, const label cellI, const label tetFaceI, const label tetPtI)
Construct from owner, position, and cloud owner.
Definition: ReactingMultiphaseParcelI.H:69
Foam::ReactingMultiphaseParcel::YSolid_
scalarField YSolid_
Mass fractions of solids [].
Definition: ReactingMultiphaseParcel.H:192
Foam::token::SPACE
@ SPACE
Definition: token.H:95