OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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     Foam::chemkinReader
00027 
00028 Description
00029     Foam::chemkinReader
00030 
00031 SourceFiles
00032     chemkinReader.C
00033     chemkinLexer.C
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                        Class chemkinReader Declaration
00061 \*---------------------------------------------------------------------------*/
00062 
00063 class chemkinReader
00064 :
00065     public chemistryReader<gasThermoPhysics>,
00066     public yyFlexLexer
00067 {
00068 
00069 public:
00070 
00071     // Public data types
00072 
00073         enum phase
00074         {
00075             solid,
00076             liquid,
00077             gas
00078         };
00079 
00080         //- species element
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     // Private data
00111 
00112         static int yyBufSize;
00113         label lineNo_;
00114 
00115         //- Table of reaction type keywords
00116         HashTable<int> reactionKeywordTable_;
00117 
00118         //- Currently supported reaction types
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         //- List of elements
00182         DynamicList<word> elementNames_;
00183 
00184         //- Element indices
00185         HashTable<label> elementIndices_;
00186 
00187         //- Isotope molecular weights
00188         HashTable<scalar> isotopeAtomicWts_;
00189 
00190         //- List of species
00191         DynamicList<word> specieNames_;
00192 
00193         //- Specie indices
00194         HashTable<label> specieIndices_;
00195 
00196         //- Table of species
00197         speciesTable speciesTable_;
00198 
00199         //- Specie phase
00200         HashTable<phase> speciePhase_;
00201 
00202         //- Table of the thermodynamic data given in the CHEMKIN file
00203         HashPtrTable<gasThermoPhysics> speciesThermo_;
00204 
00205         //- Table of species composition
00206         HashTable<List<specieElement> > specieComposition_;
00207 
00208         //- List of the reactions
00209         SLPtrList<gasReaction> reactions_;
00210 
00211 
00212     // Private Member Functions
00213 
00214         //- Flex lexer to read the CHEMKIN III file
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         // Read the CHEMKIN files
00296         void read
00297         (
00298             const fileName& CHEMKINFileName,
00299             const fileName& thermoFileName
00300         );
00301 
00302 
00303         //- Disallow default bitwise copy construct
00304         chemkinReader(const chemkinReader&);
00305 
00306         //- Disallow default bitwise assignment
00307         void operator=(const chemkinReader&);
00308 
00309 
00310 public:
00311 
00312     //- Runtime type information
00313     TypeName("chemkinReader");
00314 
00315 
00316     // Constructors
00317 
00318         //- Construct from CHEMKIN III file name
00319         chemkinReader
00320         (
00321             const fileName& chemkinFile,
00322             const fileName& thermoFileName = fileName::null
00323         );
00324 
00325         //- Construct by getting the CHEMKIN III file name from dictionary
00326         chemkinReader(const dictionary& thermoDict);
00327 
00328 
00329     // Destructor
00330 
00331         virtual ~chemkinReader()
00332         {}
00333 
00334 
00335     // Member functions
00336 
00337         //- List of elements
00338         const wordList& elementNames() const
00339         {
00340             return elementNames_;
00341         }
00342 
00343         //- Element indices
00344         const HashTable<label>& elementIndices() const
00345         {
00346             return elementIndices_;
00347         }
00348 
00349         //- Isotope molecular weights
00350         const HashTable<scalar>& isotopeAtomicWts() const
00351         {
00352             return isotopeAtomicWts_;
00353         }
00354 
00355         //- Table of species
00356         const speciesTable& species() const
00357         {
00358             return speciesTable_;
00359         }
00360 
00361         //- Specie phase
00362         const HashTable<phase>& speciePhase() const
00363         {
00364             return speciePhase_;
00365         }
00366 
00367         //- Table of the thermodynamic data given in the CHEMKIN file
00368         const HashPtrTable<gasThermoPhysics>& speciesThermo() const
00369         {
00370             return speciesThermo_;
00371         }
00372 
00373         //- Table of species composition
00374         const HashTable<List<specieElement> >& specieComposition() const
00375         {
00376             return specieComposition_;
00377         }
00378 
00379         //- List of the reactions
00380         const SLPtrList<gasReaction>& reactions() const
00381         {
00382             return reactions_;
00383         }
00384 };
00385 
00386 
00387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00388 
00389 } // End namespace Foam
00390 
00391 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00392 
00393 #endif
00394 
00395 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd