Phase Equilibrium Calculator (PEC) is an simple web-based tool designed for determining phase equilibrium of multi-component mixtures. PEC boasts a user-friendly Graphical User Interface (GUI) that simplifies the process for users, while also providing an Application Programming Interface (API) ideal for developers and researchers.
Since this project is open source, I would be more than grateful for any contribution to further improve the existing framework for more complex calculation and a wider application range.
Table of Content
- What is PEC?
- How to use PEC
- Modules
- What is VLE calculations?
- Outputs & Results
- Install PEC on your computer
PEC can manage simple VLE calculation of multicomponent mixtures that are consistent with the models used in this project, which are the PR and SRK Equations of state (EOS) and have their own limitations. In addition to VLE calculations, PEC can be helpful in creating P-x-y and P-T diagrams (also known as phase diagrams or phase envelopes).
There are 3 main ways to use PEC:
- Customize and run codes directly using the modules.
- Using the GUI designed for the website.
- Using "GET" requests via the designed API.
Each module is responsible for a narrow range of tasks, but the results are created by chaining the modules in such a way that the outputs of one module would be fed to the next module as its input.
Here is the summary of all the modules in the program:
properties:
Contains the essential data required for the calculations. Although only 3 parameter (
parameters: Calculating the desired EOS parameters and preparing all the necessary data for next modules.
phiCalc:
Two of the main parameters in the whole phase calculation, which are the Compressibility factor
bublP & dewP: Evaluation of Bubble Pressure and Dew Pressure is used for P-x-y and P-T graphs and also for initializing the VLE calculation. Thus, this is one of the most important tools in the whole framework.
vle:
VLE calculations, which is the objective of this project, would be completed in this section and the results would be filtered and reported.
The output consists of
binaryPxy: Pressure-Composition graph can be obtained for binary mixtures using this modules. It uses the results of bubP and dewP moduls to plot the desired phase diagram.
phaseEnvelope: Phase Envelopes or P-T diagrams can be plotted using this module by determining the composition and the desired temperature range.
Equilibrium is a condition in which no changes occur in the macroscopic properties of an isolated system with time. At equilibrium, all potentials that may cause change are exactly balanced, so no driving force exists for any change in the system.
Vapor Liquid Equilibrium (VLE) is a subset of phase equilibrium which solely focus on vapor and liquid phase. This subject has a significant rule in chemical engineering as it is widely used for both research and in industry.
By completing VLE calculations successfully, one can obtain vapor/liquid ratio, vapor phase and liquid phase mole fractions, bubble pressure, dew pressure, fugacity coefficients, Z factors, etc.
There are several models and equations for VLE calculations introduced by different sources. The major differences between these models are their precision and complexity. The model of choice in this project however, is the Phi-Phi Model (
By using the definition of fugacity one can obtain the equations below:
Thus by evaluating
There are several algorithms to pull off the calculations, but it is strongly recommended to read PennState University's documentation about the VLE calculations using EOS models. This and other useful resources are listed below:
- Solutions Algorithms for VLE Problems
- Cubic EOS Fugacity Expression
- PT Flash calculation using PR EOS
- Lee-Kesler method for initial guesses
For a deeper understanding of the concept of VLE and phase equilibrium in general, these sources are heavily recommended:
-
Smith, J. M, Van Ness, H. C, Abbott, Michael M., Swihart, Mark T.; Introduction To Chemical Engineering Thermodynamics, 8th Edition, McGraw-Hill Education, 2017.
-
Bruce E. Poling, John M. Prausnitz, John P. O’Connell; The Properties of Gases And Liquids, 5th Edition, McGraw-Hill Education, 2004.
-
Stanley M. Walas; Phase Equilibrium in Chemical Engineering, Butterworth-Heinemann, 2013.
A few samples of the results and possible outputs of the framework is as follows:
VLE Calculations:
P-x-y Diagrams:
P-T diagrams:
If you are a developer and want to customize or work on the existing project yourself, you can install PEC locally and use it on your computer:
- Creat a virtual environment. For example, in Windows OS, open the cmd in a folder and type the command
python -m venv {any_name_you_like}
. - Activate the venv by
{any_name_you_like}\Scripts\activate
. - Install the requirements by using the
requirements.txt
file in the repository usingpip install -r requirements.txt
.
Now that your virtual environment is ready, you can use the modules directly in your code by cloning the repository to the folder you created the venv, or pasting the project folder manually. Another way is to create a Django Project and replace the files with the vle.W1 folder in the repository. To do so, after you created the virtual environment, follow the steps below:
cd
to the same directory as you made your VE and usedjango-admin startproject vleW1
to start a project.- Use
python manage.py startapp vle
andpython manage.py startapp api
to create the apps needed for the project. - Replace the entire web-framework folder with the folder in the repository.
After you have install the requirements, you can create python files and play with the modules on your own. Here is a simple example:
from phaseEnvelope import plotter
import matplotlib.pyplot as plt
z = [0.6, 0.4]
components = ["methanol", "benzene"]
eos_model = "PR"
T_start = 400
T_finish = 600
T_step = 5
gap_ratio_treshhold = 5
fig = plotter(components, z, eos_model, T_start, T_finish, T_step, gap_ratio_treshhold)
plt.show()