Development and implementation of mathematical models of working mediums for gas part of combined cycle gas turbine system in Python programming environment

. The working mediums in the gas turbine systems are: atmospheric air, natural gas and exhaust gases. For the detailed analysis of thermodynamic performance and values at characteristic points of the cycle it is necessary to know the relations defining: specific volume, specific isobaric and isochoric heat capacity, isentropic exponent, specific enthalpy and specific entropy. Mathematical models of thermodynamic parameters for the mentioned mediums were developed based on dependencies for mixtures of ideal and semi-ideal gases. The functions obtained for semi-ideal gas mixtures were extended by pressure correction factors derived from the Redlich-Kwong and Peng-Robinson equations of state. The thermodynamic parameters of the working mediums were dependent on the mass fractions of the components, temperature and pressure. Developed models approximated the behaviour and parameters of real gas mixtures. All calculation algorithms were implemented and optimized using appropriate numerical methods in the Python programming environment. As a result, mathematical models of working mediums for the gas part of the combined cycle gas turbine system were obtained.


Introduction
Modelling thermal-flow systems should be started with precise identification of working mediums of the cycle. For the gas turbine system it will be: atmospheric humid air, natural gas and hot exhaust gases. The developed mathematical description should contain the functions of thermodynamic parameters necessary to determine unambiguously the state of the medium at characteristic points and to analyse the performance of the entire system.
In many engineering applications models are based on dependencies describing the performance of ideal and semi-ideal gas. The assumptions of the physical model for ideal gas are limiting the range of its applicability, particularly for conditions that significantly deviate from standard pressure and temperature. The area in which the Ideal Gas Law may be an equitable approximation is indicated in the range up to 2-3 MPa and 1200 °C [1]. More advanced and complex physical models for working mediums should be used to achieve better accuracy and more precise results. These models are usually based on the real gas equations of state [2][3][4]. Most of them originate from the van der Waals equation of state, which was the first equation that successfully took into account corrections for molecular volume and intermolecular interactions.

Steam
The values of thermodynamic parameters of steam were implemented on the basis of the publications of the International Association for the Properties of Water and Steam [11][12][13][14][15]. They include sets of equations approximating thermodynamic parameters of steam in the range: 0-800 °C for pressure up to 100 MPa and 800-2000 °C for pressure up to 50 MPa.
Steam was considered as one of the components of mixtures of humid atmospheric air and exhaust gases. The obtained thermodynamic functions concerning the properties of steam were used to create mathematical models of the discussed working mediums.

Atmospheric air
Dry atmospheric air was modelled as a mixture of nitrogen, oxygen and argon [16]. The physical model of humid atmospheric air additionally introduces the fraction of steam. The values of thermodynamic parameters for humid air were determined as for a mixture of dry air and steam with appropriate fractions, partial pressures and temperature.

Natural gas
Natural gas was considered as a mixture of methane, nitrogen, carbon dioxide and higher-order hydrocarbons [17]. The composition of natural gas in general includes a variety of other compounds. The content of individual components of a mixture depends not only on the type (high-methane, nitrated) but also on the supplier and location. The content of higher-order hydrocarbons (e.g. propane and butane) was included in the molar fraction of ethane.

Exhaust gases
Exhaust gases are a mixture of carbon dioxide, nitrogen, oxygen, argon and steam [1]. The composition of the exhaust gases depends on the reagent ratio and the combustion process. Only the complete combustion reactions of methane and ethane were considered. The fractions of particular components of the mixture were determined on the basis of mass balance and stoichiometry.

Equations of state
From a wide range of available equations of state, the Ideal Gas Law and two real gas equations of state were chosen: Redlich-Kwong and Peng-Robinson EoS. Selected equations can be implemented in undemanding way in calculation algorithms. Moreover, number of additional parameters is limited (e.g. in comparison to Beattie-Bridgeman and Benedict-Webb-Rubin EoS). Calculations based on these relationships have relatively low computing costs and better precision of results (e.g. in comparison to van der Waals and Berthelot EoS). The choice of implemented real gas equations of state is therefore a compromise between their complexity and accuracy [2][3][4].

Ideal Gas Law
The Clapeyron equation binds three parameters of statepressure , temperature and molar volume of ideal gas [1,3]: where is the universal molar gas constant. For the purposes of the calculation program, specific volume was determined by converting the given relation using molar mass :

