FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 
40 #include <OpenFOAM/fileName.H>
41 #include <OpenFOAM/typeInfo.H>
42 #include <OpenFOAM/HashPtrTable.H>
43 #include <OpenFOAM/SLPtrList.H>
44 #include <OpenFOAM/DynamicList.H>
45 #include <OpenFOAM/labelList.H>
46 #include <specie/speciesTable.H>
47 #include <specie/atomicWeights.H>
48 
49 #include <specie/reactionTypes.H>
50 
51 #include <FlexLexer.h>
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 /*---------------------------------------------------------------------------*\
59  Class chemkinReader Declaration
60 \*---------------------------------------------------------------------------*/
61 
63 :
64  public chemistryReader<gasThermoPhysics>,
65  public yyFlexLexer
66 {
67 
68 public:
69 
70  // Public data types
71 
72  enum phase
73  {
77  };
78 
79  //- species element
81  {
83  label nAtoms;
84 
85  bool operator==(const specieElement& se) const
86  {
87  return
88  (
89  nAtoms == se.nAtoms
90  && elementName == se.elementName
91  );
92  }
93 
94  bool operator!=(const specieElement& se) const
95  {
96  return !operator==(se);
97  }
98 
99  friend Ostream& operator<<(Ostream& os, const specieElement& se)
100  {
101  os << se.nAtoms << token::SPACE << se.elementName;
102  return os;
103  }
104  };
105 
106 
107 private:
108 
109  // Private data
110 
111  static int yyBufSize;
112  label lineNo_;
113 
114  //- Table of reaction type keywords
115  HashTable<int> reactionKeywordTable_;
116 
117  //- Currently supported reaction types
118  enum reactionKeyword
119  {
120  thirdBodyReactionType,
121  unimolecularFallOffReactionType,
122  chemicallyActivatedBimolecularReactionType,
123  TroeReactionType,
124  SRIReactionType,
125  LandauTellerReactionType,
126  reverseLandauTellerReactionType,
127  JanevReactionType,
128  powerSeriesReactionRateType,
129  radiationActivatedReactionType,
130  speciesTempReactionType,
131  energyLossReactionType,
132  plasmaMomentumTransfer,
133  collisionCrossSection,
134  nonEquilibriumReversibleReactionType,
135  duplicateReactionType,
136  speciesOrderForward,
137  speciesOrderReverse,
138  UnitsOfReaction,
139  end
140  };
141 
142  enum reactionType
143  {
144  irreversible,
145  reversible,
146  nonEquilibriumReversible,
147  unknownReactionType
148  };
149 
150  static const char* reactionTypeNames[4];
151 
152  enum reactionRateType
153  {
154  Arrhenius,
155  thirdBodyArrhenius,
156  unimolecularFallOff,
157  chemicallyActivatedBimolecular,
158  LandauTeller,
159  Janev,
160  powerSeries,
161  unknownReactionRateType
162  };
163 
164  static const char* reactionRateTypeNames[8];
165 
166  enum fallOffFunctionType
167  {
168  Lindemann,
169  Troe,
170  SRI,
171  unknownFallOffFunctionType
172  };
173 
174  static const char* fallOffFunctionNames[4];
175 
176 
177  void initReactionKeywordTable();
178 
179 
180  //- List of elements
181  DynamicList<word> elementNames_;
182 
183  //- Element indices
184  HashTable<label> elementIndices_;
185 
186  //- Isotope molecular weights
187  HashTable<scalar> isotopeAtomicWts_;
188 
189  //- List of species
190  DynamicList<word> specieNames_;
191 
192  //- Specie indices
193  HashTable<label> specieIndices_;
194 
195  //- Table of species
196  speciesTable speciesTable_;
197 
198  //- Specie phase
199  HashTable<phase> speciePhase_;
200 
201  //- Table of the thermodynamic data given in the CHEMKIN file
202  HashPtrTable<gasThermoPhysics> speciesThermo_;
203 
204  //- Table of species composition
205  HashTable<List<specieElement> > specieComposition_;
206 
207  //- List of the reactions
208  SLPtrList<gasReaction> reactions_;
209 
210 
211  // Private Member Functions
212 
213  //- Flex lexer to read the CHEMKIN III file
214  int lex();
215 
216  inline scalar stringToScalar(const string& s)
217  {
218  string& str = const_cast<string&>(s);
219  str.replaceAll(" ", "");
220  str.replaceAll("D", "e");
221  str.replaceAll("d", "e");
222  return atof(str.c_str());
223  }
224 
225  inline scalar stringToScalar(const char* cstr)
226  {
227  return stringToScalar(string(cstr));
228  }
229 
230  inline void correctElementName(word& elementName)
231  {
232  if (elementName.size() == 2)
233  {
234  elementName[1] = tolower(elementName[1]);
235  }
236  else if(elementName[0] == 'E')
237  {
238  elementName = 'e';
239  }
240  }
241 
242  scalar molecularWeight
243  (
244  const List<specieElement>& specieComposition
245  ) const;
246 
247  void finishElements(labelList& currentAtoms);
248 
249  void checkCoeffs
250  (
251  const scalarList& reactionCoeffs,
252  const char* reationRateName,
253  const label nCoeffs
254  ) const;
255 
256  template<class ReactionRateType>
257  void addReactionType
258  (
259  const reactionType rType,
260  DynamicList<gasReaction::specieCoeffs>& lhs,
261  DynamicList<gasReaction::specieCoeffs>& rhs,
262  const ReactionRateType& rr
263  );
264 
265  template<template<class, class> class PressureDependencyType>
266  void addPressureDependentReaction
267  (
268  const reactionType rType,
269  const fallOffFunctionType fofType,
270  DynamicList<gasReaction::specieCoeffs>& lhs,
271  DynamicList<gasReaction::specieCoeffs>& rhs,
272  const scalarList& thirdBodyEfficiencies,
273  const scalarList& k0Coeffs,
274  const scalarList& kInfCoeffs,
275  const HashTable<scalarList>& reactionCoeffsTable,
276  const scalar Afactor0,
277  const scalar AfactorInf,
278  const scalar RR
279  );
280 
281  void addReaction
282  (
283  DynamicList<gasReaction::specieCoeffs>& lhs,
284  DynamicList<gasReaction::specieCoeffs>& rhs,
285  const scalarList& thirdBodyEfficiencies,
286  const reactionType rType,
287  const reactionRateType rrType,
288  const fallOffFunctionType fofType,
289  const scalarList& ArrheniusReactionCoeffs,
290  HashTable<scalarList>& reactionCoeffsTable,
291  const scalar RR
292  );
293 
294  // Read the CHEMKIN files
295  void read
296  (
297  const fileName& CHEMKINFileName,
298  const fileName& thermoFileName
299  );
300 
301 
302  //- Disallow default bitwise copy construct
303  chemkinReader(const chemkinReader&);
304 
305  //- Disallow default bitwise assignment
306  void operator=(const chemkinReader&);
307 
308 
309 public:
310 
311  //- Runtime type information
312  TypeName("chemkinReader");
313 
314 
315  // Constructors
316 
317  //- Construct from CHEMKIN III file name
318  chemkinReader
319  (
320  const fileName& chemkinFile,
321  const fileName& thermoFileName = fileName::null
322  );
323 
324  //- Construct by getting the CHEMKIN III file name from dictionary
325  chemkinReader(const dictionary& thermoDict);
326 
327 
328  // Destructor
329 
330  virtual ~chemkinReader()
331  {}
332 
333 
334  // Member functions
335 
336  //- List of elements
337  const wordList& elementNames() const
338  {
339  return elementNames_;
340  }
341 
342  //- Element indices
344  {
345  return elementIndices_;
346  }
347 
348  //- Isotope molecular weights
350  {
351  return isotopeAtomicWts_;
352  }
353 
354  //- Table of species
355  const speciesTable& species() const
356  {
357  return speciesTable_;
358  }
359 
360  //- Specie phase
362  {
363  return speciePhase_;
364  }
365 
366  //- Table of the thermodynamic data given in the CHEMKIN file
368  {
369  return speciesThermo_;
370  }
371 
372  //- Table of species composition
374  {
375  return specieComposition_;
376  }
377 
378  //- List of the reactions
380  {
381  return reactions_;
382  }
383 };
384 
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 } // End namespace Foam
389 
390 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
391 
392 #endif
393 
394 // ************************ vim: set sw=4 sts=4 et: ************************ //