FreeFOAM The Cross-Platform CFD Toolkit
ReactingParcelIO.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) 1991-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 
26 #include "ReactingParcel_.H"
27 #include <OpenFOAM/IOstreams.H>
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template <class ParcelType>
33  ThermoParcel<ParcelType>::propHeader
34  + " mass0"
35  + " nPhases(Y1..YN)";
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
40 template<class ParcelType>
42 (
43  const Cloud<ParcelType>& cloud,
44  Istream& is,
45  bool readFields
46 )
47 :
49  mass0_(0.0),
50  Y_(0),
51  pc_(0.0)
52 {
53  if (readFields)
54  {
55  const ReactingCloud<ParcelType>& cR =
56  dynamic_cast<const ReactingCloud<ParcelType>&>(cloud);
57 
58  const label nMixture = cR.composition().phaseTypes().size();
59  Y_.setSize(nMixture);
60 
61  if (is.format() == IOstream::ASCII)
62  {
63  is >> mass0_ >> Y_;
64  }
65  else
66  {
67  is.read
68  (
69  reinterpret_cast<char*>(&mass0_),
70  + sizeof(mass0_)
71  );
72  is >> Y_;
73  }
74  }
75 
76  // Check state of Istream
77  is.check
78  (
79  "ReactingParcel<ParcelType>::ReactingParcel"
80  "("
81  "const Cloud<ParcelType>&, "
82  "Istream&, "
83  "bool"
84  ")"
85  );
86 }
87 
88 
89 template<class ParcelType>
91 {
92  if (!cIn.size())
93  {
94  return;
95  }
96 
98  dynamic_cast<ReactingCloud<ParcelType>&>(cIn);
99 
101 
102  IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::MUST_READ));
103  c.checkFieldIOobject(c, mass0);
104 
105  label i = 0;
106  forAllIter(typename Cloud<ParcelType>, c, iter)
107  {
108  ReactingParcel<ParcelType>& p = iter();
109  p.mass0_ = mass0[i++];
110  }
111 
112  // Get names and sizes for each Y...
113  const wordList& phaseTypes = c.composition().phaseTypes();
114  const label nPhases = phaseTypes.size();
115  wordList stateLabels(nPhases, "");
116  if (c.composition().nPhase() == 1)
117  {
118  stateLabels = c.composition().stateLabels();
119  }
120 
121 
122  // Set storage for each Y... for each parcel
123  forAllIter(typename Cloud<ParcelType>, c, iter)
124  {
125  ReactingParcel<ParcelType>& p = iter();
126  p.Y_.setSize(nPhases, 0.0);
127  }
128 
129  // Populate Y for each parcel
130  forAll(phaseTypes, j)
131  {
133  (
134  c.fieldIOobject
135  (
136  "Y" + phaseTypes[j] + stateLabels[j],
137  IOobject::MUST_READ
138  )
139  );
140 
141  label i = 0;
142  forAllIter(typename Cloud<ParcelType>, c, iter)
143  {
144  ReactingParcel<ParcelType>& p = iter();
145  p.Y_[j] = Y[i++];
146  }
147  }
148 }
149 
150 
151 template<class ParcelType>
153 (
154  const Cloud<ParcelType>& cIn
155 )
156 {
157  const ReactingCloud<ParcelType>& c =
158  dynamic_cast<const ReactingCloud<ParcelType>&>(cIn);
159 
161 
162  const label np = c.size();
163 
164  if (np > 0)
165  {
166  IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);
167 
168  label i = 0;
169  forAllConstIter(typename Cloud<ParcelType>, c, iter)
170  {
171  const ReactingParcel<ParcelType>& p = iter();
172  mass0[i++] = p.mass0_;
173  }
174  mass0.write();
175 
176  // Write the composition fractions
177  const wordList& phaseTypes = c.composition().phaseTypes();
178  wordList stateLabels(phaseTypes.size(), "");
179  if (c.composition().nPhase() == 1)
180  {
181  stateLabels = c.composition().stateLabels();
182  }
183 
184  forAll(phaseTypes, j)
185  {
187  (
188  c.fieldIOobject
189  (
190  "Y" + phaseTypes[j] + stateLabels[j],
191  IOobject::NO_READ
192  ),
193  np
194  );
195 
196  label i = 0;
197  forAllConstIter(typename Cloud<ParcelType>, c, iter)
198  {
199  const ReactingParcel<ParcelType>& p0 = iter();
200  Y[i++] = p0.Y()[j];
201  }
202 
203  Y.write();
204  }
205  }
206 }
207 
208 
209 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
210 
211 template<class ParcelType>
212 Foam::Ostream& Foam::operator<<
213 (
214  Ostream& os,
216 )
217 {
218  if (os.format() == IOstream::ASCII)
219  {
220  os << static_cast<const ThermoParcel<ParcelType>&>(p)
221  << token::SPACE << p.mass0()
222  << token::SPACE << p.Y();
223  }
224  else
225  {
226  os << static_cast<const ThermoParcel<ParcelType>&>(p);
227  os.write
228  (
229  reinterpret_cast<const char*>(&p.mass0_),
230  sizeof(p.mass0())
231  );
232  os << p.Y();
233  }
234 
235  // Check state of Ostream
236  os.check
237  (
238  "Ostream& operator<<(Ostream&, const ReactingParcel<ParcelType>&)"
239  );
240 
241  return os;
242 }
243 
244 
245 // ************************ vim: set sw=4 sts=4 et: ************************ //