From 6c1aa06d164688d53f9b74fbda73b8e2fe73a84b Mon Sep 17 00:00:00 2001 From: Henry <Henry> Date: Tue, 4 Dec 2012 15:05:19 +0000 Subject: [PATCH] perfectFluid: New EoS for gases and liquids which behaves as a perfect gas for a gas and an offset perfect gas for a liquid --- .../perfectFluid/perfectFluid.C | 76 ++++++ .../perfectFluid/perfectFluid.H | 223 ++++++++++++++++++ .../perfectFluid/perfectFluidI.H | 220 +++++++++++++++++ 3 files changed, 519 insertions(+) create mode 100644 src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.C create mode 100644 src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.H create mode 100644 src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluidI.H diff --git a/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.C b/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.C new file mode 100644 index 00000000000..844f293e2dd --- /dev/null +++ b/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.C @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2012 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 "perfectFluid.H" +#include "IOstreams.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Specie> +Foam::perfectFluid<Specie>::perfectFluid(Istream& is) +: + Specie(is), + rho0_(readScalar(is)) +{ + is.check("perfectFluid<Specie>::perfectFluid(Istream& is)"); +} + + +template<class Specie> +Foam::perfectFluid<Specie>::perfectFluid(const dictionary& dict) +: + Specie(dict), + rho0_(readScalar(dict.subDict("equationOfState").lookup("rho0"))) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Specie> +void Foam::perfectFluid<Specie>::write(Ostream& os) const +{ + Specie::write(os); + + dictionary dict("equationOfState"); + dict.add("rho0", rho0_); + + os << indent << dict.dictName() << dict; +} + + +// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // + +template<class Specie> +Foam::Ostream& Foam::operator<<(Ostream& os, const perfectFluid<Specie>& pf) +{ + os << static_cast<const Specie&>(pf) + << token::SPACE << pf.rho0_; + + os.check("Ostream& operator<<(Ostream&, const perfectFluid<Specie>&)"); + return os; +} + + +// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.H b/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.H new file mode 100644 index 00000000000..76cf80c4a8f --- /dev/null +++ b/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluid.H @@ -0,0 +1,223 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 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::perfectFluid + +Description + Perfect gas equation of state. + +SourceFiles + perfectFluidI.H + perfectFluid.C + +\*---------------------------------------------------------------------------*/ + +#ifndef perfectFluid_H +#define perfectFluid_H + +#include "autoPtr.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of friend functions and operators + +template<class Specie> class perfectFluid; + +template<class Specie> +inline perfectFluid<Specie> operator+ +( + const perfectFluid<Specie>&, + const perfectFluid<Specie>& +); + +template<class Specie> +inline perfectFluid<Specie> operator- +( + const perfectFluid<Specie>&, + const perfectFluid<Specie>& +); + +template<class Specie> +inline perfectFluid<Specie> operator* +( + const scalar, + const perfectFluid<Specie>& +); + +template<class Specie> +inline perfectFluid<Specie> operator== +( + const perfectFluid<Specie>&, + const perfectFluid<Specie>& +); + +template<class Specie> +Ostream& operator<< +( + Ostream&, + const perfectFluid<Specie>& +); + + +/*---------------------------------------------------------------------------*\ + Class perfectFluid Declaration +\*---------------------------------------------------------------------------*/ + +template<class Specie> +class perfectFluid +: + public Specie +{ + // Private data + + //- The reference density + scalar rho0_; + +public: + + // Constructors + + //- Construct from components + inline perfectFluid(const Specie& sp, const scalar rho0); + + //- Construct from Istream + perfectFluid(Istream&); + + //- Construct from dictionary + perfectFluid(const dictionary& dict); + + //- Construct as named copy + inline perfectFluid(const word& name, const perfectFluid&); + + //- Construct and return a clone + inline autoPtr<perfectFluid> clone() const; + + // Selector from Istream + inline static autoPtr<perfectFluid> New(Istream& is); + + // Selector from dictionary + inline static autoPtr<perfectFluid> New(const dictionary& dict); + + + // Member functions + + //- Return the instantiated type name + static word typeName() + { + return "perfectFluid<" + word(Specie::typeName_()) + '>'; + } + + + // Fundamental properties + + //- Is the equation of state is incompressible i.e. rho != f(p) + static const bool incompressible = false; + + //- Is the equation of state is isochoric i.e. rho = const + static const bool isochoric = false; + + //- Return density [kg/m^3] + inline scalar rho(scalar p, scalar T) const; + + //- Return compressibility rho/p [s^2/m^2] + inline scalar psi(scalar p, scalar T) const; + + //- Return compression factor [] + inline scalar Z(scalar p, scalar T) const; + + //- Return (cp - cv) [J/(kmol K] + inline scalar cpMcv(scalar p, scalar T) const; + + + // IO + + //- Write to Ostream + void write(Ostream& os) const; + + + // Member operators + + inline void operator+=(const perfectFluid&); + inline void operator-=(const perfectFluid&); + + inline void operator*=(const scalar); + + + // Friend operators + + friend perfectFluid operator+ <Specie> + ( + const perfectFluid&, + const perfectFluid& + ); + + friend perfectFluid operator- <Specie> + ( + const perfectFluid&, + const perfectFluid& + ); + + friend perfectFluid operator* <Specie> + ( + const scalar s, + const perfectFluid& + ); + + friend perfectFluid operator== <Specie> + ( + const perfectFluid&, + const perfectFluid& + ); + + + // Ostream Operator + + friend Ostream& operator<< <Specie> + ( + Ostream&, + const perfectFluid& + ); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "perfectFluidI.H" + +#ifdef NoRepository +# include "perfectFluid.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluidI.H b/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluidI.H new file mode 100644 index 00000000000..21fc092fe2a --- /dev/null +++ b/src/thermophysicalModels/specie/equationOfState/perfectFluid/perfectFluidI.H @@ -0,0 +1,220 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 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 "perfectFluid.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template<class Specie> +inline Foam::perfectFluid<Specie>::perfectFluid +( + const Specie& sp, + const scalar rho0 +) +: + Specie(sp), + rho0_(rho0) +{} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template<class Specie> +inline Foam::perfectFluid<Specie>::perfectFluid +( + const word& name, + const perfectFluid<Specie>& pf +) +: + Specie(name, pf), + rho0_(pf.rho0_) +{} + + +template<class Specie> +inline Foam::autoPtr<Foam::perfectFluid<Specie> > +Foam::perfectFluid<Specie>::clone() const +{ + return autoPtr<perfectFluid<Specie> >(new perfectFluid<Specie>(*this)); +} + + +template<class Specie> +inline Foam::autoPtr<Foam::perfectFluid<Specie> > +Foam::perfectFluid<Specie>::New(Istream& is) +{ + return autoPtr<perfectFluid<Specie> >(new perfectFluid<Specie>(is)); +} + + +template<class Specie> +inline Foam::autoPtr<Foam::perfectFluid<Specie> > +Foam::perfectFluid<Specie>::New +( + const dictionary& dict +) +{ + return autoPtr<perfectFluid<Specie> >(new perfectFluid<Specie>(dict)); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Specie> +inline Foam::scalar Foam::perfectFluid<Specie>::rho(scalar p, scalar T) const +{ + return rho0_ + p/(this->R()*T); +} + + +template<class Specie> +inline Foam::scalar Foam::perfectFluid<Specie>::psi(scalar, scalar T) const +{ + return 1.0/(this->R()*T); +} + + +template<class Specie> +inline Foam::scalar Foam::perfectFluid<Specie>::Z(scalar, scalar) const +{ + return 1.0; +} + + +template<class Specie> +inline Foam::scalar Foam::perfectFluid<Specie>::cpMcv(scalar, scalar) const +{ + return this->RR; +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template<class Specie> +inline void Foam::perfectFluid<Specie>::operator+= +( + const perfectFluid<Specie>& pf +) +{ + scalar molr1 = this->nMoles(); + + Specie::operator+=(pf); + + molr1 /= this->nMoles(); + scalar molr2 = pf.nMoles()/this->nMoles(); + + rho0_ = molr1*rho0_ + molr2*pf.rho0_; +} + + +template<class Specie> +inline void Foam::perfectFluid<Specie>::operator-= +( + const perfectFluid<Specie>& pf +) +{ + scalar molr1 = this->nMoles(); + + Specie::operator-=(pf); + + molr1 /= this->nMoles(); + scalar molr2 = pf.nMoles()/this->nMoles(); + + rho0_ = molr1*rho0_ - molr2*pf.rho0_; +} + + +template<class Specie> +inline void Foam::perfectFluid<Specie>::operator*=(const scalar s) +{ + Specie::operator*=(s); +} + + +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +template<class Specie> +inline Foam::perfectFluid<Specie> Foam::operator+ +( + const perfectFluid<Specie>& pf1, + const perfectFluid<Specie>& pf2 +) +{ + scalar nMoles = pf1.nMoles() + pf2.nMoles(); + scalar molr1 = pf1.nMoles()/nMoles; + scalar molr2 = pf2.nMoles()/nMoles; + + return rhoConst<Specie> + ( + static_cast<const Specie&>(pf1) + + static_cast<const Specie&>(pf2), + molr1*pf1.rho0_ + molr2*pf2.rho0_ + ); +} + + +template<class Specie> +inline Foam::perfectFluid<Specie> Foam::operator- +( + const perfectFluid<Specie>& pf1, + const perfectFluid<Specie>& pf2 +) +{ + scalar nMoles = pf1.nMoles() + pf2.nMoles(); + scalar molr1 = pf1.nMoles()/nMoles; + scalar molr2 = pf2.nMoles()/nMoles; + + return rhoConst<Specie> + ( + static_cast<const Specie&>(pf1) + - static_cast<const Specie&>(pf2), + molr1*pf1.rho0_ - molr2*pf2.rho0_ + ); +} + + +template<class Specie> +inline Foam::perfectFluid<Specie> Foam::operator* +( + const scalar s, + const perfectFluid<Specie>& pf +) +{ + return perfectFluid<Specie>(s*static_cast<const Specie&>(pf), pf.rho0_); +} + + +template<class Specie> +inline Foam::perfectFluid<Specie> Foam::operator== +( + const perfectFluid<Specie>& pf1, + const perfectFluid<Specie>& pf2 +) +{ + return pf2 - pf1; +} + + +// ************************************************************************* // -- GitLab