TransFlow  0.1.0
A transient pipeline flow simulation library
GERG04 Class Reference

The GERG04 class implements the GERG 2004 equation of state. More...

#include <gerg04.hpp>

Inheritance diagram for GERG04:
EquationOfStateBase

Public Member Functions

 GERG04 (const arma::vec &composition=Composition::defaultComposition)
 GERG04 constructor. More...
 
virtual arma::vec evaluate (const double pressure, const double temperature) const override
 Evaluate the GERG 2004 equation of state at the given pressure and temperature. More...
 
arma::vec evaluateAllProperties (const double pressure, const double temperature) const
 Evaluate all available gas properties at a given pressure and temperature. More...
 
virtual double calculateCompressibility (const double pressure, const double temperature) const override
 Calculate compressibility Z at given pressure and temperature. More...
 
virtual bool setComposition (const arma::vec &composition, const bool force=true) override
 Set the composition. More...
 
double findDensity (const double pressure, const double temperature) const
 Find the density of the gas at a given pressure and temperature. More...
 
double findSpeedOfSound (const double temperature, const double density) const
 Find the soundspeed in the gas at a given temperature and density. More...
 
const arma::uvec & indicesOfNonZeroComponents () const
 Get the indices of the non-zero components in the composition. More...
 
- Public Member Functions inherited from EquationOfStateBase
virtual ~EquationOfStateBase ()
 
 EquationOfStateBase (const arma::vec &composition=Composition::defaultComposition)
 EquationOfStateBase constructor. More...
 
virtual arma::vec evaluate (const double pressure, const double temperature, const arma::vec &composition)
 Virtual function for evaluating the EOS at a new composition. More...
 
virtual double calculateStandardDensity () const
 
double getMolarMassOfMixture () const
 Get the molar mass of the gas.
 
const arma::vec & getComposition () const
 Get the current composition stored in the EOS instance.
 

Private Member Functions

double findDensity (const double pressure, const double temperature, double &density, double &aroidelta, double &arijdelta, double &aroideltadelta, double &arijdeltadelta) const
 Internal (private) function used in the process of evaluating the GERG 2004 equations. More...
 
void evaluateAlpha_roi_deltas (const double tred_temperature, const double start_rhored, const double start_rhored_pow_minusOne, const double start_rhored_pow_minusTwo, double &aroidelta, double &arijdelta, double &aroideltadelta, double &arijdeltadelta) const
 Internal (private) function used in the process of evaluating the GERG 2004 equations. More...
 
void setNonZeroComponents ()
 Internal (private) function that updates the non-zero components. More...
 
void calculateCoefficients ()
 Set the pressure and temperature independent coefficients. More...
 

Private Attributes

const arma::uword N = 10
 Number of components.
 
arma::vec X
 Composition in order CH4, N2, CO2, C2H6, C3H8, nC4H10, iC4H10, nC5H12, iC5H12, nC6H14.
 
arma::vec Tc = {190.56, 126.19, 304.13, 305.32, 369.83, 425.13, 407.82, 469.7, 460.35, 507.82}
 Critical temperature [K] for components CH4, N2, CO2, C2H6, C3H8, nC4H10, iC4H10, nC5H12, iC5H12, nC6H14.
 
arma::vec rhoc = {10.14*16.04, 11.18*28.01, 10.62*44.01, 6.87*30.07, 5*44.1, 3.92*58.12, 3.86*58.12, 3.21*72.15, 3.27*72.15, 2.71*86.18}
 Critical density [kg/m3] for components CH4, N2, CO2, C2H6, C3H8, nC4H10, iC4H10, nC5H12, iC5H12, nC6H14.
 
arma::uvec m_indices
 The indices of the non-zero gas fractions (components). More...
 
arma::uvec m_firstIndices
 The indices of the two first non-zero gas fractions (components). More...
 
arma::uvec m_lastIndices
 The indices of the two last non-zero gas fractions (components). More...
 
double rhored
 Inverse reducing function for mixture density \(1/\rho_r(\bar x)\).
 
double tred
 Reducing function for mixture temperature \(T_r(\bar x)\).
 
double Ra
 Gas constant of mixture [J/mol K].
 

Static Private Attributes

static arma::mat betav
 \(\beta_{v, ij}\) density interaction coefficient, from table A3.8
 
