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