DWSIM/C3/Custom-Unit-Operation-using-Python/English-timed

From Script | Spoken-Tutorial
Jump to: navigation, search
Time Narration
00:01 Welcome to this tutorial on simulating a Custom Unit Operation using Python.
00:07 In this tutorial, we will learn to:
00:10 Create a custom unit operation using Python
00:14 Calculate Overall mass and mole flow rate
00:18 Calculate Enthalpy and outlet pressure
00:22 To record this tutorial, I am using

DWSIM 5. 6 update 8 (Classic UI) and Windows 10

00:32 But, this process is identical in Linux, Mac OS X or FOSSEE OS on ARM.
00:40 To practice this tutorial, you should know to-

Add components to a flowsheet

00:46 Select thermodynamic packages
00:49 Add material streams and specify their properties
00:54 The prerequisite tutorials are available on our website.
00:58 You can access these tutorials and all the associated files from this site.
01:04 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.
01:16 Here we give Inlet Stream Conditions and Pressure calculation parameter of the product stream.
01:22 DWSIM-Python file used in the tutorial is provided as a code file on our site.

Download the files from Code Files link.

01:33 I have already opened DWSIM on my machine.
01:37 Please ensure that DWSIM opens as an administrator.
01:42 Please note:

If DWSIM is not opened with administrator privileges, the Python unit operation will not work.

01:50 Go to File menu and click on Open File.
01:56 I have already downloaded and extracted the file on my Desktop.
02:01 Select the file from the Desktop.
02:04 This file already contains all the material streams necessary for this tutorial.
02:10 Let us maximize the simulation window.
02:13 Now at the bottom of the main simulation window, go to User Models tab.
02:19 Here we will add the Python script in the flowsheet.
02:23 Drag and drop Python Script to the flowsheet area.
02:27 Let us change the name of this Unit Operation to Custom Mixer.
02:32 Now, we will connect material streams to inlet and outlet ports of the Custom Mixer.
02:39 For this click on Custom Mixer.
02:42 Under Connections, click on the drop-down against Inlet Stream 1.

And select Methanol.

02:51 Next, click on the drop-down against Inlet Stream 2 and select Water.
02:58 Then, click on the drop-down against Outlet Stream 1 and select Mixed Product.
03:06 All the connections are now complete.

Now we will write the code to perform the computation.

03:12 On the left of the window, click on Open Python Script Editor button.
03:18 Custom Mixer - Script Editor tab opens.
03:22 Here we will type the Python script to perform the mixer operations.
03:27 First, we will import the thermodynamics package and its related functions to the script.
03:34 Type this code in the script.

This is to import the Thermodynamics Packages and related functions to Python.

03:43 Now we will extract the input from the feed streams.
03:48 Type this code in the script.

ims1 and ims2 are the reference to material streams that are connected in Inlet Stream 1 and Inlet Stream 2.

04:00 They get recorded as feed1 and feed2.
04:05 Type this code in the script.
04:08 This is to read the pressure from inlet material streams.
04:12 Here, the variables P underscore 1 and P underscore 2 store the pressures of Methanol and Water streams.
04:21 GetProp is a function which is used to extract information from the inlet material stream.
04:28 GetProp function has 5 arguments.
04:32 These arguments have to be specified according to the information that needs to be extracted.
04:39 First argument is the property name.
04:42 This is to specify the property which has to be stored in the variable.

Here pressure is specified.

04:50 Second argument is the phase.
04:53 This is to indicate the phase for which the property specified in the first argument has to be stored.
05:00 Here Overall is specified.
05:03 Third argument is the component ID.
05:07 Since we are storing the pressure of overall stream and not individual components, None is specified.
05:15 The fourth argument is the calculation type.
05:19 Here we have to enter Pure or Mixture.

Since the property calculation type doesn’t apply to pressure, we will leave blank here.

05:30 The fifth argument is the basis.
05:34 Mole or mass has to be entered here to specify the property basis.
05:40 Since the property basis doesn’t apply to pressure, we will leave it blank here.
05:46 Type this code in the script.

This is to read the overall mass flow rates from the inlet material streams.

05:54 variables massflow underscore 1 and massflow underscore 2 store total mass flow rates of Methanol and Water streams.
06:04 Type this code in the script.

This code will read the mole fractions of the components from the inlet material streams.

06:13 Here, we see the variables molefrac_1 and molefrac_2.
06:20 They store mole fractions of the components from the streams in form of 1 Dimensional array.
06:27 Type this code in the script.
06:30 Here, variables moleflow underscore 1 and moleflow underscore 2 store total mole flow rates of the streams.
06:39 Type this code in the script.
06:42 This is to read the specific enthalpy from the inlet material streams.
06:47 Variables enthalpy underscore 1 and enthalpy underscore 2 store the specific enthalpies of the streams.
06:55 Please note that the fourth argument is specified as a Mixture.
07:00 Here we are storing the specific enthalpy of the overall stream.
07:05 So, calculation type is specified as Mixture.
07:10 Type this code in the script.
07:13 All the required properties for the outlet stream are initialized here.
07:18 The variables are initialized as vectors.
07:22 This makes it easy to set the values in the outlet stream using the SetProp function.
07:29 Now we will code the calculation routine.
07:33 First we will calculate the overall mass flow rate of the outlet stream.
07:38 Type this code in the script.

Total mass flow rate of the outlet stream is calculated and stored in the variable massflow underscore 3.

07:49 Now we will calculate the overall mole flow rate of outlet stream.
07:55 Type this code in the script.
07:58 Total mole flow rate of outlet stream is calculated and stored in the variable moleflow underscore 3.
08:06 Next we will calculate the specific enthalpy of outlet stream.
08:11 Type this code in the script.
08:14 Total enthalpy of the outlet stream is calculated and stored in the variable totalenthalpy.
08:21 Similarly, specific enthalpy of the outlet stream is calculated and stored in the variable enthalpy underscore 3.
08:30 Next we will calculate the individual component mole flow rates in the outlet stream.
08:36 Type this code in the script.
08:39 Mole flow rates of component 1 and component 2 are calculated and stored in totalmolflow underscore comp1 and totalmolflow underscore comp2.
08:50 Now we will calculate the mole fraction of components in the outlet stream.
08:56 Type this code in the script.
08:59 Component mole fractions are calculated and stored in the variable molfrac underscore 3.
09:06 Now we will calculate the outlet pressure.
09:10 Type this code in the script.

Outlet pressure is calculated and stored in the variable P underscore 3.

09:19 Now we will pass the calculated output variables to the Mixed Product material stream.
09:26 Type this code in the script.

oms1 is the reference to the material stream connected to the Outlet Stream 1.

09:35 Type this code in the script.

This is to clear any calculated values stored during previous runs.

09:44 Now we will pass the calculated output variables to the Mixed Product material stream.
09:51 Type this code in the script.

This is to pass the calculated specific enthalpy to the Outlet Stream 1.

10:00 SetProp is a function used to assign values to the output stream.
10:06 It is a similar function to that of GetProp.

SetProp function has six arguments.

10:14 First five arguments are same as that of GetProp function.
10:19 The sixth argument is the output variable.
10:23 This is to specify the vector variable that we want to assign to that particular property.
10:29 We want to assign the vector enthalpy underscore 3 to enthalpy of the Outlet Stream 1.
10:37 Similarly we will pass the remaining calculated variables to the Outlet Stream 1.
10:42 Type this code in the script.
10:45 This is to pass the calculated pressure, component mole fractions and total mass flowrate to the Outlet Stream 1.
10:53 Type this code in the script.

This is to set the flash calculation method for the Outlet Stream 1.

11:01 out.PropertyPackage.DW_CalcEquilibrium is a function used to set the method of flash calculation used.
11:11 The default flash calculation method is done with the Temperature and Pressure (TP Flash).
11:17 Here we do not know the outlet temperature.

So, we set the flash type to Pressure and Enthalpy Flash (PH Flash).

11:26 The variable at the end of the PropertyPackages.FlashSpec signifies which variable is used for flash calculation.
11:35 Here in the first argument, we pass the Pressure and in the next we pass the Enthalpy.
11:43 With this, the Python script is completed.

Now we will run the simulation.

11:49 So, from the toolbar, click on Solve Flowsheet button.
11:53 Switch to Flowsheet tab.
11:56 When the calculations are completed, click on the Mixed Product in the flowsheet.
12:01 Under Stream Conditions, check Temperature, Pressure and Molar Flow.
12:10 Let's summarize.
12:12 In this tutorial, we have learnt to
12:15 Create a custom unit operation using Python
12:18 Calculate Overall mass and mole flow rate
12:22 Calculate Enthalpy and outlet pressure
12:26 As an assignment,

Create a custom model for a flash column to separate the gas-liquid phase for a mixture of compounds.

12:34 Calculate the amount of liquid and vapour generated at 0.075 bar.
12:40 Compare the results with in-built Gas-Liquid Separator available.
12:45 Watch the video available at the following link.

It summarizes the Spoken Tutorial project.

12:52 The Spoken Tutorial Project Team

Conducts workshops and Gives certificates.

12:58 For more details, please write to us.
13:01 Please post your times queries in this forum.
13:05 The FOSSEE team coordinates conversion of existing flow sheets into DWSIM.
13:11 We give honorarium and certificates.

For more details, please visit this site.

13:18 The FOSSEE team coordinates coding of solved examples of popular books.
13:24 We give honorarium and certificates.

For more details, please visit this site.

13:31 The FOSSEE team helps migrate commercial simulator labs to DWSIM.
13:38 We give honorarium and certificates.

For more details, please visit this site.

13:45 Spoken Tutorial and FOSSEE projects are funded by NMEICT, MHRD, Government of India.
13:53 This tutorial is contributed by Kaushik Datta and Priyam Nayak.

Thanks for joining.

Contributors and Content Editors

PoojaMoolya