intersection with triangle plane for miss
[OpenFOAM-1.5.x.git] / src / thermophysicalModels / combustion / chemistryReaders / chemkinReader / chemkinReader.H
blobaf17281683ed5634d2bb91e54c0aef65f5dca7ba
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 <FlexLexer.h>
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 namespace Foam
57 /*---------------------------------------------------------------------------*\
58                            Class chemkin Declaration
59 \*---------------------------------------------------------------------------*/
61 class chemkinReader
63     public chemistryReader,
64     public yyFlexLexer
67 public:
69     // Public data types
71         enum phase
72         {
73             solid,
74             liquid,
75             gas
76         };
78         //- species element
79         struct specieElement
80         {
81             word elementName;
82             label nAtoms;
84             bool operator==(const specieElement& se) const
85             {
86                 return
87                 (
88                     nAtoms == se.nAtoms
89                  && elementName == se.elementName
90                 );
91             }
93             bool operator!=(const specieElement& se) const
94             {
95                 return !operator==(se);
96             }
98             friend Ostream& operator<<(Ostream& os, const specieElement& se)
99             {
100                 os  << se.nAtoms << token::SPACE << se.elementName;
101                 return os;
102             }
103         };
106 private:
108     // Private data
110         static int yyBufSize;
111         label lineNo_;
113         //- Table of reaction type keywords
114         HashTable<int> reactionKeywordTable_;
116         //- Currently supported reaction types
117         enum reactionKeyword
118         {
119             thirdBodyReactionType,
120             unimolecularFallOffReactionType,
121             chemicallyActivatedBimolecularReactionType,
122             TroeReactionType,
123             SRIReactionType,
124             LandauTellerReactionType,
125             reverseLandauTellerReactionType,
126             JanevReactionType,
127             powerSeriesReactionRateType,
128             radiationActivatedReactionType,
129             speciesTempReactionType,
130             energyLossReactionType,
131             plasmaMomentumTransfer,
132             collisionCrossSection,
133             nonEquilibriumReversibleReactionType,
134             duplicateReactionType,
135             speciesOrderForward,
136             speciesOrderReverse,
137             UnitsOfReaction,
138             end
139         };
141         enum reactionType
142         {
143             irreversible,
144             reversible,
145             nonEquilibriumReversible,
146             unknownReactionType
147         };
149         static const char* reactionTypeNames[4];
151         enum reactionRateType
152         {
153             Arrhenius,
154             thirdBodyArrhenius,
155             unimolecularFallOff,
156             chemicallyActivatedBimolecular,
157             LandauTeller,
158             Janev,
159             powerSeries,
160             unknownReactionRateType
161         };
163         static const char* reactionRateTypeNames[8];
165         enum fallOffFunctionType
166         {
167             Lindemann,
168             Troe,
169             SRI,
170             unknownFallOffFunctionType
171         };
173         static const char* fallOffFunctionNames[4];
176         void initReactionKeywordTable();
179         //- List of elements
180         DynamicList<word> elementNames_;
182         //- Element indices
183         HashTable<label> elementIndices_;
185         //- Isotope molecular weights
186         HashTable<scalar> isotopeAtomicWts_;
188         //- List of species
189         DynamicList<word> specieNames_;
191         //- Specie indices
192         HashTable<label> specieIndices_;
194         //- Table of species
195         speciesTable speciesTable_;
197         //- Specie phase
198         HashTable<phase> speciePhase_;
200         //- Table of the thermodynamic data given in the CHEMKIN file
201         HashPtrTable<reactionThermo> speciesThermo_;
203         //- Table of species composition
204         HashTable<List<specieElement> > specieComposition_;
206         //- List of the reactions
207         SLPtrList<reaction> reactions_;
210     // Private Member Functions
212         //- Flex lexer to read the CHEMKIN III file
213         int lex();
215         inline scalar stringToScalar(const string& s)
216         {
217             string& str = const_cast<string&>(s);
218             str.replaceAll(" ", "");
219             str.replaceAll("D", "e");
220             str.replaceAll("d", "e");
221             return atof(str.c_str());
222         }
224         inline scalar stringToScalar(const char* cstr)
225         {
226             return stringToScalar(string(cstr));
227         }
229         inline void correctElementName(word& elementName)
230         {
231             if (elementName.size() == 2)
232             {
233                 elementName[1] = tolower(elementName[1]);
234             }
235             else if(elementName[0] == 'E')
236             {
237                 elementName = 'e';
238             }
239         }
241         scalar molecularWeight
242         (
243             const List<specieElement>& specieComposition
244         ) const;
246         void finishElements(labelList& currentAtoms);
248         void checkCoeffs
249         (
250             const scalarList& reactionCoeffs,
251             const char* reationRateName,
252             const label nCoeffs
253         ) const;
255         template<class ReactionRateType>
256         void addReactionType
257         (
258             const reactionType rType,
259             DynamicList<reaction::specieCoeffs>& lhs,
260             DynamicList<reaction::specieCoeffs>& rhs,
261             const ReactionRateType& rr
262         );
264         template<template<class, class> class PressureDependencyType>
265         void addPressureDependentReaction
266         (
267             const reactionType rType,
268             const fallOffFunctionType fofType,
269             DynamicList<reaction::specieCoeffs>& lhs,
270             DynamicList<reaction::specieCoeffs>& rhs,
271             const scalarList& thirdBodyEfficiencies,
272             const scalarList& k0Coeffs,
273             const scalarList& kInfCoeffs,
274             const HashTable<scalarList>& reactionCoeffsTable,
275             const scalar Afactor0,
276             const scalar AfactorInf,
277             const scalar RR
278         );
280         void addReaction
281         (
282             DynamicList<reaction::specieCoeffs>& lhs,
283             DynamicList<reaction::specieCoeffs>& rhs,
284             const scalarList& thirdBodyEfficiencies,
285             const reactionType rType,
286             const reactionRateType rrType,
287             const fallOffFunctionType fofType,
288             const scalarList& ArrheniusReactionCoeffs,
289             HashTable<scalarList>& reactionCoeffsTable,
290             const scalar RR
291         );
293         // Read the CHEMKIN files
294         void read
295         (
296             const fileName& CHEMKINFileName,
297             const fileName& thermoFileName
298         );
301         //- Disallow default bitwise copy construct
302         chemkinReader(const chemkinReader&);
304         //- Disallow default bitwise assignment
305         void operator=(const chemkinReader&);
308 public:
310     //- Runtime type information
311     TypeName("chemkinReader");
314     // Constructors
316         //- Construct from CHEMKIN III file name
317         chemkinReader
318         (
319             const fileName& chemkinFile,
320             const fileName& thermoFileName = fileName::null
321         );
323         //- Construct by getting the CHEMKIN III file name from dictionary
324         chemkinReader(const dictionary& thermoDict);
327     // 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<reactionThermo>& 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 SLPtrList<reaction>& reactions() const
379         {
380             return reactions_;
381         }
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 } // End namespace Foam
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 #endif
393 // ************************************************************************* //