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 -------------------------------------------------------------------------------
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  // 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 
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 
102  OCharStream os;
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 // ************************************************************************* //
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 as an OSstream, normally using std::ofstream for the actual output...
Definition: OFstream.H:71
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 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
An OSstream with internal List storage.
Definition: OCharStream.H:231
const dictionary & thermoDict
Definition: EEqn.H:16
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition: IOstream.H:440
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...
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)
Similar to IStringStream but using an externally managed buffer for its input. This allows the input ...
Definition: ISpanStream.H:251
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