FIX: Update foamPackSource for new SF upload scheme
[freefoam.git] / src / lagrangian / solidParticle / solidParticleIO.C
blob18f8e2e4c597c7e6a577ca57674d4a01372f65ee
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.
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 <OpenFOAM/IOstreams.H>
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 Foam::solidParticle::solidParticle
33     const Cloud<solidParticle>& cloud,
34     Istream& is,
35     bool readFields
38     Particle<solidParticle>(cloud, 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     }
68     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
69     c.checkFieldIOobject(c, d);
71     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
72     c.checkFieldIOobject(c, U);
74     label i = 0;
75     forAllIter(Cloud<solidParticle>, c, iter)
76     {
77         solidParticle& p = iter();
79         p.d_ = d[i];
80         p.U_ = U[i];
81         i++;
82     }
86 void Foam::solidParticle::writeFields(const Cloud<solidParticle>& c)
88     Particle<solidParticle>::writeFields(c);
90     label np = c.size();
92     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
93     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
95     label i = 0;
96     forAllConstIter(Cloud<solidParticle>, c, iter)
97     {
98         const solidParticle& p = iter();
100         d[i] = p.d_;
101         U[i] = p.U_;
102         i++;
103     }
105     d.write();
106     U.write();
110 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
112 Foam::Ostream& Foam::operator<<(Ostream& os, const solidParticle& p)
114     if (os.format() == IOstream::ASCII)
115     {
116         os  << static_cast<const Particle<solidParticle>&>(p)
117             << token::SPACE << p.d_
118             << token::SPACE << p.U_;
119     }
120     else
121     {
122         os  << static_cast<const Particle<solidParticle>&>(p);
123         os.write
124         (
125             reinterpret_cast<const char*>(&p.d_),
126             sizeof(p.d_) + sizeof(p.U_)
127         );
128     }
130     // Check state of Ostream
131     os.check("Ostream& operator<<(Ostream&, const solidParticle&)");
133     return os;
137 // ************************ vim: set sw=4 sts=4 et: ************************ //