BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / lagrangian / solidParticle / solidParticleIO.C
blobf2f9cc8999b57bbf6aa1959b5f8c9e848ffc1f13
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 "solidParticle.H"
27 #include "IOstreams.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::solidParticle::solidParticle
33     const polyMesh& mesh,
34     Istream& is,
35     bool readFields
38     particle(mesh, is, readFields)
40     if (readFields)
41     {
42         if (is.format() == IOstream::ASCII)
43         {
44             d_ = readScalar(is);
45             is >> U_;
46         }
47         else
48         {
49             is.read
50             (
51                 reinterpret_cast<char*>(&d_),
52                 sizeof(d_) + sizeof(U_)
53             );
54         }
55     }
57     // Check state of Istream
58     is.check("solidParticle::solidParticle(Istream&)");
62 void Foam::solidParticle::readFields(Cloud<solidParticle>& c)
64     if (!c.size())
65     {
66         return;
67     }
69     particle::readFields(c);
71     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
72     c.checkFieldIOobject(c, d);
74     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
75     c.checkFieldIOobject(c, U);
77     label i = 0;
78     forAllIter(Cloud<solidParticle>, c, iter)
79     {
80         solidParticle& p = iter();
82         p.d_ = d[i];
83         p.U_ = U[i];
84         i++;
85     }
89 void Foam::solidParticle::writeFields(const Cloud<solidParticle>& c)
91     particle::writeFields(c);
93     label np = c.size();
95     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
96     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
98     label i = 0;
99     forAllConstIter(Cloud<solidParticle>, c, iter)
100     {
101         const solidParticle& p = iter();
103         d[i] = p.d_;
104         U[i] = p.U_;
105         i++;
106     }
108     d.write();
109     U.write();
113 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
115 Foam::Ostream& Foam::operator<<(Ostream& os, const solidParticle& p)
117     if (os.format() == IOstream::ASCII)
118     {
119         os  << static_cast<const particle&>(p)
120             << token::SPACE << p.d_
121             << token::SPACE << p.U_;
122     }
123     else
124     {
125         os  << static_cast<const particle&>(p);
126         os.write
127         (
128             reinterpret_cast<const char*>(&p.d_),
129             sizeof(p.d_) + sizeof(p.U_)
130         );
131     }
133     // Check state of Ostream
134     os.check("Ostream& operator<<(Ostream&, const solidParticle&)");
136     return os;
140 // ************************************************************************* //