From 61b6cde56488eaf6971a654f79980f69ff084c95 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Wed, 19 Aug 2015 13:42:46 +0100 Subject: [PATCH] hRefConstThermo: New constant coefficient thermodynamics model for phase-change Provided by Juho Peltola --- .../specie/thermo/hRefConst/hRefConstThermo.C | 97 ++++++ .../specie/thermo/hRefConst/hRefConstThermo.H | 233 +++++++++++++++ .../thermo/hRefConst/hRefConstThermoI.H | 277 ++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.C create mode 100644 src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.H create mode 100644 src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermoI.H diff --git a/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.C b/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.C new file mode 100644 index 00000000000..fe83f1794b6 --- /dev/null +++ b/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.C @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "hRefConstThermo.H" +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class EquationOfState> +Foam::hRefConstThermo<EquationOfState>::hRefConstThermo(Istream& is) +: + EquationOfState(is), + Cp_(readScalar(is)), + Hf_(readScalar(is)), + Tref_(readScalar(is)), + Href_(readScalar(is)) +{ + is.check("hRefConstThermo::hRefConstThermo(Istream& is)"); + + Cp_ *= this->W(); + Hf_ *= this->W(); + Href_ *= this->W(); +} + + +template<class EquationOfState> +Foam::hRefConstThermo<EquationOfState>::hRefConstThermo(const dictionary& dict) +: + EquationOfState(dict), + Cp_(readScalar(dict.subDict("thermodynamics").lookup("Cp"))), + Hf_(readScalar(dict.subDict("thermodynamics").lookup("Hf"))), + Tref_(readScalar(dict.subDict("thermodynamics").lookup("Tref"))), + Href_(readScalar(dict.subDict("thermodynamics").lookup("Href"))) +{ + Cp_ *= this->W(); + Hf_ *= this->W(); + Href_ *= this->W(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class EquationOfState> +void Foam::hRefConstThermo<EquationOfState>::write(Ostream& os) const +{ + EquationOfState::write(os); + + dictionary dict("thermodynamics"); + dict.add("Cp", Cp_/this->W()); + dict.add("Hf", Hf_/this->W()); + dict.add("Tref", Tref_); + dict.add("Href", Href_/this->W()); + os << indent << dict.dictName() << dict; +} + + +// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // + +template<class EquationOfState> +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const hRefConstThermo<EquationOfState>& ct +) +{ + os << static_cast<const EquationOfState&>(ct) << tab + << ct.Cp_/ct.W() << tab << ct.Hf_/ct.W() << tab + << ct.Tref_ << tab << ct.Href_/ct.W(); + + os.check("Ostream& operator<<(Ostream& os, const hRefConstThermo& ct)"); + return os; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.H b/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.H new file mode 100644 index 00000000000..9a62231d9c0 --- /dev/null +++ b/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermo.H @@ -0,0 +1,233 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::hRefConstThermo + +Description + Constant properties thermodynamics package + templated into the EquationOfState. + +SourceFiles + hRefConstThermoI.H + hRefConstThermo.C + +\*---------------------------------------------------------------------------*/ + +#ifndef hRefConstThermo_H +#define hRefConstThermo_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +template<class EquationOfState> class hRefConstThermo; + +template<class EquationOfState> +inline hRefConstThermo<EquationOfState> operator+ +( + const hRefConstThermo<EquationOfState>&, + const hRefConstThermo<EquationOfState>& +); + +template<class EquationOfState> +inline hRefConstThermo<EquationOfState> operator- +( + const hRefConstThermo<EquationOfState>&, + const hRefConstThermo<EquationOfState>& +); + +template<class EquationOfState> +inline hRefConstThermo<EquationOfState> operator* +( + const scalar, + const hRefConstThermo<EquationOfState>& +); + +template<class EquationOfState> +inline hRefConstThermo<EquationOfState> operator== +( + const hRefConstThermo<EquationOfState>&, + const hRefConstThermo<EquationOfState>& +); + +template<class EquationOfState> +Ostream& operator<< +( + Ostream&, + const hRefConstThermo<EquationOfState>& +); + + +/*---------------------------------------------------------------------------*\ + Class hRefConstThermo Declaration +\*---------------------------------------------------------------------------*/ + +template<class EquationOfState> +class hRefConstThermo +: + public EquationOfState +{ + // Private data + + scalar Cp_; + scalar Hf_; + scalar Tref_; + scalar Href_; + + + // Private Member Functions + + //- Construct from components + inline hRefConstThermo + ( + const EquationOfState& st, + const scalar cp, + const scalar hf, + const scalar tref, + const scalar href + ); + + +public: + + // Constructors + + //- Construct from Istream + hRefConstThermo(Istream&); + + //- Construct from dictionary + hRefConstThermo(const dictionary& dict); + + //- Construct as named copy + inline hRefConstThermo(const word&, const hRefConstThermo&); + + //- Construct and return a clone + inline autoPtr<hRefConstThermo> clone() const; + + //- Selector from Istream + inline static autoPtr<hRefConstThermo> New(Istream& is); + + //- Selector from dictionary + inline static autoPtr<hRefConstThermo> New(const dictionary& dict); + + + // Member Functions + + //- Return the instantiated type name + static word typeName() + { + return "hRefConst<" + EquationOfState::typeName() + '>'; + } + + //- Limit the temperature to be in the range Tlow_ to Thigh_ + inline scalar limit(const scalar T) const; + + + // Fundamental properties + + //- Heat capacity at constant pressure [J/(kmol K)] + inline scalar cp(const scalar p, const scalar T) const; + + //- Absolute Enthalpy [J/kmol] + inline scalar ha(const scalar p, const scalar T) const; + + //- Sensible enthalpy [J/kmol] + inline scalar hs(const scalar p, const scalar T) const; + + //- Chemical enthalpy [J/kmol] + inline scalar hc() const; + + //- Entropy [J/(kmol K)] + inline scalar s(const scalar p, const scalar T) const; + + + // I-O + + //- Write to Ostream + void write(Ostream& os) const; + + + // Member operators + + inline void operator+=(const hRefConstThermo&); + inline void operator-=(const hRefConstThermo&); + + + // Friend operators + + friend hRefConstThermo operator+ <EquationOfState> + ( + const hRefConstThermo&, + const hRefConstThermo& + ); + + friend hRefConstThermo operator- <EquationOfState> + ( + const hRefConstThermo&, + const hRefConstThermo& + ); + + friend hRefConstThermo operator* <EquationOfState> + ( + const scalar, + const hRefConstThermo& + ); + + friend hRefConstThermo operator== <EquationOfState> + ( + const hRefConstThermo&, + const hRefConstThermo& + ); + + + // IOstream Operators + + friend Ostream& operator<< <EquationOfState> + ( + Ostream&, + const hRefConstThermo& + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "hRefConstThermoI.H" + +#ifdef NoRepository +# include "hRefConstThermo.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermoI.H b/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermoI.H new file mode 100644 index 00000000000..c6a699540e3 --- /dev/null +++ b/src/thermophysicalModels/specie/thermo/hRefConst/hRefConstThermoI.H @@ -0,0 +1,277 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template<class EquationOfState> +inline Foam::hRefConstThermo<EquationOfState>::hRefConstThermo +( + const EquationOfState& st, + const scalar cp, + const scalar hf, + const scalar tref, + const scalar href +) +: + EquationOfState(st), + Cp_(cp), + Hf_(hf), + Tref_(tref), + Href_(href) +{} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class EquationOfState> +inline Foam::hRefConstThermo<EquationOfState>::hRefConstThermo +( + const word& name, + const hRefConstThermo& ct +) +: + EquationOfState(name, ct), + Cp_(ct.Cp_), + Hf_(ct.Hf_), + Tref_(ct.Tref_), + Href_(ct.Href_) +{} + + +template<class EquationOfState> +inline Foam::autoPtr<Foam::hRefConstThermo<EquationOfState> > +Foam::hRefConstThermo<EquationOfState>::clone() const +{ + return autoPtr<hRefConstThermo<EquationOfState> > + ( + new hRefConstThermo<EquationOfState>(*this) + ); +} + + +template<class EquationOfState> +inline Foam::autoPtr<Foam::hRefConstThermo<EquationOfState> > +Foam::hRefConstThermo<EquationOfState>::New(Istream& is) +{ + return autoPtr<hRefConstThermo<EquationOfState> > + ( + new hRefConstThermo<EquationOfState>(is) + ); +} + + +template<class EquationOfState> +inline Foam::autoPtr<Foam::hRefConstThermo<EquationOfState> > +Foam::hRefConstThermo<EquationOfState>::New(const dictionary& dict) +{ + return autoPtr<hRefConstThermo<EquationOfState> > + ( + new hRefConstThermo<EquationOfState>(dict) + ); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class EquationOfState> +inline Foam::scalar Foam::hRefConstThermo<EquationOfState>::limit +( + const scalar T +) const +{ + return T; +} + + +template<class EquationOfState> +inline Foam::scalar Foam::hRefConstThermo<EquationOfState>::cp +( + const scalar p, + const scalar T +) const +{ + return Cp_; +} + + +template<class EquationOfState> +inline Foam::scalar Foam::hRefConstThermo<EquationOfState>::ha +( + const scalar p, const scalar T +) const +{ + return Cp_*(T-Tref_) + Href_ + Hf_; +} + + +template<class EquationOfState> +inline Foam::scalar Foam::hRefConstThermo<EquationOfState>::hs +( + const scalar p, const scalar T +) const +{ + return Cp_*(T-Tref_) + Href_ ; +} + + +template<class EquationOfState> +inline Foam::scalar Foam::hRefConstThermo<EquationOfState>::hc() const +{ + return Hf_; +} + + +template<class EquationOfState> +inline Foam::scalar Foam::hRefConstThermo<EquationOfState>::s +( + const scalar p, const scalar T +) const +{ + return Cp_*log(T/Tstd) + EquationOfState::s(p, T); +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template<class EquationOfState> +inline void Foam::hRefConstThermo<EquationOfState>::operator+= +( + const hRefConstThermo<EquationOfState>& ct +) +{ + scalar molr1 = this->nMoles(); + + EquationOfState::operator+=(ct); + + molr1 /= this->nMoles(); + scalar molr2 = ct.nMoles()/this->nMoles(); + + Cp_ = molr1*Cp_ + molr2*ct.Cp_; + Hf_ = molr1*Hf_ + molr2*ct.Hf_; +} + + +template<class EquationOfState> +inline void Foam::hRefConstThermo<EquationOfState>::operator-= +( + const hRefConstThermo<EquationOfState>& ct +) +{ + scalar molr1 = this->nMoles(); + + EquationOfState::operator-=(ct); + + molr1 /= this->nMoles(); + scalar molr2 = ct.nMoles()/this->nMoles(); + + Cp_ = molr1*Cp_ - molr2*ct.Cp_; + Hf_ = molr1*Hf_ - molr2*ct.Hf_; +} + + +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +template<class EquationOfState> +inline Foam::hRefConstThermo<EquationOfState> Foam::operator+ +( + const hRefConstThermo<EquationOfState>& ct1, + const hRefConstThermo<EquationOfState>& ct2 +) +{ + EquationOfState eofs + ( + static_cast<const EquationOfState&>(ct1) + + static_cast<const EquationOfState&>(ct2) + ); + + return hRefConstThermo<EquationOfState> + ( + eofs, + ct1.nMoles()/eofs.nMoles()*ct1.Cp_ + + ct2.nMoles()/eofs.nMoles()*ct2.Cp_, + ct1.nMoles()/eofs.nMoles()*ct1.Hf_ + + ct2.nMoles()/eofs.nMoles()*ct2.Hf_, + ct1.nMoles()/eofs.nMoles()*ct1.Tref_ + + ct2.nMoles()/eofs.nMoles()*ct2.Tref_, + ct1.nMoles()/eofs.nMoles()*ct1.Href_ + + ct2.nMoles()/eofs.nMoles()*ct2.Href_ + ); +} + + +template<class EquationOfState> +inline Foam::hRefConstThermo<EquationOfState> Foam::operator- +( + const hRefConstThermo<EquationOfState>& ct1, + const hRefConstThermo<EquationOfState>& ct2 +) +{ + EquationOfState eofs + ( + static_cast<const EquationOfState&>(ct1) + - static_cast<const EquationOfState&>(ct2) + ); + + return hRefConstThermo<EquationOfState> + ( + eofs, + ct1.nMoles()/eofs.nMoles()*ct1.Cp_ + - ct2.nMoles()/eofs.nMoles()*ct2.Cp_, + ct1.nMoles()/eofs.nMoles()*ct1.Hf_ + - ct2.nMoles()/eofs.nMoles()*ct2.Hf_ + ); +} + + +template<class EquationOfState> +inline Foam::hRefConstThermo<EquationOfState> Foam::operator* +( + const scalar s, + const hRefConstThermo<EquationOfState>& ct +) +{ + return hRefConstThermo<EquationOfState> + ( + s*static_cast<const EquationOfState&>(ct), + ct.Cp_, + ct.Hf_, + ct.Tref_, + ct.Href_ + ); +} + + +template<class EquationOfState> +inline Foam::hRefConstThermo<EquationOfState> Foam::operator== +( + const hRefConstThermo<EquationOfState>& ct1, + const hRefConstThermo<EquationOfState>& ct2 +) +{ + return ct2 - ct1; +} + + +// ************************************************************************* // -- GitLab