OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

solidParticleIO.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "solidParticle.H"
00028 #include "IOstreams.H"
00029 
00030 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00031 
00032 Foam::solidParticle::solidParticle
00033 (
00034     const Cloud<solidParticle>& cloud,
00035     Istream& is,
00036     bool readFields
00037 )
00038 :
00039     Particle<solidParticle>(cloud, is, readFields)
00040 {
00041     if (readFields)
00042     {
00043         if (is.format() == IOstream::ASCII)
00044         {
00045             d_ = readScalar(is);
00046             is >> U_;
00047         }
00048         else
00049         {
00050             is.read
00051             (
00052                 reinterpret_cast<char*>(&d_),
00053                 sizeof(d_) + sizeof(U_)
00054             );
00055         }
00056     }
00057 
00058     // Check state of Istream
00059     is.check("solidParticle::solidParticle(Istream&)");
00060 }
00061 
00062 
00063 void Foam::solidParticle::readFields(Cloud<solidParticle>& c)
00064 {
00065     if (!c.size())
00066     {
00067         return;
00068     }
00069     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
00070     c.checkFieldIOobject(c, d);
00071 
00072     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
00073     c.checkFieldIOobject(c, U);
00074 
00075     label i = 0;
00076     forAllIter(Cloud<solidParticle>::iterator, c, iter)
00077     {
00078         solidParticle& p = iter();
00079 
00080         p.d_ = d[i];
00081         p.U_ = U[i];
00082         i++;
00083     }
00084 }
00085 
00086 
00087 void Foam::solidParticle::writeFields(const Cloud<solidParticle>& c)
00088 {
00089     Particle<solidParticle>::writeFields(c);
00090 
00091     label np = c.size();
00092 
00093     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
00094     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
00095 
00096     label i = 0;
00097     forAllConstIter(Cloud<solidParticle>, c, iter)
00098     {
00099         const solidParticle& p = iter();
00100 
00101         d[i] = p.d_;
00102         U[i] = p.U_;
00103         i++;
00104     }
00105 
00106     d.write();
00107     U.write();
00108 }
00109 
00110 
00111 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00112 
00113 Foam::Ostream& Foam::operator<<(Ostream& os, const solidParticle& p)
00114 {
00115     if (os.format() == IOstream::ASCII)
00116     {
00117         os  << static_cast<const Particle<solidParticle>&>(p)
00118             << token::SPACE << p.d_
00119             << token::SPACE << p.U_;
00120     }
00121     else
00122     {
00123         os  << static_cast<const Particle<solidParticle>&>(p);
00124         os.write
00125         (
00126             reinterpret_cast<const char*>(&p.d_),
00127             sizeof(p.d_) + sizeof(p.U_)
00128         );
00129     }
00130 
00131     // Check state of Ostream
00132     os.check("Ostream& operator<<(Ostream&, const solidParticle&)");
00133 
00134     return os;
00135 }
00136 
00137 
00138 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd