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-2023 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  argList::validArgs.append("CHEMKIN file");
48  argList::validArgs.append("CHEMKIN thermodynamics file");
49  argList::validArgs.append("CHEMKIN transport file");
50  argList::validArgs.append("OpenFOAM chemistry file");
51  argList::validArgs.append("OpenFOAM thermodynamics file");
52 
54  (
55  "newFormat",
56  "read Chemkin thermo file in new format"
57  );
58 
60  (
61  "precision",
62  "label",
63  "set the write precision"
64  );
65 
66  argList args(argc, argv);
67 
68  label precision = 10;
69  args.optionReadIfPresent("precision", precision);
70 
71  // Increase the precision of the output for JANAF coefficients
72  Ostream::defaultPrecision(precision);
73 
74  bool newFormat = args.optionFound("newFormat");
75 
76  chemkinReader cr(args[1], args[3], args[2], newFormat);
77 
78  dictionary thermoDict;
79  thermoDict.add("species", cr.species());
80 
81  // Add the species thermo formatted entries
82  {
83  OStringStream os;
84  cr.speciesThermo().write(os);
85  dictionary speciesThermoDict(IStringStream(os.str())());
86  thermoDict.merge(speciesThermoDict);
87  }
88 
89  // Temporary hack to splice the specie composition data into the thermo file
90  // pending complete integration into the thermodynamics structure
91 
92  // Add elements
94  (
96  cr.speciesThermo(),
97  iter
98  )
99  {
100  const word specieName(iter.key());
101 
102  dictionary elementsDict("elements");
103  forAll(cr.specieComposition()[specieName], ei)
104  {
105  elementsDict.add
106  (
107  cr.specieComposition()[specieName][ei].name(),
108  cr.specieComposition()[specieName][ei].nAtoms()
109  );
110  }
111 
112  thermoDict.subDict(specieName).add("elements", elementsDict);
113  }
114 
115  thermoDict.write(OFstream(args[5])(), false);
116  cr.reactions().write(OFstream(args[4])());
117 
118  Info<< "End\n" << endl;
119 
120  return 0;
121 }
122 
123 
124 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:458
Input from memory buffer stream.
Definition: IStringStream.H:52
Output to file stream.
Definition: OFstream.H:86
virtual Ostream & write(const char)
Write character.
Definition: OSstream.C:32
Output to memory buffer stream.
Definition: OStringStream.H:52
string str() const
Return the string.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:204
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
Foam::chemkinReader.
Definition: chemkinReader.H:74
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:211
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:998
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1169
bool merge(const dictionary &)
Merge entries from the given dictionary.
Definition: dictionary.C:1454
A class for handling words, derived from string.
Definition: word.H:62
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
Foam::argList args(argc, argv)