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 | Copyright (C) 2011-2017 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  // Increase the precision of the output for JANAF coefficients
47 
48  argList::validArgs.append("CHEMKIN file");
49  argList::validArgs.append("CHEMKIN thermodynamics file");
50  argList::validArgs.append("CHEMKIN transport file");
51  argList::validArgs.append("OpenFOAM chemistry file");
52  argList::validArgs.append("OpenFOAM thermodynamics file");
53 
55  (
56  "newFormat",
57  "read Chemkin thermo file in new format"
58  );
59 
60  argList args(argc, argv);
61 
62  bool newFormat = args.optionFound("newFormat");
63 
64  speciesTable species;
65 
66  chemkinReader cr(species, args[1], args[3], args[2], newFormat);
67 
68 
69  OFstream reactionsFile(args[4]);
70  reactionsFile
71  << "elements" << cr.elementNames() << token::END_STATEMENT << nl << nl;
72  reactionsFile
73  << "species" << cr.species() << token::END_STATEMENT << nl << nl;
74  cr.reactions().write(reactionsFile);
75 
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 
105  Info<< "End\n" << endl;
106 
107  return 0;
108 }
109 
110 
111 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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:253
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:154
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:262
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:85
Foam::argList args(argc, argv)
Output to memory buffer stream.
Definition: OStringStream.H:49
Namespace for OpenFOAM.