OpenFOAM logo
Open Source CFD Toolkit

chemkinReader.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-2005 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     chemkinReader
00027 
00028 Description
00029 
00030 SourceFiles
00031     chemkinReader.C
00032     chemkinLexer.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef chemkinReader_H
00037 #define chemkinReader_H
00038 
00039 #include "chemistryReader.H"
00040 #include "fileName.H"
00041 #include "typeInfo.H"
00042 #include "HashPtrTable.H"
00043 #include "SLPtrList.H"
00044 #include "DynamicList.H"
00045 #include "labelList.H"
00046 #include "speciesTable.H"
00047 #include "atomicWeights.H"
00048 
00049 #include <FlexLexer.h>
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053 namespace Foam
00054 {
00055 
00056 /*---------------------------------------------------------------------------*\
00057                            Class chemkin Declaration
00058 \*---------------------------------------------------------------------------*/
00059 
00060 class chemkinReader
00061 :
00062     public chemistryReader,
00063     public yyFlexLexer
00064 {
00065 
00066 public:
00067 
00068     // Public data types
00069 
00070         enum phase
00071         {
00072             solid,
00073             liquid,
00074             gas
00075         };
00076 
00077         struct specieElement
00078         {
00079             word elementName;
00080             label nAtoms;
00081 
00082             bool operator==(const specieElement& se) const
00083             {
00084                 return 
00085                 (
00086                     nAtoms == se.nAtoms
00087                  && elementName == se.elementName
00088                 );
00089             }
00090 
00091             bool operator!=(const specieElement& se) const
00092             {
00093                 return !operator==(se);
00094             }
00095 
00096             friend Ostream& operator<<(Ostream& os, const specieElement& se)
00097             {
00098                 os  << se.nAtoms << token::SPACE << se.elementName;
00099                 return os;
00100             }
00101         };
00102 
00103 
00104 private:
00105 
00106     // Private data
00107 
00108         static int yyBufSize;
00109         label lineNo_;
00110 
00111         //- Table of reaction type keywords
00112         HashTable<int> reactionKeywordTable_;
00113 
00114         //- Currently supported reaction types
00115         enum reactionKeyword
00116         {
00117             thirdBodyReactionType,
00118             unimolecularFallOffReactionType,
00119             chemicallyActivatedBimolecularReactionType,
00120             TroeReactionType,
00121             SRIReactionType,
00122             LandauTellerReactionType,
00123             reverseLandauTellerReactionType,
00124             JanevReactionType,
00125             powerSeriesReactionRateType,
00126             radiationActivatedReactionType,
00127             speciesTempReactionType,
00128             energyLossReactionType,
00129             plasmaMomentumTransfer,
00130             collisionCrossSection,
00131             nonEquilibriumReversibleReactionType,
00132             duplicateReactionType,
00133             speciesOrderForward,
00134             speciesOrderReverse,
00135             UnitsOfReaction,
00136             end
00137         };
00138 
00139         enum reactionType
00140         {
00141             irreversible,
00142             reversible,
00143             nonEquilibriumReversible,
00144             unknownReactionType
00145         };
00146 
00147         static const char* reactionTypeNames[4];
00148 
00149         enum reactionRateType
00150         {
00151             Arrhenius,
00152             thirdBodyArrhenius,
00153             unimolecularFallOff,
00154             chemicallyActivatedBimolecular,
00155             LandauTeller,
00156             Janev,
00157             powerSeries,
00158             unknownReactionRateType
00159         };
00160 
00161         static const char* reactionRateTypeNames[8];
00162 
00163         enum fallOffFunctionType
00164         {
00165             Lindemann,
00166             Troe,
00167             SRI,
00168             unknownFallOffFunctionType
00169         };
00170 
00171         static const char* fallOffFunctionNames[4];
00172 
00173 
00174         void initReactionKeywordTable();
00175 
00176 
00177         //- List of elements
00178         DynamicList<word> elementNames_;
00179 
00180         //- Element indices
00181         HashTable<label> elementIndices_;
00182 
00183         //- Isotope molecular weights
00184         HashTable<scalar> isotopeAtomicWts_;
00185 
00186         //- List of species
00187         DynamicList<word> specieNames_;
00188 
00189         //- Specie indices
00190         HashTable<label> specieIndices_;
00191 
00192         //- Table of species
00193         speciesTable speciesTable_;
00194 
00195         //- Specie phase
00196         HashTable<phase> speciePhase_;
00197 
00198         //- Table of the thermodynamic data given in the CHEMKIN file
00199         HashPtrTable<reactionThermo> specieThermo_;
00200 
00201         //- Table of species composition
00202         HashTable<List<specieElement> > specieComposition_;
00203 
00204         //- List of the reactions
00205         SLPtrList<reaction> reactions_;
00206 
00207 
00208     // Private Member Functions
00209 
00210         //- Flex lexer to read the CHEMKIN III file
00211         int lex();
00212 
00213         inline scalar stringToScalar(const string& s)
00214         {
00215             string& str = const_cast<string&>(s);
00216             str.replaceAll(" ", "");
00217             str.replaceAll("D", "e");
00218             str.replaceAll("d", "e");
00219             return atof(str.c_str());
00220         }
00221 
00222         inline scalar stringToScalar(const char* cstr)
00223         {
00224             return stringToScalar(string(cstr));
00225         }
00226 
00227         inline void correctElementName(word& elementName)
00228         {
00229             if (elementName.size() == 2)
00230             {
00231                 elementName[1] = tolower(elementName[1]);
00232             }
00233             else if(elementName[0] == 'E')
00234             {
00235                 elementName = 'e';
00236             }
00237         }
00238 
00239         scalar molecularWeight
00240         (
00241             const List<specieElement>& specieComposition
00242         ) const;
00243 
00244         void finishElements(labelList& currentAtoms);
00245 
00246         void checkCoeffs
00247         (
00248             const scalarList& reactionCoeffs,
00249             const char* reationRateName,
00250             const label nCoeffs
00251         ) const;
00252 
00253         template<class ReactionRateType>
00254         void addReactionType
00255         (
00256             const reactionType rType,
00257             DynamicList<reaction::specieCoeffs>& lhs,
00258             DynamicList<reaction::specieCoeffs>& rhs,
00259             const ReactionRateType& rr
00260         );
00261 
00262         template<template<class, class> class PressureDependencyType>
00263         void addPressureDependentReaction
00264         (
00265             const reactionType rType,
00266             const fallOffFunctionType fofType,
00267             DynamicList<reaction::specieCoeffs>& lhs,
00268             DynamicList<reaction::specieCoeffs>& rhs,
00269             const scalarList& thirdBodyEfficiencies,
00270             const scalarList& k0Coeffs,
00271             const scalarList& kInfCoeffs,
00272             const HashTable<scalarList>& reactionCoeffsTable,
00273             const scalar Afactor0,
00274             const scalar AfactorInf,
00275             const scalar RR
00276         );
00277 
00278         void addReaction
00279         (
00280             DynamicList<reaction::specieCoeffs>& lhs,
00281             DynamicList<reaction::specieCoeffs>& rhs,
00282             const scalarList& thirdBodyEfficiencies,
00283             const reactionType rType,
00284             const reactionRateType rrType,
00285             const fallOffFunctionType fofType,
00286             const scalarList& ArrheniusReactionCoeffs,
00287             HashTable<scalarList>& reactionCoeffsTable,
00288             const scalar RR
00289         );
00290 
00291         // Read the CHEMKIN files
00292         void read
00293         (
00294             const fileName& CHEMKINFileName,
00295             const fileName& thermoFileName
00296         );
00297 
00298 
00299         //- Disallow default bitwise copy construct
00300         chemkinReader(const chemkinReader&);
00301 
00302         //- Disallow default bitwise assignment
00303         void operator=(const chemkinReader&);
00304 
00305 
00306 public:
00307 
00308     //- Runtime type information
00309     TypeName("chemkinReader");
00310 
00311 
00312     // Constructors
00313 
00314         //- Construct from CHEMKIN III file name
00315         chemkinReader
00316         (
00317             const fileName& chemkinFile,
00318             const fileName& thermoFileName = fileName::null
00319         );
00320 
00321         //- Construct by getting the CHEMKIN III file name from dictionary
00322         chemkinReader(const dictionary& thermoDict);
00323 
00324 
00325     // Destructor
00326 
00327         virtual ~chemkinReader()
00328         {}
00329 
00330 
00331     // Member functions
00332 
00333         //- List of elements
00334         const wordList& elementNames() const
00335         {
00336             return elementNames_;
00337         }
00338 
00339         //- Element indices
00340         const HashTable<label>& elementIndices() const
00341         {
00342             return elementIndices_;
00343         }
00344 
00345         //- Isotope molecular weights
00346         const HashTable<scalar>& isotopeAtomicWts() const
00347         {
00348             return isotopeAtomicWts_;
00349         }
00350 
00351         //- Table of species
00352         const speciesTable& species() const
00353         {
00354             return speciesTable_;
00355         }
00356 
00357         //- Specie phase
00358         const HashTable<phase>& speciePhase() const
00359         {
00360             return speciePhase_;
00361         }
00362 
00363         //- Table of the thermodynamic data given in the CHEMKIN file
00364         const HashPtrTable<reactionThermo>& specieThermo() const
00365         {
00366             return specieThermo_;
00367         }
00368 
00369         //- Table of species composition
00370         const HashTable<List<specieElement> >& specieComposition() const
00371         {
00372             return specieComposition_;
00373         }
00374 
00375         //- List of the reactions
00376         const SLPtrList<reaction>& reactions() const
00377         {
00378             return reactions_;
00379         }
00380 };
00381 
00382 
00383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00384 
00385 } // End namespace Foam
00386 
00387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00388 
00389 #endif
00390 
00391 // ************************************************************************* //
For further information go to www.openfoam.org