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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  chemkinToFoam
28 
29 Group
30  grpSurfaceUtilities
31 
32 Description
33  Convert CHEMKINIII thermodynamics and reaction data files into
34  OpenFOAM format.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "argList.H"
39 #include "chemkinReader.H"
40 #include "OFstream.H"
41 #include "StringStream.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 int main(int argc, char *argv[])
48 {
49  // Increase the precision of the output for JANAF coefficients
51 
53  (
54  "Convert CHEMKINIII thermodynamics and reaction data files into"
55  " OpenFOAM format."
56  );
57 
59  argList::noFunctionObjects(); // Never use function objects
60 
61  argList::addArgument("CHEMKINFile");
62  argList::addArgument("CHEMKINThermodynamicsFile");
63  argList::addArgument("CHEMKINTransport");
64  argList::addArgument("FOAMChemistryFile");
65  argList::addArgument("FOAMThermodynamicsFile");
66 
68  (
69  "newFormat",
70  "Read Chemkin thermo file in new format"
71  );
72 
73  argList args(argc, argv);
74 
75  const bool newFormat = args.found("newFormat");
76 
77  speciesTable species;
78 
79  chemkinReader cr(species, args[1], args[3], args[2], newFormat);
80 
81  {
82  // output: reactions file
83  OFstream reactionsFile(args[4]);
84 
85  reactionsFile.writeEntry("elements", cr.elementNames()) << nl;
86  reactionsFile.writeEntry("species", cr.species()) << nl;
87 
88  cr.reactions().write(reactionsFile);
89  }
90 
91  // Temporary hack to splice the specie composition data into the thermo file
92  // pending complete integration into the thermodynamics structure
93 
94  OStringStream os;
95  cr.speciesThermo().write(os);
97 
98  // Add elements
99  for (entry& dEntry : thermoDict)
100  {
101  const word& speciesName = dEntry.keyword();
102  dictionary& speciesDict = dEntry.dict();
103 
104  dictionary elemDict("elements");
105 
106  for (const specieElement& elem : cr.specieComposition()[speciesName])
107  {
108  elemDict.add(elem.name(), elem.nAtoms());
109  }
110 
111  speciesDict.add("elements", elemDict);
112  }
113 
114  // output: thermo file
115 
116  thermoDict.write(OFstream(args[5])(), false);
117 
118 
119  Info<< "End\n" << endl;
120 
121  return 0;
122 }
123 
124 
125 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::chemkinReader
Foam::chemkinReader.
Definition: chemkinReader.H:65
Foam::OSstream::write
virtual bool write(const token &tok)
Write token to stream or otherwise handle it.
Definition: OSstream.C:36
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
StringStream.H
Input/output from string buffers.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
OFstream.H
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::argList::noFunctionObjects
static void noFunctionObjects(bool addWithOption=false)
Remove '-noFunctionObjects' option and ignore any occurrences.
Definition: argList.C:454
chemkinReader.H
Foam::hashedWordList
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
Definition: hashedWordList.H:54
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::IStringStream
Input from string buffer, using a ISstream.
Definition: StringStream.H:111
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:87
Foam::Detail::StringStreamAllocator::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:91
Foam::argList::addBoolOption
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:325
thermoDict
const dictionary & thermoDict
Definition: EEqn.H:16
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:333
Foam::dictionary::write
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:206
Foam::OStringStream
Output to string buffer, using a OSstream.
Definition: StringStream.H:196
Foam::specieElement
Definition: specieElement.H:55
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:708
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
args
Foam::argList args(argc, argv)
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:157