This example is interactive. Click the play button on any cell to execute it, or run all cells in sequence.

Cubic Equations of State

Simulating the compressibility factor of methane across a pressure sweep using the Peng-Robinson and Soave-Redlich-Kwong equations of state wired into a PathSim simulation.

Cubic equations of state compute the compressibility factor MATHINLINE0ENDMATH by solving a cubic polynomial at each MATHINLINE1ENDMATH condition. The EoS blocks take two inputs (temperature and pressure) and produce two outputs (molar volume and compressibility factor).

At low pressure MATHINLINE2ENDMATH (ideal gas). At moderate pressure attractive forces cause MATHINLINE3ENDMATH, and at high pressure excluded-volume effects push MATHINLINE4ENDMATH.

Python
Loading...

System Definition

Create Peng-Robinson and SRK blocks for pure methane. A Constant block supplies a fixed temperature while a Source sweeps pressure from 0.1 MPa to 30 MPa.

Python
Loading...

Wiring

Both EoS blocks receive the same MATHINLINE0ENDMATH inputs. We record the compressibility factor (output port 1) from each.

Python
Loading...
18:18:16 - INFO - LOGGING (log: True)
18:18:16 - INFO - BLOCKS (total: 6, dynamic: 0, static: 6, eventful: 0)
18:18:16 - INFO - GRAPH (nodes: 6, edges: 6, alg. depth: 2, loop depth: 0, runtime: 0.065ms)
18:18:16 - INFO - STARTING -> TRANSIENT (Duration: 100.00s)
18:18:16 - INFO - --------------------   1% | 0.0s<0.2s | 533.8 it/s
18:18:16 - INFO - ####----------------  20% | 0.0s<0.0s | 4160.0 it/s
18:18:16 - INFO - ########------------  40% | 0.0s<0.0s | 3598.0 it/s
18:18:16 - INFO - ############--------  61% | 0.1s<0.0s | 2562.9 it/s
18:18:16 - INFO - ################----  80% | 0.1s<0.0s | 2646.9 it/s
18:18:16 - INFO - #################### 100% | 0.1s<--:-- | 3648.0 it/s
18:18:16 - INFO - FINISHED -> TRANSIENT (total steps: 100, successful: 100, runtime: 93.71 ms)
Python
Loading...

Both EoS give very similar results. The characteristic dip below MATHINLINE0ENDMATH at moderate pressures reflects attractive intermolecular forces, while the rise above MATHINLINE1ENDMATH at high pressures is due to repulsive (excluded volume) effects.

Mixture

The EoS blocks also support mixtures through van der Waals one-fluid mixing rules. Here we set up a methane-ethane mixture and sweep pressure.

Python
Loading...
18:18:17 - INFO - LOGGING (log: True)
18:18:17 - INFO - BLOCKS (total: 4, dynamic: 0, static: 4, eventful: 0)
18:18:17 - INFO - GRAPH (nodes: 4, edges: 3, alg. depth: 2, loop depth: 0, runtime: 0.052ms)
18:18:17 - INFO - STARTING -> TRANSIENT (Duration: 100.00s)
18:18:17 - INFO - --------------------   1% | 0.0s<0.1s | 1107.5 it/s
18:18:17 - INFO - ####----------------  20% | 0.0s<0.0s | 5857.1 it/s
18:18:17 - INFO - ########------------  40% | 0.0s<0.0s | 8624.3 it/s
18:18:17 - INFO - ############--------  61% | 0.0s<0.0s | 8906.9 it/s
18:18:17 - INFO - ################----  80% | 0.0s<0.0s | 8678.9 it/s
18:18:17 - INFO - #################### 100% | 0.0s<--:-- | 8676.4 it/s
18:18:17 - INFO - FINISHED -> TRANSIENT (total steps: 100, successful: 100, runtime: 18.48 ms)
Python
Loading...

The mixture shows a deeper dip because ethane (MATHINLINE0ENDMATH K) is near its critical temperature at 300 K, leading to stronger non-ideal behavior.