From cd714205efbfd2742ae62da56792b4f73b040b7b Mon Sep 17 00:00:00 2001 From: ignis Date: Fri, 12 Aug 2016 22:22:41 +0900 Subject: [PATCH] canteraTransport working --- .../psiChemistryModel/psiChemistryModels.C | 7 ++ .../rhoChemistryModel/rhoChemistryModels.C | 7 ++ .../chemistrySolver/makeChemistrySolvers.C | 2 + .../chemistryReader/makeChemistryReaders.C | 2 + .../psiReactionThermo/psiReactionThermos.C | 9 +++ src/thermophysicalModels/specie/Make/options | 10 +++ .../specie/include/reactionTypes.H | 2 + .../specie/reaction/reactions/makeReactions.C | 1 + .../transport/cantera/canteraTransport.C | 79 ++++++++++++++++--- .../transport/cantera/canteraTransport.H | 45 ++++++++--- .../transport/cantera/canteraTransportI.H | 76 +++++------------- 11 files changed, 160 insertions(+), 80 deletions(-) diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/psiChemistryModel/psiChemistryModels.C b/src/thermophysicalModels/chemistryModel/chemistryModel/psiChemistryModel/psiChemistryModels.C index 340edb3d..ddaab215 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/psiChemistryModel/psiChemistryModels.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/psiChemistryModel/psiChemistryModels.C @@ -54,6 +54,13 @@ namespace Foam gasHThermoPhysics ); + makeChemistryModel + ( + chemistryModel, + psiChemistryModel, + canteraGasHThermoPhysics + ); + makeChemistryModel ( chemistryModel, diff --git a/src/thermophysicalModels/chemistryModel/chemistryModel/rhoChemistryModel/rhoChemistryModels.C b/src/thermophysicalModels/chemistryModel/chemistryModel/rhoChemistryModel/rhoChemistryModels.C index c331cd1c..8a45d09c 100644 --- a/src/thermophysicalModels/chemistryModel/chemistryModel/rhoChemistryModel/rhoChemistryModels.C +++ b/src/thermophysicalModels/chemistryModel/chemistryModel/rhoChemistryModel/rhoChemistryModels.C @@ -54,6 +54,13 @@ namespace Foam gasHThermoPhysics ); + makeChemistryModel + ( + chemistryModel, + rhoChemistryModel, + canteraGasHThermoPhysics + ); + makeChemistryModel ( chemistryModel, diff --git a/src/thermophysicalModels/chemistryModel/chemistrySolver/chemistrySolver/makeChemistrySolvers.C b/src/thermophysicalModels/chemistryModel/chemistrySolver/chemistrySolver/makeChemistrySolvers.C index 069a7828..f17f5fa9 100644 --- a/src/thermophysicalModels/chemistryModel/chemistrySolver/chemistrySolver/makeChemistrySolvers.C +++ b/src/thermophysicalModels/chemistryModel/chemistrySolver/chemistrySolver/makeChemistrySolvers.C @@ -36,6 +36,7 @@ namespace Foam // Chemistry solvers based on sensibleEnthalpy makeChemistrySolverTypes(psiChemistryModel, constGasHThermoPhysics); makeChemistrySolverTypes(psiChemistryModel, gasHThermoPhysics); + makeChemistrySolverTypes(psiChemistryModel, canteraGasHThermoPhysics); makeChemistrySolverTypes ( psiChemistryModel, @@ -49,6 +50,7 @@ namespace Foam makeChemistrySolverTypes(psiChemistryModel, icoPoly8HThermoPhysics); makeChemistrySolverTypes(rhoChemistryModel, constGasHThermoPhysics); makeChemistrySolverTypes(rhoChemistryModel, gasHThermoPhysics); + makeChemistrySolverTypes(rhoChemistryModel, canteraGasHThermoPhysics); makeChemistrySolverTypes ( rhoChemistryModel, diff --git a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/makeChemistryReaders.C b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/makeChemistryReaders.C index 7b0561ee..4530c826 100644 --- a/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/makeChemistryReaders.C +++ b/src/thermophysicalModels/reactionThermo/chemistryReaders/chemistryReader/makeChemistryReaders.C @@ -41,12 +41,14 @@ namespace Foam makeChemistryReader(constGasHThermoPhysics); makeChemistryReader(gasHThermoPhysics); +makeChemistryReader(canteraGasHThermoPhysics); makeChemistryReader(constIncompressibleGasHThermoPhysics); makeChemistryReader(incompressibleGasHThermoPhysics); makeChemistryReader(icoPoly8HThermoPhysics); makeChemistryReaderType(foamChemistryReader, constGasHThermoPhysics); makeChemistryReaderType(foamChemistryReader, gasHThermoPhysics); +makeChemistryReaderType(foamChemistryReader, canteraGasHThermoPhysics); makeChemistryReaderType ( foamChemistryReader, diff --git a/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermos.C b/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermos.C index 015c0118..3f445204 100644 --- a/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermos.C +++ b/src/thermophysicalModels/reactionThermo/psiReactionThermo/psiReactionThermos.C @@ -241,6 +241,15 @@ makeReactionMixtureThermo gasHThermoPhysics ); +makeReactionMixtureThermo +( + psiThermo, + psiReactionThermo, + hePsiThermo, + reactingMixture, + canteraGasHThermoPhysics +); + makeReactionMixtureThermo ( psiThermo, diff --git a/src/thermophysicalModels/specie/Make/options b/src/thermophysicalModels/specie/Make/options index e69de29b..950ab5ae 100644 --- a/src/thermophysicalModels/specie/Make/options +++ b/src/thermophysicalModels/specie/Make/options @@ -0,0 +1,10 @@ +EXE_INC = \ + -I/home/ignis/OpenFOAM/cantera/include \ + -I/home/ignis/OpenFOAM/cantera/include/cantera \ + -I$(LIB_SRC)/OpenFOAM/lnInclude + +LIB_LIBS = \ + -L/home/ignis/OpenFOAM/cantera/lib \ + -lcantera_shared \ + -lOpenFOAM \ + -lboost_system diff --git a/src/thermophysicalModels/specie/include/reactionTypes.H b/src/thermophysicalModels/specie/include/reactionTypes.H index b58c3098..72fc5b1f 100644 --- a/src/thermophysicalModels/specie/include/reactionTypes.H +++ b/src/thermophysicalModels/specie/include/reactionTypes.H @@ -48,6 +48,8 @@ namespace Foam typedef Reaction gasHReaction; + typedef Reaction canteraGasHReaction; + typedef Reaction constIncompressibleGasHReaction; diff --git a/src/thermophysicalModels/specie/reaction/reactions/makeReactions.C b/src/thermophysicalModels/specie/reaction/reactions/makeReactions.C index 96352b2c..baf6c0d5 100644 --- a/src/thermophysicalModels/specie/reaction/reactions/makeReactions.C +++ b/src/thermophysicalModels/specie/reaction/reactions/makeReactions.C @@ -86,6 +86,7 @@ namespace Foam // sensible enthalpy based reactions makeReactions(constGasHThermoPhysics, constGasHReaction) makeReactions(gasHThermoPhysics, gasHReaction) + makeReactions(canteraGasHThermoPhysics, canteraGasHReaction) makeReactions ( constIncompressibleGasHThermoPhysics, diff --git a/src/thermophysicalModels/specie/transport/cantera/canteraTransport.C b/src/thermophysicalModels/specie/transport/cantera/canteraTransport.C index 43d62d94..987ed6ec 100644 --- a/src/thermophysicalModels/specie/transport/cantera/canteraTransport.C +++ b/src/thermophysicalModels/specie/transport/cantera/canteraTransport.C @@ -26,14 +26,48 @@ License #include "canteraTransport.H" #include "IOstreams.H" +#include "cantera/transport.h" +#include "cantera/IdealGasMix.h" + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template +typename Foam::canteraTransport::canteraManager Foam::canteraTransport::cm_; + + + template +Foam::canteraTransport::canteraManager::canteraManager() + : + gas_ (NULL), + tr_ (NULL), + nCanteraSp_ (0) +{ + try + { + gas_ = new Cantera::IdealGasMix("./cantera-transport.cti", "gas"); + tr_ = Cantera::newTransportMgr("Mix", gas_); + nCanteraSp_ = gas_->nSpecies(); + } + catch (Cantera::CanteraError e) + { + gas_ = NULL; + tr_ = NULL; + nCanteraSp_ = 0; + } +} + + template +Foam::canteraTransport::canteraManager::~canteraManager() +{ + delete tr_; + delete gas_; +} + + template Foam::canteraTransport::canteraTransport(Istream& is) -: - Thermo(is), - As_(readScalar(is)), - Ts_(readScalar(is)) + : + Thermo(is), + X_(cm_.gas()->nSpecies()) { is.check("canteraTransport::canteraTransport(Istream&)"); } @@ -43,9 +77,11 @@ template Foam::canteraTransport::canteraTransport(const dictionary& dict) : Thermo(dict), - As_(readScalar(dict.subDict("transport").lookup("As"))), - Ts_(readScalar(dict.subDict("transport").lookup("Ts"))) -{} + X_(cm_.gas()->nSpecies(), 0.0) +{ + label si = cm_.gas()->speciesIndex(this->specie::name()); + if (si >= 0) X_[si] = this->nMoles(); +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -59,8 +95,6 @@ void Foam::canteraTransport::write(Ostream& os) const Thermo::write(os); dictionary dict("transport"); - dict.add("As", As_); - dict.add("Ts", Ts_); os << indent << dict.dictName() << dict; os << decrIndent << token::END_BLOCK << nl; @@ -75,7 +109,7 @@ Foam::Ostream& Foam::operator<< const canteraTransport& st ) { - os << static_cast(st) << tab << st.As_ << tab << st.Ts_; + os << static_cast(st); os.check ( @@ -86,4 +120,29 @@ Foam::Ostream& Foam::operator<< } +template +Foam::scalar Foam::canteraTransport::mu +( + const scalar p, + const scalar T + ) const +{ + cm_.gas()->setState_TPX(T, p, X_.cdata()); + scalar mu_ = cm_.tr()->viscosity(); + return mu_; +} + + +template +inline Foam::scalar Foam::canteraTransport::kappa +( + const scalar p, const scalar T + ) const +{ + cm_.gas()->setState_TPX(T, p, X_.cdata()); + scalar kappa_ = cm_.tr()->thermalConductivity(); + return kappa_; +} + + // ************************************************************************* // diff --git a/src/thermophysicalModels/specie/transport/cantera/canteraTransport.H b/src/thermophysicalModels/specie/transport/cantera/canteraTransport.H index 1283e2f4..4b1bc912 100644 --- a/src/thermophysicalModels/specie/transport/cantera/canteraTransport.H +++ b/src/thermophysicalModels/specie/transport/cantera/canteraTransport.H @@ -46,6 +46,14 @@ SourceFiles // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "scalarField.H" + +namespace Cantera +{ + class IdealGasMix; + class Transport; +} + namespace Foam { @@ -98,21 +106,33 @@ class canteraTransport : public Thermo { + // Private class + + class canteraManager + { + Cantera::IdealGasMix *gas_; + Cantera::Transport *tr_; + label nCanteraSp_; + + public: + + canteraManager(); + ~canteraManager(); + inline Cantera::IdealGasMix *gas() {return gas_;} + inline Cantera::Transport *tr() {return tr_;} + inline label nCanteraSp() {return nCanteraSp_;} + }; + + // Private data - // Sutherland's coefficients - scalar As_, Ts_; + scalarField X_; + + static canteraManager cm_; // Private Member Functions - //- Calculate the Sutherland coefficients - // given two viscosities and temperatures - inline void calcCoeffs - ( - const scalar mu1, const scalar T1, - const scalar mu2, const scalar T2 - ); public: @@ -123,8 +143,7 @@ public: inline canteraTransport ( const Thermo& t, - const scalar As, - const scalar Ts + const scalarField &X ); //- Construct from two viscosities @@ -163,10 +182,10 @@ public: } //- Dynamic viscosity [kg/ms] - inline scalar mu(const scalar p, const scalar T) const; + scalar mu(const scalar p, const scalar T) const; //- Thermal conductivity [W/mK] - inline scalar kappa(const scalar p, const scalar T) const; + scalar kappa(const scalar p, const scalar T) const; //- Thermal diffusivity of enthalpy [kg/ms] inline scalar alphah(const scalar p, const scalar T) const; diff --git a/src/thermophysicalModels/specie/transport/cantera/canteraTransportI.H b/src/thermophysicalModels/specie/transport/cantera/canteraTransportI.H index b1ced0a1..e3cbf4a4 100644 --- a/src/thermophysicalModels/specie/transport/cantera/canteraTransportI.H +++ b/src/thermophysicalModels/specie/transport/cantera/canteraTransportI.H @@ -27,21 +27,6 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -inline void Foam::canteraTransport::calcCoeffs -( - const scalar mu1, const scalar T1, - const scalar mu2, const scalar T2 -) -{ - scalar rootT1 = sqrt(T1); - scalar mu1rootT2 = mu1*sqrt(T2); - scalar mu2rootT1 = mu2*rootT1; - - Ts_ = (mu2rootT1 - mu1rootT2)/(mu1rootT2/T1 - mu2rootT1/T2); - - As_ = mu1*(1.0 + Ts_/T1)/rootT1; -} // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -50,13 +35,11 @@ template inline Foam::canteraTransport::canteraTransport ( const Thermo& t, - const scalar As, - const scalar Ts + const scalarField &X ) : Thermo(t), - As_(As), - Ts_(Ts) + X_(X) {} @@ -68,9 +51,9 @@ inline Foam::canteraTransport::canteraTransport const scalar mu2, const scalar T2 ) : - Thermo(t) + Thermo(t), + X_(cm_.nCanteraSp()) { - calcCoeffs(mu1, T1, mu2, T2); } @@ -82,8 +65,7 @@ inline Foam::canteraTransport::canteraTransport ) : Thermo(name, st), - As_(st.As_), - Ts_(st.Ts_) + X_(st.X_) {} @@ -128,28 +110,6 @@ Foam::canteraTransport::New // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -inline Foam::scalar Foam::canteraTransport::mu -( - const scalar p, - const scalar T -) const -{ - return As_*::sqrt(T)/(1.0 + Ts_/T); -} - - -template -inline Foam::scalar Foam::canteraTransport::kappa -( - const scalar p, const scalar T -) const -{ - scalar Cv_ = this->Cv(p, T); - return mu(p, T)*Cv_*(1.32 + 1.77*this->R()/Cv_); -} - - template inline Foam::scalar Foam::canteraTransport::alphah ( @@ -173,8 +133,7 @@ Foam::canteraTransport::operator= { Thermo::operator=(st); - As_ = st.As_; - Ts_ = st.Ts_; + X_ = st.X_; return *this; } @@ -193,8 +152,10 @@ inline void Foam::canteraTransport::operator+= molr1 /= this->nMoles(); scalar molr2 = st.nMoles()/this->nMoles(); - As_ = molr1*As_ + molr2*st.As_; - Ts_ = molr1*Ts_ + molr2*st.Ts_; + // X_ = molr1*X_ + molr2*st.X_; + // X_ *= molr1; + // X_ += molr2*st.X_; + X_ += st.X_; } @@ -211,8 +172,10 @@ inline void Foam::canteraTransport::operator-= molr1 /= this->nMoles(); scalar molr2 = st.nMoles()/this->nMoles(); - As_ = molr1*As_ - molr2*st.As_; - Ts_ = molr1*Ts_ - molr2*st.Ts_; + // X_ = molr1*X_ - molr2*st.X_; + // X_ *= molr1; + // X_ -= molr2*st.X_; + X_ -= st.X_; } @@ -246,8 +209,8 @@ inline Foam::canteraTransport Foam::operator+ return canteraTransport ( t, - molr1*st1.As_ + molr2*st2.As_, - molr1*st1.Ts_ + molr2*st2.Ts_ + // molr1*st1.X_ + molr2*st2.X_ + st1.X_ + st2.X_ ); } @@ -270,8 +233,8 @@ inline Foam::canteraTransport Foam::operator- return canteraTransport ( t, - molr1*st1.As_ - molr2*st2.As_, - molr1*st1.Ts_ - molr2*st2.Ts_ + // molr1*st1.X_ - molr2*st2.X_ + st1.X_ - st2.X_ ); } @@ -286,8 +249,7 @@ inline Foam::canteraTransport Foam::operator* return canteraTransport ( s*static_cast(st), - st.As_, - st.Ts_ + s*st.X_ ); }