chemkinToFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  chemkinToFoam
26 
27 Description
28  Converts CHEMKINIII thermodynamics and reaction data files into
29  OpenFOAM format.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "chemkinReader.H"
35 #include "OFstream.H"
36 #include "OStringStream.H"
37 #include "IStringStream.H"
38 
39 using namespace Foam;
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 int main(int argc, char *argv[])
44 {
45  #include "removeCaseOptions.H"
46 
47  // Increase the precision of the output for JANAF coefficients
49 
50  argList::validArgs.append("CHEMKIN file");
51  argList::validArgs.append("CHEMKIN thermodynamics file");
52  argList::validArgs.append("CHEMKIN transport file");
53  argList::validArgs.append("OpenFOAM chemistry file");
54  argList::validArgs.append("OpenFOAM thermodynamics file");
55 
57  (
58  "newFormat",
59  "read Chemkin thermo file in new format"
60  );
61 
62  argList args(argc, argv);
63 
64  bool newFormat = args.optionFound("newFormat");
65 
66  speciesTable species;
67 
68  chemkinReader cr(species, args[1], args[3], args[2], newFormat);
69 
70  OFstream reactionsFile(args[4]);
71  writeEntry(reactionsFile, "elements", cr.elementNames());
72  reactionsFile << nl;
73  writeEntry(reactionsFile, "species", cr.species());
74  reactionsFile << nl;
75  cr.reactions().write(reactionsFile);
76 
77  // Temporary hack to splice the specie composition data into the thermo file
78  // pending complete integration into the thermodynamics structure
79 
80  OStringStream os;
81  cr.speciesThermo().write(os);
82  dictionary thermoDict(IStringStream(os.str())());
83 
84  wordList speciesList(thermoDict.toc());
85 
86  // Add elements
87  forAll(speciesList, si)
88  {
89  dictionary elementsDict("elements");
90  forAll(cr.specieComposition()[speciesList[si]], ei)
91  {
92  elementsDict.add
93  (
94  cr.specieComposition()[speciesList[si]][ei].name(),
95  cr.specieComposition()[speciesList[si]][ei].nAtoms()
96  );
97  }
98 
99  thermoDict.subDict(speciesList[si]).add("elements", elementsDict);
100  }
101 
102  thermoDict.write(OFstream(args[5])(), false);
103 
104  reactionsFile << nl;
105 
106  writeEntry
107  (
108  reactionsFile,
109  "Tlow",
111  );
112  writeEntry
113  (
114  reactionsFile,
115  "Thigh",
117  );
118 
119  Info<< "End\n" << endl;
120 
121  return 0;
122 }
123 
124 
125 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
Output to file stream.
Definition: OFstream.H:82
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:461
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:56
Foam::chemkinReader.
Definition: chemkinReader.H:61
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static const char nl
Definition: Ostream.H:265
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual Ostream & write(const token &)
Write next token to stream.
Definition: OSstream.C:32
A wordList with hashed indices for faster lookup by name.
Input from memory buffer stream.
Definition: IStringStream.H:49
string str() const
Return the string.
messageStream Info
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:117
Foam::argList args(argc, argv)
Output to memory buffer stream.
Definition: OStringStream.H:49
Namespace for OpenFOAM.