Redlich-Kwong equation of state
The Redlich-Kwong EoS is considered to be the first significant improvement of the van der Waals equation. It introduces an empirical dependence of the cohesive pressure on the gas temperature [3,4]: where: -correction constant for molecular interactions (cohesive pressure) -correction constant for volume of molecules (co-volume).
The characteristic constants for the Redlich-Kwong equation were estimated experimentally in relation to the critical parameters of the gas [3,4]: where: , -critical temperature and critical pressure.

Peng-Robinson equation of state
The Peng-Robinson equation of state is another modification of the van der Waals equation. It introduces the dependence of the cohesive pressure on the gas temperature (similarly to the Redlich-Kwong EoS) and the acentric factor of molecules [2]: where: -correction constant for molecular interactions (cohesive pressure) -correction constant for volume of molecules (co-volume) -correction coefficient for acentric factor of molecules.
The characteristic constants for the Peng-Robinson equation were estimated experimentally in relation to the critical parameters of the gas [2]: The coefficient in the Peng-Robinson equation of state is defined as: where: ( ) = 0.37464 + 1.54226 − 0.2699 2 (10) where is the acentric factor of molecules.

Mixing and combining rules for real gas equations of state
Appropriate rules were established for the calculation of equivalent coefficients for multicomponent mixtures. For the equations of state based on the van der Waals equation it is recommended to use a combination of linear (coefficient ) and geometric (coefficients and ) approach [2, 3, 9, 10]: or: where: , -molar fractions of components , -characteristic coefficients for particular components -characteristic coefficients for particular components -binary interaction parameter for a pair of components , -coefficients for particular components.
Geometric approach was also used to calculate pseudocritical temperature of the mixture [3]: where: , -critical temperature of particular components.

Thermodynamic parameters of semiideal and real gases
The thermodynamic parameters of a real gas can be expressed as a sum of the components for a semiideal gas and a pressure correction factor [1]. Correction factors for pressure were determined with the Redlich-Kwong or Peng-Robinson equations of state. For multicomponent systems the dependencies used for semi-ideal gas mixtures were applied [18,19]. The values of derivatives and integrals were determined analytically (if possible) or by numerical methods. Detailed presentation of the relations and derivations of thermodynamic parameters of real gas can be found in the literature [1,3,4].

Specific isobaric heat capacity
The specific isobaric heat capacity of a semi-ideal gas is a function of temperature. The general form of the relationship can be approximated as [1]: where: -coefficients of the approximation polynomial.
There are many models available in the literature that approximate specific isobaric heat capacities of pure compounds [1,3,5,6,7]. They vary in accuracy and temperature range of application. Dependencies used in this paper can be found in thermodynamic tables [3,6]. As a result implemented models covered the temperature range from 50 K to 3000 K (1500 K for ethane) as it is presented in the figures below.  The specific isobaric heat capacity of a real gas can be expressed as the sum of the components for a semiideal gas ( ) and a correction factor for pressure ∆ ( , ): Eventually, the relation can be presented as [1]: = 0 (18)

Specific isochoric heat capacity
The specific isochoric heat capacity of semi-ideal gas can be found using the relation [18,19]: The specific isochoric heat capacity of the real gas is given in the form of [3]: In this case the partial derivatives were calculated analytically directly from the equations of state.

Isentropic exponent
Isentropic exponent is the ratio of specific heat capacity at constant pressure to specific heat capacity at constant volume [18,19]. For real gas its value can be calculated as:

Specific enthalpy
Specific enthalpy of semi-ideal gas can be calculated on the basis of the relation [18,19]: Taking into account the reference value of specific enthalpy ( 0 ) at a given temperature 0 [5][6][7]: The specific enthalpy of a real gas can be presented as

Specific entropy
In a similar way the specific entropy of semi-ideal gas [18,19] can be determined in relation to the reference specific entropy 0 in the reference conditions 0 , 0 [5][6][7]: Eventually, the specific entropy of a real gas can be calculated as the sum of components:

Implementation of numerical methods in the mathematical model in Python
All dependencies determining thermodynamic parameters were implemented in the object-oriented Python programming language. It is a general-purpose language that allows to create complex applications and integrate with other programming environments. Moreover, it is independent of the operating system and has a significant number of accessible libraries. Comprehensive overview of the implemented numerical methods can be found in the literature [20,21].

Analytical solution of third-degree equations
In order to solve the real gas equations of state a calculation algorithm was implemented. It examines the existence of real solutions on the basis of the value of canonical form discriminant. The created function takes coefficients of unknown variables as input data and returns value of the gas specific volume.

Numerical solution of non-linear equations
Backward functions (calculating temperature on the basis of pressure and specific enthalpy or entropy) were built upon algorithms solving non-linear equations. The methods of bisection and Fibonacci (golden-section search) were chosen.

Numerical integration
Numerical integration was performed with the use of rectangular or trapezoidal methods. Integration step for each iteration for the temperature components of specific enthalpy and entropy was set to 0.1 K. Integration step for the pressure components of specific enthalpy and entropy was dependent on temperature and pressure (narrower intervals for the low-temperature range due to the greater variability of the specific heat capacity in that area).

Numerical differentiation
Numerical estimation of the values for the first and second derivative of function at a given point was based on the expansion of the function into Taylor's series. Algorithms used central differences: four-point for the first derivative and five-point for the second derivative.

Discretisation of intervals
Additionally, the functions discretising intervals (creating lists of nodes) and determining the step of discretisation depending on the enforced precision of division were implemented.

Results
Mathematical models of all working mediums were implemented in such a way that thermodynamic parameters were a function of: mass/molar fractions of components (various humidity content of atmospheric air, composition of natural gas, air-fuel equivalence ratio in the combustion process), temperature and pressure. One of the input data to the functions was also the chosen equation of state which was used to perform calculations.
Presented results were chosen in order to illustrate the possibilities of created calculation program on substantive examples. These are demonstrative combinations of chosen thermodynamic parameters of working mediums as functions of input parameters with use of implemented equations of state. The program allows to test any combination of the above. Selected results are presented in the figures below.

Specific isobaric heat capacity of dry air as a function of temperature and pressure
The influence of pressure on the specific isobaric heat capacity of dry air is significant for the low-temperature range. Decreasing distances between molecules result in increasing role of intermolecular interactions. As the temperature rises, the differences for the respective pressure values fade. Intermolecular interactions increase due to the growth of kinetic energy of the molecules. For this reason, an additional increase in pressure does not cause a further significant increase in intermolecular interactions and specific isobaric heat capacity. Fig. 3. Specific isobaric heat capacity of dry air as a function of temperature and pressure (Redlich-Kwong EoS).

Specific isobaric heat capacity of air as a function of temperature and relative humidity
The influence of relative humidity on the specific isobaric heat capacity of atmospheric humid air increases with the temperature. The progression of function for respective levels of relative humidity is illustrated in the diagram. Steam is characterised by a much higher specific isobaric heat capacity than dry air. Increase of water vapour content in the humid air mixture directly affects the increase in specific isobaric heat capacity of the whole mixture. Fig. 4. Specific isobaric heat capacity of air as a function of temperature and relative humidity (Redlich-Kwong EoS).

6.3
Specific enthalpy of natural gas as a function of temperature and pressure The influence of pressure on the specific enthalpy of natural gas is visible in the low-temperature region. The pressure impact decreases with temperature. Specific enthalpy can be considered as the sum of internal energy of the system and work done on the environment to create space for this system [18]. From this relation it results that an increase in pressure leads to a decrease in its specific enthalpy at the constant temperature.

Specific entropy of exhaust gases as a function of temperature and air-fuel equivalence ratio
The progression of specific entropy as a function of air-fuel equivalence ratio and temperature is illustrated in the diagram. Specific entropy increases with temperature due to increasing kinetic energy of molecules that leads to growth of disorder and randomness of the system. Moreover, increasing air-fuel equivalent ratio leads to dilution of exhaust gases, decrease fractions of compounds generated in combustion process and approximate its composition and properties to the atmospheric air mixture.

Summary and conclusions
Individual computational modules were developed for each working medium. They consisted of functions and calculation algorithms, which on the basis of input data (fractions of individual components, pressure, temperature, equation of state) determined the values of thermodynamic parameters. In areas where it was impossible to determine analytical solutions, numerical methods were used. In this case it is necessary to point out the operations of integration, differentiation, interval discretization, solving non-linear equations and optimization (e.g. with use of bisection method and golden-section search). Algorithms of necessary numerical methods were implemented in a separate calculation module.
The semi-ideal gas model was extended by applying pressure correction factors based on the Redlich-Kwong and Peng-Robinson equations of state. The obtained mathematical models of working mediums allowed for more accurate calculation of thermodynamic parameters in a wide range of temperature and pressure.
The designed calculation modules can be used for thermodynamic analysis of gas turbine performance and other combined heat and power systems based on natural gas combustion. Furthermore, the way of implementing computational algorithms allows to extend the program with new pure compounds and more advanced real gas equations of the state.