From 509133ecbb84173d641bec55dad5ce2070352e6b Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sat, 3 Aug 2019 09:22:43 +0100 Subject: [PATCH] ReactionList: Simplified and rationalised so that it can be used as the container for the reaction system in reactingMixture. --- .../chemkinReader/chemkinReader.C | 4 +- .../chemkinToFoam/chemkinToFoam.C | 20 +--- .../multiComponentMixture.C | 71 +++++++++++- .../multiComponentMixture.H | 45 ++++++-- .../reactingMixture/reactingMixture.C | 88 +------------- .../reactingMixture/reactingMixture.H | 27 +---- .../Reactions/ReactionList/ReactionList.C | 107 +++++++----------- .../Reactions/ReactionList/ReactionList.H | 50 ++------ 8 files changed, 152 insertions(+), 260 deletions(-) diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinReader/chemkinReader.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinReader/chemkinReader.C index 7b22428935..d3596895e4 100644 --- a/applications/utilities/thermophysical/chemkinToFoam/chemkinReader/chemkinReader.C +++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinReader/chemkinReader.C @@ -24,7 +24,7 @@ License \*---------------------------------------------------------------------------*/ #include "chemkinReader.H" -#include +#include "IFstream.H" #include "atomicWeights.H" #include "ReactionProxy.H" #include "IrreversibleReaction.H" @@ -839,7 +839,6 @@ Foam::chemkinReader::chemkinReader lineNo_(1), specieNames_(10), speciesTable_(species), - reactions_(speciesTable_, speciesThermo_), newFormat_(newFormat), imbalanceTol_(rootSmall) { @@ -856,7 +855,6 @@ Foam::chemkinReader::chemkinReader lineNo_(1), specieNames_(10), speciesTable_(species), - reactions_(speciesTable_, speciesThermo_), newFormat_(thermoDict.lookupOrDefault("newFormat", false)), imbalanceTol_(thermoDict.lookupOrDefault("imbalanceTolerance", rootSmall)) { diff --git a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C index 5bb1758577..316fb6bb5c 100644 --- a/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C +++ b/applications/utilities/thermophysical/chemkinToFoam/chemkinToFoam.C @@ -100,25 +100,7 @@ int main(int argc, char *argv[]) } thermoDict.write(OFstream(args[5])(), false); - - - OFstream reactionsFile(args[4]); - cr.reactions().write(reactionsFile); - - reactionsFile << nl; - - writeEntry - ( - reactionsFile, - "Tlow", - Reaction::TlowDefault - ); - writeEntry - ( - reactionsFile, - "Thigh", - Reaction::ThighDefault - ); + cr.reactions().write(OFstream(args[4])()); Info<< "End\n" << endl; diff --git a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C index dabc9779e8..4df6d5facb 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C +++ b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C @@ -28,21 +28,79 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -const ThermoType& Foam::multiComponentMixture::constructSpeciesData +Foam::PtrList +Foam::multiComponentMixture::readSpeciesData ( const dictionary& thermoDict -) +) const { + PtrList speciesData(species_.size()); + forAll(species_, i) { - speciesData_.set + speciesData.set ( i, new ThermoType(thermoDict.subDict(species_[i])) ); } - return speciesData_[0]; + return speciesData; +} + + +template +typename Foam::multiComponentMixture::speciesCompositionTable +Foam::multiComponentMixture::readSpeciesComposition +( + const dictionary& thermoDict, + const speciesTable& species +) const +{ + speciesCompositionTable speciesComposition_; + + // Loop through all species in thermoDict to retrieve + // the species composition + forAll(species, si) + { + if (thermoDict.subDict(species[si]).isDict("elements")) + { + dictionary currentElements + ( + thermoDict.subDict(species[si]).subDict("elements") + ); + + wordList currentElementsName(currentElements.toc()); + List currentComposition(currentElementsName.size()); + + forAll(currentElementsName, eni) + { + currentComposition[eni].name() = currentElementsName[eni]; + + currentComposition[eni].nAtoms() = + currentElements.lookupOrDefault + ( + currentElementsName[eni], + 0 + ); + } + + // Add current specie composition to the hash table + speciesCompositionTable::iterator specieCompositionIter + ( + speciesComposition_.find(species[si]) + ); + + if (specieCompositionIter != speciesComposition_.end()) + { + speciesComposition_.erase(specieCompositionIter); + } + + speciesComposition_.insert(species[si], currentComposition); + } + } + + return speciesComposition_; } @@ -88,8 +146,9 @@ Foam::multiComponentMixture::multiComponentMixture mesh, phaseName ), - speciesData_(species_.size()), - mixture_("mixture", constructSpeciesData(thermoDict)), + speciesData_(readSpeciesData(thermoDict)), + speciesComposition_(readSpeciesComposition(thermoDict, species())), + mixture_("mixture", speciesData_[0]), mixtureVol_("volMixture", speciesData_[0]) { correctMassFractions(); diff --git a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H index c7a3cb0401..4d2ce49152 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H +++ b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.H @@ -37,6 +37,7 @@ SourceFiles #include "basicSpecieMixture.H" #include "HashPtrTable.H" +#include "specieElement.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -57,6 +58,11 @@ class multiComponentMixture //- Species data PtrList speciesData_; + typedef HashTable> speciesCompositionTable; + + //- Table of species composition + speciesCompositionTable speciesComposition_; + //- Temporary storage for the cell/face mixture thermo data mutable ThermoType mixture_; @@ -67,16 +73,19 @@ class multiComponentMixture // Private Member Functions - //- Construct the species data from the given dictionary and return the - // data for the first specie to initialise the mixture thermo data - const ThermoType& constructSpeciesData(const dictionary& thermoDict); + //- Read the species data from the given dictionary and return + PtrList readSpeciesData(const dictionary& thermoDict) const; + + //- Read the species composition from the given dictionary and return + speciesCompositionTable readSpeciesComposition + ( + const dictionary& thermoDict, + const speciesTable& speciesTable_ + ) const; //- Correct the mass fractions to sum to 1 void correctMassFractions(); - //- Construct as copy (not implemented) - multiComponentMixture(const multiComponentMixture&); - public: @@ -89,6 +98,12 @@ public: //- Construct from dictionary, mesh and phase name multiComponentMixture(const dictionary&, const fvMesh&, const word&); + //- Disallow default bitwise copy construction + multiComponentMixture + ( + const multiComponentMixture& + ) = delete; + //- Destructor virtual ~multiComponentMixture() @@ -103,6 +118,18 @@ public: return "multiComponentMixture<" + ThermoType::typeName() + '>'; } + //- Return the raw specie thermodynamic data + const PtrList& speciesData() const + { + return speciesData_; + } + + //- Return the table of species composition + const speciesCompositionTable& specieComposition() const + { + return speciesComposition_; + } + const ThermoType& cellMixture(const label celli) const; const ThermoType& patchFaceMixture @@ -126,12 +153,6 @@ public: const label facei ) const; - //- Return the raw specie thermodynamic data - const PtrList& speciesData() const - { - return speciesData_; - } - //- Read dictionary void read(const dictionary&); diff --git a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C index 7c566bb28b..591677595d 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C +++ b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.C @@ -26,63 +26,6 @@ License #include "reactingMixture.H" #include "fvMesh.H" -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -Foam::speciesCompositionTable -Foam::reactingMixture::readSpeciesComposition -( - const dictionary& thermoDict, - const speciesTable& species -) const -{ - speciesCompositionTable speciesComposition_; - - // Loop through all species in thermoDict to retrieve - // the species composition - forAll(species, si) - { - if (thermoDict.subDict(species[si]).isDict("elements")) - { - dictionary currentElements - ( - thermoDict.subDict(species[si]).subDict("elements") - ); - - wordList currentElementsName(currentElements.toc()); - List currentComposition(currentElementsName.size()); - - forAll(currentElementsName, eni) - { - currentComposition[eni].name() = currentElementsName[eni]; - - currentComposition[eni].nAtoms() = - currentElements.lookupOrDefault - ( - currentElementsName[eni], - 0 - ); - } - - // Add current specie composition to the hash table - speciesCompositionTable::iterator specieCompositionIter - ( - speciesComposition_.find(species[si]) - ); - - if (specieCompositionIter != speciesComposition_.end()) - { - speciesComposition_.erase(specieCompositionIter); - } - - speciesComposition_.insert(species[si], currentComposition); - } - } - - return speciesComposition_; -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template @@ -99,36 +42,7 @@ Foam::reactingMixture::reactingMixture mesh, phaseName ), - speciesComposition_(readSpeciesComposition(thermoDict, this->species())) -{ - HashPtrTable thermoDatabase; - const PtrList& speciesData = this->speciesData(); - - forAll(speciesData, i) - { - thermoDatabase.insert - ( - speciesData[i].name(), - speciesData[i].clone().ptr() - ); - } - - reactions_ = PtrList> - ( - ReactionList - ( - this->species(), - thermoDatabase, - thermoDict - ) - ); -} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::reactingMixture::read(const dictionary& thermoDict) + reactions_(thermoDict, this->species(), this->speciesData()) {} diff --git a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H index 32b2892cd5..3288991883 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H +++ b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H @@ -37,15 +37,12 @@ SourceFiles #include "multiComponentMixture.H" #include "ReactionList.H" -#include "specieElement.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -typedef HashTable> speciesCompositionTable; - /*---------------------------------------------------------------------------*\ Class reactingMixture Declaration \*---------------------------------------------------------------------------*/ @@ -57,24 +54,11 @@ class reactingMixture { // Private member data - //- Table of species composition - speciesCompositionTable speciesComposition_; - - PtrList> reactions_; - - speciesCompositionTable readSpeciesComposition - ( - const dictionary& thermoDict, - const speciesTable& speciesTable_ - ) const; + ReactionList reactions_; public: - //- The type of thermo package this mixture is instantiated for - typedef ThermoType thermoType; - - // Constructors //- Construct from dictionary, mesh and phase name @@ -97,20 +81,11 @@ public: return "reactingMixture<" + ThermoType::typeName() + '>'; } - //- Read dictionary - void read(const dictionary&); - const PtrList>& reactions() const { return reactions_; } - //- Table of species composition - const speciesCompositionTable& specieComposition() const - { - return speciesComposition_; - } - // Member Operators diff --git a/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C b/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C index 33b5123cdb..be44cf38f7 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C +++ b/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.C @@ -24,109 +24,84 @@ License \*---------------------------------------------------------------------------*/ #include "ReactionList.H" -#include "IFstream.H" -#include "SLPtrList.H" +#include "HashPtrTable.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::ReactionList::ReactionList ( + const dictionary& dict, const speciesTable& species, - const HashPtrTable& thermoDb + const PtrList& speciesThermo ) -: - SLPtrList>(), - species_(species), - thermoDb_(thermoDb), - dict_(dictionary::null) -{} - - -template -Foam::ReactionList::ReactionList -( - const speciesTable& species, - const HashPtrTable& thermoDb, - const dictionary& dict -) -: - SLPtrList>(), - species_(species), - thermoDb_(thermoDb), - dict_(dict) { - readReactionDict(); -} - - -template -Foam::ReactionList::ReactionList(const ReactionList& reactions) -: - SLPtrList>(reactions), - species_(reactions.species_), - thermoDb_(reactions.thermoDb_), - dict_(reactions.dict_) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::ReactionList::~ReactionList() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -bool Foam::ReactionList::readReactionDict() -{ - const dictionary& reactions(dict_.subDict("reactions")); - // Set general temperature limits from the dictionary Reaction::TlowDefault = - dict_.lookupOrDefault("Tlow", 0); + dict.lookupOrDefault("Tlow", 0); Reaction::ThighDefault = - dict_.lookupOrDefault("Thigh", great); + dict.lookupOrDefault("Thigh", great); - forAllConstIter(dictionary, reactions, iter) + const dictionary& reactions(dict.subDict("reactions")); + + HashPtrTable thermoDatabase; + forAll(speciesThermo, i) { - const word reactionName = iter().keyword(); - - this->append + thermoDatabase.insert ( - Reaction::New - ( - species_, - thermoDb_, - reactions.subDict(reactionName) - ).ptr() + speciesThermo[i].name(), + speciesThermo[i].clone().ptr() ); } - return true; + this->setSize(reactions.size()); + label i = 0; + + forAllConstIter(dictionary, reactions, iter) + { + this->set + ( + i++, + Reaction::New + ( + species, + thermoDatabase, + reactions.subDict(iter().keyword()) + ).ptr() + ); + } } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + template void Foam::ReactionList::write(Ostream& os) const { os << "reactions" << nl; os << token::BEGIN_BLOCK << incrIndent << nl; - forAllConstIter(typename SLPtrList>, *this, iter) + forAll(*this, i) { - const Reaction& r = iter(); + const Reaction& r = this->operator[](i); + os << indent << r.name() << nl << indent << token::BEGIN_BLOCK << incrIndent << nl; + writeEntry(os, "type", r.type()); + r.write(os); + os << decrIndent << indent << token::END_BLOCK << nl; } os << decrIndent << token::END_BLOCK << nl; + + writeEntry(os, "Tlow", Reaction::TlowDefault); + writeEntry(os, "Thigh", Reaction::ThighDefault); + + os << nl; } diff --git a/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.H b/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.H index 049e6e17c6..9b2a8b59d8 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.H +++ b/src/thermophysicalModels/specie/reaction/Reactions/ReactionList/ReactionList.H @@ -35,12 +35,9 @@ SourceFiles #ifndef ReactionList_H #define ReactionList_H -#include "PtrList.H" -#include "SLPtrList.H" -#include "speciesTable.H" -#include "HashPtrTable.H" #include "Reaction.H" -#include "fileName.H" +#include "speciesTable.H" +#include "PtrList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -54,60 +51,31 @@ namespace Foam template class ReactionList : - public SLPtrList> + public PtrList> { - // Private Data - - //- Reference to the table of species - const speciesTable& species_; - - //- Reference to the thermo database - const HashPtrTable& thermoDb_; - - //- The dictionary used for construction - const dictionary dict_; - public: // Constructors - //- Construct null - ReactionList - ( - const speciesTable& species, - const HashPtrTable& thermoDatabase - ); - - //- Construct from thermoDatabase and dictionary - ReactionList - ( - const speciesTable& species, - const HashPtrTable& thermoDatabase, - const dictionary& dict - ); + //- Construct empty + ReactionList() + {} //- Construct from thermo list and dictionary ReactionList ( + const dictionary& dict, const speciesTable& species, - const PtrList& thermoDatabase, - const dictionary& dict + const PtrList& thermoDatabase ); //- Construct copy - ReactionList(const ReactionList& reactions); - - - //- Destructor - ~ReactionList(); + ReactionList(const ReactionList& reactions) = delete; // Public Member Functions - //- Read reactions from dictionary - bool readReactionDict(); - //- Write void write(Ostream& os) const;