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

ReactingParcelIO.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 "ReactingParcel_.H"
00027 #include <OpenFOAM/IOstreams.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 template <class ParcelType>
00032 Foam::string Foam::ReactingParcel<ParcelType>::propHeader =
00033     ThermoParcel<ParcelType>::propHeader
00034   + " mass0"
00035   + " nPhases(Y1..YN)";
00036 
00037 
00038 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00039 
00040 template<class ParcelType>
00041 Foam::ReactingParcel<ParcelType>::ReactingParcel
00042 (
00043     const Cloud<ParcelType>& cloud,
00044     Istream& is,
00045     bool readFields
00046 )
00047 :
00048     ThermoParcel<ParcelType>(cloud, is, readFields),
00049     mass0_(0.0),
00050     Y_(0),
00051     pc_(0.0)
00052 {
00053     if (readFields)
00054     {
00055         const ReactingCloud<ParcelType>& cR =
00056             dynamic_cast<const ReactingCloud<ParcelType>&>(cloud);
00057 
00058         const label nMixture = cR.composition().phaseTypes().size();
00059         Y_.setSize(nMixture);
00060 
00061         if (is.format() == IOstream::ASCII)
00062         {
00063             is >> mass0_ >> Y_;
00064         }
00065         else
00066         {
00067             is.read
00068             (
00069                 reinterpret_cast<char*>(&mass0_),
00070               + sizeof(mass0_)
00071             );
00072             is >> Y_;
00073         }
00074     }
00075 
00076     // Check state of Istream
00077     is.check
00078     (
00079         "ReactingParcel<ParcelType>::ReactingParcel"
00080         "("
00081             "const Cloud<ParcelType>&, "
00082             "Istream&, "
00083             "bool"
00084         ")"
00085     );
00086 }
00087 
00088 
00089 template<class ParcelType>
00090 void Foam::ReactingParcel<ParcelType>::readFields(Cloud<ParcelType>& cIn)
00091 {
00092     if (!cIn.size())
00093     {
00094         return;
00095     }
00096 
00097     ReactingCloud<ParcelType>& c =
00098         dynamic_cast<ReactingCloud<ParcelType>&>(cIn);
00099 
00100     ThermoParcel<ParcelType>::readFields(c);
00101 
00102     IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::MUST_READ));
00103     c.checkFieldIOobject(c, mass0);
00104 
00105     label i = 0;
00106     forAllIter(typename Cloud<ParcelType>, c, iter)
00107     {
00108         ReactingParcel<ParcelType>& p = iter();
00109         p.mass0_ = mass0[i++];
00110     }
00111 
00112     // Get names and sizes for each Y...
00113     const wordList& phaseTypes = c.composition().phaseTypes();
00114     const label nPhases = phaseTypes.size();
00115     wordList stateLabels(nPhases, "");
00116     if (c.composition().nPhase() == 1)
00117     {
00118         stateLabels = c.composition().stateLabels();
00119     }
00120 
00121 
00122     // Set storage for each Y... for each parcel
00123     forAllIter(typename Cloud<ParcelType>, c, iter)
00124     {
00125         ReactingParcel<ParcelType>& p = iter();
00126         p.Y_.setSize(nPhases, 0.0);
00127     }
00128 
00129     // Populate Y for each parcel
00130     forAll(phaseTypes, j)
00131     {
00132         IOField<scalar> Y
00133         (
00134             c.fieldIOobject
00135             (
00136                 "Y" + phaseTypes[j] + stateLabels[j],
00137                  IOobject::MUST_READ
00138             )
00139         );
00140 
00141         label i = 0;
00142         forAllIter(typename Cloud<ParcelType>, c, iter)
00143         {
00144             ReactingParcel<ParcelType>& p = iter();
00145             p.Y_[j] = Y[i++];
00146         }
00147     }
00148 }
00149 
00150 
00151 template<class ParcelType>
00152 void Foam::ReactingParcel<ParcelType>::writeFields
00153 (
00154     const Cloud<ParcelType>& cIn
00155 )
00156 {
00157     const ReactingCloud<ParcelType>& c =
00158         dynamic_cast<const ReactingCloud<ParcelType>&>(cIn);
00159 
00160     ThermoParcel<ParcelType>::writeFields(c);
00161 
00162     const label np = c.size();
00163 
00164     if (np > 0)
00165     {
00166         IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);
00167 
00168         label i = 0;
00169         forAllConstIter(typename Cloud<ParcelType>, c, iter)
00170         {
00171             const ReactingParcel<ParcelType>& p = iter();
00172             mass0[i++] = p.mass0_;
00173         }
00174         mass0.write();
00175 
00176         // Write the composition fractions
00177         const wordList& phaseTypes = c.composition().phaseTypes();
00178         wordList stateLabels(phaseTypes.size(), "");
00179         if (c.composition().nPhase() == 1)
00180         {
00181             stateLabels = c.composition().stateLabels();
00182         }
00183 
00184         forAll(phaseTypes, j)
00185         {
00186             IOField<scalar> Y
00187             (
00188                 c.fieldIOobject
00189                 (
00190                     "Y" + phaseTypes[j] + stateLabels[j],
00191                     IOobject::NO_READ
00192                 ),
00193                 np
00194             );
00195 
00196             label i = 0;
00197             forAllConstIter(typename Cloud<ParcelType>, c, iter)
00198             {
00199                 const ReactingParcel<ParcelType>& p0 = iter();
00200                 Y[i++] = p0.Y()[j];
00201             }
00202 
00203             Y.write();
00204         }
00205     }
00206 }
00207 
00208 
00209 // * * * * * * * * * * * * * * * IOstream Operators  * * * * * * * * * * * * //
00210 
00211 template<class ParcelType>
00212 Foam::Ostream& Foam::operator<<
00213 (
00214     Ostream& os,
00215     const ReactingParcel<ParcelType>& p
00216 )
00217 {
00218     if (os.format() == IOstream::ASCII)
00219     {
00220         os  << static_cast<const ThermoParcel<ParcelType>&>(p)
00221             << token::SPACE << p.mass0()
00222             << token::SPACE << p.Y();
00223     }
00224     else
00225     {
00226         os  << static_cast<const ThermoParcel<ParcelType>&>(p);
00227         os.write
00228         (
00229             reinterpret_cast<const char*>(&p.mass0_),
00230             sizeof(p.mass0())
00231         );
00232         os  << p.Y();
00233     }
00234 
00235     // Check state of Ostream
00236     os.check
00237     (
00238         "Ostream& operator<<(Ostream&, const ReactingParcel<ParcelType>&)"
00239     );
00240 
00241     return os;
00242 }
00243 
00244 
00245 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines