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

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-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 Class
00026     Foam::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 friend functions and operators
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 its 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                 index(-1),
00086                 stoichCoeff(0),
00087                 exponent(1)
00088             {}
00089 
00090             specieCoeffs(const speciesTable& species, Istream& is);
00091 
00092             bool operator==(const specieCoeffs& sc) const
00093             {
00094                 return index == sc.index;
00095             }
00096 
00097             bool operator!=(const specieCoeffs& sc) const
00098             {
00099                 return index != sc.index;
00100             }
00101 
00102             friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
00103             {
00104                 os  << sc.index << token::SPACE
00105                     << sc.stoichCoeff << token::SPACE
00106                     << sc.exponent;
00107                 return os;
00108             }
00109         };
00110 
00111 
00112 private:
00113 
00114     // Private data
00115 
00116         //- List of specie names present in reaction system
00117         const speciesTable& species_;
00118 
00119         //- Specie info for the left-hand-side of the reaction
00120         List<specieCoeffs> lhs_;
00121 
00122         //- Specie info for the right-hand-side of the reaction
00123         List<specieCoeffs> rhs_;
00124 
00125 
00126     // Private member functions
00127 
00128         void setLRhs(Istream&);
00129         void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
00130 
00131         //- Disallow default bitwise assignment
00132         void operator=(const Reaction<ReactionThermo>&);
00133 
00134 
00135 public:
00136 
00137     //- Runtime type information
00138     TypeName("Reaction");
00139 
00140 
00141     // Declare run-time constructor selection tables
00142 
00143         declareRunTimeSelectionTable
00144         (
00145             autoPtr,
00146             Reaction,
00147             Istream,
00148             (
00149                 const speciesTable& species,
00150                 const HashPtrTable<ReactionThermo>& thermoDatabase,
00151                 Istream& is
00152             ),
00153             (species, thermoDatabase, is)
00154         );
00155 
00156 
00157     // Public classes
00158 
00159         //- Class used for the read-construction of PtrLists of reaction
00160         class iNew
00161         {
00162             const speciesTable& species_;
00163             const HashPtrTable<ReactionThermo>& thermoDatabase_;
00164 
00165         public:
00166 
00167             iNew
00168             (
00169                 const speciesTable& species,
00170                 const HashPtrTable<ReactionThermo>& thermoDatabase
00171             )
00172             :
00173                 species_(species),
00174                 thermoDatabase_(thermoDatabase)
00175             {}
00176 
00177             autoPtr<Reaction> operator()(Istream& is) const
00178             {
00179                 return autoPtr<Reaction>
00180                 (
00181                     Reaction::New(species_, thermoDatabase_, is)
00182                 );
00183             }
00184         };
00185 
00186 
00187     // Constructors
00188 
00189         //- Construct from components
00190         Reaction
00191         (
00192             const speciesTable& species,
00193             const List<specieCoeffs>& lhs,
00194             const List<specieCoeffs>& rhs,
00195             const HashPtrTable<ReactionThermo>& thermoDatabase
00196         );
00197 
00198         //- Construct as copy given new speciesTable
00199         Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
00200 
00201         //- Construct from Istream
00202         Reaction
00203         (
00204             const speciesTable& species,
00205             const HashPtrTable<ReactionThermo>& thermoDatabase,
00206             Istream& is
00207         );
00208 
00209         //- Construct and return a clone
00210         virtual autoPtr<Reaction<ReactionThermo> > clone() const
00211         {
00212             return autoPtr<Reaction<ReactionThermo> >
00213             (
00214                 new Reaction<ReactionThermo>(*this)
00215             );
00216         }
00217 
00218         //- Construct and return a clone with new speciesTable
00219         virtual autoPtr<Reaction<ReactionThermo> > clone
00220         (
00221             const speciesTable& species
00222         ) const
00223         {
00224             return autoPtr<Reaction<ReactionThermo> >
00225             (
00226                 new Reaction<ReactionThermo>(*this, species)
00227             );
00228         }
00229 
00230 
00231     // Selectors
00232 
00233         //- Return a pointer to a new patchField created on freestore from input
00234         static autoPtr<Reaction<ReactionThermo> > New
00235         (
00236             const speciesTable& species,
00237             const HashPtrTable<ReactionThermo>& thermoDatabase,
00238             Istream&
00239         );
00240 
00241 
00242     // Destructor
00243 
00244         virtual ~Reaction()
00245         {}
00246 
00247 
00248     // Member Functions
00249 
00250         // Access
00251 
00252             inline const List<specieCoeffs>& lhs() const;
00253             inline const List<specieCoeffs>& rhs() const;
00254 
00255 
00256         // Reaction rate coefficients
00257 
00258             //- Forward rate constant
00259             virtual scalar kf
00260             (
00261                 const scalar T,
00262                 const scalar p,
00263                 const scalarField& c
00264             ) const;
00265 
00266             //- Reverse rate constant from the given forward rate constant
00267             virtual scalar kr
00268             (
00269                 const scalar kfwd,
00270                 const scalar T,
00271                 const scalar p,
00272                 const scalarField& c
00273             ) const;
00274 
00275             //- Reverse rate constant.
00276             //  Note this evaluates the forward rate constant and divides by the
00277             //  equilibrium constant
00278             virtual scalar kr
00279             (
00280                 const scalar T,
00281                 const scalar p,
00282                 const scalarField& c
00283             ) const;
00284 
00285 
00286         //- Write
00287         virtual void write(Ostream&) const;
00288 
00289 
00290     // Ostream Operator
00291 
00292         friend Ostream& operator<< <ReactionThermo>
00293         (
00294             Ostream&,
00295             const Reaction<ReactionThermo>&
00296         );
00297 };
00298 
00299 
00300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00301 
00302 } // End namespace Foam
00303 
00304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00305 
00306 #include "ReactionI.H"
00307 
00308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00309 
00310 #ifdef NoRepository
00311 #   include "Reaction.C"
00312 #endif
00313 
00314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00315 
00316 #endif
00317 
00318 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd