chemkinReader.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 "fileName.H"
40 #include "typeInfo.H"
41 #include "Switch.H"
42 #include "HashPtrTable.H"
43 #include "ReactionList.H"
44 #include "DynamicList.H"
45 #include "labelList.H"
46 #include "speciesTable.H"
47 #include "specieElement.H"
48 #include "atomicWeights.H"
49 
50 #include "specie.H"
51 #include "perfectGas.H"
52 #include "janafThermo.H"
53 #include "sensibleEnthalpy.H"
54 #include "sutherlandTransport.H"
55 #include "thermo.H"
56 
57 #include <FlexLexer.h>
58 
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61 namespace Foam
62 {
63 
64 
65 
67 
68 /*---------------------------------------------------------------------------*\
69  Class chemkinReader Declaration
70 \*---------------------------------------------------------------------------*/
71 
72 class chemkinReader
73 :
74  public yyFlexLexer
75 {
76 
77 public:
78 
79  // Public data types
80 
81  enum phase
82  {
85  gas
86  };
87 
88  // Public typedefs
89 
90  typedef
92  <
94  <
96  <
98  >,
100  >
101  > thermoPhysics;
102 
103 
104 private:
105 
106  // Private Data
107 
108  static int yyBufSize;
109  label lineNo_;
110 
111  //- Table of reaction type keywords
112  HashTable<int> reactionKeywordTable_;
113 
114  //- Currently supported reaction types
115  enum reactionKeyword
116  {
117  thirdBodyReactionType,
118  unimolecularFallOffReactionType,
119  chemicallyActivatedBimolecularReactionType,
120  TroeReactionType,
121  SRIReactionType,
122  LandauTellerReactionType,
123  reverseLandauTellerReactionType,
124  JanevReactionType,
125  powerSeriesReactionRateType,
126  radiationActivatedReactionType,
127  speciesTempReactionType,
128  energyLossReactionType,
129  plasmaMomentumTransfer,
130  collisionCrossSection,
131  nonEquilibriumReversibleReactionType,
132  duplicateReactionType,
133  speciesOrderForward,
134  speciesOrderReverse,
135  UnitsOfReaction,
136  end
137  };
138 
139  enum reactionType
140  {
141  irreversible,
142  reversible,
143  nonEquilibriumReversible,
144  unknownReactionType
145  };
146 
147  static const char* reactionTypeNames[4];
148 
149  enum reactionRateType
150  {
151  Arrhenius,
152  thirdBodyArrhenius,
153  unimolecularFallOff,
154  chemicallyActivatedBimolecular,
155  LandauTeller,
156  Janev,
157  powerSeries,
158  unknownReactionRateType
159  };
160 
161  static const char* reactionRateTypeNames[8];
162 
163  enum fallOffFunctionType
164  {
165  Lindemann,
166  Troe,
167  SRI,
168  unknownFallOffFunctionType
169  };
170 
171  static const char* fallOffFunctionNames[4];
172 
173 
174  void initReactionKeywordTable();
175 
176 
177  //- List of elements
178  DynamicList<word> elementNames_;
179 
180  //- Element indices
181  HashTable<label> elementIndices_;
182 
183  //- Isotope molecular weights
184  HashTable<scalar> isotopeAtomicWts_;
185 
186  //- List of species
187  DynamicList<word> specieNames_;
188 
189  //- Specie indices
190  HashTable<label> specieIndices_;
191 
192  //- Table of species
193  speciesTable& speciesTable_;
194 
195  //- Specie phase
196  HashTable<phase> speciePhase_;
197 
198  //- Table of the thermodynamic data given in the CHEMKIN file
199  HashPtrTable<thermoPhysics> speciesThermo_;
200 
201  //- Table of species composition
202  speciesCompositionTable speciesComposition_;
203 
204  //- List of the reactions
205  ReactionList<thermoPhysics> reactions_;
206 
207  //- Transport properties dictionary
208  dictionary transportDict_;
209 
210  //- Flag to indicate that file is in new format
211  Switch newFormat_;
212 
213  //- Tolerance for element imbalance in a reaction
214  scalar imbalanceTol_;
215 
216 
217  // Private Member Functions
218 
219  //- Flex lexer to read the CHEMKIN III file
220  int lex();
221 
222  inline scalar stringToScalar(const string& s)
223  {
224  string& str = const_cast<string&>(s);
225  str.replaceAll(" ", "");
226  str.replaceAll("D", "e");
227  str.replaceAll("d", "e");
228  return atof(str.c_str());
229  }
230 
231  inline scalar stringToScalar(const char* cstr)
232  {
233  return stringToScalar(string(cstr));
234  }
235 
236  inline void correctElementName(word& elementName)
237  {
238  if (elementName.size() == 2)
239  {
240  elementName[1] = tolower(elementName[1]);
241  }
242  else if (elementName[0] == 'E')
243  {
244  elementName = 'e';
245  }
246  }
247 
248  scalar molecularWeight
249  (
251  ) const;
252 
253  void finishElements(labelList& currentAtoms);
254 
255  void checkCoeffs
256  (
257  const scalarList& reactionCoeffs,
258  const char* reactionRateName,
259  const label nCoeffs
260  ) const;
261 
262  template<class ReactionRateType>
263  void addReactionType
264  (
265  const reactionType rType,
268  const ReactionRateType& rr
269  );
270 
271  template<template<class, class> class PressureDependencyType>
272  void addPressureDependentReaction
273  (
274  const reactionType rType,
275  const fallOffFunctionType fofType,
279  const scalarList& k0Coeffs,
280  const scalarList& kInfCoeffs,
281  const HashTable<scalarList>& reactionCoeffsTable,
282  const scalar Afactor0,
283  const scalar AfactorInf,
284  const scalar RR
285  );
286 
287  void addReaction
288  (
291  const scalarList& thirdBodyEfficiencies,
292  const reactionType rType,
293  const reactionRateType rrType,
294  const fallOffFunctionType fofType,
295  const scalarList& ArrheniusReactionCoeffs,
296  HashTable<scalarList>& reactionCoeffsTable,
297  const scalar RR
298  );
299 
300  // Read the CHEMKIN files
301  void read
302  (
303  const fileName& CHEMKINFileName,
304  const fileName& thermoFileName,
305  const fileName& transportFileName
306  );
307 
308  //- Disallow default bitwise copy construction
309  chemkinReader(const chemkinReader&) = delete;
310 
311  //- Disallow default bitwise assignment
312  void operator=(const chemkinReader&) = delete;
313 
314 
315 public:
316 
317  // Constructors
318 
319  //- Construct from CHEMKIN III file name
321  (
323  const fileName& CHEMKINFileName,
324  const fileName& transportFileName,
325  const fileName& thermoFileName = fileName::null,
326  const bool newFormat = false
327  );
328 
329  //- Construct by getting the CHEMKIN III file name from dictionary
330  chemkinReader(const dictionary& thermoDict, speciesTable& species);
331 
332 
333  //- Destructor
334  virtual ~chemkinReader()
335  {}
336 
337 
338  // Member Functions
339 
340  //- List of elements
341  const wordList& elementNames() const
342  {
343  return elementNames_;
344  }
345 
346  //- Element indices
347  const HashTable<label>& elementIndices() const
348  {
349  return elementIndices_;
350  }
351 
352  //- Isotope molecular weights
353  const HashTable<scalar>& isotopeAtomicWts() const
354  {
355  return isotopeAtomicWts_;
356  }
357 
358  //- Table of species
359  const speciesTable& species() const
360  {
361  return speciesTable_;
362  }
363 
364  //- Table of species composition
365  const speciesCompositionTable& specieComposition() const
366  {
367  return speciesComposition_;
368  }
369 
370  //- Specie phase
371  const HashTable<phase>& speciePhase() const
372  {
373  return speciePhase_;
374  }
375 
376  //- Table of the thermodynamic data given in the CHEMKIN file
378  {
379  return speciesThermo_;
380  }
381 
382  //- List of the reactions
384  {
385  return reactions_;
386  }
387 };
388 
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 } // End namespace Foam
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 #endif
397 
398 // ************************************************************************* //
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
In this string replace all occurrences of sub-string oldStr.
Definition: string.C:93
A class for handling file names.
Definition: fileName.H:79
const HashPtrTable< thermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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
static const fileName null
An empty fileName.
Definition: fileName.H:97
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
const ReactionList< thermoPhysics > & reactions() const
List of the reactions.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:50
Foam::chemkinReader.
Definition: chemkinReader.H:71
const dimensionedScalar RR
Universal gas constant: default SI units: [J/kmol/K].
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))
const HashTable< phase > & speciePhase() const
Specie phase.
const HashTable< scalar > & isotopeAtomicWts() const
Isotope molecular weights.
A class for handling words, derived from string.
Definition: word.H:59
virtual ~chemkinReader()
Destructor.
const wordList & elementNames() const
List of elements.
HashTable< List< specieElement > > speciesCompositionTable
Definition: chemkinReader.H:65
An STL-conforming hash table.
Definition: HashTable.H:61
sutherlandTransport< species::thermo< janafThermo< perfectGas< specie > >, sensibleEnthalpy > > thermoPhysics
Perfect gas equation of state:
Definition: perfectGas.H:57
const HashTable< label > & elementIndices() const
Element indices.
Thermodynamics mapping class to expose the sensible enthalpy functions.
List of templated reactions.
Definition: ReactionList.H:51
A wordList with hashed indices for faster lookup by name.
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Definition: thermo.H:52
Enthalpy based thermodynamics package using JANAF tables:
Definition: janafThermo.H:113
const speciesCompositionTable & specieComposition() const
Table of species composition.
Transport package using Sutherland&#39;s formula for viscosity:
Third body efficiencies.
Namespace for OpenFOAM.
const speciesTable & species() const
Table of species.