chemkinReader.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::chemkinReader
26 
27 Description
28  Foam::chemkinReader
29 
30 SourceFiles
31  chemkinReader.C
32  chemkinLexer.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef chemkinReader_H
37 #define chemkinReader_H
38 
39 #include "chemistryReader.H"
40 #include "fileName.H"
41 #include "typeInfo.H"
42 #include "Switch.H"
43 #include "HashPtrTable.H"
44 #include "ReactionList.H"
45 #include "DynamicList.H"
46 #include "labelList.H"
47 #include "speciesTable.H"
48 #include "atomicWeights.H"
49 
50 #include "reactionTypes.H"
51 
52 #include <FlexLexer.h>
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class chemkinReader Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class chemkinReader
64 :
65  public chemistryReader<gasHThermoPhysics>,
66  public yyFlexLexer
67 {
68 
69 public:
70 
71  // Public data types
72 
73  enum phase
74  {
77  gas
78  };
79 
80  //- species element
81  struct specieElement
82  {
84  label nAtoms;
85 
86  bool operator==(const specieElement& se) const
87  {
88  return
89  (
90  nAtoms == se.nAtoms
91  && elementName == se.elementName
92  );
93  }
94 
95  bool operator!=(const specieElement& se) const
96  {
97  return !operator==(se);
98  }
99 
100  friend Ostream& operator<<(Ostream& os, const specieElement& se)
101  {
102  os << se.nAtoms << token::SPACE << se.elementName;
103  return os;
104  }
105  };
106 
107 
108 private:
109 
110  // Private data
111 
112  static int yyBufSize;
113  label lineNo_;
114 
115  //- Table of reaction type keywords
117 
118  //- Currently supported reaction types
119  enum reactionKeyword
120  {
140  end
141  };
142 
143  enum reactionType
144  {
149  };
150 
151  static const char* reactionTypeNames[4];
152 
153  enum reactionRateType
154  {
163  };
164 
165  static const char* reactionRateTypeNames[8];
166 
168  {
173  };
174 
175  static const char* fallOffFunctionNames[4];
176 
177 
179 
180 
181  //- List of elements
183 
184  //- Element indices
186 
187  //- Isotope molecular weights
189 
190  //- List of species
192 
193  //- Specie indices
195 
196  //- Table of species
198 
199  //- Specie phase
201 
202  //- Table of the thermodynamic data given in the CHEMKIN file
204 
205  //- Table of species composition
207 
208  //- List of the reactions
210 
211  //- Transport properties dictionary
213 
214  //- Flag to indicate that file is in new format
216 
217  //- Tolerance for element imbalance in a reaction
218  scalar imbalanceTol_;
219 
220 
221  // Private Member Functions
222 
223  //- Flex lexer to read the CHEMKIN III file
224  int lex();
225 
226  inline scalar stringToScalar(const string& s)
227  {
228  string& str = const_cast<string&>(s);
229  str.replaceAll(" ", "");
230  str.replaceAll("D", "e");
231  str.replaceAll("d", "e");
232  return atof(str.c_str());
233  }
234 
235  inline scalar stringToScalar(const char* cstr)
236  {
237  return stringToScalar(string(cstr));
238  }
239 
240  inline void correctElementName(word& elementName)
241  {
242  if (elementName.size() == 2)
243  {
244  elementName[1] = tolower(elementName[1]);
245  }
246  else if (elementName[0] == 'E')
247  {
248  elementName = 'e';
249  }
250  }
251 
252  scalar molecularWeight
253  (
255  ) const;
256 
257  void finishElements(labelList& currentAtoms);
258 
259  void checkCoeffs
260  (
261  const scalarList& reactionCoeffs,
262  const char* reationRateName,
263  const label nCoeffs
264  ) const;
265 
266  template<class ReactionRateType>
267  void addReactionType
268  (
269  const reactionType rType,
272  const ReactionRateType& rr
273  );
274 
275  template<template<class, class> class PressureDependencyType>
277  (
278  const reactionType rType,
279  const fallOffFunctionType fofType,
283  const scalarList& k0Coeffs,
284  const scalarList& kInfCoeffs,
285  const HashTable<scalarList>& reactionCoeffsTable,
286  const scalar Afactor0,
287  const scalar AfactorInf,
288  const scalar RR
289  );
290 
291  void addReaction
292  (
296  const reactionType rType,
297  const reactionRateType rrType,
298  const fallOffFunctionType fofType,
299  const scalarList& ArrheniusReactionCoeffs,
300  HashTable<scalarList>& reactionCoeffsTable,
301  const scalar RR
302  );
303 
304  // Read the CHEMKIN files
305  void read
306  (
307  const fileName& CHEMKINFileName,
308  const fileName& thermoFileName,
309  const fileName& transportFileName
310  );
311 
312  //- Disallow default bitwise copy construct
314 
315  //- Disallow default bitwise assignment
316  void operator=(const chemkinReader&);
317 
318 
319 public:
320 
321  //- Runtime type information
322  TypeName("chemkinReader");
323 
324 
325  // Constructors
326 
327  //- Construct from CHEMKIN III file name
329  (
331  const fileName& CHEMKINFileName,
332  const fileName& transportFileName,
333  const fileName& thermoFileName = fileName::null,
334  const bool newFormat = false
335  );
336 
337  //- Construct by getting the CHEMKIN III file name from dictionary
338  chemkinReader(const dictionary& thermoDict, speciesTable& species);
339 
340 
341  //- Destructor
342  virtual ~chemkinReader()
343  {}
344 
345 
346  // Member functions
347 
348  //- List of elements
349  const wordList& elementNames() const
350  {
351  return elementNames_;
352  }
353 
354  //- Element indices
355  const HashTable<label>& elementIndices() const
356  {
357  return elementIndices_;
358  }
359 
360  //- Isotope molecular weights
361  const HashTable<scalar>& isotopeAtomicWts() const
362  {
363  return isotopeAtomicWts_;
364  }
365 
366  //- Table of species
367  const speciesTable& species() const
368  {
369  return speciesTable_;
370  }
371 
372  //- Specie phase
373  const HashTable<phase>& speciePhase() const
374  {
375  return speciePhase_;
376  }
377 
378  //- Table of the thermodynamic data given in the CHEMKIN file
380  {
381  return speciesThermo_;
382  }
383 
384  //- Table of species composition
386  {
387  return specieComposition_;
388  }
389 
390  //- List of the reactions
392  {
393  return reactions_;
394  }
395 };
396 
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 } // End namespace Foam
401 
402 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
403 
404 #endif
405 
406 // ************************************************************************* //
Foam::chemkinReader::fallOffFunctionType
fallOffFunctionType
Definition: chemkinReader.H:166
Foam::constant::thermodynamic::RR
const scalar RR
Universal gas constant (default in [J/(kmol K)])
Definition: thermodynamicConstants.C:44
ReactionList.H
Foam::chemkinReader::unimolecularFallOff
@ unimolecularFallOff
Definition: chemkinReader.H:156
Foam::chemkinReader::unknownReactionRateType
@ unknownReactionRateType
Definition: chemkinReader.H:161
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::chemistryReader
Abstract class for reading chemistry.
Definition: chemistryReader.H:52
Foam::chemkinReader::Arrhenius
@ Arrhenius
Definition: chemkinReader.H:154
Foam::chemkinReader
Foam::chemkinReader.
Definition: chemkinReader.H:62
Foam::string::replaceAll
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurences of sub-string oldStr with newStr.
Definition: string.C:77
Foam::chemkinReader::powerSeriesReactionRateType
@ powerSeriesReactionRateType
Definition: chemkinReader.H:128
Foam::chemkinReader::elementIndices_
HashTable< label > elementIndices_
Element indices.
Definition: chemkinReader.H:184
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::chemkinReader::plasmaMomentumTransfer
@ plasmaMomentumTransfer
Definition: chemkinReader.H:132
Foam::chemkinReader::speciesThermo
const HashPtrTable< gasHThermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
Definition: chemkinReader.H:378
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::chemkinReader::reactionKeywordTable_
HashTable< int > reactionKeywordTable_
Table of reaction type keywords.
Definition: chemkinReader.H:115
typeInfo.H
Foam::chemkinReader::checkCoeffs
void checkCoeffs(const scalarList &reactionCoeffs, const char *reationRateName, const label nCoeffs) const
Definition: chemkinReader.C:148
Foam::chemkinReader::thirdBodyReactionType
@ thirdBodyReactionType
Definition: chemkinReader.H:120
Foam::chemkinReader::gas
@ gas
Definition: chemkinReader.H:76
Foam::DynamicList< word >
Foam::chemkinReader::yyBufSize
static int yyBufSize
Definition: chemkinReader.H:111
Foam::chemkinReader::speciesOrderReverse
@ speciesOrderReverse
Definition: chemkinReader.H:137
atomicWeights.H
Foam::chemkinReader::read
void read(const fileName &CHEMKINFileName, const fileName &thermoFileName, const fileName &transportFileName)
Definition: chemkinReader.C:775
Foam::chemkinReader::stringToScalar
scalar stringToScalar(const string &s)
Definition: chemkinReader.H:225
Foam::chemkinReader::specieElement::operator==
bool operator==(const specieElement &se) const
Definition: chemkinReader.H:85
Foam::chemkinReader::reactionKeyword
reactionKeyword
Currently supported reaction types.
Definition: chemkinReader.H:118
speciesTable.H
Foam::chemkinReader::chemkinReader
chemkinReader(const chemkinReader &)
Disallow default bitwise copy construct.
Foam::chemkinReader::end
@ end
Definition: chemkinReader.H:139
Foam::chemkinReader::SRIReactionType
@ SRIReactionType
Definition: chemkinReader.H:124
Foam::chemkinReader::specieComposition
const HashTable< List< specieElement > > & specieComposition() const
Table of species composition.
Definition: chemkinReader.H:384
Foam::chemkinReader::nonEquilibriumReversible
@ nonEquilibriumReversible
Definition: chemkinReader.H:146
Foam::chemkinReader::addReactionType
void addReactionType(const reactionType rType, DynamicList< gasHReaction::specieCoeffs > &lhs, DynamicList< gasHReaction::specieCoeffs > &rhs, const ReactionRateType &rr)
Definition: chemkinReader.C:169
Foam::chemkinReader::finishElements
void finishElements(labelList &currentAtoms)
Foam::chemkinReader::elementNames
const wordList & elementNames() const
List of elements.
Definition: chemkinReader.H:348
Foam::chemkinReader::specieIndices_
HashTable< label > specieIndices_
Specie indices.
Definition: chemkinReader.H:193
Foam::chemkinReader::specieElement
species element
Definition: chemkinReader.H:80
Foam::chemkinReader::reactions
const ReactionList< gasHThermoPhysics > & reactions() const
List of the reactions.
Definition: chemkinReader.H:390
Foam::chemkinReader::liquid
@ liquid
Definition: chemkinReader.H:75
Foam::chemkinReader::collisionCrossSection
@ collisionCrossSection
Definition: chemkinReader.H:133
Foam::chemkinReader::radiationActivatedReactionType
@ radiationActivatedReactionType
Definition: chemkinReader.H:129
Foam::chemkinReader::LandauTeller
@ LandauTeller
Definition: chemkinReader.H:158
Foam::thirdBodyEfficiencies
Third body efficiencies.
Definition: thirdBodyEfficiencies.H:55
Foam::chemkinReader::newFormat_
Switch newFormat_
Flag to indicate that file is in new format.
Definition: chemkinReader.H:214
Foam::chemkinReader::SRI
@ SRI
Definition: chemkinReader.H:170
Foam::chemkinReader::Lindemann
@ Lindemann
Definition: chemkinReader.H:168
Foam::chemkinReader::solid
@ solid
Definition: chemkinReader.H:74
Foam::chemkinReader::fallOffFunctionNames
static const char * fallOffFunctionNames[4]
Definition: chemkinReader.H:174
Foam::chemkinReader::unknownReactionType
@ unknownReactionType
Definition: chemkinReader.H:147
Foam::chemkinReader::powerSeries
@ powerSeries
Definition: chemkinReader.H:160
Foam::ReactionList
List of templated reactions.
Definition: ReactionList.H:54
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
labelList.H
Foam::chemkinReader::specieNames_
DynamicList< word > specieNames_
List of species.
Definition: chemkinReader.H:190
Foam::hashedWordList
A wordList with hashed indices for faster lookup by name.
Definition: hashedWordList.H:57
Foam::chemkinReader::chemicallyActivatedBimolecularReactionType
@ chemicallyActivatedBimolecularReactionType
Definition: chemkinReader.H:122
Foam::chemkinReader::reactionTypeNames
static const char * reactionTypeNames[4]
Definition: chemkinReader.H:150
Foam::chemkinReader::speciePhase
const HashTable< phase > & speciePhase() const
Specie phase.
Definition: chemkinReader.H:372
Foam::chemkinReader::Janev
@ Janev
Definition: chemkinReader.H:159
Foam::chemkinReader::isotopeAtomicWts
const HashTable< scalar > & isotopeAtomicWts() const
Isotope molecular weights.
Definition: chemkinReader.H:360
fileName.H
Foam::chemkinReader::lex
int lex()
Flex lexer to read the CHEMKIN III file.
Switch.H
Foam::chemkinReader::addReaction
void addReaction(DynamicList< gasHReaction::specieCoeffs > &lhs, DynamicList< gasHReaction::specieCoeffs > &rhs, const scalarList &thirdBodyEfficiencies, const reactionType rType, const reactionRateType rrType, const fallOffFunctionType fofType, const scalarList &ArrheniusReactionCoeffs, HashTable< scalarList > &reactionCoeffsTable, const scalar RR)
Definition: chemkinReader.C:412
Foam::chemkinReader::TypeName
TypeName("chemkinReader")
Runtime type information.
Foam::chemkinReader::specieElement::elementName
word elementName
Definition: chemkinReader.H:82
Foam::chemkinReader::lineNo_
label lineNo_
Definition: chemkinReader.H:112
Foam::chemkinReader::reactionRateType
reactionRateType
Definition: chemkinReader.H:152
Foam::chemkinReader::species
const speciesTable & species() const
Table of species.
Definition: chemkinReader.H:366
Foam::chemkinReader::speciesTempReactionType
@ speciesTempReactionType
Definition: chemkinReader.H:130
Foam::chemkinReader::chemicallyActivatedBimolecular
@ chemicallyActivatedBimolecular
Definition: chemkinReader.H:157
Foam::chemkinReader::thirdBodyArrhenius
@ thirdBodyArrhenius
Definition: chemkinReader.H:155
Foam::chemkinReader::stringToScalar
scalar stringToScalar(const char *cstr)
Definition: chemkinReader.H:234
Foam::chemkinReader::molecularWeight
scalar molecularWeight(const List< specieElement > &specieComposition) const
Definition: chemkinReader.C:114
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::chemkinReader::energyLossReactionType
@ energyLossReactionType
Definition: chemkinReader.H:131
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::chemkinReader::specieElement::operator<<
friend Ostream & operator<<(Ostream &os, const specieElement &se)
Definition: chemkinReader.H:99
s
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Foam::chemkinReader::speciesOrderForward
@ speciesOrderForward
Definition: chemkinReader.H:136
Foam::chemkinReader::phase
phase
Definition: chemkinReader.H:72
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::HashTable< int >
Foam::chemkinReader::correctElementName
void correctElementName(word &elementName)
Definition: chemkinReader.H:239
Foam::chemkinReader::initReactionKeywordTable
void initReactionKeywordTable()
Definition: chemkinReader.C:83
Foam::chemkinReader::reactions_
ReactionList< gasHThermoPhysics > reactions_
List of the reactions.
Definition: chemkinReader.H:208
Foam::chemkinReader::specieElement::operator!=
bool operator!=(const specieElement &se) const
Definition: chemkinReader.H:94
Foam::chemkinReader::speciesTable_
speciesTable & speciesTable_
Table of species.
Definition: chemkinReader.H:196
Foam::chemkinReader::operator=
void operator=(const chemkinReader &)
Disallow default bitwise assignment.
Foam::chemkinReader::JanevReactionType
@ JanevReactionType
Definition: chemkinReader.H:127
Foam::chemkinReader::reactionType
reactionType
Definition: chemkinReader.H:142
Foam::chemkinReader::unknownFallOffFunctionType
@ unknownFallOffFunctionType
Definition: chemkinReader.H:171
Foam::chemkinReader::nonEquilibriumReversibleReactionType
@ nonEquilibriumReversibleReactionType
Definition: chemkinReader.H:134
Foam::chemkinReader::duplicateReactionType
@ duplicateReactionType
Definition: chemkinReader.H:135
Foam::HashPtrTable
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::chemkinReader::imbalanceTol_
scalar imbalanceTol_
Tolerance for element imbalance in a reaction.
Definition: chemkinReader.H:217
Foam::chemkinReader::LandauTellerReactionType
@ LandauTellerReactionType
Definition: chemkinReader.H:125
Foam::chemkinReader::specieComposition_
HashTable< List< specieElement > > specieComposition_
Table of species composition.
Definition: chemkinReader.H:205
Foam::chemkinReader::addPressureDependentReaction
void addPressureDependentReaction(const reactionType rType, const fallOffFunctionType fofType, DynamicList< gasHReaction::specieCoeffs > &lhs, DynamicList< gasHReaction::specieCoeffs > &rhs, const scalarList &thirdBodyEfficiencies, const scalarList &k0Coeffs, const scalarList &kInfCoeffs, const HashTable< scalarList > &reactionCoeffsTable, const scalar Afactor0, const scalar AfactorInf, const scalar RR)
Definition: chemkinReader.C:240
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
HashPtrTable.H
Foam::chemkinReader::TroeReactionType
@ TroeReactionType
Definition: chemkinReader.H:123
Foam::chemkinReader::speciesThermo_
HashPtrTable< gasHThermoPhysics > speciesThermo_
Table of the thermodynamic data given in the CHEMKIN file.
Definition: chemkinReader.H:202
Foam::chemkinReader::irreversible
@ irreversible
Definition: chemkinReader.H:144
DynamicList.H
Foam::chemkinReader::UnitsOfReaction
@ UnitsOfReaction
Definition: chemkinReader.H:138
Foam::chemkinReader::elementNames_
DynamicList< word > elementNames_
List of elements.
Definition: chemkinReader.H:181
Foam::chemkinReader::unimolecularFallOffReactionType
@ unimolecularFallOffReactionType
Definition: chemkinReader.H:121
Foam::chemkinReader::transportDict_
dictionary transportDict_
Transport properties dictionary.
Definition: chemkinReader.H:211
Foam::chemkinReader::isotopeAtomicWts_
HashTable< scalar > isotopeAtomicWts_
Isotope molecular weights.
Definition: chemkinReader.H:187
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::chemkinReader::Troe
@ Troe
Definition: chemkinReader.H:169
Foam::chemkinReader::speciePhase_
HashTable< phase > speciePhase_
Specie phase.
Definition: chemkinReader.H:199
Foam::chemkinReader::elementIndices
const HashTable< label > & elementIndices() const
Element indices.
Definition: chemkinReader.H:354
reactionTypes.H
Type definitions for reactions.
Foam::chemkinReader::reversible
@ reversible
Definition: chemkinReader.H:145
Foam::chemkinReader::~chemkinReader
virtual ~chemkinReader()
Destructor.
Definition: chemkinReader.H:341
Foam::chemkinReader::reactionRateTypeNames
static const char * reactionRateTypeNames[8]
Definition: chemkinReader.H:164
chemistryReader.H
Foam::chemkinReader::specieElement::nAtoms
label nAtoms
Definition: chemkinReader.H:83
Foam::token::SPACE
@ SPACE
Definition: token.H:95
Foam::chemkinReader::reverseLandauTellerReactionType
@ reverseLandauTellerReactionType
Definition: chemkinReader.H:126