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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::chemkinReader
28 
29 Group
30  grpReactionThermophysicalChemistryReaders
31 
32 Description
33  Foam::chemkinReader
34 
35 SourceFiles
36  chemkinReader.C
37  chemkinLexer.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef chemkinReader_H
42 #define chemkinReader_H
43 
44 #include "chemistryReader.H"
45 #include "fileName.H"
46 #include "typeInfo.H"
47 #include "HashPtrTable.H"
48 #include "ReactionList.H"
49 #include "DynamicList.H"
50 #include "labelList.H"
51 #include "speciesTable.H"
52 #include "atomicWeights.H"
53 #include "reactionTypes.H"
54 
55 #include <FlexLexer.h>
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class chemkinReader Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 class chemkinReader
67 :
68  public chemistryReader<gasHThermoPhysics>,
69  public yyFlexLexer
70 {
71 
72 public:
73 
74  // Public data types
75 
76  enum phase
77  {
80  gas
81  };
82 
83 
84 private:
85 
86  // Private data
87 
88  static int yyBufSize;
89  label lineNo_;
90 
91  //- Table of reaction type keywords
92  HashTable<int> reactionKeywordTable_;
93 
94  //- Currently supported reaction types
95  enum reactionKeyword
96  {
97  thirdBodyReactionType,
98  unimolecularFallOffReactionType,
99  chemicallyActivatedBimolecularReactionType,
100  TroeReactionType,
101  SRIReactionType,
102  LandauTellerReactionType,
103  reverseLandauTellerReactionType,
104  JanevReactionType,
105  powerSeriesReactionRateType,
106  radiationActivatedReactionType,
107  speciesTempReactionType,
108  energyLossReactionType,
109  plasmaMomentumTransfer,
110  collisionCrossSection,
111  nonEquilibriumReversibleReactionType,
112  duplicateReactionType,
113  speciesOrderForward,
114  speciesOrderReverse,
115  UnitsOfReaction,
116  end
117  };
118 
119  enum reactionType
120  {
121  irreversible,
122  reversible,
123  nonEquilibriumReversible,
124  unknownReactionType
125  };
126 
127  static const char* reactionTypeNames[4];
128 
129  enum reactionRateType
130  {
131  Arrhenius,
132  thirdBodyArrhenius,
133  unimolecularFallOff,
134  chemicallyActivatedBimolecular,
135  LandauTeller,
136  Janev,
137  powerSeries,
138  unknownReactionRateType
139  };
140 
141  static const char* reactionRateTypeNames[8];
142 
143  enum fallOffFunctionType
144  {
145  Lindemann,
146  Troe,
147  SRI,
148  unknownFallOffFunctionType
149  };
150 
151  static const char* fallOffFunctionNames[4];
152 
153 
154  void initReactionKeywordTable();
155 
156 
157  //- List of elements
158  DynamicList<word> elementNames_;
159 
160  //- Element indices
161  HashTable<label> elementIndices_;
162 
163  //- Isotope molecular weights
164  HashTable<scalar> isotopeAtomicWts_;
165 
166  //- List of species
167  DynamicList<word> specieNames_;
168 
169  //- Specie indices
170  HashTable<label> specieIndices_;
171 
172  //- Table of species
173  speciesTable& speciesTable_;
174 
175  //- Specie phase
176  HashTable<phase> speciePhase_;
177 
178  //- Table of the thermodynamic data given in the CHEMKIN file
179  HashPtrTable<gasHThermoPhysics> speciesThermo_;
180 
181  //- Table of species composition
182  speciesCompositionTable speciesComposition_;
183 
184  //- List of the reactions
185  ReactionList<gasHThermoPhysics> reactions_;
186 
187  //- Transport properties dictionary
188  dictionary transportDict_;
189 
190  //- Flag to indicate that file is in new format
191  bool newFormat_;
192 
193  //- Tolerance for element imbalance in a reaction
194  scalar imbalanceTol_;
195 
196 
197  // Private Member Functions
198 
199  //- Flex lexer to read the CHEMKIN III file
200  int lex();
201 
202  inline scalar stringToScalar(const string& s)
203  {
204  string& str = const_cast<string&>(s);
205  str.replaceAll(" ", "");
206  str.replaceAll("D", "e");
207  str.replaceAll("d", "e");
208  return atof(str.c_str());
209  }
210 
211  inline scalar stringToScalar(const char* cstr)
212  {
213  return stringToScalar(string(cstr));
214  }
215 
216  inline void correctElementName(word& elementName)
217  {
218  if (elementName.size() == 2)
219  {
220  elementName[1] = tolower(elementName[1]);
221  }
222  else if (elementName[0] == 'E')
223  {
224  elementName = "e";
225  }
226  }
227 
228  scalar molecularWeight
229  (
230  const List<specieElement>& specieComposition
231  ) const;
232 
233  void finishElements(labelList& currentAtoms);
234 
235  void checkCoeffs
236  (
237  const scalarList& reactionCoeffs,
238  const char* reationRateName,
239  const label nCoeffs
240  ) const;
241 
242  template<class ReactionRateType>
243  void addReactionType
244  (
245  const reactionType rType,
246  DynamicList<gasHReaction::specieCoeffs>& lhs,
247  DynamicList<gasHReaction::specieCoeffs>& rhs,
248  const ReactionRateType& rr
249  );
250 
251  template<template<class, class> class PressureDependencyType>
252  void addPressureDependentReaction
253  (
254  const reactionType rType,
255  const fallOffFunctionType fofType,
256  DynamicList<gasHReaction::specieCoeffs>& lhs,
257  DynamicList<gasHReaction::specieCoeffs>& rhs,
258  const scalarList& thirdBodyEfficiencies,
259  const scalarList& k0Coeffs,
260  const scalarList& kInfCoeffs,
261  const HashTable<scalarList>& reactionCoeffsTable,
262  const scalar Afactor0,
263  const scalar AfactorInf,
264  const scalar RR
265  );
266 
267  void addReaction
268  (
269  DynamicList<gasHReaction::specieCoeffs>& lhs,
270  DynamicList<gasHReaction::specieCoeffs>& rhs,
271  const scalarList& thirdBodyEfficiencies,
272  const reactionType rType,
273  const reactionRateType rrType,
274  const fallOffFunctionType fofType,
275  const scalarList& ArrheniusReactionCoeffs,
276  HashTable<scalarList>& reactionCoeffsTable,
277  const scalar RR
278  );
279 
280  // Read the CHEMKIN files
281  void read
282  (
283  const fileName& CHEMKINFileName,
284  const fileName& thermoFileName,
285  const fileName& transportFileName
286  );
287 
288  //- No copy construct
289  chemkinReader(const chemkinReader&) = delete;
290 
291  //- No copy assignment
292  void operator=(const chemkinReader&) = delete;
293 
294 
295 public:
296 
297  //- Runtime type information
298  TypeName("chemkinReader");
299 
300 
301  // Constructors
302 
303  //- Construct from CHEMKIN III file name
304  chemkinReader
305  (
307  const fileName& CHEMKINFileName,
308  const fileName& transportFileName,
309  const fileName& thermoFileName = fileName::null,
310  const bool newFormat = false
311  );
312 
313  //- Construct by getting the CHEMKIN III file name from dictionary
314  chemkinReader(const dictionary& thermoDict, speciesTable& species);
315 
316 
317  //- Destructor
318  virtual ~chemkinReader() = default;
319 
320 
321  // Member functions
322 
323  //- List of elements
324  const wordList& elementNames() const
325  {
326  return elementNames_;
327  }
328 
329  //- Element indices
330  const HashTable<label>& elementIndices() const
331  {
332  return elementIndices_;
333  }
334 
335  //- Isotope molecular weights
336  const HashTable<scalar>& isotopeAtomicWts() const
337  {
338  return isotopeAtomicWts_;
339  }
340 
341  //- Table of species
342  const speciesTable& species() const
343  {
344  return speciesTable_;
345  }
346 
347  //- Table of species composition
349  {
350  return speciesComposition_;
351  }
352 
353  //- Specie phase
354  const HashTable<phase>& speciePhase() const
355  {
356  return speciePhase_;
357  }
358 
359  //- Table of the thermodynamic data given in the CHEMKIN file
361  {
362  return speciesThermo_;
363  }
364 
365  //- List of the reactions
367  {
368  return reactions_;
369  }
370 };
371 
372 
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 
375 } // End namespace Foam
376 
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 
379 #endif
380 
381 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::constant::thermodynamic::RR
const scalar RR
Universal gas constant: default in [J/(kmol K)].
Definition: thermodynamicConstants.C:46
ReactionList.H
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
Foam::chemistryReader
Abstract class for reading chemistry.
Definition: chemistryReader.H:61
Foam::chemkinReader
Foam::chemkinReader.
Definition: chemkinReader.H:65
Foam::chemkinReader::speciesThermo
const HashPtrTable< gasHThermoPhysics > & speciesThermo() const
Table of the thermodynamic data given in the CHEMKIN file.
Definition: chemkinReader.H:359
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
Definition: gmvOutputSpray.H:25
typeInfo.H
Foam::chemkinReader::gas
Definition: chemkinReader.H:79
Foam::chemkinReader::~chemkinReader
virtual ~chemkinReader()=default
Destructor.
atomicWeights.H
speciesTable.H
Foam::speciesCompositionTable
HashTable< List< specieElement > > speciesCompositionTable
Definition: chemistryReader.H:53
Foam::chemkinReader::elementNames
const wordList & elementNames() const
List of elements.
Definition: chemkinReader.H:323
Foam::chemkinReader::reactions
const ReactionList< gasHThermoPhysics > & reactions() const
List of the reactions.
Definition: chemkinReader.H:365
Foam::chemkinReader::liquid
Definition: chemkinReader.H:78
Foam::chemkinReader::specieComposition
const speciesCompositionTable & specieComposition() const
Table of species composition.
Definition: chemkinReader.H:347
Foam::chemkinReader::solid
Definition: chemkinReader.H:77
Foam::ReactionList
List of templated reactions.
Definition: ReactionList.H:57
labelList.H
Foam::hashedWordList
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
Definition: hashedWordList.H:54
Foam::speciesTable
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:43
Foam::chemkinReader::speciePhase
const HashTable< phase > & speciePhase() const
Specie phase.
Definition: chemkinReader.H:353
Foam::chemkinReader::isotopeAtomicWts
const HashTable< scalar > & isotopeAtomicWts() const
Isotope molecular weights.
Definition: chemkinReader.H:335
fileName.H
Foam::chemkinReader::TypeName
TypeName("chemkinReader")
Runtime type information.
Foam::chemkinReader::species
const speciesTable & species() const
Table of species.
Definition: chemkinReader.H:341
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::chemkinReader::phase
phase
Definition: chemkinReader.H:75
Foam::fileName::null
static const fileName null
An empty fileName.
Definition: fileName.H:97
Foam::HashTable< int >
thermoDict
const dictionary & thermoDict
Definition: EEqn.H:16
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:54
Foam::List< word >
HashPtrTable.H
DynamicList.H
Foam::chemkinReader::elementIndices
const HashTable< label > & elementIndices() const
Element indices.
Definition: chemkinReader.H:329
reactionTypes.H
Type definitions for reactions.
chemistryReader.H