From 87d79261a3adc74beb033dca673b0ad7495bbe2b Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:31:47 +0800 Subject: [PATCH 01/11] Update CanteraMixture.H --- src/dfCanteraMixture/CanteraMixture.H | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dfCanteraMixture/CanteraMixture.H b/src/dfCanteraMixture/CanteraMixture.H index 09701e22..29d304ff 100644 --- a/src/dfCanteraMixture/CanteraMixture.H +++ b/src/dfCanteraMixture/CanteraMixture.H @@ -66,6 +66,7 @@ class CanteraMixture const string CanteraMechanismFile_; std::shared_ptr CanteraSolution_; std::shared_ptr CanteraGas_; + std::shared_ptr CanteraKinetics_; word transportModelName_; Cantera::Transport* CanteraTransport_; hashedWordList species_; @@ -223,10 +224,13 @@ public: const hashedWordList& species() const {return species_;} int nSpecies() {return int(CanteraGas_->nSpecies());} + int nReactions() {return int(CanteraKinetics_->nReactions());} std::shared_ptr CanteraGas() {return CanteraGas_;} std::shared_ptr CanteraSolution() {return CanteraSolution_;} + + std::shared_ptr CanteraKinetics() {return CanteraKinetics_;} Cantera::Transport* CanteraTransport() {return CanteraTransport_;} From cbbcbfc950812eec7c76e2f655a3f07680fddb91 Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:34:00 +0800 Subject: [PATCH 02/11] Update CanteraMixture.C --- src/dfCanteraMixture/CanteraMixture.C | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dfCanteraMixture/CanteraMixture.C b/src/dfCanteraMixture/CanteraMixture.C index 7ed93b10..1e3ff53a 100644 --- a/src/dfCanteraMixture/CanteraMixture.C +++ b/src/dfCanteraMixture/CanteraMixture.C @@ -63,6 +63,7 @@ Foam::CanteraMixture::CanteraMixture CanteraSolution_=Cantera::newSolution(CanteraMechanismFile_, ""); CanteraGas_=CanteraSolution_->thermo(); + CanteraKinetics_=CanteraSolution_->kinetics(); CanteraTransport_=newTransportMgr(transportModelName_, CanteraGas_.get()); Y_.resize(nSpecies()); From 4f5d8fab0735032e075120a8a36011ba4d24478f Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:43:25 +0800 Subject: [PATCH 03/11] Update dfChemistryModel.H --- src/dfChemistryModel/dfChemistryModel.H | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dfChemistryModel/dfChemistryModel.H b/src/dfChemistryModel/dfChemistryModel.H index 5502965c..d345560d 100644 --- a/src/dfChemistryModel/dfChemistryModel.H +++ b/src/dfChemistryModel/dfChemistryModel.H @@ -93,6 +93,7 @@ public IOdictionary ThermoType& thermo_; CanteraMixture& mixture_; std::shared_ptr CanteraGas_; + std::shared_ptr CanteraKinetics_; const fvMesh& mesh_; Switch chemistry_; @@ -110,6 +111,8 @@ public IOdictionary scalarList hc_; // temp mass fraction mutable scalarList yTemp_; + // mole fraction + mutable scalarList c_; // temp mass diffusion coefficients mutable scalarList dTemp_; // temp H/RT @@ -284,6 +287,12 @@ public: //- Return access to chemical source terms [kg/m^3/s] volScalarField::Internal& RR(const label i) {return RR_[i];} + virtual tmp calculateRR + ( + const label reactionI, + const label speciei + ) const; + //- Return the heat release rate [J/m/s^3] const volScalarField& Qdot() const { From c8069279ddc105aa2568d079ca4f37b7daa1081a Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:46:30 +0800 Subject: [PATCH 04/11] Update dfChemistryModel.C --- src/dfChemistryModel/dfChemistryModel.C | 68 +++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C index 84be9b41..64fb51c4 100644 --- a/src/dfChemistryModel/dfChemistryModel.C +++ b/src/dfChemistryModel/dfChemistryModel.C @@ -60,6 +60,7 @@ Foam::dfChemistryModel::dfChemistryModel hai_(mixture_.nSpecies()), hc_(mixture_.nSpecies()), yTemp_(mixture_.nSpecies()), + c_(mixture_.nSpecies()), dTemp_(mixture_.nSpecies()), hrtTemp_(mixture_.nSpecies()), cTemp_(mixture_.nSpecies()), @@ -719,7 +720,74 @@ Foam::dfChemistryModel::updateReactionRates return deltaTMin; } +template +Foam::tmp> +Foam::dfChemistryModel::calculateRR +( + const label reactionI, + const label speciei +) const +{ + tmp tRR + ( + volScalarField::Internal::New + ( + "RR", + mesh_, + dimensionedScalar(dimMass/dimVolume/dimTime, 0) + ) + ); + + volScalarField::Internal& RR = tRR.ref(); + + doublereal netRate[mixture_.nReactions()]; + doublereal X[mixture_.nSpecies()]; + + forAll(rho_, celli) + { + const scalar rhoi = rho_[celli]; + const scalar Ti = T_[celli]; + const scalar pi = p_[celli]; + + for (label i=0; imolecularWeight(i); + } + + for(label i=0; isetState_TPX(Ti, pi, X); + + CanteraKinetics_->getNetRatesOfProgress(netRate); + + auto R = CanteraKinetics_->reaction(reactionI); + + for (const auto& sp : R->reactants) + { + if (speciei == static_cast(CanteraGas_->speciesIndex(sp.first))) + { + RR[celli] -= sp.second*netRate[reactionI]; + } + + } + for (const auto& sp : R->products) + { + if (speciei == static_cast(CanteraGas_->speciesIndex(sp.first))) + { + RR[celli] += sp.second*netRate[reactionI]; + } + } + + RR[celli] *= CanteraGas_->molecularWeight(speciei); + } + + return tRR; +} template Foam::LoadBalancer From d1f82230155bcffe65e0521bf2bf0b15f2585625 Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:48:16 +0800 Subject: [PATCH 05/11] Update dfChemistryModel.C --- src/dfChemistryModel/dfChemistryModel.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C index 64fb51c4..b49eca18 100644 --- a/src/dfChemistryModel/dfChemistryModel.C +++ b/src/dfChemistryModel/dfChemistryModel.C @@ -59,8 +59,8 @@ Foam::dfChemistryModel::dfChemistryModel rhoD_(mixture_.nSpecies()), hai_(mixture_.nSpecies()), hc_(mixture_.nSpecies()), - yTemp_(mixture_.nSpecies()), c_(mixture_.nSpecies()), + yTemp_(mixture_.nSpecies()), dTemp_(mixture_.nSpecies()), hrtTemp_(mixture_.nSpecies()), cTemp_(mixture_.nSpecies()), From bb0074fc78a39b4a076c68cb9eda8320ded26679 Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:48:52 +0800 Subject: [PATCH 06/11] Update dfChemistryModel.H --- src/dfChemistryModel/dfChemistryModel.H | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dfChemistryModel/dfChemistryModel.H b/src/dfChemistryModel/dfChemistryModel.H index d345560d..e7222b6f 100644 --- a/src/dfChemistryModel/dfChemistryModel.H +++ b/src/dfChemistryModel/dfChemistryModel.H @@ -109,10 +109,10 @@ public IOdictionary PtrList hai_; // species chemistry enthalpy, [J/kg] scalarList hc_; + // mole fraction + mutable scalarList c_; // temp mass fraction mutable scalarList yTemp_; - // mole fraction - mutable scalarList c_; // temp mass diffusion coefficients mutable scalarList dTemp_; // temp H/RT From 165bad77a6ba7ed7f66916f3f7c5ce9599c7d09a Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 10:52:23 +0800 Subject: [PATCH 07/11] Update dfChemistryModel.C --- src/dfChemistryModel/dfChemistryModel.C | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C index b49eca18..eababea8 100644 --- a/src/dfChemistryModel/dfChemistryModel.C +++ b/src/dfChemistryModel/dfChemistryModel.C @@ -51,6 +51,7 @@ Foam::dfChemistryModel::dfChemistryModel thermo_(thermo), mixture_(dynamic_cast(thermo)), CanteraGas_(mixture_.CanteraGas()), + CanteraKinetics_(mixture_.CanteraKinetics()), mesh_(thermo.p().mesh()), chemistry_(lookup("chemistry")), relTol_(this->subDict("odeCoeffs").lookupOrDefault("relTol",1e-9)), From 880a82bac545634bf89979edb8c3594f59f9d6ec Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Tue, 30 May 2023 12:58:10 +0800 Subject: [PATCH 08/11] Update CanteraMixture.H --- src/dfCanteraMixture/CanteraMixture.H | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dfCanteraMixture/CanteraMixture.H b/src/dfCanteraMixture/CanteraMixture.H index 29d304ff..80443318 100644 --- a/src/dfCanteraMixture/CanteraMixture.H +++ b/src/dfCanteraMixture/CanteraMixture.H @@ -39,6 +39,7 @@ SourceFiles #include "cantera/zerodim.h" #include "cantera/transport.h" #include "cantera/thermo/IdealGasPhase.h" +#include "cantera/kinetics.h" #include "IOdictionary.H" #include "fvMesh.H" #include "word.H" From 10f001c8893958c6c4cb2407aa7a5811e10ecb58 Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Wed, 31 May 2023 22:20:54 +0800 Subject: [PATCH 09/11] Update dfChemistryModel.H --- src/dfChemistryModel/dfChemistryModel.H | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dfChemistryModel/dfChemistryModel.H b/src/dfChemistryModel/dfChemistryModel.H index e7222b6f..b1554042 100644 --- a/src/dfChemistryModel/dfChemistryModel.H +++ b/src/dfChemistryModel/dfChemistryModel.H @@ -108,9 +108,7 @@ public IOdictionary // species absolute enthalpy, [J/kg] PtrList hai_; // species chemistry enthalpy, [J/kg] - scalarList hc_; - // mole fraction - mutable scalarList c_; + scalarList hc_; // temp mass fraction mutable scalarList yTemp_; // temp mass diffusion coefficients @@ -287,7 +285,7 @@ public: //- Return access to chemical source terms [kg/m^3/s] volScalarField::Internal& RR(const label i) {return RR_[i];} - virtual tmp calculateRR + tmp calculateRR ( const label reactionI, const label speciei From 9fadf6bceb2d8bbd6372d9adb0ad627776ca01b5 Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Wed, 31 May 2023 22:28:02 +0800 Subject: [PATCH 10/11] Update dfChemistryModel.C --- src/dfChemistryModel/dfChemistryModel.C | 64 +++++++++++++------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C index eababea8..17f6575a 100644 --- a/src/dfChemistryModel/dfChemistryModel.C +++ b/src/dfChemistryModel/dfChemistryModel.C @@ -59,8 +59,7 @@ Foam::dfChemistryModel::dfChemistryModel Y_(mixture_.Y()), rhoD_(mixture_.nSpecies()), hai_(mixture_.nSpecies()), - hc_(mixture_.nSpecies()), - c_(mixture_.nSpecies()), + hc_(mixture_.nSpecies()), yTemp_(mixture_.nSpecies()), dTemp_(mixture_.nSpecies()), hrtTemp_(mixture_.nSpecies()), @@ -729,20 +728,23 @@ Foam::dfChemistryModel::calculateRR const label speciei ) const { - tmp tRR - ( - volScalarField::Internal::New - ( + tmp tRR + ( + volScalarField::Internal::New + ( "RR", mesh_, dimensionedScalar(dimMass/dimVolume/dimTime, 0) - ) - ); + ) + ); - volScalarField::Internal& RR = tRR.ref(); + volScalarField::Internal& RR = tRR.ref(); + + // mole fraction + mutable scalarList c[mixture_.nSpecies()]; - doublereal netRate[mixture_.nReactions()]; - doublereal X[mixture_.nSpecies()]; + doublereal netRate[mixture_.nReactions()]; + doublereal X[mixture_.nSpecies()]; forAll(rho_, celli) { @@ -754,35 +756,35 @@ Foam::dfChemistryModel::calculateRR { const scalar Yi = Y_[i][celli]; - c_[i] = rhoi*Yi/CanteraGas_->molecularWeight(i); + c[i] = rhoi*Yi/CanteraGas_->molecularWeight(i); } - for(label i=0; isetState_TPX(Ti, pi, X); + CanteraGas_->setState_TPX(Ti, pi, X); - CanteraKinetics_->getNetRatesOfProgress(netRate); + CanteraKinetics_->getNetRatesOfProgress(netRate); - auto R = CanteraKinetics_->reaction(reactionI); + auto R = CanteraKinetics_->reaction(reactionI); - for (const auto& sp : R->reactants) + for (const auto& sp : R->reactants) + { + if (speciei == static_cast(CanteraGas_->speciesIndex(sp.first))) { - if (speciei == static_cast(CanteraGas_->speciesIndex(sp.first))) - { - RR[celli] -= sp.second*netRate[reactionI]; - } + RR[celli] -= sp.second*netRate[reactionI]; + } - } - for (const auto& sp : R->products) + } + for (const auto& sp : R->products) + { + if (speciei == static_cast(CanteraGas_->speciesIndex(sp.first))) { - if (speciei == static_cast(CanteraGas_->speciesIndex(sp.first))) - { - RR[celli] += sp.second*netRate[reactionI]; - } - } + RR[celli] += sp.second*netRate[reactionI]; + } + } RR[celli] *= CanteraGas_->molecularWeight(speciei); } From aa0d89548566749e6986b407564ec34913250b1c Mon Sep 17 00:00:00 2001 From: minzhang0929 <78373564+minzhang0929@users.noreply.github.com> Date: Thu, 1 Jun 2023 09:13:05 +0800 Subject: [PATCH 11/11] Update dfChemistryModel.C --- src/dfChemistryModel/dfChemistryModel.C | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C index 17f6575a..19fcc557 100644 --- a/src/dfChemistryModel/dfChemistryModel.C +++ b/src/dfChemistryModel/dfChemistryModel.C @@ -740,9 +740,6 @@ Foam::dfChemistryModel::calculateRR volScalarField::Internal& RR = tRR.ref(); - // mole fraction - mutable scalarList c[mixture_.nSpecies()]; - doublereal netRate[mixture_.nReactions()]; doublereal X[mixture_.nSpecies()]; @@ -756,14 +753,9 @@ Foam::dfChemistryModel::calculateRR { const scalar Yi = Y_[i][celli]; - c[i] = rhoi*Yi/CanteraGas_->molecularWeight(i); + X[i] = rhoi*Yi/CanteraGas_->molecularWeight(i); } - for(label i=0; isetState_TPX(Ti, pi, X); CanteraKinetics_->getNetRatesOfProgress(netRate);