Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / thermophysicalModels / reactionThermo / chemistryReaders / chemkinReader / chemkinReader.H
blob41b3a1ad032ac0cc02793a72815c0d0e93bf3c29
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::chemkinReader
27 Description
28     Foam::chemkinReader
30 SourceFiles
31     chemkinReader.C
32     chemkinLexer.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef chemkinReader_H
37 #define chemkinReader_H
39 #include "chemistryReader.H"
40 #include "fileName.H"
41 #include "typeInfo.H"
42 #include "HashPtrTable.H"
43 #include "ReactionList.H"
44 #include "DynamicList.H"
45 #include "labelList.H"
46 #include "speciesTable.H"
47 #include "atomicWeights.H"
49 #include "reactionTypes.H"
51 #include <FlexLexer.h>
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 namespace Foam
58 /*---------------------------------------------------------------------------*\
59                        Class chemkinReader Declaration
60 \*---------------------------------------------------------------------------*/
62 class chemkinReader
64     public chemistryReader<gasThermoPhysics>,
65     public yyFlexLexer
68 public:
70     // Public data types
72         enum phase
73         {
74             solid,
75             liquid,
76             gas
77         };
79         //- species element
80         struct specieElement
81         {
82             word elementName;
83             label nAtoms;
85             bool operator==(const specieElement& se) const
86             {
87                 return
88                 (
89                     nAtoms == se.nAtoms
90                  && elementName == se.elementName
91                 );
92             }
94             bool operator!=(const specieElement& se) const
95             {
96                 return !operator==(se);
97             }
99             friend Ostream& operator<<(Ostream& os, const specieElement& se)
100             {
101                 os  << se.nAtoms << token::SPACE << se.elementName;
102                 return os;
103             }
104         };
107 private:
109     // Private data
111         static int yyBufSize;
112         label lineNo_;
114         //- Table of reaction type keywords
115         HashTable<int> reactionKeywordTable_;
117         //- Currently supported reaction types
118         enum reactionKeyword
119         {
120             thirdBodyReactionType,
121             unimolecularFallOffReactionType,
122             chemicallyActivatedBimolecularReactionType,
123             TroeReactionType,
124             SRIReactionType,
125             LandauTellerReactionType,
126             reverseLandauTellerReactionType,
127             JanevReactionType,
128             powerSeriesReactionRateType,
129             radiationActivatedReactionType,
130             speciesTempReactionType,
131             energyLossReactionType,
132             plasmaMomentumTransfer,
133             collisionCrossSection,
134             nonEquilibriumReversibleReactionType,
135             duplicateReactionType,
136             speciesOrderForward,
137             speciesOrderReverse,
138             UnitsOfReaction,
139             end
140         };
142         enum reactionType
143         {
144             irreversible,
145             reversible,
146             nonEquilibriumReversible,
147             unknownReactionType
148         };
150         static const char* reactionTypeNames[4];
152         enum reactionRateType
153         {
154             Arrhenius,
155             thirdBodyArrhenius,
156             unimolecularFallOff,
157             chemicallyActivatedBimolecular,
158             LandauTeller,
159             Janev,
160             powerSeries,
161             unknownReactionRateType
162         };
164         static const char* reactionRateTypeNames[8];
166         enum fallOffFunctionType
167         {
168             Lindemann,
169             Troe,
170             SRI,
171             unknownFallOffFunctionType
172         };
174         static const char* fallOffFunctionNames[4];
177         void initReactionKeywordTable();
180         //- List of elements
181         DynamicList<word> elementNames_;
183         //- Element indices
184         HashTable<label> elementIndices_;
186         //- Isotope molecular weights
187         HashTable<scalar> isotopeAtomicWts_;
189         //- List of species
190         DynamicList<word> specieNames_;
192         //- Specie indices
193         HashTable<label> specieIndices_;
195         //- Table of species
196         speciesTable speciesTable_;
198         //- Specie phase
199         HashTable<phase> speciePhase_;
201         //- Table of the thermodynamic data given in the CHEMKIN file
202         HashPtrTable<gasThermoPhysics> speciesThermo_;
204         //- Table of species composition
205         HashTable<List<specieElement> > specieComposition_;
207         //- List of the reactions
208         ReactionList<gasThermoPhysics> reactions_;
211     // Private Member Functions
213         //- Flex lexer to read the CHEMKIN III file
214         int lex();
216         inline scalar stringToScalar(const string& s)
217         {
218             string& str = const_cast<string&>(s);
219             str.replaceAll(" ", "");
220             str.replaceAll("D", "e");
221             str.replaceAll("d", "e");
222             return atof(str.c_str());
223         }
225         inline scalar stringToScalar(const char* cstr)
226         {
227             return stringToScalar(string(cstr));
228         }
230         inline void correctElementName(word& elementName)
231         {
232             if (elementName.size() == 2)
233             {
234                 elementName[1] = tolower(elementName[1]);
235             }
236             else if (elementName[0] == 'E')
237             {
238                 elementName = 'e';
239             }
240         }
242         scalar molecularWeight
243         (
244             const List<specieElement>& specieComposition
245         ) const;
247         void finishElements(labelList& currentAtoms);
249         void checkCoeffs
250         (
251             const scalarList& reactionCoeffs,
252             const char* reationRateName,
253             const label nCoeffs
254         ) const;
256         template<class ReactionRateType>
257         void addReactionType
258         (
259             const reactionType rType,
260             DynamicList<gasReaction::specieCoeffs>& lhs,
261             DynamicList<gasReaction::specieCoeffs>& rhs,
262             const ReactionRateType& rr
263         );
265         template<template<class, class> class PressureDependencyType>
266         void addPressureDependentReaction
267         (
268             const reactionType rType,
269             const fallOffFunctionType fofType,
270             DynamicList<gasReaction::specieCoeffs>& lhs,
271             DynamicList<gasReaction::specieCoeffs>& rhs,
272             const scalarList& thirdBodyEfficiencies,
273             const scalarList& k0Coeffs,
274             const scalarList& kInfCoeffs,
275             const HashTable<scalarList>& reactionCoeffsTable,
276             const scalar Afactor0,
277             const scalar AfactorInf,
278             const scalar RR
279         );
281         void addReaction
282         (
283             DynamicList<gasReaction::specieCoeffs>& lhs,
284             DynamicList<gasReaction::specieCoeffs>& rhs,
285             const scalarList& thirdBodyEfficiencies,
286             const reactionType rType,
287             const reactionRateType rrType,
288             const fallOffFunctionType fofType,
289             const scalarList& ArrheniusReactionCoeffs,
290             HashTable<scalarList>& reactionCoeffsTable,
291             const scalar RR
292         );
294         // Read the CHEMKIN files
295         void read
296         (
297             const fileName& CHEMKINFileName,
298             const fileName& thermoFileName
299         );
302         //- Disallow default bitwise copy construct
303         chemkinReader(const chemkinReader&);
305         //- Disallow default bitwise assignment
306         void operator=(const chemkinReader&);
309 public:
311     //- Runtime type information
312     TypeName("chemkinReader");
315     // Constructors
317         //- Construct from CHEMKIN III file name
318         chemkinReader
319         (
320             const fileName& chemkinFile,
321             const fileName& thermoFileName = fileName::null
322         );
324         //- Construct by getting the CHEMKIN III file name from dictionary
325         chemkinReader(const dictionary& thermoDict);
328     //- Destructor
329     virtual ~chemkinReader()
330     {}
333     // Member functions
335         //- List of elements
336         const wordList& elementNames() const
337         {
338             return elementNames_;
339         }
341         //- Element indices
342         const HashTable<label>& elementIndices() const
343         {
344             return elementIndices_;
345         }
347         //- Isotope molecular weights
348         const HashTable<scalar>& isotopeAtomicWts() const
349         {
350             return isotopeAtomicWts_;
351         }
353         //- Table of species
354         const speciesTable& species() const
355         {
356             return speciesTable_;
357         }
359         //- Specie phase
360         const HashTable<phase>& speciePhase() const
361         {
362             return speciePhase_;
363         }
365         //- Table of the thermodynamic data given in the CHEMKIN file
366         const HashPtrTable<gasThermoPhysics>& speciesThermo() const
367         {
368             return speciesThermo_;
369         }
371         //- Table of species composition
372         const HashTable<List<specieElement> >& specieComposition() const
373         {
374             return specieComposition_;
375         }
377         //- List of the reactions
378         const ReactionList<gasThermoPhysics>& reactions() const
379         {
380             return reactions_;
381         }
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 } // End namespace Foam
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 #endif
393 // ************************************************************************* //