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 #include "chemkinReader.H"
00028 #include <fstream>
00029 #include "atomicWeights.H"
00030 #include "IrreversibleReaction.H"
00031 #include "ReversibleReaction.H"
00032 #include "NonEquilibriumReversibleReaction.H"
00033 #include "ArrheniusReactionRate.H"
00034 #include "thirdBodyArrheniusReactionRate.H"
00035 #include "FallOffReactionRate.H"
00036 #include "ChemicallyActivatedReactionRate.H"
00037 #include "LindemannFallOffFunction.H"
00038 #include "TroeFallOffFunction.H"
00039 #include "SRIFallOffFunction.H"
00040 #include "LandauTellerReactionRate.H"
00041 #include "JanevReactionRate.H"
00042 #include "powerSeriesReactionRate.H"
00043 #include "addToRunTimeSelectionTable.H"
00044
00045
00046
00047 namespace Foam
00048 {
00049 addChemistryReaderType(chemkinReader, gasThermoPhysics);
00050 };
00051
00052
00053
00054 const char* Foam::chemkinReader::reactionTypeNames[4] =
00055 {
00056 "irreversible",
00057 "reversible",
00058 "nonEquilibriumReversible",
00059 "unknownReactionType"
00060 };
00061
00062 const char* Foam::chemkinReader::reactionRateTypeNames[8] =
00063 {
00064 "Arrhenius",
00065 "thirdBodyArrhenius",
00066 "unimolecularFallOff",
00067 "chemicallyActivatedBimolecular",
00068 "LandauTeller",
00069 "Janev",
00070 "powerSeries",
00071 "unknownReactionRateType"
00072 };
00073
00074 const char* Foam::chemkinReader::fallOffFunctionNames[4] =
00075 {
00076 "Lindemann",
00077 "Troe",
00078 "SRI",
00079 "unknownFallOffFunctionType"
00080 };
00081
00082 void Foam::chemkinReader::initReactionKeywordTable()
00083 {
00084 reactionKeywordTable_.insert("M", thirdBodyReactionType);
00085 reactionKeywordTable_.insert("LOW", unimolecularFallOffReactionType);
00086 reactionKeywordTable_.insert("HIGH", chemicallyActivatedBimolecularReactionType);
00087 reactionKeywordTable_.insert("TROE", TroeReactionType);
00088 reactionKeywordTable_.insert("SRI", SRIReactionType);
00089 reactionKeywordTable_.insert("LT", LandauTellerReactionType);
00090 reactionKeywordTable_.insert("RLT", reverseLandauTellerReactionType);
00091 reactionKeywordTable_.insert("JAN", JanevReactionType);
00092 reactionKeywordTable_.insert("FIT1", powerSeriesReactionRateType);
00093 reactionKeywordTable_.insert("HV", radiationActivatedReactionType);
00094 reactionKeywordTable_.insert("TDEP", speciesTempReactionType);
00095 reactionKeywordTable_.insert("EXCI", energyLossReactionType);
00096 reactionKeywordTable_.insert("MOME", plasmaMomentumTransfer);
00097 reactionKeywordTable_.insert("XSMI", collisionCrossSection);
00098 reactionKeywordTable_.insert("REV", nonEquilibriumReversibleReactionType);
00099 reactionKeywordTable_.insert("DUPLICATE", duplicateReactionType);
00100 reactionKeywordTable_.insert("DUP", duplicateReactionType);
00101 reactionKeywordTable_.insert("FORD", speciesOrderForward);
00102 reactionKeywordTable_.insert("RORD", speciesOrderReverse);
00103 reactionKeywordTable_.insert("UNITS", UnitsOfReaction);
00104 reactionKeywordTable_.insert("END", end);
00105 }
00106
00107
00108 Foam::scalar Foam::chemkinReader::molecularWeight
00109 (
00110 const List<specieElement>& specieComposition
00111 ) const
00112 {
00113 scalar molWt = 0.0;
00114
00115 forAll (specieComposition, i)
00116 {
00117 label nAtoms = specieComposition[i].nAtoms;
00118 const word& elementName = specieComposition[i].elementName;
00119
00120 if (isotopeAtomicWts_.found(elementName))
00121 {
00122 molWt += nAtoms*isotopeAtomicWts_[elementName];
00123 }
00124 else if (atomicWeights.found(elementName))
00125 {
00126 molWt += nAtoms*atomicWeights[elementName];
00127 }
00128 else
00129 {
00130 FatalErrorIn("chemkinReader::lex()")
00131 << "Unknown element " << elementName
00132 << " on line " << lineNo_-1 << nl
00133 << " specieComposition: " << specieComposition
00134 << exit(FatalError);
00135 }
00136 }
00137
00138 return molWt;
00139 }
00140
00141
00142 void Foam::chemkinReader::checkCoeffs
00143 (
00144 const scalarList& reactionCoeffs,
00145 const char* reactionRateName,
00146 const label nCoeffs
00147 ) const
00148 {
00149 if (reactionCoeffs.size() != nCoeffs)
00150 {
00151 FatalErrorIn("chemkinReader::checkCoeffs")
00152 << "Wrong number of coefficients for the " << reactionRateName
00153 << " rate expression on line "
00154 << lineNo_-1 << ", should be "
00155 << nCoeffs << " but " << reactionCoeffs.size() << " supplied." << nl
00156 << "Coefficients are "
00157 << reactionCoeffs << nl
00158 << exit(FatalError);
00159 }
00160 }
00161
00162 template<class ReactionRateType>
00163 void Foam::chemkinReader::addReactionType
00164 (
00165 const reactionType rType,
00166 DynamicList<gasReaction::specieCoeffs>& lhs,
00167 DynamicList<gasReaction::specieCoeffs>& rhs,
00168 const ReactionRateType& rr
00169 )
00170 {
00171 switch (rType)
00172 {
00173 case irreversible:
00174 {
00175 reactions_.append
00176 (
00177 new IrreversibleReaction<gasThermoPhysics, ReactionRateType>
00178 (
00179 Reaction<gasThermoPhysics>
00180 (
00181 speciesTable_,
00182 lhs.shrink(),
00183 rhs.shrink(),
00184 speciesThermo_
00185 ),
00186 rr
00187 )
00188 );
00189 }
00190 break;
00191
00192 case reversible:
00193 {
00194 reactions_.append
00195 (
00196 new ReversibleReaction<gasThermoPhysics, ReactionRateType>
00197 (
00198 Reaction<gasThermoPhysics>
00199 (
00200 speciesTable_,
00201 lhs.shrink(),
00202 rhs.shrink(),
00203 speciesThermo_
00204 ),
00205 rr
00206 )
00207 );
00208 }
00209 break;
00210
00211 default:
00212
00213 if (rType < 3)
00214 {
00215 FatalErrorIn("chemkinReader::addReactionType")
00216 << "Reaction type " << reactionTypeNames[rType]
00217 << " on line " << lineNo_-1
00218 << " not handled by this function"
00219 << exit(FatalError);
00220 }
00221 else
00222 {
00223 FatalErrorIn("chemkinReader::addReactionType")
00224 << "Unknown reaction type " << rType
00225 << " on line " << lineNo_-1
00226 << exit(FatalError);
00227 }
00228 }
00229 }
00230
00231 template<template<class, class> class PressureDependencyType>
00232 void Foam::chemkinReader::addPressureDependentReaction
00233 (
00234 const reactionType rType,
00235 const fallOffFunctionType fofType,
00236 DynamicList<gasReaction::specieCoeffs>& lhs,
00237 DynamicList<gasReaction::specieCoeffs>& rhs,
00238 const scalarList& efficiencies,
00239 const scalarList& k0Coeffs,
00240 const scalarList& kInfCoeffs,
00241 const HashTable<scalarList>& reactionCoeffsTable,
00242 const scalar Afactor0,
00243 const scalar AfactorInf,
00244 const scalar RR
00245 )
00246 {
00247 checkCoeffs(k0Coeffs, "k0", 3);
00248 checkCoeffs(kInfCoeffs, "kInf", 3);
00249
00250 switch (fofType)
00251 {
00252 case Lindemann:
00253 {
00254 addReactionType
00255 (
00256 rType,
00257 lhs, rhs,
00258 PressureDependencyType
00259 <ArrheniusReactionRate, LindemannFallOffFunction>
00260 (
00261 ArrheniusReactionRate
00262 (
00263 Afactor0*k0Coeffs[0],
00264 k0Coeffs[1],
00265 k0Coeffs[2]/RR
00266 ),
00267 ArrheniusReactionRate
00268 (
00269 AfactorInf*kInfCoeffs[0],
00270 kInfCoeffs[1],
00271 kInfCoeffs[2]/RR
00272 ),
00273 LindemannFallOffFunction(),
00274 thirdBodyEfficiencies(speciesTable_, efficiencies)
00275 )
00276 );
00277 }
00278 break;
00279
00280 case Troe:
00281 {
00282 scalarList TroeCoeffs
00283 (
00284 reactionCoeffsTable[fallOffFunctionNames[fofType]]
00285 );
00286
00287 if (TroeCoeffs.size() != 4 && TroeCoeffs.size() != 3)
00288 {
00289 FatalErrorIn("chemkinReader::addPressureDependentReaction")
00290 << "Wrong number of coefficients for Troe rate expression"
00291 " on line " << lineNo_-1 << ", should be 3 or 4 but "
00292 << TroeCoeffs.size() << " supplied." << nl
00293 << "Coefficients are "
00294 << TroeCoeffs << nl
00295 << exit(FatalError);
00296 }
00297
00298 if (TroeCoeffs.size() == 3)
00299 {
00300 TroeCoeffs.setSize(4);
00301 TroeCoeffs[3] = GREAT;
00302 }
00303
00304 addReactionType
00305 (
00306 rType,
00307 lhs, rhs,
00308 PressureDependencyType
00309 <ArrheniusReactionRate, TroeFallOffFunction>
00310 (
00311 ArrheniusReactionRate
00312 (
00313 Afactor0*k0Coeffs[0],
00314 k0Coeffs[1],
00315 k0Coeffs[2]/RR
00316 ),
00317 ArrheniusReactionRate
00318 (
00319 AfactorInf*kInfCoeffs[0],
00320 kInfCoeffs[1],
00321 kInfCoeffs[2]/RR
00322 ),
00323 TroeFallOffFunction
00324 (
00325 TroeCoeffs[0],
00326 TroeCoeffs[1],
00327 TroeCoeffs[2],
00328 TroeCoeffs[3]
00329 ),
00330 thirdBodyEfficiencies(speciesTable_, efficiencies)
00331 )
00332 );
00333 }
00334 break;
00335
00336 case SRI:
00337 {
00338 scalarList SRICoeffs
00339 (
00340 reactionCoeffsTable[fallOffFunctionNames[fofType]]
00341 );
00342
00343 if (SRICoeffs.size() != 5 && SRICoeffs.size() != 3)
00344 {
00345 FatalErrorIn("chemkinReader::addPressureDependentReaction")
00346 << "Wrong number of coefficients for SRI rate expression"
00347 " on line " << lineNo_-1 << ", should be 3 or 5 but "
00348 << SRICoeffs.size() << " supplied." << nl
00349 << "Coefficients are "
00350 << SRICoeffs << nl
00351 << exit(FatalError);
00352 }
00353
00354 if (SRICoeffs.size() == 3)
00355 {
00356 SRICoeffs.setSize(5);
00357 SRICoeffs[3] = 1.0;
00358 SRICoeffs[4] = 0.0;
00359 }
00360
00361 addReactionType
00362 (
00363 rType,
00364 lhs, rhs,
00365 PressureDependencyType
00366 <ArrheniusReactionRate, SRIFallOffFunction>
00367 (
00368 ArrheniusReactionRate
00369 (
00370 Afactor0*k0Coeffs[0],
00371 k0Coeffs[1],
00372 k0Coeffs[2]/RR
00373 ),
00374 ArrheniusReactionRate
00375 (
00376 AfactorInf*kInfCoeffs[0],
00377 kInfCoeffs[1],
00378 kInfCoeffs[2]/RR
00379 ),
00380 SRIFallOffFunction
00381 (
00382 SRICoeffs[0],
00383 SRICoeffs[1],
00384 SRICoeffs[2],
00385 SRICoeffs[3],
00386 SRICoeffs[4]
00387 ),
00388 thirdBodyEfficiencies(speciesTable_, efficiencies)
00389 )
00390 );
00391 }
00392 break;
00393
00394 default:
00395 {
00396 if (fofType < 4)
00397 {
00398 FatalErrorIn("chemkinReader::addPressureDependentReaction")
00399 << "Fall-off function type "
00400 << fallOffFunctionNames[fofType]
00401 << " on line " << lineNo_-1
00402 << " not implemented"
00403 << exit(FatalError);
00404 }
00405 else
00406 {
00407 FatalErrorIn("chemkinReader::addPressureDependentReaction")
00408 << "Unknown fall-off function type " << fofType
00409 << " on line " << lineNo_-1
00410 << exit(FatalError);
00411 }
00412 }
00413 }
00414 }
00415
00416
00417 void Foam::chemkinReader::addReaction
00418 (
00419 DynamicList<gasReaction::specieCoeffs>& lhs,
00420 DynamicList<gasReaction::specieCoeffs>& rhs,
00421 const scalarList& efficiencies,
00422 const reactionType rType,
00423 const reactionRateType rrType,
00424 const fallOffFunctionType fofType,
00425 const scalarList& ArrheniusCoeffs,
00426 HashTable<scalarList>& reactionCoeffsTable,
00427 const scalar RR
00428 )
00429 {
00430 checkCoeffs(ArrheniusCoeffs, "Arrhenius", 3);
00431
00432 scalarList nAtoms(elementNames_.size(), 0.0);
00433
00434 forAll (lhs, i)
00435 {
00436 const List<specieElement>& specieComposition =
00437 specieComposition_[speciesTable_[lhs[i].index]];
00438
00439 forAll (specieComposition, j)
00440 {
00441 label elementi = elementIndices_[specieComposition[j].elementName];
00442 nAtoms[elementi] += lhs[i].stoichCoeff*specieComposition[j].nAtoms;
00443 }
00444 }
00445
00446 forAll (rhs, i)
00447 {
00448 const List<specieElement>& specieComposition =
00449 specieComposition_[speciesTable_[rhs[i].index]];
00450
00451 forAll (specieComposition, j)
00452 {
00453 label elementi = elementIndices_[specieComposition[j].elementName];
00454 nAtoms[elementi] -= rhs[i].stoichCoeff*specieComposition[j].nAtoms;
00455 }
00456 }
00457
00458
00459
00460
00461 const scalar concFactor = 0.001;
00462 scalar sumExp = 0.0;
00463 forAll (lhs, i)
00464 {
00465 sumExp += lhs[i].exponent;
00466 }
00467 scalar Afactor = pow(concFactor, sumExp - 1.0);
00468
00469 scalar AfactorRev = Afactor;
00470
00471 if (rType == nonEquilibriumReversible)
00472 {
00473 sumExp = 0.0;
00474 forAll (rhs, i)
00475 {
00476 sumExp += rhs[i].exponent;
00477 }
00478 AfactorRev = pow(concFactor, sumExp - 1.0);
00479 }
00480
00481 switch (rrType)
00482 {
00483 case Arrhenius:
00484 {
00485 if (rType == nonEquilibriumReversible)
00486 {
00487 const scalarList& reverseArrheniusCoeffs =
00488 reactionCoeffsTable[reactionTypeNames[rType]];
00489
00490 checkCoeffs(reverseArrheniusCoeffs, "reverse Arrhenius", 3);
00491
00492 reactions_.append
00493 (
00494 new NonEquilibriumReversibleReaction
00495 <gasThermoPhysics, ArrheniusReactionRate>
00496 (
00497 Reaction<gasThermoPhysics>
00498 (
00499 speciesTable_,
00500 lhs.shrink(),
00501 rhs.shrink(),
00502 speciesThermo_
00503 ),
00504 ArrheniusReactionRate
00505 (
00506 Afactor*ArrheniusCoeffs[0],
00507 ArrheniusCoeffs[1],
00508 ArrheniusCoeffs[2]/RR
00509 ),
00510 ArrheniusReactionRate
00511 (
00512 AfactorRev*reverseArrheniusCoeffs[0],
00513 reverseArrheniusCoeffs[1],
00514 reverseArrheniusCoeffs[2]/RR
00515 )
00516 )
00517 );
00518 }
00519 else
00520 {
00521 addReactionType
00522 (
00523 rType,
00524 lhs, rhs,
00525 ArrheniusReactionRate
00526 (
00527 Afactor*ArrheniusCoeffs[0],
00528 ArrheniusCoeffs[1],
00529 ArrheniusCoeffs[2]/RR
00530 )
00531 );
00532 }
00533 }
00534 break;
00535
00536 case thirdBodyArrhenius:
00537 {
00538 if (rType == nonEquilibriumReversible)
00539 {
00540 const scalarList& reverseArrheniusCoeffs =
00541 reactionCoeffsTable[reactionTypeNames[rType]];
00542
00543 checkCoeffs(reverseArrheniusCoeffs, "reverse Arrhenius", 3);
00544
00545 reactions_.append
00546 (
00547 new NonEquilibriumReversibleReaction
00548 <gasThermoPhysics, thirdBodyArrheniusReactionRate>
00549 (
00550 Reaction<gasThermoPhysics>
00551 (
00552 speciesTable_,
00553 lhs.shrink(),
00554 rhs.shrink(),
00555 speciesThermo_
00556 ),
00557 thirdBodyArrheniusReactionRate
00558 (
00559 Afactor*concFactor*ArrheniusCoeffs[0],
00560 ArrheniusCoeffs[1],
00561 ArrheniusCoeffs[2]/RR,
00562 thirdBodyEfficiencies(speciesTable_, efficiencies)
00563 ),
00564 thirdBodyArrheniusReactionRate
00565 (
00566 AfactorRev*concFactor*reverseArrheniusCoeffs[0],
00567 reverseArrheniusCoeffs[1],
00568 reverseArrheniusCoeffs[2]/RR,
00569 thirdBodyEfficiencies(speciesTable_, efficiencies)
00570 )
00571 )
00572 );
00573 }
00574 else
00575 {
00576 addReactionType
00577 (
00578 rType,
00579 lhs, rhs,
00580 thirdBodyArrheniusReactionRate
00581 (
00582 Afactor*concFactor*ArrheniusCoeffs[0],
00583 ArrheniusCoeffs[1],
00584 ArrheniusCoeffs[2]/RR,
00585 thirdBodyEfficiencies(speciesTable_, efficiencies)
00586 )
00587 );
00588 }
00589 }
00590 break;
00591
00592 case unimolecularFallOff:
00593 {
00594 addPressureDependentReaction<FallOffReactionRate>
00595 (
00596 rType,
00597 fofType,
00598 lhs,
00599 rhs,
00600 efficiencies,
00601 reactionCoeffsTable[reactionRateTypeNames[rrType]],
00602 ArrheniusCoeffs,
00603 reactionCoeffsTable,
00604 concFactor*Afactor,
00605 Afactor,
00606 RR
00607 );
00608 }
00609 break;
00610
00611 case chemicallyActivatedBimolecular:
00612 {
00613 addPressureDependentReaction<ChemicallyActivatedReactionRate>
00614 (
00615 rType,
00616 fofType,
00617 lhs,
00618 rhs,
00619 efficiencies,
00620 ArrheniusCoeffs,
00621 reactionCoeffsTable[reactionRateTypeNames[rrType]],
00622 reactionCoeffsTable,
00623 Afactor,
00624 Afactor/concFactor,
00625 RR
00626 );
00627 }
00628 break;
00629
00630 case LandauTeller:
00631 {
00632 const scalarList& LandauTellerCoeffs =
00633 reactionCoeffsTable[reactionRateTypeNames[rrType]];
00634 checkCoeffs(LandauTellerCoeffs, "Landau-Teller", 2);
00635
00636 if (rType == nonEquilibriumReversible)
00637 {
00638 const scalarList& reverseArrheniusCoeffs =
00639 reactionCoeffsTable[reactionTypeNames[rType]];
00640 checkCoeffs(reverseArrheniusCoeffs, "reverse Arrhenius", 3);
00641
00642 const scalarList& reverseLandauTellerCoeffs =
00643 reactionCoeffsTable
00644 [
00645 word(reactionTypeNames[rType])
00646 + reactionRateTypeNames[rrType]
00647 ];
00648 checkCoeffs(LandauTellerCoeffs, "reverse Landau-Teller", 2);
00649
00650 reactions_.append
00651 (
00652 new NonEquilibriumReversibleReaction
00653 <gasThermoPhysics, LandauTellerReactionRate>
00654 (
00655 Reaction<gasThermoPhysics>
00656 (
00657 speciesTable_,
00658 lhs.shrink(),
00659 rhs.shrink(),
00660 speciesThermo_
00661 ),
00662 LandauTellerReactionRate
00663 (
00664 Afactor*ArrheniusCoeffs[0],
00665 ArrheniusCoeffs[1],
00666 ArrheniusCoeffs[2]/RR,
00667 LandauTellerCoeffs[0],
00668 LandauTellerCoeffs[1]
00669 ),
00670 LandauTellerReactionRate
00671 (
00672 AfactorRev*reverseArrheniusCoeffs[0],
00673 reverseArrheniusCoeffs[1],
00674 reverseArrheniusCoeffs[2]/RR,
00675 reverseLandauTellerCoeffs[0],
00676 reverseLandauTellerCoeffs[1]
00677 )
00678 )
00679 );
00680 }
00681 else
00682 {
00683 addReactionType
00684 (
00685 rType,
00686 lhs, rhs,
00687 LandauTellerReactionRate
00688 (
00689 Afactor*ArrheniusCoeffs[0],
00690 ArrheniusCoeffs[1],
00691 ArrheniusCoeffs[2]/RR,
00692 LandauTellerCoeffs[0],
00693 LandauTellerCoeffs[1]
00694 )
00695 );
00696 }
00697 }
00698 break;
00699
00700 case Janev:
00701 {
00702 const scalarList& JanevCoeffs =
00703 reactionCoeffsTable[reactionRateTypeNames[rrType]];
00704
00705 checkCoeffs(JanevCoeffs, "Janev", 9);
00706
00707 addReactionType
00708 (
00709 rType,
00710 lhs, rhs,
00711 JanevReactionRate
00712 (
00713 Afactor*ArrheniusCoeffs[0],
00714 ArrheniusCoeffs[1],
00715 ArrheniusCoeffs[2]/RR,
00716 JanevCoeffs.begin()
00717 )
00718 );
00719 }
00720 break;
00721
00722 case powerSeries:
00723 {
00724 const scalarList& powerSeriesCoeffs =
00725 reactionCoeffsTable[reactionRateTypeNames[rrType]];
00726
00727 checkCoeffs(powerSeriesCoeffs, "power-series", 4);
00728
00729 addReactionType
00730 (
00731 rType,
00732 lhs, rhs,
00733 powerSeriesReactionRate
00734 (
00735 Afactor*ArrheniusCoeffs[0],
00736 ArrheniusCoeffs[1],
00737 ArrheniusCoeffs[2]/RR,
00738 powerSeriesCoeffs.begin()
00739 )
00740 );
00741 }
00742 break;
00743
00744 case unknownReactionRateType:
00745 {
00746 FatalErrorIn("chemkinReader::addReaction")
00747 << "Internal error on line " << lineNo_-1
00748 << ": reaction rate type has not been set"
00749 << exit(FatalError);
00750 }
00751 break;
00752
00753 default:
00754 {
00755 if (rrType < 9)
00756 {
00757 FatalErrorIn("chemkinReader::addReaction")
00758 << "Reaction rate type " << reactionRateTypeNames[rrType]
00759 << " on line " << lineNo_-1
00760 << " not implemented"
00761 << exit(FatalError);
00762 }
00763 else
00764 {
00765 FatalErrorIn("chemkinReader::addReaction")
00766 << "Unknown reaction rate type " << rrType
00767 << " on line " << lineNo_-1
00768 << exit(FatalError);
00769 }
00770 }
00771 }
00772
00773
00774 forAll (nAtoms, i)
00775 {
00776 if (mag(nAtoms[i]) > SMALL)
00777 {
00778 FatalErrorIn("chemkinReader::addReaction")
00779 << "Elemental imbalance in " << elementNames_[i]
00780 << " in reaction" << nl
00781 << reactions_.last() << nl
00782 << " on line " << lineNo_-1
00783 << exit(FatalError);
00784 }
00785 }
00786
00787 lhs.clear();
00788 rhs.clear();
00789 reactionCoeffsTable.clear();
00790 }
00791
00792
00793 void Foam::chemkinReader::read
00794 (
00795 const fileName& CHEMKINFileName,
00796 const fileName& thermoFileName
00797 )
00798 {
00799 if (thermoFileName != fileName::null)
00800 {
00801 std::ifstream thermoStream(thermoFileName.c_str());
00802
00803 if (!thermoStream)
00804 {
00805 FatalErrorIn
00806 (
00807 "chemkin::chemkin(const fileName& CHEMKINFileName, "
00808 "const fileName& thermoFileName)"
00809 ) << "file " << thermoFileName << " not found"
00810 << exit(FatalError);
00811 }
00812
00813 yy_buffer_state* bufferPtr(yy_create_buffer(&thermoStream, yyBufSize));
00814 yy_switch_to_buffer(bufferPtr);
00815
00816 while(lex() != 0)
00817 {}
00818
00819 yy_delete_buffer(bufferPtr);
00820
00821 lineNo_ = 1;
00822 }
00823
00824 std::ifstream CHEMKINStream(CHEMKINFileName.c_str());
00825
00826 if (!CHEMKINStream)
00827 {
00828 FatalErrorIn
00829 (
00830 "chemkin::chemkin(const fileName& CHEMKINFileName, "
00831 "const fileName& thermoFileName)"
00832 ) << "file " << CHEMKINFileName << " not found"
00833 << exit(FatalError);
00834 }
00835
00836 yy_buffer_state* bufferPtr(yy_create_buffer(&CHEMKINStream, yyBufSize));
00837 yy_switch_to_buffer(bufferPtr);
00838
00839 initReactionKeywordTable();
00840
00841 while(lex() != 0)
00842 {}
00843
00844 yy_delete_buffer(bufferPtr);
00845 }
00846
00847
00848
00849
00850
00851 Foam::chemkinReader::chemkinReader
00852 (
00853 const fileName& CHEMKINFileName,
00854 const fileName& thermoFileName
00855 )
00856 :
00857 lineNo_(1),
00858 specieNames_(10),
00859 speciesTable_(static_cast<const wordList&>(wordList()))
00860 {
00861 read(CHEMKINFileName, thermoFileName);
00862 }
00863
00864
00865
00866 Foam::chemkinReader::chemkinReader(const dictionary& thermoDict)
00867 :
00868 lineNo_(1),
00869 specieNames_(10),
00870 speciesTable_(static_cast<const wordList&>(wordList()))
00871 {
00872 fileName chemkinFile
00873 (
00874 fileName(thermoDict.lookup("CHEMKINFile")).expand()
00875 );
00876
00877 fileName thermoFile = fileName::null;
00878
00879 if (thermoDict.found("CHEMKINThermoFile"))
00880 {
00881 thermoFile = fileName(thermoDict.lookup("CHEMKINThermoFile")).expand();
00882 }
00883
00884
00885 fileName relPath = thermoDict.name().path();
00886 if (relPath.size())
00887 {
00888 if (chemkinFile.size() && chemkinFile[0] != '/')
00889 {
00890 chemkinFile = relPath/chemkinFile;
00891 }
00892
00893 if (thermoFile.size() && thermoFile[0] != '/')
00894 {
00895 thermoFile = relPath/thermoFile;
00896 }
00897 }
00898
00899 read(chemkinFile, thermoFile);
00900 }
00901
00902