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