initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / specie / reaction / Reactions / Reaction / Reaction.H
blob4e2603742d4fdce93a298f806b35a02b1e8afca5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::Reaction
28 Description
29     Simple extension of ReactionThermo to handle reaction kinetics in addition
30     to the equilibrium thermodynamics already handled.
32 SourceFiles
33     ReactionI.H
34     Reaction.C
36 \*---------------------------------------------------------------------------*/
38 #ifndef Reaction_H
39 #define Reaction_H
41 #include "speciesTable.H"
42 #include "HashPtrTable.H"
43 #include "scalarField.H"
44 #include "typeInfo.H"
45 #include "runTimeSelectionTables.H"
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 namespace Foam
52 // Forward declaration of friend functions and operators
54 template<class ReactionThermo>
55 class Reaction;
57 template<class ReactionThermo>
58 inline Ostream& operator<<(Ostream&, const Reaction<ReactionThermo>&);
61 /*---------------------------------------------------------------------------*\
62                            Class Reaction Declaration
63 \*---------------------------------------------------------------------------*/
65 template<class ReactionThermo>
66 class Reaction
68     public ReactionThermo
71 public:
73     // Public data types
75         //- Class to hold the specie index and its coefficients in the
76         //  reaction rate expression
77         struct specieCoeffs
78         {
79             label index;
80             scalar stoichCoeff;
81             scalar exponent;
83             specieCoeffs()
84             :
85                 index(-1),
86                 stoichCoeff(0),
87                 exponent(1)
88             {}
90             specieCoeffs(const speciesTable& species, Istream& is);
92             bool operator==(const specieCoeffs& sc) const
93             {
94                 return index == sc.index;
95             }
97             bool operator!=(const specieCoeffs& sc) const
98             {
99                 return index != sc.index;
100             }
102             friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
103             {
104                 os  << sc.index << token::SPACE
105                     << sc.stoichCoeff << token::SPACE
106                     << sc.exponent;
107                 return os;
108             }
109         };
112 private:
114     // Private data
116         //- List of specie names present in reaction system
117         const speciesTable& species_;
119         //- Specie info for the left-hand-side of the reaction
120         List<specieCoeffs> lhs_;
122         //- Specie info for the right-hand-side of the reaction
123         List<specieCoeffs> rhs_;
126     // Private member functions
128         void setLRhs(Istream&);
129         void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
131         //- Disallow default bitwise assignment
132         void operator=(const Reaction<ReactionThermo>&);
135 public:
137     //- Runtime type information
138     TypeName("Reaction");
141     // Declare run-time constructor selection tables
143         declareRunTimeSelectionTable
144         (
145             autoPtr,
146             Reaction,
147             Istream,
148             (
149                 const speciesTable& species,
150                 const HashPtrTable<ReactionThermo>& thermoDatabase,
151                 Istream& is
152             ),
153             (species, thermoDatabase, is)
154         );
157     // Public classes
159         //- Class used for the read-construction of PtrLists of reaction
160         class iNew
161         {
162             const speciesTable& species_;
163             const HashPtrTable<ReactionThermo>& thermoDatabase_;
165         public:
167             iNew
168             (
169                 const speciesTable& species,
170                 const HashPtrTable<ReactionThermo>& thermoDatabase
171             )
172             :
173                 species_(species),
174                 thermoDatabase_(thermoDatabase)
175             {}
177             autoPtr<Reaction> operator()(Istream& is) const
178             {
179                 return autoPtr<Reaction>
180                 (
181                     Reaction::New(species_, thermoDatabase_, is)
182                 );
183             }
184         };
187     // Constructors
189         //- Construct from components
190         Reaction
191         (
192             const speciesTable& species,
193             const List<specieCoeffs>& lhs,
194             const List<specieCoeffs>& rhs,
195             const HashPtrTable<ReactionThermo>& thermoDatabase
196         );
198         //- Construct as copy given new speciesTable
199         Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
201         //- Construct from Istream
202         Reaction
203         (
204             const speciesTable& species,
205             const HashPtrTable<ReactionThermo>& thermoDatabase,
206             Istream& is
207         );
209         //- Construct and return a clone
210         virtual autoPtr<Reaction<ReactionThermo> > clone() const
211         {
212             return autoPtr<Reaction<ReactionThermo> >
213             (
214                 new Reaction<ReactionThermo>(*this)
215             );
216         }
218         //- Construct and return a clone with new speciesTable
219         virtual autoPtr<Reaction<ReactionThermo> > clone
220         (
221             const speciesTable& species
222         ) const
223         {
224             return autoPtr<Reaction<ReactionThermo> >
225             (
226                 new Reaction<ReactionThermo>(*this, species)
227             );
228         }
231     // Selectors
233         //- Return a pointer to a new patchField created on freestore from input
234         static autoPtr<Reaction<ReactionThermo> > New
235         (
236             const speciesTable& species,
237             const HashPtrTable<ReactionThermo>& thermoDatabase,
238             Istream&
239         );
242     // Destructor
244         virtual ~Reaction()
245         {}
248     // Member Functions
250         // Access
252             inline const List<specieCoeffs>& lhs() const;
253             inline const List<specieCoeffs>& rhs() const;
256         // Reaction rate coefficients
258             //- Forward rate constant
259             virtual scalar kf
260             (
261                 const scalar T,
262                 const scalar p,
263                 const scalarField& c
264             ) const;
266             //- Reverse rate constant from the given forward rate constant
267             virtual scalar kr
268             (
269                 const scalar kfwd,
270                 const scalar T,
271                 const scalar p,
272                 const scalarField& c
273             ) const;
275             //- Reverse rate constant.
276             //  Note this evaluates the forward rate constant and divides by the
277             //  equilibrium constant
278             virtual scalar kr
279             (
280                 const scalar T,
281                 const scalar p,
282                 const scalarField& c
283             ) const;
286         //- Write
287         virtual void write(Ostream&) const;
290     // Ostream Operator
292         friend Ostream& operator<< <ReactionThermo>
293         (
294             Ostream&,
295             const Reaction<ReactionThermo>&
296         );
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302 } // End namespace Foam
304 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 #include "ReactionI.H"
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 #ifdef NoRepository
311 #   include "Reaction.C"
312 #endif
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 #endif
318 // ************************************************************************* //