BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / lagrangian / intermediate / parcels / Templates / KinematicParcel / KinematicParcelIO.C
blobadd7b1b78f4b558db85e23f04fdaa791c9739ae5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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 "KinematicParcel.H"
27 #include "IOstreams.H"
28 #include "IOField.H"
29 #include "Cloud.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 template<class ParcelType>
34 Foam::string Foam::KinematicParcel<ParcelType>::propHeader =
35     ParcelType::propHeader
36   + " active"
37   + " typeId"
38   + " nParticle"
39   + " d"
40   + " dTarget "
41   + " (Ux Uy Uz)"
42   + " (fx fy fz)"
43   + " (angularMomentumx angularMomentumy angularMomentumz)"
44   + " (torquex torquey torquez)"
45   + " rho"
46   + " age"
47   + " tTurb"
48   + " (UTurbx UTurby UTurbz)";
50 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
52 template<class ParcelType>
53 Foam::KinematicParcel<ParcelType>::KinematicParcel
55     const polyMesh& mesh,
56     Istream& is,
57     bool readFields
60     ParcelType(mesh, is, readFields),
61     active_(false),
62     typeId_(0),
63     nParticle_(0.0),
64     d_(0.0),
65     dTarget_(0.0),
66     U_(vector::zero),
67     f_(vector::zero),
68     angularMomentum_(vector::zero),
69     torque_(vector::zero),
70     rho_(0.0),
71     age_(0.0),
72     tTurb_(0.0),
73     UTurb_(vector::zero),
74     rhoc_(0.0),
75     Uc_(vector::zero),
76     muc_(0.0)
78     if (readFields)
79     {
80         if (is.format() == IOstream::ASCII)
81         {
82             active_ = readBool(is);
83             typeId_ = readLabel(is);
84             nParticle_ = readScalar(is);
85             d_ = readScalar(is);
86             dTarget_ = readScalar(is);
87             is >> U_;
88             is >> f_;
89             is >> angularMomentum_;
90             is >> torque_;
91             rho_ = readScalar(is);
92             age_ = readScalar(is);
93             tTurb_ = readScalar(is);
94             is >> UTurb_;
95         }
96         else
97         {
98             is.read
99             (
100                 reinterpret_cast<char*>(&active_),
101                 sizeof(active_)
102               + sizeof(typeId_)
103               + sizeof(nParticle_)
104               + sizeof(d_)
105               + sizeof(dTarget_)
106               + sizeof(U_)
107               + sizeof(f_)
108               + sizeof(angularMomentum_)
109               + sizeof(torque_)
110               + sizeof(rho_)
111               + sizeof(age_)
112               + sizeof(tTurb_)
113               + sizeof(UTurb_)
114             );
115         }
116     }
118     // Check state of Istream
119     is.check
120     (
121         "KinematicParcel<ParcelType>::KinematicParcel"
122         "(const polyMesh&, Istream&, bool)"
123     );
127 template<class ParcelType>
128 template<class CloudType>
129 void Foam::KinematicParcel<ParcelType>::readFields(CloudType& c)
131     if (!c.size())
132     {
133         return;
134     }
136     ParcelType::readFields(c);
138     IOField<label> active(c.fieldIOobject("active", IOobject::MUST_READ));
139     c.checkFieldIOobject(c, active);
141     IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
142     c.checkFieldIOobject(c, typeId);
144     IOField<scalar>
145         nParticle(c.fieldIOobject("nParticle", IOobject::MUST_READ));
146     c.checkFieldIOobject(c, nParticle);
148     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
149     c.checkFieldIOobject(c, d);
151     IOField<scalar> dTarget(c.fieldIOobject("dTarget", IOobject::MUST_READ));
152     c.checkFieldIOobject(c, dTarget);
154     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
155     c.checkFieldIOobject(c, U);
157     IOField<vector> f(c.fieldIOobject("f", IOobject::MUST_READ));
158     c.checkFieldIOobject(c, f);
160     IOField<vector> angularMomentum
161     (
162         c.fieldIOobject("angularMomentum", IOobject::MUST_READ)
163     );
164     c.checkFieldIOobject(c, angularMomentum);
166     IOField<vector> torque(c.fieldIOobject("torque", IOobject::MUST_READ));
167     c.checkFieldIOobject(c, torque);
169     IOField<scalar> rho(c.fieldIOobject("rho", IOobject::MUST_READ));
170     c.checkFieldIOobject(c, rho);
172     IOField<scalar> age(c.fieldIOobject("age", IOobject::MUST_READ));
173     c.checkFieldIOobject(c, age);
175     IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::MUST_READ));
176     c.checkFieldIOobject(c, tTurb);
178     IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::MUST_READ));
179     c.checkFieldIOobject(c, UTurb);
181     label i = 0;
183     forAllIter(typename CloudType, c, iter)
184     {
185         KinematicParcel<ParcelType>& p = iter();
187         p.active_ = active[i];
188         p.typeId_ = typeId[i];
189         p.nParticle_ = nParticle[i];
190         p.d_ = d[i];
191         p.dTarget_ = dTarget[i];
192         p.U_ = U[i];
193         p.f_ = f[i];
194         p.angularMomentum_ = angularMomentum[i];
195         p.rho_ = rho[i];
196         p.age_ = age[i];
197         p.tTurb_ = tTurb[i];
198         p.UTurb_ = UTurb[i];
200         i++;
201     }
205 template<class ParcelType>
206 template<class CloudType>
207 void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
209     ParcelType::writeFields(c);
211     label np =  c.size();
213     IOField<label> active(c.fieldIOobject("active", IOobject::NO_READ), np);
214     IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
215     IOField<scalar> nParticle
216     (
217         c.fieldIOobject("nParticle", IOobject::NO_READ),
218         np
219     );
220     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
221     IOField<scalar> dTarget(c.fieldIOobject("dTarget", IOobject::NO_READ), np);
222     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
223     IOField<vector> f(c.fieldIOobject("f", IOobject::NO_READ), np);
224     IOField<vector> angularMomentum
225     (
226         c.fieldIOobject("angularMomentum", IOobject::NO_READ),
227         np
228     );
229     IOField<vector> torque(c.fieldIOobject("torque", IOobject::NO_READ), np);
230     IOField<scalar> rho(c.fieldIOobject("rho", IOobject::NO_READ), np);
231     IOField<scalar> age(c.fieldIOobject("age", IOobject::NO_READ), np);
232     IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::NO_READ), np);
233     IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::NO_READ), np);
235     label i = 0;
237     forAllConstIter(typename CloudType, c, iter)
238     {
239         const KinematicParcel<ParcelType>& p = iter();
241         active[i] = p.active();
242         typeId[i] = p.typeId();
243         nParticle[i] = p.nParticle();
244         d[i] = p.d();
245         dTarget[i] = p.dTarget();
246         U[i] = p.U();
247         f[i] = p.f();
248         angularMomentum[i] = p.angularMomentum();
249         torque[i] = p.torque();
250         rho[i] = p.rho();
251         age[i] = p.age();
252         tTurb[i] = p.tTurb();
253         UTurb[i] = p.UTurb();
255         i++;
256     }
258     active.write();
259     typeId.write();
260     nParticle.write();
261     d.write();
262     dTarget.write();
263     U.write();
264     f.write();
265     angularMomentum.write();
266     torque.write();
267     rho.write();
268     age.write();
269     tTurb.write();
270     UTurb.write();
274 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
276 template<class ParcelType>
277 Foam::Ostream& Foam::operator<<
279     Ostream& os,
280     const KinematicParcel<ParcelType>& p
283     if (os.format() == IOstream::ASCII)
284     {
285         os  << static_cast<const ParcelType&>(p)
286             << token::SPACE << p.active()
287             << token::SPACE << p.typeId()
288             << token::SPACE << p.nParticle()
289             << token::SPACE << p.d()
290             << token::SPACE << p.dTarget()
291             << token::SPACE << p.U()
292             << token::SPACE << p.f()
293             << token::SPACE << p.angularMomentum()
294             << token::SPACE << p.torque()
295             << token::SPACE << p.rho()
296             << token::SPACE << p.age()
297             << token::SPACE << p.tTurb()
298             << token::SPACE << p.UTurb();
299     }
300     else
301     {
302         os  << static_cast<const ParcelType&>(p);
303         os.write
304         (
305             reinterpret_cast<const char*>(&p.active_),
306             sizeof(p.active())
307           + sizeof(p.typeId())
308           + sizeof(p.nParticle())
309           + sizeof(p.d())
310           + sizeof(p.dTarget())
311           + sizeof(p.U())
312           + sizeof(p.f())
313           + sizeof(p.angularMomentum())
314           + sizeof(p.torque())
315           + sizeof(p.rho())
316           + sizeof(p.age())
317           + sizeof(p.tTurb())
318           + sizeof(p.UTurb())
319         );
320     }
322     // Check state of Ostream
323     os.check
324     (
325         "Ostream& operator<<(Ostream&, const KinematicParcel<ParcelType>&)"
326     );
328     return os;
332 // ************************************************************************* //