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-2018 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 #include "reactionTypes.H"
50 
51 #include <FlexLexer.h>
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 /*---------------------------------------------------------------------------*\
59  Class chemkinReader Declaration
60 \*---------------------------------------------------------------------------*/
61 
62 class chemkinReader
63 :
64  public chemistryReader<gasHThermoPhysics>,
65  public yyFlexLexer
66 {
67 
68 public:
69 
70  // Public data types
71 
72  enum phase
73  {
76  gas
77  };
78 
79 
80 private:
81 
82  // Private data
83 
84  static int yyBufSize;
85  label lineNo_;
86 
87  //- Table of reaction type keywords
88  HashTable<int> reactionKeywordTable_;
89 
90  //- Currently supported reaction types
91  enum reactionKeyword
92  {
93  thirdBodyReactionType,
94  unimolecularFallOffReactionType,
95  chemicallyActivatedBimolecularReactionType,
96  TroeReactionType,
97  SRIReactionType,
98  LandauTellerReactionType,
99  reverseLandauTellerReactionType,
100  JanevReactionType,
101  powerSeriesReactionRateType,
102  radiationActivatedReactionType,
103  speciesTempReactionType,
104  energyLossReactionType,
105  plasmaMomentumTransfer,
106  collisionCrossSection,
107  nonEquilibriumReversibleReactionType,
108  duplicateReactionType,
109  speciesOrderForward,
110  speciesOrderReverse,
111  UnitsOfReaction,
112  end
113  };
114 
115  enum reactionType
116  {
117  irreversible,
118  reversible,
119  nonEquilibriumReversible,
120  unknownReactionType
121  };
122 
123  static const char* reactionTypeNames[4];
124 
125  enum reactionRateType
126  {
127  Arrhenius,
128  thirdBodyArrhenius,
129  unimolecularFallOff,
130  chemicallyActivatedBimolecular,
131  LandauTeller,
132  Janev,
133  powerSeries,
134  unknownReactionRateType
135  };
136 
137  static const char* reactionRateTypeNames[8];
138 
139  enum fallOffFunctionType
140  {
141  Lindemann,
142  Troe,
143  SRI,
144  unknownFallOffFunctionType
145  };
146 
147  static const char* fallOffFunctionNames[4];
148 
149 
150  void initReactionKeywordTable();
151 
152 
153  //- List of elements
154  DynamicList<word> elementNames_;
155 
156  //- Element indices
157  HashTable<label> elementIndices_;
158 
159  //- Isotope molecular weights
160  HashTable<scalar> isotopeAtomicWts_;
161 
162  //- List of species
163  DynamicList<word> specieNames_;
164 
165  //- Specie indices
166  HashTable<label> specieIndices_;
167 
168  //- Table of species
169  speciesTable& speciesTable_;
170 
171  //- Specie phase
172  HashTable<phase> speciePhase_;
173 
174  //- Table of the thermodynamic data given in the CHEMKIN file
175  HashPtrTable<gasHThermoPhysics> speciesThermo_;
176 
177  //- Table of species composition
178  speciesCompositionTable speciesComposition_;
179 
180  //- List of the reactions
182 
183  //- Transport properties dictionary
184  dictionary transportDict_;
185 
186  //- Flag to indicate that file is in new format
187  Switch newFormat_;
188 
189  //- Tolerance for element imbalance in a reaction
190  scalar imbalanceTol_;
191 
192 
193  // Private Member Functions
194 
195  //- Flex lexer to read the CHEMKIN III file
196  int lex();
197 
198  inline scalar stringToScalar(const string& s)
199  {
200  string& str = const_cast<string&>(s);
201  str.replaceAll(" ", "");
202  str.replaceAll("D", "e");
203  str.replaceAll("d", "e");
204  return atof(str.c_str());
205  }
206 
207  inline scalar stringToScalar(const char* cstr)
208  {
209  return stringToScalar(string(cstr));
210  }
211 
212  inline void correctElementName(word& elementName)
213  {
214  if (elementName.size() == 2)
215  {
216  elementName[1] = tolower(elementName[1]);
217  }
218  else if (elementName[0] == 'E')
219  {
220  elementName = 'e';
221  }
222  }
223 
224  scalar molecularWeight
225  (
227  ) const;
228 
229  void finishElements(labelList& currentAtoms);
230 
231  void checkCoeffs
232  (
233  const scalarList& reactionCoeffs,
234  const char* reationRateName,
235  const label nCoeffs
236  ) const;
237 
238  template<class ReactionRateType>
239  void addReactionType
240  (
241  const reactionType rType,
244  const ReactionRateType& rr
245  );
246 
247  template<template<class, class> class PressureDependencyType>
248  void addPressureDependentReaction
249  (
250  const reactionType rType,
251  const fallOffFunctionType fofType,
255  const scalarList& k0Coeffs,
256  const scalarList& kInfCoeffs,
257  const HashTable<scalarList>& reactionCoeffsTable,
258  const scalar Afactor0,
259  const scalar AfactorInf,
260  const scalar RR
261  );
262 
263  void addReaction
264  (
267  const scalarList& thirdBodyEfficiencies,
268  const reactionType rType,
269  const reactionRateType rrType,
270  const fallOffFunctionType fofType,
271  const scalarList& ArrheniusReactionCoeffs,
272  HashTable<scalarList>& reactionCoeffsTable,
273  const scalar RR
274  );
275 
276  // Read the CHEMKIN files
277  void read
278  (
279  const fileName& CHEMKINFileName,
280  const fileName& thermoFileName,
281  const fileName& transportFileName
282  );
283 
284  //- Disallow default bitwise copy construct
286 
287  //- Disallow default bitwise assignment
288  void operator=(const chemkinReader&);
289 
290 
291 public:
292 
293  //- Runtime type information
294  TypeName("chemkinReader");
295 
296 
297  // Constructors
298 
299  //- Construct from CHEMKIN III file name
301  (
303  const fileName& CHEMKINFileName,
304  const fileName& transportFileName,
305  const fileName& thermoFileName = fileName::null,
306  const bool newFormat = false
307  );
308 
309  //- Construct by getting the CHEMKIN III file name from dictionary
310  chemkinReader(const dictionary& thermoDict, speciesTable& species);
311 
312 
313  //- Destructor
314  virtual ~chemkinReader()
315  {}
316 
317 
318  // Member functions
319 
320  //- List of elements
321  const wordList& elementNames() const
322  {
323  return elementNames_;
324  }
325 
326  //- Element indices
327  const HashTable<label>& elementIndices() const
328  {
329  return elementIndices_;
330  }
331 
332  //- Isotope molecular weights
333  const HashTable<scalar>& isotopeAtomicWts() const
334  {
335  return isotopeAtomicWts_;
336  }
337 
338  //- Table of species
339  const speciesTable& species() const
340  {
341  return speciesTable_;
342  }
343 
344  //- Table of species composition
346  {
347  return speciesComposition_;
348  }
349 
350  //- Specie phase
351  const HashTable<phase>& speciePhase() const
352  {
353  return speciePhase_;
354  }
355 
356  //- Table of the thermodynamic data given in the CHEMKIN file
358  {
359  return speciesThermo_;
360  }
361 
362  //- List of the reactions
364  {
365  return reactions_;
366  }
367 };
368 
369 
370 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 
372 } // End namespace Foam
373 
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 
376 #endif
377 
378 // ************************************************************************* //
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurrences of sub-string oldStr with newStr.
Definition: string.C:74
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
TypeName("chemkinReader")
Runtime type information.
A class for handling file names.
Definition: fileName.H:69
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
static const fileName null
An empty fileName.
Definition: fileName.H:97
Type definitions for reactions.
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.
Definition: Switch.H:60
const ReactionList< gasHThermoPhysics > & reactions() const
List of the reactions.
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::chemkinReader.
Definition: chemkinReader.H:61
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.
const HashPtrTable< gasHThermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
const HashTable< label > & elementIndices() const
Element indices.
List of templated reactions.
Definition: ReactionList.H:54
A wordList with hashed indices for faster lookup by name.
const scalar RR
Universal gas constant (default in [J/(kmol K)])
const speciesCompositionTable & specieComposition() const
Table of species composition.
Third body efficiencies.
Abstract class for reading chemistry.
Namespace for OpenFOAM.
const speciesTable & species() const
Table of species.