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-2023 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  {
84  liquid,
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  //- List of the thermodynamic data given in the CHEMKIN file
202  mutable PtrList<thermoPhysics> speciesThermoList_;
203 
204  //- Table of species composition
205  speciesCompositionTable speciesComposition_;
206 
207  //- List of the reactions
208  ReactionList<thermoPhysics> reactions_;
209 
210  //- Transport properties dictionary
211  dictionary transportDict_;
212 
213  //- Flag to indicate that file is in new format
214  Switch newFormat_;
215 
216  //- Tolerance for element imbalance in a reaction
217  scalar imbalanceTol_;
218 
219 
220  // Private Member Functions
221 
222  //- Flex lexer to read the CHEMKIN III file
223  int lex();
224 
225  inline scalar stringToScalar(const string& s)
226  {
227  string& str = const_cast<string&>(s);
228  str.replaceAll(" ", "");
229  str.replaceAll("D", "e");
230  str.replaceAll("d", "e");
231  return atof(str.c_str());
232  }
233 
234  inline scalar stringToScalar(const char* cstr)
235  {
236  return stringToScalar(string(cstr));
237  }
238 
239  inline void correctElementName(word& elementName)
240  {
241  if (elementName.size() == 2)
242  {
243  elementName[1] = tolower(elementName[1]);
244  }
245  else if (elementName[0] == 'E')
246  {
247  elementName = 'e';
248  }
249  }
250 
251  scalar molecularWeight
252  (
253  const List<specieElement>& specieComposition
254  ) const;
255 
256  void finishElements(labelList& currentAtoms);
257 
258  void checkCoeffs
259  (
260  const scalarList& reactionCoeffs,
261  const char* reactionRateName,
262  const label nCoeffs
263  ) const;
264 
265  template<class ReactionRateType>
266  void addReactionType
267  (
268  const reactionType rType,
269  DynamicList<specieCoeffs>& lhs,
270  DynamicList<specieCoeffs>& rhs,
271  const ReactionRateType& rr
272  );
273 
274  template<template<class, class> class PressureDependencyType>
275  void addPressureDependentReaction
276  (
277  const reactionType rType,
278  const fallOffFunctionType fofType,
279  DynamicList<specieCoeffs>& lhs,
280  DynamicList<specieCoeffs>& rhs,
281  const scalarList& thirdBodyEfficiencies,
282  const scalarList& k0Coeffs,
283  const scalarList& kInfCoeffs,
284  const HashTable<scalarList>& reactionCoeffsTable,
285  const scalar Afactor0,
286  const scalar AfactorInf,
287  const scalar RR
288  );
289 
290  void addReaction
291  (
292  DynamicList<specieCoeffs>& lhs,
293  DynamicList<specieCoeffs>& rhs,
294  const scalarList& thirdBodyEfficiencies,
295  const reactionType rType,
296  const reactionRateType rrType,
297  const fallOffFunctionType fofType,
298  const scalarList& ArrheniusReactionCoeffs,
299  HashTable<scalarList>& reactionCoeffsTable,
300  const scalar RR
301  );
302 
303  // Read the CHEMKIN files
304  void read
305  (
306  const fileName& CHEMKINFileName,
307  const fileName& thermoFileName,
308  const fileName& transportFileName
309  );
310 
311  //- Disallow default bitwise copy construction
312  chemkinReader(const chemkinReader&) = delete;
313 
314  //- Disallow default bitwise assignment
315  void operator=(const chemkinReader&) = delete;
316 
317 
318 public:
319 
320  // Constructors
321 
322  //- Construct from CHEMKIN III file name
324  (
325  const fileName& CHEMKINFileName,
326  const fileName& transportFileName,
327  const fileName& thermoFileName = fileName::null,
328  const bool newFormat = false
329  );
330 
331 
332  //- Destructor
333  virtual ~chemkinReader()
334  {}
335 
336 
337  // Member Functions
338 
339  //- List of elements
340  const wordList& elementNames() const
341  {
342  return elementNames_;
343  }
344 
345  //- Element indices
346  const HashTable<label>& elementIndices() const
347  {
348  return elementIndices_;
349  }
350 
351  //- Isotope molecular weights
352  const HashTable<scalar>& isotopeAtomicWts() const
353  {
354  return isotopeAtomicWts_;
355  }
356 
357  //- Table of species
358  const speciesTable& species() const
359  {
360  return speciesTable_;
361  }
362 
363  //- Table of species composition
365  {
366  return speciesComposition_;
367  }
368 
369  //- Specie phase
370  const HashTable<phase>& speciePhase() const
371  {
372  return speciePhase_;
373  }
374 
375  //- Table of the thermodynamic data given in the CHEMKIN file
377  {
378  return speciesThermo_;
379  }
380 
381  //- List of the thermodynamic data given in the CHEMKIN file
383  {
384  speciesThermoList_.resize(speciesTable_.size());
385 
386  forAll(speciesTable_, speciei)
387  {
388  if (speciesThermoList_.set(speciei)) continue;
389 
391  speciesThermo_.find(speciesTable_[speciei]);
392 
393  speciesThermoList_.set(speciei, iter()->clone());
394  }
395 
396  return speciesThermoList_;
397  }
398 
399  //- List of the reactions
401  {
402  return reactions_;
403  }
404 };
405 
406 
407 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
408 
409 } // End namespace Foam
410 
411 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
412 
413 #endif
414 
415 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
An STL-conforming const_iterator.
Definition: HashTable.H:484
An STL-conforming hash table.
Definition: HashTable.H:127
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
List of templated reactions.
Definition: ReactionList.H:54
Foam::chemkinReader.
Definition: chemkinReader.H:74
const ReactionList< thermoPhysics > & reactions() const
List of the reactions.
const wordList & elementNames() const
List of elements.
const HashTable< label > & elementIndices() const
Element indices.
sutherlandTransport< species::thermo< janafThermo< perfectGas< specie > >, sensibleEnthalpy > > thermoPhysics
const HashPtrTable< thermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
const speciesCompositionTable & specieComposition() const
Table of species composition.
const speciesTable & species() const
Table of species.
const PtrList< thermoPhysics > & speciesThermoList() const
List of the thermodynamic data given in the CHEMKIN file.
virtual ~chemkinReader()
Destructor.
const HashTable< scalar > & isotopeAtomicWts() const
Isotope molecular weights.
const HashTable< phase > & speciePhase() const
Specie phase.
A class for handling file names.
Definition: fileName.H:82
static const fileName null
An empty fileName.
Definition: fileName.H:97
A wordList with hashed indices for faster lookup by name.
Enthalpy based thermodynamics package using JANAF tables:
Definition: janafThermo.H:152
Perfect gas equation of state:
Definition: perfectGas.H:96
Thermodynamics mapping class to expose the sensible enthalpy functions.
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Definition: thermo.H:92
Transport package using Sutherland's formula for viscosity:
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar RR
Universal gas constant: default SI units: [J/kmol/K].
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:41
HashTable< List< specieElement > > speciesCompositionTable
Definition: chemkinReader.H:65
T clone(const T &t)
Definition: List.H:55