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

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