initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / lagrangian / solidParticle / solidParticleIO.C
blob9b23efd6a89c300b672b4ca0404cc3e9b23a7fd5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "solidParticle.H"
28 #include "IOstreams.H"
30 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
32 Foam::solidParticle::solidParticle
34     const Cloud<solidParticle>& cloud,
35     Istream& is,
36     bool readFields
39     Particle<solidParticle>(cloud, is, readFields)
41     if (readFields)
42     {
43         if (is.format() == IOstream::ASCII)
44         {
45             d_ = readScalar(is);
46             is >> U_;
47         }
48         else
49         {
50             is.read
51             (
52                 reinterpret_cast<char*>(&d_),
53                 sizeof(d_) + sizeof(U_)
54             );
55         }
56     }
58     // Check state of Istream
59     is.check("solidParticle::solidParticle(Istream&)");
63 void Foam::solidParticle::readFields(Cloud<solidParticle>& c)
65     if (!c.size())
66     {
67         return;
68     }
69     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
70     c.checkFieldIOobject(c, d);
72     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
73     c.checkFieldIOobject(c, U);
75     label i = 0;
76     forAllIter(Cloud<solidParticle>::iterator, c, iter)
77     {
78         solidParticle& p = iter();
80         p.d_ = d[i];
81         p.U_ = U[i];
82         i++;
83     }
87 void Foam::solidParticle::writeFields(const Cloud<solidParticle>& c)
89     Particle<solidParticle>::writeFields(c);
91     label np = c.size();
93     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
94     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
96     label i = 0;
97     forAllConstIter(Cloud<solidParticle>, c, iter)
98     {
99         const solidParticle& p = iter();
101         d[i] = p.d_;
102         U[i] = p.U_;
103         i++;
104     }
106     d.write();
107     U.write();
111 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
113 Foam::Ostream& Foam::operator<<(Ostream& os, const solidParticle& p)
115     if (os.format() == IOstream::ASCII)
116     {
117         os  << static_cast<const Particle<solidParticle>&>(p)
118             << token::SPACE << p.d_
119             << token::SPACE << p.U_;
120     }
121     else
122     {
123         os  << static_cast<const Particle<solidParticle>&>(p);
124         os.write
125         (
126             reinterpret_cast<const char*>(&p.d_),
127             sizeof(p.d_) + sizeof(p.U_)
128         );
129     }
131     // Check state of Ostream
132     os.check("Ostream& operator<<(Ostream&, const solidParticle&)");
134     return os;
138 // ************************************************************************* //