From bccf754d24d3d718c7be8149091d2018904b26af Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Wed, 6 Jul 2016 16:24:56 +0100 Subject: [PATCH] chemkinToFoam: Added support for converting elements and species composition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based of patch contributed by Francesco Contino, Tommaso Lucchini, Gianluca D’Errico, Hervé Jeanmart, Nicolas Bourgeois and Stéphane Backaert. --- .../chemkinToFoam/chemkinToFoam.C | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C index e91f968a87..a4d35cdcc8 100644 --- a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C +++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -33,6 +33,8 @@ Description #include "argList.H" #include "chemkinReader.H" #include "OFstream.H" +#include "OStringStream.H" +#include "IStringStream.H" using namespace Foam; @@ -60,15 +62,42 @@ int main(int argc, char *argv[]) chemkinReader cr(species, args[1], args[3], args[2], newFormat); + OFstream reactionsFile(args[4]); + reactionsFile + << "elements" << cr.elementNames() << token::END_STATEMENT << nl << nl; reactionsFile << "species" << cr.species() << token::END_STATEMENT << nl << nl; - cr.reactions().write(reactionsFile); - OFstream thermoFile(args[5]); - cr.speciesThermo().write(thermoFile); + // Temporary hack to splice the specie composition data into the thermo file + // pending complete integration into the thermodynamics structure + + OStringStream os; + cr.speciesThermo().write(os); + dictionary thermoDict(IStringStream(os.str())()); + + wordList speciesList(thermoDict.toc()); + + // Add elements + forAll(speciesList, si) + { + dictionary elementsDict("elements"); + forAll(cr.specieComposition()[speciesList[si]], ei) + { + elementsDict.add + ( + cr.specieComposition()[speciesList[si]][ei].elementName, + cr.specieComposition()[speciesList[si]][ei].nAtoms + ); + } + + thermoDict.subDict(speciesList[si]).add("elements", elementsDict); + } + + thermoDict.write(OFstream(args[5])(), false); + Info<< "End\n" << endl;