static arma::mat betat
 \(\beta_{T, ij}\) temperature coefficient, from table A3.8
 
static arma::mat gammav
 \(\gamma_{v, ij}\) density interaction coefficient, from table A3.8
 
static arma::mat gammat
 \(\gamma_{T, ij}\) temperature interaction coefficient, from table A3.8
 
static arma::mat noipol
 \(n_{oi, k}\), from Table A3.2 in TM15, used in the first sum of alpha^r_{oi}
 
static arma::mat doipol
 \(d_{oi, k}\), from Table A3.2 in TM15, used in the first sum of alpha^r_{oi}
 
static arma::mat toipol
 \(t_{oi, k}\), from Table A3.2 in TM15, used in the first sum of alpha^r_{oi}
 
static arma::mat noiexp
 \(n_{oi, k}\), from Table A3.3 in TM15, used in the second sum of alpha^r_{oi}
 
static arma::mat doiexp
 \(d_{oi, k}\), from Table A3.3 in TM15, used in the second sum of alpha^r_{oi}
 
static arma::mat coiexp
 \(c_{oi, k}\), from Table A3.3 in TM15, used in the second sum of alpha^r_{oi}
 
static arma::mat toiexp
 \(t_{oi, k}\), from Table A3.3 in TM15, used in the second sum of alpha^r_{oi}
 
static arma::mat Fij
 \(F_{ij}\) interaction coefficient
 
static arma::cube nijpol
 \(n_{ij, k}\), from Table A3.7 in TM15, used in the first sum of alpha^r_{ij}
 
static arma::cube dijpol
 \(d_{ij, k}\), from Table A3.7 in TM15, used in the first sum of alpha^r_{ij}
 
static arma::cube tijpol
 \(t_{ij, k}\), from Table A3.7 in TM15, used in the first sum of alpha^r_{ij}
 
