Difference between revisions of "DWSIM/C3/Custom-Unit-Operation-using-Python/English"
Line 527: | Line 527: | ||
|| Let's summarize. | || Let's summarize. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 9''' |
Line 538: | Line 538: | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 10''' |
Line 581: | Line 581: | ||
Compare the results with in-built Gas-Liquid Separator available. | Compare the results with in-built Gas-Liquid Separator available. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 11''' |
'''About the Spoken Tutorial Project''' | '''About the Spoken Tutorial Project''' | ||
Line 590: | Line 590: | ||
It summarizes the Spoken Tutorial project. | It summarizes the Spoken Tutorial project. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 12''' |
+ | '''Spoken Tutorial Workshops''' | ||
|| The Spoken Tutorial Project Team | || The Spoken Tutorial Project Team | ||
Line 598: | Line 599: | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 13''' |
'''Forum Slide''' | '''Forum Slide''' | ||
Line 613: | Line 614: | ||
|| Please post your times queries in this forum. | || Please post your times queries in this forum. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 14''' |
'''DWSIM Flowsheeting Project''' | '''DWSIM Flowsheeting Project''' | ||
Line 622: | Line 623: | ||
For more details, please visit this site. | For more details, please visit this site. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 15''' |
'''TextBook Companion Project''' | '''TextBook Companion Project''' | ||
Line 631: | Line 632: | ||
For more details, please visit this site. | For more details, please visit this site. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 16''' |
'''Lab Migration Project''' | '''Lab Migration Project''' | ||
Line 640: | Line 641: | ||
For more details, please visit this site. | For more details, please visit this site. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 17''' |
'''Acknowledgements''' | '''Acknowledgements''' | ||
|| '''Spoken Tutorial''' and '''FOSSEE''' projects are funded by '''NMEICT, MHRD''', Government of India. | || '''Spoken Tutorial''' and '''FOSSEE''' projects are funded by '''NMEICT, MHRD''', Government of India. | ||
|- | |- | ||
− | || '''Slide Number | + | || '''Slide Number 18''' |
'''Thanks''' | '''Thanks''' |
Revision as of 17:00, 12 July 2019
Time | Narration |
Slide Number 1
Title Slide |
Welcome to this tutorial on simulating a Custom Unit Operation using Python. |
Slide Number 2
Learning Objective |
In this tutorial, we will learn to:
|
Slide Number 3 System Requirements |
To record this tutorial, I am using
But, this process is identical in Linux, Mac OS X or FOSSEE OS on ARM. |
Slide Number 4
Pre-requisites |
To practice this tutorial, you should know to-
|
Slide Number 5
Prerequisite Tutorials and Files |
The prerequisite tutorials are available on our website, spoken-tutorial.org.
|
Slide Number 6
Components: Methanol and Water
|
We will develop a flowsheet to determine the product stream temperature, pressure.
Molar flowrate, compositions and molar enthalpy from a mixer model created using Python. |
Slide Number 7
Temperature: 300 K Pressure: 101325 Pa Mass Flow: 20 kg/s
Temperature: 320 K Pressure: 202650 Pa Mass Flow: 10 kg/s Outlet Pressure: Average of Inlet Stream |
Here we give Inlet Stream Conditions and Pressure calculation parameter of the product stream. |
Slide Number 8
|
DWSIM-Python file used in the tutorial is provided as a code file on our site.
Download the files from Code Files link. |
I have already opened DWSIM on my machine. | |
Please ensure that DWSIM opens as an administrator.
Please note: If DWSIM is not opened with administrator privileges, the Python unit operation will not work. | |
File >> Open File
|
Go to File menu and click on Open File. |
Point to the file on the Desktop.
Select the file from the Desktop. |
I have already downloaded and extracted the file on my Desktop.
Select the file from the Desktop. This file already contains all the material streams necessary for this tutorial. |
Click on Maximize button. | Let us maximize the simulation window. |
Cursor to User Models tab | Now at the bottom of the main simulation window, go to User Models tab. |
Here we will add the Python script in the flowsheet. | |
Click and drag Python Script to the flowsheet | Drag and drop Python Script to the flowsheet area. |
Type Custom Mixer | Let us change the name of this Unit Operation to Custom Mixer. |
Cursor on the interface. | Now, we will connect material streams to inlet and outlet ports of the Custom Mixer. |
Click Custom Mixer | For this click on Custom Mixer. |
Go to Connections
Click on drop down arrow against Inlet Stream 1 Select Methanol. |
Under Connections, click on the drop-down against Inlet Stream 1.
And select Methanol. |
Click on drop down arrow against Inlet Stream 2
Select Water. |
Next, click on the drop-down against Inlet Stream 2 and select Water. |
Click on drop down arrow against Outlet Stream 1
|
Then, click on the drop-down against Outlet Stream 1 and select Mixed Product. |
Point to all the connections. | All the connections are now complete.
Now we will write the code to perform the computation. |
Point to the left of the window.
|
On the left of the window, click on Open Python Script Editor button. |
Cursor to Custom Mixer - Script Editor tab | Custom Mixer - Script Editor tab opens. |
Here we will type the Python script to perform the mixer operations. | |
First, we will import the thermodynamics package and its related functions to the script. | |
Type:
from DWSIM.Thermodynamics import * |
Type this code in the script.
|
Now we will extract the input from the feed streams. | |
Type:
feed2=ims2 |
Type this code in the script.
|
Type:
P_2 = feed2.GetProp("pressure", "Overall", None, "", "") |
Type this code in the script.
|
Cursor to GetProp command | GetProp is a function which is used to extract information from the inlet material stream. |
Point to the arguments. | GetProp function has 5 arguments.
|
Cursor to first argument "pressure" keyword | First argument is the property name.
|
Cursor to second argument "Overall" keyword | Second argument is the phase.
|
Cursor to third argument "None" keyword. | Third argument is the component ID.
|
Cursor to fourth argument. | The fourth argument is the calculation type.
|
Cursor to fifth argument | The fifth argument is the basis.
|
Type:
massflow_2 = feed2.GetProp("totalFlow" ,"Overall", None, "", "mass") |
Type this code in the script.
|
Type:
|
Type this code in the script.
|
Type:
molflow_2 = feed2.GetProp("totalFlow" ,"Overall", None, "", "mole") |
Type this code in the script.
Here, variables moleflow_1 and moleflow_2 store total mole flow rates of the streams. |
Type:
enthalpy_1 = feed1.GetProp("enthalpy" ,"Overall", None, "Mixture", "mass") enthalpy_2 = feed2.GetProp("enthalpy" ,"Overall", None, "Mixture", "mass") |
Type this code in the script.
This is to read the specific enthalpy from the inlet material streams. Variables enthalpy_1 and enthalpy_2 store the specific enthalpies of the streams. |
Cursor to fourth argument “Mixture” | Please note that the fourth argument is specified as a Mixture.
Here we are storing the specific enthalpy of the overall stream. So, calculation type is specified as Mixture. |
Type:
massflow_3 = [0] molflow_3 = [0] enthalpy_3= [0] |
Type this code in the script.
All the required properties for the outlet stream are initialized here. The variables are initialized as vectors. This makes it easy to set the values in the outlet stream using the SetProp function. |
Now we will code the calculation routine. | |
First we will calculate the overall mass flow rate of the outlet stream. | |
Type:
massflow_3[0] = massflow_1[0] + massflow_2[0] |
Type this code in the script.
Total mass flow rate of the outlet stream is calculated and stored in the variable massflow_3. |
Now we will calculate the overall mole flow rate of outlet stream. | |
Type:
molflow_3[0] = molflow_1[0] + molflow_2[0] |
Type this code in the script.
Total mole flow rate of outlet stream is calculated and stored in the variable moleflow_3. |
Next we will calculate the specific enthalpy of outlet stream. | |
Type:
totalenthalpy = (massflow_1[0] * enthalpy_1[0]) + (massflow_2[0] * enthalpy_2[0]) enthalpy_3[0] = totalenthalpy/massflow_3[0] |
Type this code in the script.
Total enthalpy of the outlet stream is calculated and stored in the variable totalenthalpy. Similarly, specific enthalpy of the outlet stream is calculated and stored in the variable enthalpy_3. |
Next we will calculate the individual component mole flow rates in the outlet stream. | |
Type:
totalmolflow_comp2= (molfrac_1[1] * molflow_1[0]) + (molfrac_2[1] * molflow_2[0]) |
Type this code in the script.
Mole flow rates of component 1 and 2 are calculated and stored in totalmolflow_comp1 and totalmolflow_comp2. |
Now we will calculate the mole fraction of components in the outlet stream. | |
Type:
|
Type this code in the script.
Component mole fractions are calculated and stored in the variable molfrac_3. |
Now we will calculate the outlet pressure. | |
Type:
|
Type this code in the script.
Outlet pressure is calculated and stored in the variable P_3. |
Point to MixedProduct. | Now we will pass the calculated output variables to the Mixed Product material stream. |
Type:
out = oms1 |
Type this code in the script.
|
Type:
out.Clear() |
Type this code in the script.
This is to clear any calculated values stored during previous runs. |
Now we will pass the calculated output variables to the Mixed Product material stream. | |
Type:
out.SetProp("enthalpy", "Overall", None, "", "mass",enthalpy_3) |
Type this code in the script.
|
Cursor to SetProp keyword | SetProp is a function used to assign values to the output stream.
It is a similar function to that of GetProp. SetProp function has six arguments. First five arguments are same as that of GetProp function. |
Cursor to “enthalpy_3” keyword | The sixth argument is the output variable.
This is to specify the vector variable that we want to assign to that particular property. We want to assign the vector enthalpy_3 to enthalpy of the Outlet Stream 1. |
Similarly we will pass the remaining calculated variables to the Outlet Stream 1. | |
Type:
out.SetProp("pressure", "Overall", None, "", "", P_3) out.SetProp("fraction", "Overall", None, "", "mole", molfrac_3) out.SetProp("totalFlow", "Overall", None, "", "mass", massflow_3) |
Type this code in the script.
This is to pass the calculated pressure, component mole fractions and total mass flowrate to the Outlet Stream 1. |
Type:
out.PropertyPackage.DW_CalcEquilibrium(PropertyPackages.FlashSpec.P, PropertyPackages.FlashSpec.H) |
Type this code in the script.
|
Cursor on out.PropertyPackage.DW_CalcEquilibrium keyword | out.PropertyPackage.DW_CalcEquilibrium is a function used to set the method of flash calculation used.
The default flash calculation method is done with the Temperature and Pressure (TP Flash). Here we do not know the outlet temperature. So, we set the flash type to Pressure and Enthalpy Flash (PH Flash). |
Cursor on PropertyPackages.FlashSpec.P, PropertyPackages.FlashSpec.H keyword | The variable at the end of the PropertyPackages.FlashSpec signifies which variable is used for flash calculation.
Here in the first argument, we pass the Pressure and in the next we pass the Enthalpy. |
With this, the Python script is completed. | |
Now we will run the simulation. | |
Click Solve Flowsheet | So, from the toolbar, click on Solve Flowsheet button. |
Point to Flowsheet tab. | Switch to Flowsheet tab. |
Click Mixed Product | When the calculations are completed, click on the Mixed Product in the flowsheet. |
Point to Property Editor Window
Hover mouse at Input Data |
Under Stream Conditions, check Temperature, Pressure and Molar Flow. |
Let's summarize. | |
Slide Number 9
|
In this tutorial, we have learnt to
|
Slide Number 10
Methanol (CH3OH) Water (H2O) Property Package: Raoult’s Law Inlet stream: Mass Flow: 1000 kg/h Temperature: 50 degree C Pressure: 1 bar
|
As an assignment,
Create a custom model for a flash column to separate the gas-liquid phase for a mixture of compounds.
Calculate the amount of liquid and vapour generated at 0.075 bar.
|
Slide Number 11
About the Spoken Tutorial Project |
Watch the video available at the following link.
It summarizes the Spoken Tutorial project. |
Slide Number 12
Spoken Tutorial Workshops |
The Spoken Tutorial Project Team
|
Slide Number 13
Forum Slide Do you have questions in this Spoken Tutorial? Please visit this site Choose the minute and second where you have the question. Explain your question briefly. Someone from the FOSSEE team will answer them. |
Please post your times queries in this forum. |
Slide Number 14
DWSIM Flowsheeting Project |
The FOSSEE team coordinates conversion of existing flow sheets into DWSIM.
We give honorarium and certificates. For more details, please visit this site. |
Slide Number 15
TextBook Companion Project |
The FOSSEE team coordinates coding of solved examples of popular books.
We give honorarium and certificates. For more details, please visit this site. |
Slide Number 16
Lab Migration Project |
The FOSSEE team helps migrate commercial simulator labs to DWSIM.
We give honorarium and certificates. For more details, please visit this site. |
Slide Number 17
Acknowledgements |
Spoken Tutorial and FOSSEE projects are funded by NMEICT, MHRD, Government of India. |
Slide Number 18
Thanks |
This tutorial is contributed by Kaushik Datta and Priyam Nayak.
Thanks for joining. |