FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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