static arma::cube nijexp
 \(n_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::cube dijexp
 \(d_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::cube tijexp
 \(t_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::cube nuijexp
 \(\nu_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::cube epijexp
 \(\epsilon_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::cube beijexp
 \(\beta_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::cube gaijexp
 \(\gamma_{ij, k}\), from Table A3.7 in TM15, used in the second sum of alpha^r_{ij}
 
static arma::mat noik
 \(n^o_{oi, k}\), from Table A3.1 in TM15, used in alpha^o_{oi}
 
static arma::mat voik
 \(n^o_{oi, k}\), from Table A3.1 in TM15, used in alpha^o_{oi}
 
static arma::cube nijpol_times_tijpol
 \(n_{ij, k} \times t_{ij, k}\) (GERG04::nijpol x GERG04::tijpol)
 
static arma::cube nijpol_times_tijpol_times_tijpol_minus_one
 \((n_{ij, k} \times t_{ij, k}) \times (t_{ij, k} - 1)\) ((GERG04::nijpol x GERG04::tijpol) x (GERG04::tijpol - 1.0))
 
static arma::cube nijexp_times_tijexp
 \(n_{ij, k} \times t_{ij, k}\) (GERG04::nijexp x GERG04::tijexp)
 
static arma::cube nijexp_times_tijexp_times_tijexp_minus_one
 \((n_{ij, k} \times t_{ij, k}) \times (t_{ij, k} - 1)\) ((GERG04::nijpol x GERG04::tijpol) x (GERG04::tijpol - 1.0))
 
static arma::cube nijpol_times_dijpol
 \(n_{ij, k} \times d_{ij, k}\) (GERG04::nijpol x GERG04::dijpol)
 
static arma::cube nijpol_times_dijpol_times_tijpol
 \(n_{ij, k} \times d_{ij, k} \times t_{ij, k}\) (GERG04::nijpol x GERG04::dijpol x GERG04::tijpol)
 
static arma::cube nijpol_times_dijpol_times_dijpol_minus_one
 \(n_{ij, k} \times d_{ij, k} \times(d_{ij, k} - 1) \) (GERG04::nijpol x GERG04::dijpol x (GERG04::dijpol - 1.0))
 

Additional Inherited Members

- Protected Attributes inherited from EquationOfStateBase
arma::vec m_molarMass = { 16.04, 30.07, 44.1, 58.12, 58.12, 72.15, 72.15, 86.18, 28.13, 44.01}
 The molar mass [g/mol] of the different gas components, in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.
 
arma::vec::fixed< 10 > m_composition = arma::vec(10)
 The composition of the gas as fractions, in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.
 
double m_molarMassOfMixture
 The molar mass of the gas mixture [g/mol].
 
double m_density = 0
 Cache density for optimization [kg/m3].
 

Detailed Description

The GERG04 class implements the GERG 2004 equation of state.

This is a higly accurate, but extremely complex equation of state. It has explicit forms for a lot of properties like heat capacity etc., which are utilized where possible.

Warning
Note that the composition stored internally in GERG04::X is not in the typical order, but in order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.

More info:

Constructor & Destructor Documentation

◆ GERG04()

GERG04::GERG04 ( const arma::vec &  composition = Composition::defaultComposition)
explicit

GERG04 constructor.

Initializes the coefficients that only depend on composition.

Parameters
compositionGas composition in arma::vec, in the order C1, C2, C3, iC4, nC4, iC5, nC5, C6, N2, CO2.

Member Function Documentation

◆ calculateCoefficients()

void GERG04::calculateCoefficients ( )
private

Set the pressure and temperature independent coefficients.

This calculates and sets the pressure and temperature independent factors GERG04::rhored and GERG04::tred, which are stored for efficient' computation.

◆ calculateCompressibility()

virtual double GERG04::calculateCompressibility ( const double  pressure,
const double  temperature 
) const
overridevirtual

Calculate compressibility Z at given pressure and temperature.

Parameters
pressureGas pressure [Pa].
temperatureGas temperature [K].
Returns
Compressibility factor Z [-].

Implements EquationOfStateBase.

◆ evaluate()

virtual arma::vec GERG04::evaluate ( const double  pressure,
const double  temperature 
) const
overridevirtual

Evaluate the GERG 2004 equation of state at the given pressure and temperature.

This is a wrapper around evaluateAllProperties(), which selects the wanted properties from that function. This could perhaps be optimized a bit, since some of the calculations are not required. But the brunt of the cpu time is spent in findDensity() anyway, so there probably isn't that much to save.

Parameters
pressureGas pressure [Pa]
temperatureGas temperature [K]
Returns
See EquationOfStateBase::evaluate().

Implements EquationOfStateBase.

◆ evaluateAllProperties()

arma::vec GERG04::evaluateAllProperties ( const double  pressure,
const double  temperature 
) const

Evaluate all available gas properties at a given pressure and temperature.

We have implemented 15 of the explicit equations for different properties given in the GERG 2004 documentation.

The method returns an arma::vec containing:

  • compressibility factor Z
  • partial derivative of Z wrt. temperature at constant pressure \(\frac{\partial Z}{\partial T}|_p\)
  • partial derivative of Z wrt. pressure at constant temperature \(\frac{\partial Z}{\partial p}|_T\)
  • partial derivative of Z wrt. temperature at constant density \(\frac{\partial Z}{\partial T}|_\rho\)
  • entropy S
  • internal energy U
  • heat capacity at constant volume \(c_v\)
  • enthalpy H
  • heat capacity at constant pressure \(c_p\)
  • gibbs free energy G
  • Joule-Thomson coefficient
  • speed of sound
  • isothermal throttling coefficient
  • density ρ
  • isentropic exponent \(\gamma = \frac{c_p}{c_v}\)
Warning
Other than the compressibility factor, the partial derivatives, and the heat capacity, the output of this function has not been tested properly. Feel free to implement tests for the other results.
Parameters
pressureGas pressure [Pa].
temperatureGas temperature [K].
Returns
An arma::vec containing all the properties. See the detailed description for more details.

◆ evaluateAlpha_roi_deltas()

void GERG04::evaluateAlpha_roi_deltas ( const double  tred_temperature,
const double  start_rhored,
const double  start_rhored_pow_minusOne,
const double  start_rhored_pow_minusTwo,
double &  aroidelta,
double &  arijdelta,
double &  aroideltadelta,
double &  arijdeltadelta 
) const
private

Internal (private) function used in the process of evaluating the GERG 2004 equations.

Parameters
tred_temperatureInverse reduced mixture temperature.
start_rhoredReduced mixture density.
start_rhored_pow_minusOnepow(reduced mixture density, -1)
start_rhored_pow_minusTwopow(reduced mixture density, -2)
aroideltaOutput argument – left sum in eq. (7.21b) in TM15 (also appears in other equations).
arijdeltaOutput argument – the right (double) sum in eq. (7.21b) in TM15 (also appears in other equations).
aroideltadeltaOutput argument – the left sum in eq. (7.21c) in TM15 (also appears in other equations).
arijdeltadeltaOutput argument – the right (double) sum in eq. (7.21c) in TM15 (also appears in other equations).

◆ findDensity() [1/2]

double GERG04::findDensity ( const double  pressure,
const double  temperature 
) const

Find the density of the gas at a given pressure and temperature.

Parameters
pressureGas pressure [Pa].
temperatureGas temperature [K].
Returns
Gas density [kg/m3]

◆ findDensity() [2/2]

double GERG04::findDensity ( const double  pressure,
const double  temperature,
double &  density,
double &  aroidelta,
double &  arijdelta,
double &  aroideltadelta,
double &  arijdeltadelta 
) const
private

Internal (private) function used in the process of evaluating the GERG 2004 equations.

Uses Newton-Raphson to find the density, so will be pretty cpu heavy (depending on the starting point).

Parameters
pressureGas pressure [P].
temperatureGas Temperature [K].
densityGas density [kg/m3].
aroideltaOutput argument - left sum in eq. (7.21b) in TM15 (also appears in other equations).
arijdeltaOutput argument - the right (double) sum in eq. (7.21b) in TM15 (also appears in other equations).
aroideltadeltaOutput argument - the left sum in eq. (7.21c) in TM15 (also appears in other equations).
arijdeltadeltaOutput argument - the right (double) sum in eq. (7.21c) in TM15 (also appears in other equations).
Returns
The gas density [kg/m3] as well as many other factors via the output arguments.

◆ findSpeedOfSound()

double GERG04::findSpeedOfSound ( const double  temperature,
const double  density 
) const

Find the soundspeed in the gas at a given temperature and density.

Parameters
temperatureGas temperature [K].
densityGas density [kg/m3]
Returns
Speed of sound in gas [m/s].

◆ indicesOfNonZeroComponents()

const arma::uvec& GERG04::indicesOfNonZeroComponents ( ) const
inline

Get the indices of the non-zero components in the composition.

Warning
Note that the components are stored internally in GERG04 in a different order than the input order and the usual order, so it's not straight-forward to relate this to usual composition.
Returns
The indices of the non-zero components.

◆ setComposition()

virtual bool GERG04::setComposition ( const arma::vec &  composition,
const bool  force = true 
)
overridevirtual

Set the composition.

This calls EquationOfStateBase::setComposition(), updates the non-zero component indices GERG04::m_indices, and calculates the inverse reducing function for mixture density GERG04::rhored and the reducing function for mixture temperature GERG04::tred.

Parameters
compositionNew gas composition.
forceIf the composition should be changed even if it's within machine precision of the previous composition.
Returns
True if composition was changed, else false.

Reimplemented from EquationOfStateBase.

◆ setNonZeroComponents()

void GERG04::setNonZeroComponents ( )
private

Internal (private) function that updates the non-zero components.

This function updates GERG04::m_indices, GERG04::m_firstIndices, and GERG04::m_lastIndices according to the current composition stored in GERG04::X.

Member Data Documentation

◆ m_firstIndices

arma::uvec GERG04::m_firstIndices
private

The indices of the two first non-zero gas fractions (components).

Warning
Note that the components are stored internally in GERG04 in a different order than the input order and the usual order, so it's not straight-forward to relate this to usual composition.

◆ m_indices

arma::uvec GERG04::m_indices
private

The indices of the non-zero gas fractions (components).

Warning
Note that the components are stored internally in GERG04 in a different order than the input order and the usual order, so it's not straight-forward to relate this to usual composition.

◆ m_lastIndices

arma::uvec GERG04::m_lastIndices
private

The indices of the two last non-zero gas fractions (components).

Warning
Note that the components are stored internally in GERG04 in a different order than the input order and the usual order, so it's not straight-forward to relate this to usual composition.

The documentation for this class was generated from the following file: