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

KinematicParcelIO.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 "KinematicParcel.H"
00028 #include "IOstreams.H"
00029 #include "IOField.H"
00030 #include "Cloud.H"
00031 
00032 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00033 
00034 template <class ParcelType>
00035 Foam::string Foam::KinematicParcel<ParcelType>::propHeader =
00036     Particle<ParcelType>::propHeader
00037   + " typeId"
00038   + " nParticle"
00039   + " d"
00040   + " (Ux Uy Uz)"
00041   + " rho"
00042   + " tTurb"
00043   + " UTurb";
00044 
00045 
00046 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00047 
00048 template <class ParcelType>
00049 Foam::KinematicParcel<ParcelType>::KinematicParcel
00050 (
00051     const Cloud<ParcelType>& cloud,
00052     Istream& is,
00053     bool readFields
00054 )
00055 :
00056     Particle<ParcelType>(cloud, is, readFields),
00057     typeId_(0),
00058     nParticle_(0.0),
00059     d_(0.0),
00060     U_(vector::zero),
00061     rho_(0.0),
00062     tTurb_(0.0),
00063     UTurb_(vector::zero),
00064     rhoc_(0.0),
00065     Uc_(vector::zero),
00066     muc_(0.0)
00067 {
00068     if (readFields)
00069     {
00070         if (is.format() == IOstream::ASCII)
00071         {
00072             typeId_ = readLabel(is);
00073             nParticle_ = readScalar(is);
00074             d_ = readScalar(is);
00075             is >> U_;
00076             rho_ = readScalar(is);
00077             tTurb_ = readScalar(is);
00078             is >> UTurb_;
00079         }
00080         else
00081         {
00082             is.read
00083             (
00084                 reinterpret_cast<char*>(&typeId_),
00085                 sizeof(typeId_)
00086               + sizeof(nParticle_)
00087               + sizeof(d_)
00088               + sizeof(U_)
00089               + sizeof(rho_)
00090               + sizeof(tTurb_)
00091               + sizeof(UTurb_)
00092             );
00093         }
00094     }
00095 
00096     // Check state of Istream
00097     is.check
00098     (
00099         "KinematicParcel<ParcelType>::KinematicParcel"
00100         "(const Cloud<ParcelType>&, Istream&, bool)"
00101     );
00102 }
00103 
00104 
00105 template<class ParcelType>
00106 void Foam::KinematicParcel<ParcelType>::readFields
00107 (
00108     KinematicCloud<ParcelType>& c
00109 )
00110 {
00111     if (!c.size())
00112     {
00113         return;
00114     }
00115 
00116     IOField<label> typeId(c.fieldIOobject("typeId", IOobject::MUST_READ));
00117     c.checkFieldIOobject(c, typeId);
00118 
00119     IOField<scalar>
00120         nParticle(c.fieldIOobject("nParticle", IOobject::MUST_READ));
00121     c.checkFieldIOobject(c, nParticle);
00122 
00123     IOField<scalar> d(c.fieldIOobject("d", IOobject::MUST_READ));
00124     c.checkFieldIOobject(c, d);
00125 
00126     IOField<vector> U(c.fieldIOobject("U", IOobject::MUST_READ));
00127     c.checkFieldIOobject(c, U);
00128 
00129     IOField<scalar> rho(c.fieldIOobject("rho", IOobject::MUST_READ));
00130     c.checkFieldIOobject(c, rho);
00131 
00132     IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::MUST_READ));
00133     c.checkFieldIOobject(c, tTurb);
00134 
00135     IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::MUST_READ));
00136     c.checkFieldIOobject(c, UTurb);
00137 
00138     label i = 0;
00139     forAllIter(typename Cloud<ParcelType>, c, iter)
00140     {
00141         ParcelType& p = iter();
00142 
00143         p.typeId_ = typeId[i];
00144         p.nParticle_ = nParticle[i];
00145         p.d_ = d[i];
00146         p.U_ = U[i];
00147         p.rho_ = rho[i];
00148         p.tTurb_ = tTurb[i];
00149         p.UTurb_ = UTurb[i];
00150         i++;
00151     }
00152 }
00153 
00154 
00155 template<class ParcelType>
00156 void Foam::KinematicParcel<ParcelType>::writeFields
00157 (
00158     const KinematicCloud<ParcelType>& c
00159 )
00160 {
00161     Particle<ParcelType>::writeFields(c);
00162 
00163     label np =  c.size();
00164 
00165     IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
00166     IOField<scalar> nParticle
00167     (
00168         c.fieldIOobject("nParticle", IOobject::NO_READ),
00169         np
00170     );
00171     IOField<scalar> d(c.fieldIOobject("d", IOobject::NO_READ), np);
00172     IOField<vector> U(c.fieldIOobject("U", IOobject::NO_READ), np);
00173     IOField<scalar> rho(c.fieldIOobject("rho", IOobject::NO_READ), np);
00174     IOField<scalar> tTurb(c.fieldIOobject("tTurb", IOobject::NO_READ), np);
00175     IOField<vector> UTurb(c.fieldIOobject("UTurb", IOobject::NO_READ), np);
00176 
00177     label i = 0;
00178     forAllConstIter(typename Cloud<ParcelType>, c, iter)
00179     {
00180         const KinematicParcel<ParcelType>& p = iter();
00181 
00182         typeId[i] = p.typeId();
00183         nParticle[i] = p.nParticle();
00184         d[i] = p.d();
00185         U[i] = p.U();
00186         rho[i] = p.rho();
00187         tTurb[i] = p.tTurb();
00188         UTurb[i] = p.UTurb();
00189         i++;
00190     }
00191 
00192     typeId.write();
00193     nParticle.write();
00194     d.write();
00195     U.write();
00196     rho.write();
00197     tTurb.write();
00198     UTurb.write();
00199 }
00200 
00201 
00202 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00203 
00204 template<class ParcelType>
00205 Foam::Ostream& Foam::operator<<
00206 (
00207     Ostream& os,
00208     const KinematicParcel<ParcelType>& p
00209 )
00210 {
00211     if (os.format() == IOstream::ASCII)
00212     {
00213         os  << static_cast<const Particle<ParcelType>&>(p)
00214             << token::SPACE << p.typeId()
00215             << token::SPACE << p.nParticle()
00216             << token::SPACE << p.d()
00217             << token::SPACE << p.U()
00218             << token::SPACE << p.rho()
00219             << token::SPACE << p.tTurb()
00220             << token::SPACE << p.UTurb();
00221     }
00222     else
00223     {
00224         os  << static_cast<const Particle<ParcelType>&>(p);
00225         os.write
00226         (
00227             reinterpret_cast<const char*>(&p.typeId_),
00228             sizeof(p.typeId())
00229           + sizeof(p.nParticle())
00230           + sizeof(p.d())
00231           + sizeof(p.U())
00232           + sizeof(p.rho())
00233           + sizeof(p.tTurb())
00234           + sizeof(p.UTurb())
00235         );
00236     }
00237 
00238     // Check state of Ostream
00239     os.check
00240     (
00241         "Ostream& operator<<(Ostream&, const KinematicParcel<ParcelType>&)"
00242     );
00243 
00244     return os;
00245 }
00246 
00247 
00248 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd