Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / lagrangian / dieselSpray / parcel / parcelIO.C
blob8ce302574d4cec59658f64092ccf5b1d4a8b5724
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2011 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "parcel.H"
27 #include "IOstreams.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::parcel::parcel
33     const polyMesh& mesh,
34     Istream& is,
35     bool readFields
38     particle(mesh, is, readFields),
40     liquidComponents_
41     (
42         (
43             mesh.lookupObject<dictionary>("thermophysicalProperties")
44         ).lookup("liquidComponents")
45     ),
46     X_(liquidComponents_.size(), 0.0),
48     tMom_(GREAT)
51     label nX = X_.size();
53     if (readFields)
54     {
55         if (is.format() == IOstream::ASCII)
56         {
57             d_ = readScalar(is);
58             T_ = readScalar(is);
59             m_ = readScalar(is);
60             y_ = readScalar(is);
61             yDot_ = readScalar(is);
62             ct_ = readScalar(is);
63             ms_ = readScalar(is);
64             tTurb_ = readScalar(is);
65             liquidCore_ = readScalar(is);
66             injector_ = readScalar(is);
67             is >> U_;
68             is >> Uturb_;
69             is >> n_;
70             for (label j=0; j<nX; j++)
71             {
72                 X_[j] = readScalar(is);
73             }
74         }
75         else
76         {
77             is.read
78             (
79                 reinterpret_cast<char*>(&d_),
80                 sizeof(d_) + sizeof(T_) + sizeof(m_) + sizeof(y_)
81               + sizeof(yDot_) + sizeof(ct_) + sizeof(ms_) + sizeof(tTurb_)
82               + sizeof(liquidCore_) + sizeof(injector_)
83               + sizeof(U_) + sizeof(Uturb_) + sizeof(n_)
84             );
86             is.read
87             (
88                 reinterpret_cast<char*>(X_.begin()),
89                 X_.size()*sizeof(scalar)
90             );
91         }
92     }
94     // Check state of Istream
95     is.check("parcel::parcel(Istream&)");
99 void Foam::parcel::readFields(Cloud<parcel>& c)
101     if (!c.size())
102     {
103         return;
104     }
106     particle::readFields(c);
108     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
109     c.checkFieldIOobject(c, d);
111     IOField<scalar> T(c.fieldIOobject("T", IOobject::MUST_READ));
112     c.checkFieldIOobject(c, T);
114     IOField<scalar> m(c.fieldIOobject("m", IOobject::MUST_READ));
115     c.checkFieldIOobject(c, m);
117     IOField<scalar> y(c.fieldIOobject("y", IOobject::MUST_READ));
118     c.checkFieldIOobject(c, y);
120     IOField<scalar> yDot(c.fieldIOobject("yDot", IOobject::MUST_READ));
121     c.checkFieldIOobject(c, yDot);
123     IOField<scalar> ct(c.fieldIOobject("ct", IOobject::MUST_READ));
124     c.checkFieldIOobject(c, ct);
126     IOField<scalar> ms(c.fieldIOobject("ms", IOobject::MUST_READ));
127     c.checkFieldIOobject(c, ms);
129     IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::MUST_READ));
130     c.checkFieldIOobject(c, tTurb);
132     IOField<scalar> liquidCore
133     (
134         c.fieldIOobject("liquidCore", IOobject::MUST_READ)
135     );
136     c.checkFieldIOobject(c, liquidCore);
138     IOField<scalar> injector(c.fieldIOobject("injector", IOobject::MUST_READ));
139     c.checkFieldIOobject(c, injector);
141     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
142     c.checkFieldIOobject(c, U);
144     IOField<vector> Uturb(c.fieldIOobject("Uturb", IOobject::MUST_READ));
145     c.checkFieldIOobject(c, Uturb);
147     IOField<vector> n(c.fieldIOobject("n", IOobject::MUST_READ));
148     c.checkFieldIOobject(c, n);
150     label i = 0;
151     forAllIter(Cloud<parcel>, c, iter)
152     {
153         parcel& p = iter();
155         p.d_ = d[i];
156         p.T_ = T[i];
157         p.m_ = m[i];
158         p.y_ = y[i];
159         p.yDot_ = yDot[i];
160         p.ct_ = ct[i];
161         p.ms_ = ms[i];
162         p.tTurb_ = tTurb[i];
163         p.liquidCore_ = liquidCore[i];
164         p.injector_ = injector[i];
166         p.U_ = U[i];
167         p.Uturb_ = Uturb[i];
168         p.n_ = n[i];
170         i++;
171     }
173     // read the liquid molar fractions
174     if (c.size())
175     {
176         Cloud<parcel>::const_iterator iter = c.begin();
177         const parcel& p0 = iter();
179         label nX = p0.X().size();
180         const List<word>& names = p0.liquidNames();
182         for (label j=0; j<nX; j++)
183         {
184             IOField<scalar> X(c.fieldIOobject(names[j], IOobject::MUST_READ));
186             label i = 0;
187             forAllIter(Cloud<parcel>, c, iter)
188             {
189                 parcel& p = iter();
190                 p.X_[j] = X[i++];
191             }
192         }
193     }
197 void Foam::parcel::writeFields(const Cloud<parcel>& c)
199     particle::writeFields(c);
201     label np = c.size();
203     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
204     IOField<scalar> T(c.fieldIOobject("T", IOobject::NO_READ), np);
205     IOField<scalar> m(c.fieldIOobject("m", IOobject::NO_READ), np);
206     IOField<scalar> y(c.fieldIOobject("y", IOobject::NO_READ), np);
207     IOField<scalar> yDot(c.fieldIOobject("yDot", IOobject::NO_READ), np);
208     IOField<scalar> ct(c.fieldIOobject("ct", IOobject::NO_READ), np);
209     IOField<scalar> ms(c.fieldIOobject("ms", IOobject::NO_READ), np);
210     IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::NO_READ), np);
211     IOField<scalar> liquidCore
212     (
213         c.fieldIOobject("liquidCore", IOobject::NO_READ),
214         np
215     );
216     IOField<scalar> injector
217     (
218         c.fieldIOobject("injector", IOobject::NO_READ),
219         np
220     );
221     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
222     IOField<vector> Uturb(c.fieldIOobject("Uturb", IOobject::NO_READ), np);
223     IOField<vector> n(c.fieldIOobject("n", IOobject::NO_READ), np);
225     label i = 0;
226     forAllConstIter(Cloud<parcel>, c, iter)
227     {
228         const parcel& p = iter();
230         d[i] = p.d_;
231         T[i] = p.T_;
232         m[i] = p.m_;
233         y[i] = p.y_;
234         yDot[i] = p.yDot_;
235         ct[i] = p.ct_;
236         ms[i] = p.ms_;
237         tTurb[i] = p.tTurb_;
238         liquidCore[i] = p.liquidCore_;
239         injector[i] = p.injector_;
241         U[i] = p.U_;
242         Uturb[i] = p.Uturb_;
243         n[i] = p.n_;
245         i++;
246     }
248     d.write();
249     T.write();
250     m.write();
251     y.write();
252     yDot.write();
253     ct.write();
254     ms.write();
255     tTurb.write();
256     liquidCore.write();
257     injector.write();
259     U.write();
260     Uturb.write();
261     n.write();
263     // write the liquid molar fractions
264     if (np > 0)
265     {
266         Cloud<parcel>::const_iterator iter = c.begin();
267         const parcel& p0 = iter();
269         label nX = p0.X().size();
270         const List<word>& names = p0.liquidNames();
272         for (label j=0; j<nX; j++)
273         {
274             IOField<scalar> X(c.fieldIOobject(names[j], IOobject::NO_READ), np);
276             label i = 0;
277             forAllConstIter(Cloud<parcel>, c, iter)
278             {
279                 const parcel& p = iter();
280                 X[i++] = p.X()[j];
281             }
283             X.write();
284         }
285     }
289 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
291 Foam::Ostream& Foam::operator<<(Ostream& os, const parcel& p)
293     if (os.format() == IOstream::ASCII)
294     {
295         os  << static_cast<const particle&>(p)
296             << token::SPACE << p.d_
297             << token::SPACE << p.T_
298             << token::SPACE << p.m_
299             << token::SPACE << p.y_
300             << token::SPACE << p.yDot_
301             << token::SPACE << p.ct_
302             << token::SPACE << p.ms_
303             << token::SPACE << p.tTurb_
304             << token::SPACE << p.liquidCore_
305             << token::SPACE << p.injector_
306             << token::SPACE << p.U_
307             << token::SPACE << p.Uturb_
308             << token::SPACE << p.n_
309             << token::SPACE << p.X_;
310     }
311     else
312     {
313         os  << static_cast<const particle>(p);
314         os.write
315         (
316             reinterpret_cast<const char*>(&p.d_),
317             sizeof(p.d_) + sizeof(p.T_) + sizeof(p.m_) + sizeof(p.y_)
318           + sizeof(p.yDot_) + sizeof(p.ct_) + sizeof(p.ms_) + sizeof(p.tTurb_)
319           + sizeof(p.liquidCore_) + sizeof(p.injector_)
320           + sizeof(p.U_) + sizeof(p.Uturb_) + sizeof(p.n_)
321         );
323         os.write
324         (
325             reinterpret_cast<const char*>(p.X_.begin()),
326             p.X_.size()*sizeof(scalar)
327         );
328     }
330     // Check state of Ostream
331     os.check("Ostream& operator<<(Ostream&, const parcel&)");
333     return os;
337 // ************************************************************************* //