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