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-2016 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
116  HashTable<int> reactionKeywordTable_;
117 
118  //- Currently supported reaction types
119  enum reactionKeyword
120  {
121  thirdBodyReactionType,
122  unimolecularFallOffReactionType,
123  chemicallyActivatedBimolecularReactionType,
124  TroeReactionType,
125  SRIReactionType,
126  LandauTellerReactionType,
127  reverseLandauTellerReactionType,
128  JanevReactionType,
129  powerSeriesReactionRateType,
130  radiationActivatedReactionType,
131  speciesTempReactionType,
132  energyLossReactionType,
133  plasmaMomentumTransfer,
134  collisionCrossSection,
135  nonEquilibriumReversibleReactionType,
136  duplicateReactionType,
137  speciesOrderForward,
138  speciesOrderReverse,
139  UnitsOfReaction,
140  end
141  };
142 
143  enum reactionType
144  {
145  irreversible,
146  reversible,
147  nonEquilibriumReversible,
148  unknownReactionType
149  };
150 
151  static const char* reactionTypeNames[4];
152 
153  enum reactionRateType
154  {
155  Arrhenius,
156  thirdBodyArrhenius,
157  unimolecularFallOff,
158  chemicallyActivatedBimolecular,
159  LandauTeller,
160  Janev,
161  powerSeries,
162  unknownReactionRateType
163  };
164 
165  static const char* reactionRateTypeNames[8];
166 
167  enum fallOffFunctionType
168  {
169  Lindemann,
170  Troe,
171  SRI,
172  unknownFallOffFunctionType
173  };
174 
175  static const char* fallOffFunctionNames[4];
176 
177 
178  void initReactionKeywordTable();
179 
180 
181  //- List of elements
182  DynamicList<word> elementNames_;
183 
184  //- Element indices
185  HashTable<label> elementIndices_;
186 
187  //- Isotope molecular weights
188  HashTable<scalar> isotopeAtomicWts_;
189 
190  //- List of species
191  DynamicList<word> specieNames_;
192 
193  //- Specie indices
194  HashTable<label> specieIndices_;
195 
196  //- Table of species
197  speciesTable& speciesTable_;
198 
199  //- Specie phase
200  HashTable<phase> speciePhase_;
201 
202  //- Table of the thermodynamic data given in the CHEMKIN file
203  HashPtrTable<gasHThermoPhysics> speciesThermo_;
204 
205  //- Table of species composition
206  HashTable<List<specieElement>> specieComposition_;
207 
208  //- List of the reactions
210 
211  //- Transport properties dictionary
212  dictionary transportDict_;
213 
214  //- Flag to indicate that file is in new format
215  Switch newFormat_;
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>
276  void addPressureDependentReaction
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  (
295  const scalarList& thirdBodyEfficiencies,
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 // ************************************************************************* //
bool operator!=(const specieElement &se) const
Definition: chemkinReader.H:94
string & replaceAll(const string &oldStr, const string &newStr, size_type start=0)
Replace all occurences 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.
bool operator==(const specieElement &se) const
Definition: chemkinReader.H:85
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
const ReactionList< gasHThermoPhysics > & reactions() const
List of the reactions.
friend Ostream & operator<<(Ostream &os, const specieElement &se)
Definition: chemkinReader.H:99
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
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
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Foam::chemkinReader.
Definition: chemkinReader.H:62
bool read(const char *, int32_t &)
Definition: int32IO.C:85
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))
A class for handling words, derived from string.
Definition: word.H:59
virtual ~chemkinReader()
Destructor.
const speciesTable & species() const
Table of species.
const HashTable< List< specieElement > > & specieComposition() const
Table of species composition.
const HashTable< label > & elementIndices() const
Element indices.
const HashTable< phase > & speciePhase() const
Specie phase.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const HashPtrTable< gasHThermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
List of templated reactions.
Definition: ReactionList.H:54
const wordList & elementNames() const
List of elements.
const HashTable< scalar > & isotopeAtomicWts() const
Isotope molecular weights.
A wordList with hashed indices for faster lookup by name.
const scalar RR
Universal gas constant (default in [J/(kmol K)])
Third body efficiencies.
Abstract class for reading chemistry.
Namespace for OpenFOAM.