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

ThermoParcelIO.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 "ThermoParcel.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 template <class ParcelType>
00032 Foam::string Foam::ThermoParcel<ParcelType>::propHeader =
00033     KinematicParcel<ParcelType>::propHeader
00034   + " T"
00035   + " cp";
00036 
00037 
00038 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00039 
00040 template<class ParcelType>
00041 Foam::ThermoParcel<ParcelType>::ThermoParcel
00042 (
00043     const Cloud<ParcelType>& cloud,
00044     Istream& is,
00045     bool readFields
00046 )
00047 :
00048     KinematicParcel<ParcelType>(cloud, is, readFields),
00049     T_(0.0),
00050     cp_(0.0),
00051     Tc_(0.0),
00052     cpc_(0.0)
00053 {
00054     if (readFields)
00055     {
00056         if (is.format() == IOstream::ASCII)
00057         {
00058             T_ = readScalar(is);
00059             cp_ = readScalar(is);
00060         }
00061         else
00062         {
00063             is.read
00064             (
00065                 reinterpret_cast<char*>(&T_),
00066               + sizeof(T_)
00067               + sizeof(cp_)
00068             );
00069         }
00070     }
00071 
00072     // Check state of Istream
00073     is.check
00074     (
00075         "ThermoParcel::ThermoParcel(const Cloud<ParcelType>&, Istream&, bool)"
00076     );
00077 }
00078 
00079 
00080 template<class ParcelType>
00081 void Foam::ThermoParcel<ParcelType>::readFields(Cloud<ParcelType>& c)
00082 {
00083     if (!c.size())
00084     {
00085         return;
00086     }
00087 
00088     KinematicParcel<ParcelType>::readFields(c);
00089 
00090     IOField<scalar> T(c.fieldIOobject("T", IOobject::MUST_READ));
00091     c.checkFieldIOobject(c, T);
00092 
00093     IOField<scalar> cp(c.fieldIOobject("cp", IOobject::MUST_READ));
00094     c.checkFieldIOobject(c, cp);
00095 
00096 
00097     label i = 0;
00098     forAllIter(typename Cloud<ParcelType>, c, iter)
00099     {
00100         ThermoParcel<ParcelType>& p = iter();
00101 
00102         p.T_ = T[i];
00103         p.cp_ = cp[i];
00104         i++;
00105     }
00106 }
00107 
00108 
00109 template<class ParcelType>
00110 void Foam::ThermoParcel<ParcelType>::writeFields(const Cloud<ParcelType>& c)
00111 {
00112     KinematicParcel<ParcelType>::writeFields(c);
00113 
00114     label np =  c.size();
00115 
00116     IOField<scalar> T(c.fieldIOobject("T", IOobject::NO_READ), np);
00117     IOField<scalar> cp(c.fieldIOobject("cp", IOobject::NO_READ), np);
00118 
00119     label i = 0;
00120     forAllConstIter(typename Cloud<ParcelType>, c, iter)
00121     {
00122         const ThermoParcel<ParcelType>& p = iter();
00123 
00124         T[i] = p.T_;
00125         cp[i] = p.cp_;
00126         i++;
00127     }
00128 
00129     T.write();
00130     cp.write();
00131 }
00132 
00133 
00134 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00135 
00136 template<class ParcelType>
00137 Foam::Ostream& Foam::operator<<
00138 (
00139     Ostream& os,
00140     const ThermoParcel<ParcelType>& p
00141 )
00142 {
00143     if (os.format() == IOstream::ASCII)
00144     {
00145         os  << static_cast<const KinematicParcel<ParcelType>&>(p)
00146             << token::SPACE << p.T()
00147             << token::SPACE << p.cp();
00148     }
00149     else
00150     {
00151         os  << static_cast<const KinematicParcel<ParcelType>&>(p);
00152         os.write
00153         (
00154             reinterpret_cast<const char*>(&p.T_),
00155             sizeof(p.T()) + sizeof(p.cp())
00156         );
00157     }
00158 
00159     // Check state of Ostream
00160     os.check
00161     (
00162         "Ostream& operator<<(Ostream&, const ThermoParcel<ParcelType>&)"
00163     );
00164 
00165     return os;
00166 }
00167 
00168 
00169 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines