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 -------------------------------------------------------------------------------
11 License
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 
27 Application
28  chemkinToFoam
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
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 
44 using namespace Foam;
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 int main(int argc, char *argv[])
49 {
50  // Increase the precision of the output for 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 
78  speciesTable species;
79 
80  chemkinReader cr
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 // ************************************************************************* //
static void noFunctionObjects(bool addWithOption=false)
Remove &#39;-noFunctionObjects&#39; option and ignore any occurrences.
Definition: argList.C:547
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
A class for handling file names.
Definition: fileName.H:72
virtual Ostream & write(const char c) override
Write character.
Definition: OBJstream.C:69
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Input/output from string buffers.
Output to file stream, using an OSstream.
Definition: OFstream.H:49
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:423
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
Foam::chemkinReader.
Definition: chemkinReader.H:60
A class for handling words, derived from Foam::string.
Definition: word.H:63
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
const dictionary & thermoDict
Definition: EEqn.H:16
OBJstream os(runTime.globalPath()/outputName)
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:204
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
Input from string buffer, using a ISstream. Always UNCOMPRESSED.
Definition: StringStream.H:120
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::argList args(argc, argv)
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:256
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63