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-2020 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  chemkinReader cr(species, args[1], args[3], args[2], newFormat);
68  const HashPtrTable<chemkinReader::thermoPhysics>& speciesThermo =
69  cr.speciesThermo();
70 
71  dictionary thermoDict;
72  thermoDict.add("species", cr.species());
73 
74  // Add the species thermo formatted entries
75  {
76  OStringStream os;
77  speciesThermo.write(os);
78  dictionary speciesThermoDict(IStringStream(os.str())());
79  thermoDict.merge(speciesThermoDict);
80  }
81 
82  // Temporary hack to splice the specie composition data into the thermo file
83  // pending complete integration into the thermodynamics structure
84 
85  // Add elements
87  (
89  speciesThermo,
90  iter
91  )
92  {
93  const word specieName(iter.key());
94 
95  dictionary elementsDict("elements");
96  forAll(cr.specieComposition()[specieName], ei)
97  {
98  elementsDict.add
99  (
100  cr.specieComposition()[specieName][ei].name(),
101  cr.specieComposition()[specieName][ei].nAtoms()
102  );
103  }
104 
105  thermoDict.subDict(specieName).add("elements", elementsDict);
106  }
107 
108  thermoDict.write(OFstream(args[5])(), false);
109  cr.reactions().write(OFstream(args[4])());
110 
111  Info<< "End\n" << endl;
112 
113  return 0;
114 }
115 
116 
117 // ************************************************************************* //
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:174
#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:251
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
void write(Ostream &os) const
Write.
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1056
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:934
Foam::chemkinReader.
Definition: chemkinReader.H:71
A class for handling words, derived from string.
Definition: word.H:59
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
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
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1343
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
Foam::argList args(argc, argv)
Output to memory buffer stream.
Definition: OStringStream.H:49
Namespace for OpenFOAM.