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
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  //- Flag to indicate that file is in new format
212  Switch newFormat_;
213 
214  //- Tolerance for element imbalance in a reaction
215  scalar imbalanceTol_;
216 
217 
218  // Private Member Functions
219 
220  //- Flex lexer to read the CHEMKIN III file
221  int lex();
222 
223  inline scalar stringToScalar(const string& s)
224  {
225  string& str = const_cast<string&>(s);
226  str.replaceAll(" ", "");
227  str.replaceAll("D", "e");
228  str.replaceAll("d", "e");
229  return atof(str.c_str());
230  }
231 
232  inline scalar stringToScalar(const char* cstr)
233  {
234  return stringToScalar(string(cstr));
235  }
236 
237  inline void correctElementName(word& elementName)
238  {
239  if (elementName.size() == 2)
240  {
241  elementName[1] = tolower(elementName[1]);
242  }
243  else if (elementName[0] == 'E')
244  {
245  elementName = 'e';
246  }
247  }
248 
249  scalar molecularWeight
250  (
252  ) const;
253 
254  void finishElements(labelList& currentAtoms);
255 
256  void checkCoeffs
257  (
258  const scalarList& reactionCoeffs,
259  const char* reationRateName,
260  const label nCoeffs
261  ) const;
262 
263  template<class ReactionRateType>
264  void addReactionType
265  (
266  const reactionType rType,
269  const ReactionRateType& rr
270  );
271 
272  template<template<class, class> class PressureDependencyType>
273  void addPressureDependentReaction
274  (
275  const reactionType rType,
276  const fallOffFunctionType fofType,
280  const scalarList& k0Coeffs,
281  const scalarList& kInfCoeffs,
282  const HashTable<scalarList>& reactionCoeffsTable,
283  const scalar Afactor0,
284  const scalar AfactorInf,
285  const scalar RR
286  );
287 
288  void addReaction
289  (
292  const scalarList& thirdBodyEfficiencies,
293  const reactionType rType,
294  const reactionRateType rrType,
295  const fallOffFunctionType fofType,
296  const scalarList& ArrheniusReactionCoeffs,
297  HashTable<scalarList>& reactionCoeffsTable,
298  const scalar RR
299  );
300 
301  // Read the CHEMKIN files
302  void read
303  (
304  const fileName& CHEMKINFileName,
305  const fileName& thermoFileName
306  );
307 
308 
309  //- Disallow default bitwise copy construct
311 
312  //- Disallow default bitwise assignment
313  void operator=(const chemkinReader&);
314 
315 
316 public:
317 
318  //- Runtime type information
319  TypeName("chemkinReader");
320 
321 
322  // Constructors
323 
324  //- Construct from CHEMKIN III file name
326  (
327  const fileName& chemkinFile,
329  const fileName& thermoFileName = fileName::null,
330  const bool newFormat = false
331  );
332 
333  //- Construct by getting the CHEMKIN III file name from dictionary
334  chemkinReader(const dictionary& thermoDict, speciesTable& species);
335 
336 
337  //- Destructor
338  virtual ~chemkinReader()
339  {}
340 
341 
342  // Member functions
343 
344  //- List of elements
345  const wordList& elementNames() const
346  {
347  return elementNames_;
348  }
349 
350  //- Element indices
351  const HashTable<label>& elementIndices() const
352  {
353  return elementIndices_;
354  }
355 
356  //- Isotope molecular weights
357  const HashTable<scalar>& isotopeAtomicWts() const
358  {
359  return isotopeAtomicWts_;
360  }
361 
362  //- Table of species
363  const speciesTable& species() const
364  {
365  return speciesTable_;
366  }
367 
368  //- Specie phase
369  const HashTable<phase>& speciePhase() const
370  {
371  return speciePhase_;
372  }
373 
374  //- Table of the thermodynamic data given in the CHEMKIN file
376  {
377  return speciesThermo_;
378  }
379 
380  //- Table of species composition
382  {
383  return specieComposition_;
384  }
385 
386  //- List of the reactions
388  {
389  return reactions_;
390  }
391 };
392 
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 } // End namespace Foam
397 
398 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
399 
400 #endif
401 
402 // ************************************************************************* //
const wordList & elementNames() const
List of elements.
virtual ~chemkinReader()
Destructor.
Foam::chemkinReader.
Definition: chemkinReader.H:62
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 ))
Type definitions for reactions.
A class for handling words, derived from string.
Definition: word.H:59
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
Third body efficiencies.
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 list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
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
const speciesTable & species() const
Table of species.
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
List of templated reactions.
Definition: ReactionList.H:54
const HashTable< scalar > & isotopeAtomicWts() const
Isotope molecular weights.
const HashPtrTable< gasHThermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
bool operator==(const specieElement &se) const
Definition: chemkinReader.H:85
const HashTable< List< specieElement > > & specieComposition() const
Table of species composition.
const HashTable< label > & elementIndices() const
Element indices.
static const fileName null
An empty fileName.
Definition: fileName.H:97
bool operator!=(const specieElement &se) const
Definition: chemkinReader.H:94
friend Ostream & operator<<(Ostream &os, const specieElement &se)
Definition: chemkinReader.H:99
Abstract class for reading chemistry.
const HashTable< phase > & speciePhase() const
Specie phase.
const scalar RR
Universal gas constant (default in [J/(kmol K)])
const ReactionList< gasHThermoPhysics > & reactions() const
List of the reactions.
A class for handling file names.
Definition: fileName.H:69
A wordList with hashed indices for faster lookup by name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool read(const char *, int32_t &)
Definition: int32IO.C:87
TypeName("chemkinReader")
Runtime type information.
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50