From 04d4f75f70323735b89a99e940c91d14a730ce9c Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 21 Jan 2015 09:35:38 +0000 Subject: [PATCH] thermophysicalModels: Resolve issue with the construction of RR from physicoChemicalConstants which may or may not be already constructed Solution: Move RR, Pstd and Tstd used by specie into thermodynamicConstants constructed in global.C in the OpenFOAM library --- src/OpenFOAM/global/constants/constants.C | 7 +- src/OpenFOAM/global/constants/constants.H | 8 +-- .../physicoChemicalConstants.H | 1 - .../thermodynamic/thermodynamicConstants.C | 55 ++++++++++++++++ .../thermodynamic/thermodynamicConstants.H | 66 +++++++++++++++++++ .../liquidMixtureProperties.C | 2 +- .../solidProperties/solidPropertiesI.H | 2 +- src/thermophysicalModels/specie/Make/options | 1 + .../PengRobinsonGas/PengRobinsonGas.C | 2 +- .../PengRobinsonGas/PengRobinsonGasI.H | 10 +-- .../incompressiblePerfectGasI.H | 2 +- .../equationOfState/perfectGas/perfectGasI.H | 2 +- .../specie/specie/specie.C | 13 +--- .../specie/specie/specie.H | 17 +---- .../thermo/hExponential/hExponentialThermoI.H | 4 +- .../thermo/hPolynomial/hPolynomialThermo.C | 8 +-- .../specie/thermo/janaf/janafThermoI.H | 9 ++- .../specie/thermo/thermo/thermo.H | 3 + .../specie/thermo/thermo/thermoI.H | 8 +-- 19 files changed, 160 insertions(+), 60 deletions(-) create mode 100644 src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.C create mode 100644 src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.H diff --git a/src/OpenFOAM/global/constants/constants.C b/src/OpenFOAM/global/constants/constants.C index 202855d8d..926bcdf1a 100644 --- a/src/OpenFOAM/global/constants/constants.C +++ b/src/OpenFOAM/global/constants/constants.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,11 +28,12 @@ License // Constants supplied in the main controlDict #include "fundamentalConstants.C" -// Derived constants. Note:order is important +// Derived constants. +// Note: order is important #include "universalConstants.C" #include "electromagneticConstants.C" #include "atomicConstants.C" #include "physicoChemicalConstants.C" - +#include "thermodynamicConstants.C" // ************************************************************************* // diff --git a/src/OpenFOAM/global/constants/constants.H b/src/OpenFOAM/global/constants/constants.H index e00b31bb6..ae139b035 100644 --- a/src/OpenFOAM/global/constants/constants.H +++ b/src/OpenFOAM/global/constants/constants.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,14 +34,9 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -// Dimensionless coefficents - // Mathematical constants #include "mathematicalConstants.H" - -// Dimensioned constants - // Fundamental constants #include "fundamentalConstants.H" @@ -50,6 +45,7 @@ Description #include "electromagneticConstants.H" #include "atomicConstants.H" #include "physicoChemicalConstants.H" +#include "thermodynamicConstants.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/global/constants/physicoChemical/physicoChemicalConstants.H b/src/OpenFOAM/global/constants/physicoChemical/physicoChemicalConstants.H index e1c872ff7..40cee9b5f 100644 --- a/src/OpenFOAM/global/constants/physicoChemical/physicoChemicalConstants.H +++ b/src/OpenFOAM/global/constants/physicoChemical/physicoChemicalConstants.H @@ -66,7 +66,6 @@ namespace physicoChemical //- Second radiation constant: default SI units: [m.K] extern const dimensionedScalar c2; - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace physicoChemical diff --git a/src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.C b/src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.C new file mode 100644 index 000000000..65fedd44e --- /dev/null +++ b/src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.C @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +\*---------------------------------------------------------------------------*/ + +#include "thermodynamicConstants.H" +#include "physicoChemicalConstants.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace constant +{ +namespace thermodynamic +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + // Note: the 1e3 converts from /mol to /kmol for consistency with the + // SI choice of kg rather than g for mass. + // This is not appropriate for USCS and will be changed to an entry in + // the DimensionedConstants dictionary in etc/controlDict + const scalar RR = 1e3*physicoChemical::R.value(); + + const scalar Pstd = standard::Pstd.value(); + const scalar Tstd = standard::Tstd.value(); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace thermodynamic +} // End namespace constant +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.H b/src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.H new file mode 100644 index 000000000..0c8378f87 --- /dev/null +++ b/src/OpenFOAM/global/constants/thermodynamic/thermodynamicConstants.H @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 . + +Namespace + Foam::constant::thermodynamic + +Description + Thermodynamic scalar constants + +\*---------------------------------------------------------------------------*/ + +#ifndef thermodynamicConstants_H +#define thermodynamicConstants_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace constant +{ +namespace thermodynamic +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + //- Universal gas constant (default in [J/(kmol K)]) + extern const scalar RR; + + //- Standard pressure (default in [Pa]) + extern const scalar Pstd; + + //- Standard temperature (default in [K]) + extern const scalar Tstd; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace thermodynamic +} // End namespace constant +} // End namespace Foam + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/thermophysicalModels/properties/liquidMixtureProperties/liquidMixtureProperties/liquidMixtureProperties.C b/src/thermophysicalModels/properties/liquidMixtureProperties/liquidMixtureProperties/liquidMixtureProperties.C index ac26ec139..5fec22dc9 100644 --- a/src/thermophysicalModels/properties/liquidMixtureProperties/liquidMixtureProperties/liquidMixtureProperties.C +++ b/src/thermophysicalModels/properties/liquidMixtureProperties/liquidMixtureProperties/liquidMixtureProperties.C @@ -187,7 +187,7 @@ Foam::scalar Foam::liquidMixtureProperties::Ppc(const scalarField& x) const Zc += x[i]*properties_[i].Zc(); } - return specie::RR*Zc*Tpc(x)/Vc; + return RR*Zc*Tpc(x)/Vc; } diff --git a/src/thermophysicalModels/properties/solidProperties/solidProperties/solidPropertiesI.H b/src/thermophysicalModels/properties/solidProperties/solidProperties/solidPropertiesI.H index 05b6ad9c9..dda7e9428 100644 --- a/src/thermophysicalModels/properties/solidProperties/solidProperties/solidPropertiesI.H +++ b/src/thermophysicalModels/properties/solidProperties/solidProperties/solidPropertiesI.H @@ -53,7 +53,7 @@ inline Foam::scalar Foam::solidProperties::Hf() const inline Foam::scalar Foam::solidProperties::Hs(const scalar T) const { - return Cp_*(T - specie::Tstd); + return Cp_*(T - Tstd); } diff --git a/src/thermophysicalModels/specie/Make/options b/src/thermophysicalModels/specie/Make/options index e69de29bb..345729850 100644 --- a/src/thermophysicalModels/specie/Make/options +++ b/src/thermophysicalModels/specie/Make/options @@ -0,0 +1 @@ +LIB_LIBS = -lOpenFOAM diff --git a/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGas.C b/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGas.C index c3fefab77..baf20aeba 100644 --- a/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGas.C +++ b/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGas.C @@ -55,7 +55,7 @@ Foam::PengRobinsonGas::PengRobinsonGas Pc_(readScalar(dict.subDict("equationOfState").lookup("Pc"))), omega_(readScalar(dict.subDict("equationOfState").lookup("omega"))) { - Zc_ = Pc_*Vc_/(specie::RR*Tc_); + Zc_ = Pc_*Vc_/(RR*Tc_); } diff --git a/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGasI.H b/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGasI.H index d5b0c4759..696195420 100644 --- a/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGasI.H +++ b/src/thermophysicalModels/specie/equationOfState/PengRobinsonGas/PengRobinsonGasI.H @@ -201,7 +201,7 @@ inline Foam::scalar Foam::PengRobinsonGas::cpMcv scalar T ) const { - return this->RR*Z(p, T); + return RR*Z(p, T); } @@ -222,7 +222,7 @@ inline void Foam::PengRobinsonGas::operator+= Tc_ = molr1*Tc_ + molr2*pg.Tc_; Vc_ = molr1*Vc_ + molr2*pg.Vc_; Zc_ = molr1*Zc_ + molr2*pg.Zc_; - Pc_ = specie::RR*Zc_*Tc_/Vc_; + Pc_ = RR*Zc_*Tc_/Vc_; omega_ = molr1*omega_ + molr2*pg.omega_; } @@ -243,7 +243,7 @@ inline void Foam::PengRobinsonGas::operator-= Tc_ = molr1*Tc_ - molr2*pg.Tc_; Vc_ = molr1*Vc_ - molr2*pg.Vc_; Zc_ = molr1*Zc_ - molr2*pg.Zc_; - Pc_ = specie::RR*Zc_*Tc_/Vc_; + Pc_ = RR*Zc_*Tc_/Vc_; omega_ = molr1*omega_ - molr2*pg.omega_; } @@ -280,7 +280,7 @@ Foam::PengRobinsonGas Foam::operator+ Tc, Vc, Zc, - specie::RR*Zc*Tc/Vc, + RR*Zc*Tc/Vc, molr1*pg1.omega_ + molr2*pg2.omega_ ); } @@ -308,7 +308,7 @@ Foam::PengRobinsonGas Foam::operator- Tc, Vc, Zc, - specie::RR*Zc*Tc/Vc, + RR*Zc*Tc/Vc, molr1*pg1.omega_ - molr2*pg2.omega_ ); } diff --git a/src/thermophysicalModels/specie/equationOfState/incompressiblePerfectGas/incompressiblePerfectGasI.H b/src/thermophysicalModels/specie/equationOfState/incompressiblePerfectGas/incompressiblePerfectGasI.H index 0444104e1..e84b5a226 100644 --- a/src/thermophysicalModels/specie/equationOfState/incompressiblePerfectGas/incompressiblePerfectGasI.H +++ b/src/thermophysicalModels/specie/equationOfState/incompressiblePerfectGas/incompressiblePerfectGasI.H @@ -143,7 +143,7 @@ inline Foam::scalar Foam::incompressiblePerfectGas::cpMcv scalar ) const { - return this->RR; + return RR; } diff --git a/src/thermophysicalModels/specie/equationOfState/perfectGas/perfectGasI.H b/src/thermophysicalModels/specie/equationOfState/perfectGas/perfectGasI.H index 7d5c6832b..a97eb1b4f 100644 --- a/src/thermophysicalModels/specie/equationOfState/perfectGas/perfectGasI.H +++ b/src/thermophysicalModels/specie/equationOfState/perfectGas/perfectGasI.H @@ -99,7 +99,7 @@ inline Foam::scalar Foam::perfectGas::Z(scalar, scalar) const template inline Foam::scalar Foam::perfectGas::cpMcv(scalar, scalar) const { - return this->RR; + return RR; } diff --git a/src/thermophysicalModels/specie/specie/specie.C b/src/thermophysicalModels/specie/specie/specie.C index a35e5850e..8a4f7612a 100644 --- a/src/thermophysicalModels/specie/specie/specie.C +++ b/src/thermophysicalModels/specie/specie/specie.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,18 +29,9 @@ License /* * * * * * * * * * * * * * * public constants * * * * * * * * * * * * * * */ -//- Universal gas constant (default in [J/(kmol K)]) -const Foam::scalar Foam::specie::RR = constant::physicoChemical::R.value()*1000; - -//- Standard pressure (default in [Pa]) -const Foam::scalar Foam::specie::Pstd = constant::standard::Pstd.value(); - -//- Standard temperature (default in [K]) -const Foam::scalar Foam::specie::Tstd = constant::standard::Tstd.value(); - namespace Foam { -defineTypeNameAndDebug(specie, 0); + defineTypeNameAndDebug(specie, 0); } diff --git a/src/thermophysicalModels/specie/specie/specie.H b/src/thermophysicalModels/specie/specie/specie.H index 354fdccee..ffe602dc4 100644 --- a/src/thermophysicalModels/specie/specie/specie.H +++ b/src/thermophysicalModels/specie/specie/specie.H @@ -40,6 +40,9 @@ SourceFiles #include "scalar.H" #include "dictionary.H" +#include "thermodynamicConstants.H" +using namespace Foam::constant::thermodynamic; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -72,20 +75,6 @@ public: ClassName("specie"); - // Public constants - - // Thermodynamic constants - - //- Universal gas constant [J/(kmol K)] - static const scalar RR; - - //- Standard pressure [Pa] - static const scalar Pstd; - - //- Standard temperature [K] - static const scalar Tstd; - - // Constructors diff --git a/src/thermophysicalModels/specie/thermo/hExponential/hExponentialThermoI.H b/src/thermophysicalModels/specie/thermo/hExponential/hExponentialThermoI.H index d0130eb51..33e3b31c8 100644 --- a/src/thermophysicalModels/specie/thermo/hExponential/hExponentialThermoI.H +++ b/src/thermophysicalModels/specie/thermo/hExponential/hExponentialThermoI.H @@ -156,7 +156,7 @@ inline Foam::scalar Foam::hExponentialThermo::ha const scalar p, const scalar T ) const { - scalar hOffset = integrateCp(specie::Tstd); + scalar hOffset = integrateCp(Tstd); return ( @@ -171,7 +171,7 @@ inline Foam::scalar Foam::hExponentialThermo::hs const scalar p, const scalar T ) const { - scalar hOffset = integrateCp(specie::Tstd); + scalar hOffset = integrateCp(Tstd); return (integrateCp(T) - hOffset); } diff --git a/src/thermophysicalModels/specie/thermo/hPolynomial/hPolynomialThermo.C b/src/thermophysicalModels/specie/thermo/hPolynomial/hPolynomialThermo.C index 4824b997d..bda645c0f 100644 --- a/src/thermophysicalModels/specie/thermo/hPolynomial/hPolynomialThermo.C +++ b/src/thermophysicalModels/specie/thermo/hPolynomial/hPolynomialThermo.C @@ -49,10 +49,10 @@ Foam::hPolynomialThermo::hPolynomialThermo sCoeffs_ = CpCoeffs_.integralMinus1(); // Offset h poly so that it is relative to the enthalpy at Tstd - hCoeffs_[0] += Hf_ - hCoeffs_.value(specie::Tstd); + hCoeffs_[0] += Hf_ - hCoeffs_.value(Tstd); // Offset s poly so that it is relative to the entropy at Tstd - sCoeffs_[0] += Sf_ - sCoeffs_.value(specie::Tstd); + sCoeffs_[0] += Sf_ - sCoeffs_.value(Tstd); } @@ -83,10 +83,10 @@ Foam::hPolynomialThermo::hPolynomialThermo sCoeffs_ = CpCoeffs_.integralMinus1(); // Offset h poly so that it is relative to the enthalpy at Tstd - hCoeffs_[0] += Hf_ - hCoeffs_.value(specie::Tstd); + hCoeffs_[0] += Hf_ - hCoeffs_.value(Tstd); // Offset s poly so that it is relative to the entropy at Tstd - sCoeffs_[0] += Sf_ - sCoeffs_.value(specie::Tstd); + sCoeffs_[0] += Sf_ - sCoeffs_.value(Tstd); } diff --git a/src/thermophysicalModels/specie/thermo/janaf/janafThermoI.H b/src/thermophysicalModels/specie/thermo/janaf/janafThermoI.H index 1b0843f78..f639ffce9 100644 --- a/src/thermophysicalModels/specie/thermo/janaf/janafThermoI.H +++ b/src/thermophysicalModels/specie/thermo/janaf/janafThermoI.H @@ -164,7 +164,7 @@ inline Foam::scalar Foam::janafThermo::cp ) const { const coeffArray& a = coeffs(T); - return this->RR*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]); + return RR*((((a[4]*T + a[3])*T + a[2])*T + a[1])*T + a[0]); } @@ -176,7 +176,7 @@ inline Foam::scalar Foam::janafThermo::ha ) const { const coeffArray& a = coeffs(T); - return this->RR* + return RR* ( ((((a[4]/5.0*T + a[3]/4.0)*T + a[2]/3.0)*T + a[1]/2.0)*T + a[0])*T + a[5] @@ -199,8 +199,7 @@ template inline Foam::scalar Foam::janafThermo::hc() const { const coeffArray& a = lowCpCoeffs_; - const scalar Tstd = specie::Tstd; - return this->RR* + return RR* ( ( (((a[4]/5.0*Tstd + a[3]/4.0)*Tstd + a[2]/3.0)*Tstd + a[1]/2.0)*Tstd @@ -219,7 +218,7 @@ inline Foam::scalar Foam::janafThermo::s { const coeffArray& a = coeffs(T); return - this->RR* + RR* ( (((a[4]/4.0*T + a[3]/3.0)*T + a[2]/2.0)*T + a[1])*T + a[0]*::log(T) + a[6] diff --git a/src/thermophysicalModels/specie/thermo/thermo/thermo.H b/src/thermophysicalModels/specie/thermo/thermo/thermo.H index f545b798f..3136307fe 100644 --- a/src/thermophysicalModels/specie/thermo/thermo/thermo.H +++ b/src/thermophysicalModels/specie/thermo/thermo/thermo.H @@ -38,6 +38,9 @@ SourceFiles #ifndef thermo_H #define thermo_H +#include "thermodynamicConstants.H" +using namespace Foam::constant::thermodynamic; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam diff --git a/src/thermophysicalModels/specie/thermo/thermo/thermoI.H b/src/thermophysicalModels/specie/thermo/thermo/thermoI.H index 1de314991..070683638 100644 --- a/src/thermophysicalModels/specie/thermo/thermo/thermoI.H +++ b/src/thermophysicalModels/specie/thermo/thermo/thermoI.H @@ -290,7 +290,7 @@ template class Type> inline Foam::scalar Foam::species::thermo::K(const scalar p, const scalar T) const { - scalar arg = -this->nMoles()*this->g(p, T)/(this->RR*T); + scalar arg = -this->nMoles()*this->g(p, T)/(RR*T); if (arg < 600.0) { @@ -321,7 +321,7 @@ Foam::species::thermo::Kc(const scalar p, const scalar T) const } else { - return Kp(p, T)*pow(this->Pstd/(this->RR*T), this->nMoles()); + return Kp(p, T)*pow(Pstd/(RR*T), this->nMoles()); } } @@ -339,7 +339,7 @@ inline Foam::scalar Foam::species::thermo::Kx } else { - return Kp(p, T)*pow(this->Pstd/p, this->nMoles()); + return Kp(p, T)*pow(Pstd/p, this->nMoles()); } } @@ -358,7 +358,7 @@ inline Foam::scalar Foam::species::thermo::Kn } else { - return Kp(p, T)*pow(n*this->Pstd/p, this->nMoles()); + return Kp(p, T)*pow(n*Pstd/p, this->nMoles()); } }