Loading...
Searching...
No Matches
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-2024 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 // More precision (for output of JANAF coefficients)
52
54 (
55 "Convert CHEMKINIII thermodynamics and reaction data files into"
56 " OpenFOAM format."
57 );
58
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
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
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);
104
105 ISpanStream is(os.view());
107
108 // Add elements
109 for (entry& dEntry : thermoDict)
110 {
111 const word& speciesName = dEntry.keyword();
112 dictionary& speciesDict = dEntry.dict();
113
114 dictionary elemDict("elements");
115
116 for (const specieElement& elem : cr.specieComposition()[speciesName])
117 {
118 elemDict.add(elem.name(), elem.nAtoms());
119 }
120
121 speciesDict.add("elements", elemDict);
122 }
123
124 // output: thermo file
125
126 thermoDict.write(OFstream(args.get<fileName>(5))(), false);
127
128
129 Info<< "End\n" << endl;
130
131 return 0;
132}
133
134
135// ************************************************************************* //
Input/output from string buffers.
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition IOstream.H:459
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
An OSstream with internal List storage.
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition argList.C:562
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Foam::chemkinReader.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition dictionary.C:625
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
A class for handling file names.
Definition fileName.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
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).
hashedWordList speciesTable
A table of species as a hashedWordList.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)