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

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