From a16c4ae920c6b554963338e3d705a0303dd06aa7 Mon Sep 17 00:00:00 2001 From: Sergio Ferraris Date: Mon, 14 Dec 2020 14:58:57 +0000 Subject: [PATCH] ENH: Exposing specieComposition from ReactingMixture The FO BilgerMixtureFraction needs access to specieComposition which is stored in ReactingMixture. A virtual mechanism was added to basicSpecieMixture to access specieComposition form rho and psi reationThermos. ptr was changed to autoPtr to avoid memory leaks (Kutalmis Bercin) --- .../TDACChemistryModel/TDACChemistryModel.C | 8 +++++--- .../reactionThermo/Make/files | 1 + .../reactionThermo/Make/options | 1 + .../basicSpecieMixture/basicSpecieMixture.H | 14 ++++++++++++++ .../mixtures/reactingMixture/reactingMixture.H | 9 +++++++-- .../psiReactionThermo/psiReactionThermo.H | 15 ++++++++++++++- .../rhoReactionThermo/rhoReactionThermo.H | 15 ++++++++++++++- 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C index 187e300932..c4d502ebe0 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/TDACChemistryModel/TDACChemistryModel.C @@ -75,13 +75,15 @@ Foam::TDACChemistryModel::TDACChemistryModel // Store the species composition according to the species index speciesTable speciesTab = composition.species(); - const HashTable>& specComp = + autoPtr>> specCompPtr + ( dynamicCast&>(this->thermo()) - .specieComposition(); + .specieComposition() + ); forAll(specieComp_, i) { - specieComp_[i] = specComp[this->Y()[i].member()]; + specieComp_[i] = (specCompPtr.ref())[this->Y()[i].member()]; } mechRed_ = chemistryReductionMethod::New diff --git a/src/thermophysicalModels/reactionThermo/Make/files b/src/thermophysicalModels/reactionThermo/Make/files index 8870103dfe..e31e2076ff 100644 --- a/src/thermophysicalModels/reactionThermo/Make/files +++ b/src/thermophysicalModels/reactionThermo/Make/files @@ -21,4 +21,5 @@ derivedFvPatchFields/mixedUnburntEnthalpy/mixedUnburntEnthalpyFvPatchScalarField functionObjects/moleFractions/moleFractionsFunctionObjects.C + LIB = $(FOAM_LIBBIN)/libreactionThermophysicalModels diff --git a/src/thermophysicalModels/reactionThermo/Make/options b/src/thermophysicalModels/reactionThermo/Make/options index 26ee649fb4..20754771fa 100644 --- a/src/thermophysicalModels/reactionThermo/Make/options +++ b/src/thermophysicalModels/reactionThermo/Make/options @@ -4,6 +4,7 @@ EXE_INC = \ -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \ -I$(LIB_SRC)/thermophysicalModels/solidSpecie/lnInclude \ + -I$(LIB_SRC)/functionObjects/field/lnInclude LIB_LIBS = \ -lfiniteVolume \ diff --git a/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H index d7db29cc42..522c4be19e 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H +++ b/src/thermophysicalModels/reactionThermo/mixtures/basicSpecieMixture/basicSpecieMixture.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2017 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,12 +43,15 @@ SourceFiles #define basicSpecieMixture_H #include "basicMultiComponentMixture.H" +#include "specieElement.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +typedef HashTable> speciesCompositionTable; + /*---------------------------------------------------------------------------*\ Class basicSpecieMixture Declaration \*---------------------------------------------------------------------------*/ @@ -202,6 +206,16 @@ public: const scalar p, const scalar T ) const = 0; + + //- Species composition + virtual autoPtr specieComposition() const + { + return + autoPtr + ( + new speciesCompositionTable() + ); + } }; diff --git a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H index 08763c8a2a..bb33b6cfbf 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H +++ b/src/thermophysicalModels/reactionThermo/mixtures/reactingMixture/reactingMixture.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation + Copyright (C) 2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -115,9 +116,13 @@ public: using PtrList>::operator[]; //- Table of species composition - const speciesCompositionTable& specieComposition() const + virtual autoPtr specieComposition() const { - return speciesComposition_; + return + autoPtr + ( + new speciesCompositionTable(speciesComposition_) + ); } }; diff --git a/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermo.H b/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermo.H index fe1035f45a..080e26315e 100644 --- a/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermo.H +++ b/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermo.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,12 +45,15 @@ SourceFiles #include "basicSpecieMixture.H" #include "autoPtr.H" #include "runTimeSelectionTables.H" +#include "specieElement.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +typedef HashTable> speciesCompositionTable; + /*---------------------------------------------------------------------------*\ Class psiReactionThermo Declaration \*---------------------------------------------------------------------------*/ @@ -137,6 +140,16 @@ public: //- Return the composition of the multi-component mixture virtual const basicSpecieMixture& composition() const = 0; + + //- Table of species composition + autoPtr specieComposition() const + { + return + autoPtr + ( + composition().specieComposition() + ); + } }; diff --git a/src/thermophysicalModels/reactionThermo/rhoReactionThermo/rhoReactionThermo.H b/src/thermophysicalModels/reactionThermo/rhoReactionThermo/rhoReactionThermo.H index e28274331a..72ce0177b6 100644 --- a/src/thermophysicalModels/reactionThermo/rhoReactionThermo/rhoReactionThermo.H +++ b/src/thermophysicalModels/reactionThermo/rhoReactionThermo/rhoReactionThermo.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2017 OpenCFD Ltd. + Copyright (C) 2017-2020 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,12 +45,15 @@ SourceFiles #include "basicSpecieMixture.H" #include "autoPtr.H" #include "runTimeSelectionTables.H" +#include "specieElement.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { +typedef HashTable> speciesCompositionTable; + /*---------------------------------------------------------------------------*\ Class rhoReactionThermo Declaration \*---------------------------------------------------------------------------*/ @@ -137,6 +140,16 @@ public: //- Return the composition of the multi-component mixture virtual const basicSpecieMixture& composition() const = 0; + + //- Table of species composition + autoPtr specieComposition() const + { + return + autoPtr + ( + composition().specieComposition() + ); + } };