From 17e203992098ab929b568388a339b26140e0f0bc Mon Sep 17 00:00:00 2001 From: andy <andy> Date: Fri, 1 Feb 2013 16:38:52 +0000 Subject: [PATCH] ENH: Added option to read new chemkin format --- .../chemkinToFoam/chemkinToFoam.C | 13 +++++++++-- .../chemkinReader/chemkinLexer.L | 23 +++++++++++-------- .../chemkinReader/chemkinReader.C | 16 +++++++++---- .../chemkinReader/chemkinReader.H | 9 ++++++-- 4 files changed, 44 insertions(+), 17 deletions(-) diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C index 2f56ee07dea..f844195ae93 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 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -42,11 +42,20 @@ int main(int argc, char *argv[]) argList::validArgs.append("CHEMKINThermodynamicsFile"); argList::validArgs.append("FOAMChemistryFile"); argList::validArgs.append("FOAMThermodynamicsFile"); + + argList::addBoolOption + ( + "newFormat", + "read Chemkin thermo file in new format" + ); + argList args(argc, argv); + bool newFormat = args.optionFound("newFormat"); + speciesTable species; - chemkinReader cr(args[1], species, args[2]); + chemkinReader cr(args[1], species, args[2], newFormat); OFstream reactionsFile(args[3]); reactionsFile diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L index 678300a172c..6db89e7a69e 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinLexer.L @@ -439,20 +439,25 @@ bool finishReaction = false; <readThermoSpecieName>{thermoSpecieName} { string specieString(foamSpecieString(YYText())); - // Old format - size_t spacePos = specieString.find(' '); - if (spacePos != string::npos) + if (newFormat_) { - currentSpecieName = specieString(0, spacePos); + specieString.replaceAll(" ", "_"); + size_t strEnd = specieString.find_last_not_of('_'); + currentSpecieName = specieString.substr(0, strEnd + 1); } else { - currentSpecieName = specieString; + size_t spacePos = specieString.find(' '); + if (spacePos != string::npos) + { + currentSpecieName = specieString(0, spacePos); + } + else + { + currentSpecieName = specieString; + } } - // New format - // specieString.replaceAll(" ", "_"); - // size_t strEnd = specieString.find_last_not_of('_'); - // currentSpecieName = specieString.substr(0, strEnd + 1); + BEGIN(readThermoDate); } diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C index 5ee2a03ac3d..63dd057f3d9 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -862,13 +862,15 @@ Foam::chemkinReader::chemkinReader ( const fileName& CHEMKINFileName, speciesTable& species, - const fileName& thermoFileName + const fileName& thermoFileName, + const bool newFormat ) : lineNo_(1), specieNames_(10), speciesTable_(species), - reactions_(speciesTable_, speciesThermo_) + reactions_(speciesTable_, speciesThermo_), + newFormat_(newFormat) { read(CHEMKINFileName, thermoFileName); } @@ -883,8 +885,14 @@ Foam::chemkinReader::chemkinReader lineNo_(1), specieNames_(10), speciesTable_(species), - reactions_(speciesTable_, speciesThermo_) + reactions_(speciesTable_, speciesThermo_), + newFormat_(thermoDict.lookupOrDefault("newFormat", false)) { + if (newFormat_) + { + Info<< "Reading CHEMKIN thermo data in new file format" << endl; + } + fileName chemkinFile(fileName(thermoDict.lookup("CHEMKINFile")).expand()); fileName thermoFile = fileName::null; diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H index 4cd84f59a50..ad1c50abd85 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemkinReader/chemkinReader.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2013-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,6 +39,7 @@ SourceFiles #include "chemistryReader.H" #include "fileName.H" #include "typeInfo.H" +#include "Switch.H" #include "HashPtrTable.H" #include "ReactionList.H" #include "DynamicList.H" @@ -207,6 +208,9 @@ private: //- List of the reactions ReactionList<gasHThermoPhysics> reactions_; + //- Flag to indicate that file is in new format + Switch newFormat_; + // Private Member Functions @@ -319,7 +323,8 @@ public: ( const fileName& chemkinFile, speciesTable& species, - const fileName& thermoFileName = fileName::null + const fileName& thermoFileName = fileName::null, + const bool newFormat = false ); //- Construct by getting the CHEMKIN III file name from dictionary -- GitLab