FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "solidParticle.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 Foam::solidParticle::solidParticle
00032 (
00033     const Cloud<solidParticle>& cloud,
00034     Istream& is,
00035     bool readFields
00036 )
00037 :
00038     Particle<solidParticle>(cloud, is, readFields)
00039 {
00040     if (readFields)
00041     {
00042         if (is.format() == IOstream::ASCII)
00043         {
00044             d_ = readScalar(is);
00045             is >> U_;
00046         }
00047         else
00048         {
00049             is.read
00050             (
00051                 reinterpret_cast<char*>(&d_),
00052                 sizeof(d_) + sizeof(U_)
00053             );
00054         }
00055     }
00056 
00057     // Check state of Istream
00058     is.check("solidParticle::solidParticle(Istream&)");
00059 }
00060 
00061 
00062 void Foam::solidParticle::readFields(Cloud<solidParticle>& c)
00063 {
00064     if (!c.size())
00065     {
00066         return;
00067     }
00068     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
00069     c.checkFieldIOobject(c, d);
00070 
00071     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
00072     c.checkFieldIOobject(c, U);
00073 
00074     label i = 0;
00075     forAllIter(Cloud<solidParticle>, c, iter)
00076     {
00077         solidParticle& p = iter();
00078 
00079         p.d_ = d[i];
00080         p.U_ = U[i];
00081         i++;
00082     }
00083 }
00084 
00085 
00086 void Foam::solidParticle::writeFields(const Cloud<solidParticle>& c)
00087 {
00088     Particle<solidParticle>::writeFields(c);
00089 
00090     label np = c.size();
00091 
00092     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
00093     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
00094 
00095     label i = 0;
00096     forAllConstIter(Cloud<solidParticle>, c, iter)
00097     {
00098         const solidParticle& p = iter();
00099 
00100         d[i] = p.d_;
00101         U[i] = p.U_;
00102         i++;
00103     }
00104 
00105     d.write();
00106     U.write();
00107 }
00108 
00109 
00110 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00111 
00112 Foam::Ostream& Foam::operator<<(Ostream& os, const solidParticle& p)
00113 {
00114     if (os.format() == IOstream::ASCII)
00115     {
00116         os  << static_cast<const Particle<solidParticle>&>(p)
00117             << token::SPACE << p.d_
00118             << token::SPACE << p.U_;
00119     }
00120     else
00121     {
00122         os  << static_cast<const Particle<solidParticle>&>(p);
00123         os.write
00124         (
00125             reinterpret_cast<const char*>(&p.d_),
00126             sizeof(p.d_) + sizeof(p.U_)
00127         );
00128     }
00129 
00130     // Check state of Ostream
00131     os.check("Ostream& operator<<(Ostream&, const solidParticle&)");
00132 
00133     return os;
00134 }
00135 
00136 
00137 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines