Introduction to Cubic Equations of State: Using the thermo Library to Work with Pure Components
Published: 2023-01-06 19:14:36

## Introduction to Cubic Equations of State
Cubic equations of state (EOS) are mathematical models that describe the relationship between the thermodynamic properties of a substance, such as pressure, volume, and temperature. They are called "cubic" because they are typically written in the form of a polynomial equation with cubic terms.

Cubic EOS are widely used in chemical engineering to predict the behavior of gases, liquids, and their mixtures under a wide range of conditions. Some examples of the types of properties that can be calculated using cubic EOS include enthalpy, entropy, pressure, volume, and density.

There are many different types of cubic EOS that have been developed over the years, each with its own set of parameters and assumptions. Some examples of popular cubic EOS include the Peng-Robinson (PR) EOS, the Redlich-Kwong (RK) EOS, and the Soave-Redlich-Kwong (SRK) EOS.

The generic three-parameter form is as follows:

 P = RT / (V - b)  - a α / [V(V + b) + b(V - b)]

Where:

P is the pressure of the substance
R is the universal gas constant
T is the temperature of the substance
V is the volume of the substance
a and b are constants that are specific to the substance and depend on its molecular structure and the intermolecular forces present.

## Introduction to Working with Pure Components:

we will learn how to use the thermo library to work with pure components using the General Cubic Equation of State (GCEOS) interface. The GCEOS interface allows us to use any implemented equation of state (EOS) model, such as the Peng-Robinson (PR) EOS, to predict the thermodynamic properties of a pure substance.

We will start by importing the necessary modules and initializing a GCEOS object for n-hexane, a commonly used test substance in chemical engineering. n-Hexane has a critical temperature of 507.6 K, critical pressure of 3.025 MPa, and an acentric factor of 0.2975.

```
from thermo import *
eos = PR(Tc=507.6, Pc=3025000.0, omega=0.2975, T=400., P=1E6)

```
**Wait a minute what are critical temperature , critical pressure and an acentric factor?**


The state_specs attribute of the GCEOS object displays the input variables used to initialize the object.


```
eos.state_specs
{'T': 400.0, 'P': 1000000.0}
```

We can also check the volume solutions for the substance at the specified state using the raw_volumes attribute. 
In this case, there are three real volume solutions, indicating that both a liquid-like and a vapor-like phase are present. 
The phase attribute will have the value of 'l/g' in this state; 
otherwise, it will be 'l' or 'g'.



```
eos.raw_volumes
(0.0001560731847856, 0.002141876816741, 0.000919295474982)
eos.phase
'l/g'
```

Basic properties calculated at initialization are directly accessible as attributes of the GCEOS object. Properties for the liquid-like phase have an '_l' suffix, while those for the vapor-like phase have an '_g' suffix. For example:


```
eos.H_dep_l
-26111.877
eos.S_dep_g
-6.4394518
eos.dP_dT_l
288501.633
```
There are many other properties that can be calculated using the GCEOS object, either as methods that require additional input arguments or as Python properties that are calculated on the fly. For example:



```
eos.fugacity_l
421597.00785
eos.beta_g
0.0101232239
```

The GCEOS object can also be used to instantiate new GCEOS objects at different conditions without re-specifying the critical constants and other parameters. This is done using the to method, which takes two of the three state variables (temperature, pressure, and volume) as input.

```
eos.to(T=300.0, P=1e5)
PR(Tc=507.6, Pc=3025000.0, omega=0.2975, T=300.0, P=100000.0)
eos.to(V=1e2, P=1e5)
PR(Tc=507.6, Pc=3025000.0, omega=0.2975, P=100000.0, V=100.0)
eos.to(V=1e2, T=300)
PR(Tc=507.6, Pc=3025000.0, omega=0.2975, T=300, V=100.0)
```

The input variables of the object are stored in the state_specs field, which can be accessed as follows:


```
eos.state_specs
```
This will return a dictionary containing the variables T, P, and V. Any two of these variables can be used to specify the state of the object. For example:

```
{'T': 400.0, 'P': 1000000.0}
```
The individual parts of the generic cubic equation are also stored within the object. These can be used to check that the pressure equation is satisfied for both the liquid and gas phases:

```
from thermo.eos import R

R*eos.T/(eos.V_l-eos.b) - eos.a_alpha/(eos.V_l**2 + eos.V_l*eos.delta + eos.epsilon)
R*eos.T/(eos.V_g-eos.b) - eos.a_alpha/(eos.V_g**2 + eos.V_g*eos.delta + eos.epsilon)
```

Note that the gas constant, R, is set to a value of 8.31446261815324 J/(mol*K). 
This value is nearly at the full precision of floating point numbers, but it is not quite exact.
It is now used as a "definition" in the SI system. It is recommended that anyone implementing their own equation of state uses the full value of the gas constant to allow for more interchangeable results.