OpenFOAM logo
Open Source CFD Toolkit

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