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

Reaction.H

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 Class
00025     Foam::Reaction
00026 
00027 Description
00028     Simple extension of ReactionThermo to handle reaction kinetics in addition
00029     to the equilibrium thermodynamics already handled.
00030 
00031 SourceFiles
00032     ReactionI.H
00033     Reaction.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef Reaction_H
00038 #define Reaction_H
00039 
00040 #include <specie/speciesTable.H>
00041 #include <OpenFOAM/HashPtrTable.H>
00042 #include <OpenFOAM/scalarField.H>
00043 #include <OpenFOAM/typeInfo.H>
00044 #include <OpenFOAM/runTimeSelectionTables.H>
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 // Forward declaration of friend functions and operators
00052 
00053 template<class ReactionThermo>
00054 class Reaction;
00055 
00056 template<class ReactionThermo>
00057 inline Ostream& operator<<(Ostream&, const Reaction<ReactionThermo>&);
00058 
00059 
00060 /*---------------------------------------------------------------------------*\
00061                            Class Reaction Declaration
00062 \*---------------------------------------------------------------------------*/
00063 
00064 template<class ReactionThermo>
00065 class Reaction
00066 :
00067     public ReactionThermo
00068 {
00069 
00070 public:
00071 
00072     // Public data types
00073 
00074         //- Class to hold the specie index and its coefficients in the
00075         //  reaction rate expression
00076         struct specieCoeffs
00077         {
00078             label index;
00079             scalar stoichCoeff;
00080             scalar exponent;
00081 
00082             specieCoeffs()
00083             :
00084                 index(-1),
00085                 stoichCoeff(0),
00086                 exponent(1)
00087             {}
00088 
00089             specieCoeffs(const speciesTable& species, Istream& is);
00090 
00091             bool operator==(const specieCoeffs& sc) const
00092             {
00093                 return index == sc.index;
00094             }
00095 
00096             bool operator!=(const specieCoeffs& sc) const
00097             {
00098                 return index != sc.index;
00099             }
00100 
00101             friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
00102             {
00103                 os  << sc.index << token::SPACE
00104                     << sc.stoichCoeff << token::SPACE
00105                     << sc.exponent;
00106                 return os;
00107             }
00108         };
00109 
00110 
00111 private:
00112 
00113     // Private data
00114 
00115         //- List of specie names present in reaction system
00116         const speciesTable& species_;
00117 
00118         //- Specie info for the left-hand-side of the reaction
00119         List<specieCoeffs> lhs_;
00120 
00121         //- Specie info for the right-hand-side of the reaction
00122         List<specieCoeffs> rhs_;
00123 
00124 
00125     // Private member functions
00126 
00127         void setLRhs(Istream&);
00128         void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
00129 
00130         //- Disallow default bitwise assignment
00131         void operator=(const Reaction<ReactionThermo>&);
00132 
00133 
00134 public:
00135 
00136     //- Runtime type information
00137     TypeName("Reaction");
00138 
00139 
00140     // Declare run-time constructor selection tables
00141 
00142         declareRunTimeSelectionTable
00143         (
00144             autoPtr,
00145             Reaction,
00146             Istream,
00147             (
00148                 const speciesTable& species,
00149                 const HashPtrTable<ReactionThermo>& thermoDatabase,
00150                 Istream& is
00151             ),
00152             (species, thermoDatabase, is)
00153         );
00154 
00155 
00156     // Public classes
00157 
00158         //- Class used for the read-construction of PtrLists of reaction
00159         class iNew
00160         {
00161             const speciesTable& species_;
00162             const HashPtrTable<ReactionThermo>& thermoDatabase_;
00163 
00164         public:
00165 
00166             iNew
00167             (
00168                 const speciesTable& species,
00169                 const HashPtrTable<ReactionThermo>& thermoDatabase
00170             )
00171             :
00172                 species_(species),
00173                 thermoDatabase_(thermoDatabase)
00174             {}
00175 
00176             autoPtr<Reaction> operator()(Istream& is) const
00177             {
00178                 return autoPtr<Reaction>
00179                 (
00180                     Reaction::New(species_, thermoDatabase_, is)
00181                 );
00182             }
00183         };
00184 
00185 
00186     // Constructors
00187 
00188         //- Construct from components
00189         Reaction
00190         (
00191             const speciesTable& species,
00192             const List<specieCoeffs>& lhs,
00193             const List<specieCoeffs>& rhs,
00194             const HashPtrTable<ReactionThermo>& thermoDatabase
00195         );
00196 
00197         //- Construct as copy given new speciesTable
00198         Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
00199 
00200         //- Construct from Istream
00201         Reaction
00202         (
00203             const speciesTable& species,
00204             const HashPtrTable<ReactionThermo>& thermoDatabase,
00205             Istream& is
00206         );
00207 
00208         //- Construct and return a clone
00209         virtual autoPtr<Reaction<ReactionThermo> > clone() const
00210         {
00211             return autoPtr<Reaction<ReactionThermo> >
00212             (
00213                 new Reaction<ReactionThermo>(*this)
00214             );
00215         }
00216 
00217         //- Construct and return a clone with new speciesTable
00218         virtual autoPtr<Reaction<ReactionThermo> > clone
00219         (
00220             const speciesTable& species
00221         ) const
00222         {
00223             return autoPtr<Reaction<ReactionThermo> >
00224             (
00225                 new Reaction<ReactionThermo>(*this, species)
00226             );
00227         }
00228 
00229 
00230     // Selectors
00231 
00232         //- Return a pointer to a new patchField created on freestore from input
00233         static autoPtr<Reaction<ReactionThermo> > New
00234         (
00235             const speciesTable& species,
00236             const HashPtrTable<ReactionThermo>& thermoDatabase,
00237             Istream&
00238         );
00239 
00240 
00241     // Destructor
00242 
00243         virtual ~Reaction()
00244         {}
00245 
00246 
00247     // Member Functions
00248 
00249         // Access
00250 
00251             inline const List<specieCoeffs>& lhs() const;
00252             inline const List<specieCoeffs>& rhs() const;
00253 
00254 
00255         // Reaction rate coefficients
00256 
00257             //- Forward rate constant
00258             virtual scalar kf
00259             (
00260                 const scalar T,
00261                 const scalar p,
00262                 const scalarField& c
00263             ) const;
00264 
00265             //- Reverse rate constant from the given forward rate constant
00266             virtual scalar kr
00267             (
00268                 const scalar kfwd,
00269                 const scalar T,
00270                 const scalar p,
00271                 const scalarField& c
00272             ) const;
00273 
00274             //- Reverse rate constant.
00275             //  Note this evaluates the forward rate constant and divides by the
00276             //  equilibrium constant
00277             virtual scalar kr
00278             (
00279                 const scalar T,
00280                 const scalar p,
00281                 const scalarField& c
00282             ) const;
00283 
00284 
00285         //- Write
00286         virtual void write(Ostream&) const;
00287 
00288 
00289     // Ostream Operator
00290 
00291         friend Ostream& operator<< <ReactionThermo>
00292         (
00293             Ostream&,
00294             const Reaction<ReactionThermo>&
00295         );
00296 };
00297 
00298 
00299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00300 
00301 } // End namespace Foam
00302 
00303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00304 
00305 #include <specie/ReactionI.H>
00306 
00307 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00308 
00309 #ifdef NoRepository
00310 #   include <specie/Reaction.C>
00311 #endif
00312 
00313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00314 
00315 #endif
00316 
00317 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines