initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / thermophysicalModels / reactionThermo / chemistryReaders / chemkinReader / chemkinReader.H
blobde679103806b55e96a6a8a9faad1edd41bca973a
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::chemkinReader
28 Description
29     Foam::chemkinReader
31 SourceFiles
32     chemkinReader.C
33     chemkinLexer.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef chemkinReader_H
38 #define chemkinReader_H
40 #include "chemistryReader.H"
41 #include "fileName.H"
42 #include "typeInfo.H"
43 #include "HashPtrTable.H"
44 #include "SLPtrList.H"
45 #include "DynamicList.H"
46 #include "labelList.H"
47 #include "speciesTable.H"
48 #include "atomicWeights.H"
50 #include "reactionTypes.H"
52 #include <FlexLexer.h>
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 namespace Foam
59 /*---------------------------------------------------------------------------*\
60                        Class chemkinReader Declaration
61 \*---------------------------------------------------------------------------*/
63 class chemkinReader
65     public chemistryReader<gasThermoPhysics>,
66     public yyFlexLexer
69 public:
71     // Public data types
73         enum phase
74         {
75             solid,
76             liquid,
77             gas
78         };
80         //- species element
81         struct specieElement
82         {
83             word elementName;
84             label nAtoms;
86             bool operator==(const specieElement& se) const
87             {
88                 return
89                 (
90                     nAtoms == se.nAtoms
91                  && elementName == se.elementName
92                 );
93             }
95             bool operator!=(const specieElement& se) const
96             {
97                 return !operator==(se);
98             }
100             friend Ostream& operator<<(Ostream& os, const specieElement& se)
101             {
102                 os  << se.nAtoms << token::SPACE << se.elementName;
103                 return os;
104             }
105         };
108 private:
110     // Private data
112         static int yyBufSize;
113         label lineNo_;
115         //- Table of reaction type keywords
116         HashTable<int> reactionKeywordTable_;
118         //- Currently supported reaction types
119         enum reactionKeyword
120         {
121             thirdBodyReactionType,
122             unimolecularFallOffReactionType,
123             chemicallyActivatedBimolecularReactionType,
124             TroeReactionType,
125             SRIReactionType,
126             LandauTellerReactionType,
127             reverseLandauTellerReactionType,
128             JanevReactionType,
129             powerSeriesReactionRateType,
130             radiationActivatedReactionType,
131             speciesTempReactionType,
132             energyLossReactionType,
133             plasmaMomentumTransfer,
134             collisionCrossSection,
135             nonEquilibriumReversibleReactionType,
136             duplicateReactionType,
137             speciesOrderForward,
138             speciesOrderReverse,
139             UnitsOfReaction,
140             end
141         };
143         enum reactionType
144         {
145             irreversible,
146             reversible,
147             nonEquilibriumReversible,
148             unknownReactionType
149         };
151         static const char* reactionTypeNames[4];
153         enum reactionRateType
154         {
155             Arrhenius,
156             thirdBodyArrhenius,
157             unimolecularFallOff,
158             chemicallyActivatedBimolecular,
159             LandauTeller,
160             Janev,
161             powerSeries,
162             unknownReactionRateType
163         };
165         static const char* reactionRateTypeNames[8];
167         enum fallOffFunctionType
168         {
169             Lindemann,
170             Troe,
171             SRI,
172             unknownFallOffFunctionType
173         };
175         static const char* fallOffFunctionNames[4];
178         void initReactionKeywordTable();
181         //- List of elements
182         DynamicList<word> elementNames_;
184         //- Element indices
185         HashTable<label> elementIndices_;
187         //- Isotope molecular weights
188         HashTable<scalar> isotopeAtomicWts_;
190         //- List of species
191         DynamicList<word> specieNames_;
193         //- Specie indices
194         HashTable<label> specieIndices_;
196         //- Table of species
197         speciesTable speciesTable_;
199         //- Specie phase
200         HashTable<phase> speciePhase_;
202         //- Table of the thermodynamic data given in the CHEMKIN file
203         HashPtrTable<gasThermoPhysics> speciesThermo_;
205         //- Table of species composition
206         HashTable<List<specieElement> > specieComposition_;
208         //- List of the reactions
209         SLPtrList<gasReaction> reactions_;
212     // Private Member Functions
214         //- Flex lexer to read the CHEMKIN III file
215         int lex();
217         inline scalar stringToScalar(const string& s)
218         {
219             string& str = const_cast<string&>(s);
220             str.replaceAll(" ", "");
221             str.replaceAll("D", "e");
222             str.replaceAll("d", "e");
223             return atof(str.c_str());
224         }
226         inline scalar stringToScalar(const char* cstr)
227         {
228             return stringToScalar(string(cstr));
229         }
231         inline void correctElementName(word& elementName)
232         {
233             if (elementName.size() == 2)
234             {
235                 elementName[1] = tolower(elementName[1]);
236             }
237             else if(elementName[0] == 'E')
238             {
239                 elementName = 'e';
240             }
241         }
243         scalar molecularWeight
244         (
245             const List<specieElement>& specieComposition
246         ) const;
248         void finishElements(labelList& currentAtoms);
250         void checkCoeffs
251         (
252             const scalarList& reactionCoeffs,
253             const char* reationRateName,
254             const label nCoeffs
255         ) const;
257         template<class ReactionRateType>
258         void addReactionType
259         (
260             const reactionType rType,
261             DynamicList<gasReaction::specieCoeffs>& lhs,
262             DynamicList<gasReaction::specieCoeffs>& rhs,
263             const ReactionRateType& rr
264         );
266         template<template<class, class> class PressureDependencyType>
267         void addPressureDependentReaction
268         (
269             const reactionType rType,
270             const fallOffFunctionType fofType,
271             DynamicList<gasReaction::specieCoeffs>& lhs,
272             DynamicList<gasReaction::specieCoeffs>& rhs,
273             const scalarList& thirdBodyEfficiencies,
274             const scalarList& k0Coeffs,
275             const scalarList& kInfCoeffs,
276             const HashTable<scalarList>& reactionCoeffsTable,
277             const scalar Afactor0,
278             const scalar AfactorInf,
279             const scalar RR
280         );
282         void addReaction
283         (
284             DynamicList<gasReaction::specieCoeffs>& lhs,
285             DynamicList<gasReaction::specieCoeffs>& rhs,
286             const scalarList& thirdBodyEfficiencies,
287             const reactionType rType,
288             const reactionRateType rrType,
289             const fallOffFunctionType fofType,
290             const scalarList& ArrheniusReactionCoeffs,
291             HashTable<scalarList>& reactionCoeffsTable,
292             const scalar RR
293         );
295         // Read the CHEMKIN files
296         void read
297         (
298             const fileName& CHEMKINFileName,
299             const fileName& thermoFileName
300         );
303         //- Disallow default bitwise copy construct
304         chemkinReader(const chemkinReader&);
306         //- Disallow default bitwise assignment
307         void operator=(const chemkinReader&);
310 public:
312     //- Runtime type information
313     TypeName("chemkinReader");
316     // Constructors
318         //- Construct from CHEMKIN III file name
319         chemkinReader
320         (
321             const fileName& chemkinFile,
322             const fileName& thermoFileName = fileName::null
323         );
325         //- Construct by getting the CHEMKIN III file name from dictionary
326         chemkinReader(const dictionary& thermoDict);
329     // Destructor
331         virtual ~chemkinReader()
332         {}
335     // Member functions
337         //- List of elements
338         const wordList& elementNames() const
339         {
340             return elementNames_;
341         }
343         //- Element indices
344         const HashTable<label>& elementIndices() const
345         {
346             return elementIndices_;
347         }
349         //- Isotope molecular weights
350         const HashTable<scalar>& isotopeAtomicWts() const
351         {
352             return isotopeAtomicWts_;
353         }
355         //- Table of species
356         const speciesTable& species() const
357         {
358             return speciesTable_;
359         }
361         //- Specie phase
362         const HashTable<phase>& speciePhase() const
363         {
364             return speciePhase_;
365         }
367         //- Table of the thermodynamic data given in the CHEMKIN file
368         const HashPtrTable<gasThermoPhysics>& speciesThermo() const
369         {
370             return speciesThermo_;
371         }
373         //- Table of species composition
374         const HashTable<List<specieElement> >& specieComposition() const
375         {
376             return specieComposition_;
377         }
379         //- List of the reactions
380         const SLPtrList<gasReaction>& reactions() const
381         {
382             return reactions_;
383         }
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 } // End namespace Foam
391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
393 #endif
395 // ************************************************************************* //