chemkinToFoam.C
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-2017 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
27Application
28 chemkinToFoam
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Convert CHEMKINIII thermodynamics and reaction data files into
35 OpenFOAM format.
36
37\*---------------------------------------------------------------------------*/
38
39#include "argList.H"
40#include "chemkinReader.H"
41#include "OFstream.H"
42#include "StringStream.H"
43
44using namespace Foam;
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48int main(int argc, char *argv[])
49{
50 // Increase the precision of the output for JANAF coefficients
51 Ostream::defaultPrecision(10);
52
53 argList::addNote
54 (
55 "Convert CHEMKINIII thermodynamics and reaction data files into"
56 " OpenFOAM format."
57 );
58
59 argList::noParallel();
60 argList::noFunctionObjects(); // Never use function objects
61
62 argList::addArgument("CHEMKINFile");
63 argList::addArgument("CHEMKINThermodynamicsFile");
64 argList::addArgument("CHEMKINTransport");
65 argList::addArgument("FOAMChemistryFile");
66 argList::addArgument("FOAMThermodynamicsFile");
67
68 argList::addBoolOption
69 (
70 "newFormat",
71 "Read Chemkin thermo file in new format"
72 );
73
74 argList args(argc, argv);
75
76 const bool newFormat = args.found("newFormat");
77
78 speciesTable species;
79
81 (
82 species,
83 args.get<fileName>(1), // chemkin fileName
84 args.get<fileName>(3), // thermo fileName
85 args.get<fileName>(2), // transport fileName
86 newFormat
87 );
88
89 {
90 // output: reactions file
91 OFstream reactionsFile(args.get<fileName>(4));
92
93 reactionsFile.writeEntry("elements", cr.elementNames()) << nl;
94 reactionsFile.writeEntry("species", cr.species()) << nl;
95
96 cr.reactions().write(reactionsFile);
97 }
98
99 // Temporary hack to splice the specie composition data into the thermo file
100 // pending complete integration into the thermodynamics structure
101
103 cr.speciesThermo().write(os);
105
106 // Add elements
107 for (entry& dEntry : thermoDict)
108 {
109 const word& speciesName = dEntry.keyword();
110 dictionary& speciesDict = dEntry.dict();
111
112 dictionary elemDict("elements");
113
114 for (const specieElement& elem : cr.specieComposition()[speciesName])
115 {
116 elemDict.add(elem.name(), elem.nAtoms());
117 }
118
119 speciesDict.add("elements", elemDict);
120 }
121
122 // output: thermo file
123
124 thermoDict.write(OFstream(args.get<fileName>(5))(), false);
125
126
127 Info<< "End\n" << endl;
128
129 return 0;
130}
131
132
133// ************************************************************************* //
Input/output from string buffers.
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:112
Output to file stream, using an OSstream.
Definition: OFstream.H:57
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
Foam::chemkinReader.
Definition: chemkinReader.H:68
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
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...
A class for handling words, derived from Foam::string.
Definition: word.H:68
const dictionary & thermoDict
Definition: EEqn.H:16
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)