Welcome to this tutorial on simulating a Custom Unit Operation using Scilab.
In this tutorial, we will learn to: Create a custom unit operation using Scilab
Calculate the Outlet pressure of product stream
Calculate Molar flow rate and Enthalpy
To record this tutorial, I am using DWSIM 5. 6 update 8 (Classic UI) and Windows 10
But, this process is identical in Linux, Mac OS X or FOSSEE OS on ARM.
To practice this tutorial, you should know to- Add components to a flowsheet
Select thermodynamic packages
Add material streams and specify their properties
The prerequisite tutorials are available on our website.
You can access these tutorials and all the associated files from this site.
You should also have Scilab 5.02 (or higher) installed on your system.
First let us learn what is Scilab CAPE-OPEN Unit Operation.
It is an unit operation implementation for which the calculations can be entered in Scilab.
More information on this is given in the Additional reading material link of this tutorial.
We will develop a flowsheet to determine the product stream Temperature, Pressure, Molar flow rate and Molar enthalpy from a Mixer model created using Scilab.
Here we give Inlet Stream Conditions of the product stream.
To open DWSIM, go to the Desktop. Right-click on DWSIM (Classic UI) and click Run as Administrator.
Welcome to DWSIM window opens. Close this window.
Now go to the File menu and select New Steady-state Simulation.
Simulation Configuration Wizard window appears.
At the bottom, click on the Next button.
In the Compounds search tab, type Water.
Select Water from the ChemSep database.
Similarly, add Methanol.
Followed by Ethanol.
And then click on the Next button at the bottom.
The Property Packages window opens.
From Available Property Packages list, double-click on Raoult’s Law.
Then click on the Next button at the bottom.
The next option after this, is System of Units.
Under System of Units, select SI.
Click on the Finish button at the bottom.
Let us maximize the simulation window.
Let’s insert the feed streams that enter the Custom Mixer.
Go to Streams tab, at the bottom of the main simulation.
From the displayed list, drag and drop three Material Streams to the Flowsheet.
Click on the first material stream named as MSTR-000
Let’s change the name of this stream to Water.
Now we will specify the Water stream properties.
Go to Input Data.
Under Stream Conditions tab, select Flash Spec as Temperature and Pressure (TP).
By default, Temperature and Pressure should already be selected as Flash Spec.
Change Temperature to 300 Kelvin and press Enter.
Change Pressure to 100000 Pascals and press Enter.
Change Mass Flow to 10 kg per second and press Enter.
Now let us specify the Water stream compositions.
For this, click on Compound Amounts tab under Input Data.
Choose the Basis as Mole Fractions, if not already selected.
By default, Mole Fractions is already selected as Basis.
Now for Water, enter the Amount as 1 and press Enter.
For Methanol, enter 0 and press Enter.
For Ethanol, enter 0 and press Enter.
On the right, click on the Accept Changes button.
Similarly, we will define the other two material streams.
Click on the second material stream named MSTR-001.
Let’s change the name of this stream to Methanol.
Now we will specify the Methanol stream properties.
Go to Input Data.
Under Stream Conditions tab, select Flash Spec as Temperature and Pressure (TP).
Change Temperature to 305 Kelvin and press Enter.
Change Pressure' to 150000 Pa'scals and press Enter.
Change Mass Flow to 15 kg per second and press Enter.
Now click on the Compound Amounts tab under Input Data.
Choose Basis as Mole Fractions.
Now for Water, enter the Amount as 0 and press Enter.
For Methanol, enter 1 and press Enter.
For Ethanol, enter 0 and press Enter.
On the right, click on the Accept Changes button.
Now, click on the third material stream named as MSTR-002.
Let’s change the name of this stream to Ethanol.
Now we will specify the Ethanol stream properties.
Go to Input Data. Under Stream Conditions tab, select Flash Spec as Temperature and Pressure (TP)
Change Temperature to 310 Kelvin and press Enter.
Change Pressure to 200000 Pascal and press Enter.
Change Mass Flow to 20 kg per second and press Enter.
Then under Input Data click on Compound Amounts tab.
Choose the Basis as Mole Fractions.
For Water, enter the Amount as 0 and press Enter.
For Methanol, enter 0 and press Enter.
For Ethanol, enter 1 and press Enter.
On the right side, click on the Accept Changes button.
Now, let us insert another material stream that exits the custom mixer.
To do that, let us drag one material stream to the flowsheet.
Let us arrange the stream.
We will leave that stream as unspecified.
Then we will change the name of this stream to Mixed Product.
At the bottom of the main simulation window, go to CAPE-OPEN tab.
Drag and drop CAPE-OPEN Unit Operation to the flowsheet area.
Add CAPE-OPEN Unit Operation window opens.
From the displayed list, select SciLab Unit Operation. Click on OK at the bottom.
Let us change the name of this Unit Operation to Custom Mixer.
Now, we will create the inlet and outlet connection ports for the Custom Mixer.
For this, click on Custom Mixer.
From Property Editor window, click on Open CAPE-OPEN Object Editor.
Scilab CAPE-OPEN Unit Operation window opens.
Click on Ports tab.
Under Feed ports, there is an Add button at the bottom.
Click on Add button thrice to create three inlet ports for the three input material streams.
Under Product ports, click on Add button at the bottom.
This will create an outlet port for the output material stream.
Click on the Close button at the bottom.
Go to Property Editor Window.
Under Connections, go to inlet tab.
Click on the drop-down against Feed 1 and select Water.
Next, click on the drop-down against Feed 2 and select Methanol.
Next, click on the drop-down against Feed 3 and select Ethanol.
Now click on the Outlet tab.
Click on the drop-down against Product 1 and select Mixed Product.
All the connections now are completed.
Now we will write the code to perform the computation.
Click on Open CAPE-OPEN Object Editor.
Click on SciLab tab.
First we will get the feed properties of the material streams.
Then we will write the calculation routines.
Type this code in the Script tab.
This is to read the molar flow rate of the compounds from the inlet material streams.
Here, f1, f2 and f3 are the variables.
They store molar flow rate of the compounds from the inlet material streams.
getFeedProp is the command used to read the specified feed property.
1, 2 and 3 are the feed port numbers in SciLab to which the material streams in DWSIM is connected.
flow is the keyword.
flow indicates that components in the streams, has to be stored in f1,f2,f3 in form of an array.
Type this code in the Script tab.
This is to read the molar enthalpy of the inlet streams from the added inlet material stream.
Here, variables h1, h2 and h3 store the molar enthalpy of the added input material streams.
enthalpy is the keyword.
It indicate that molar enthalpy of material streams has to be stored in h1, h2 and h3.
Next, type this code.
This is to read the pressure of the inlet streams from the added inlet material stream.
Here, variables p1, p2 and p3 store the pressures of Water, Methanol and Ethanol streams.
pressure is the keyword.
It indicates that the pressure of material streams has to be stored in the variables p1, p2 and p3.
Now we will code the calculation routine
First we will calculate the outlet pressure.
For this let us consider the outlet pressure to be average pressure of all the 3 inlet streams.
Now, type this code. Outlet pressure is calculated and stored in the variable p.
Now we will calculate the molar flow rate of the compounds in the output stream.
Type this code in the Script tab.
Molar flow rate of compounds in the product stream is calculated. It is stored in the variable f in form of an array.
Now we will calculate the total molar flow rate of the product stream.
Type this code in the Script tab. Molar flow rate of product stream is calculated and stored in the variable totF.
Now we will calculate the enthalpy of the product stream.
Type this code. Enthalpy of the product stream is calculated and stored in the variable h.
Now we will pass the calculated variables to the Mixed Product material stream.
Type this code. setProduct indicates that, variables in the braces are to be passed to the stream in the product.
At the bottom, click Test.
Values stored and calculated in all the variables, are displayed in the Output tab.
Click Close button at the bottom.
Now we will run the simulation.
So, from the toolbar, click on Solve Flowsheet button.
When the calculations are completed, click on the Mixed Product in the flowsheet.
Under Stream Conditions, check Temperature, Pressure, Molar Flow.
Let's summarize.
In this tutorial, we have learnt to Create a custom unit operation using Scilab , Calculate the Outlet pressure of product stream, Calculate Molar flow rate and Enthalpy
As an assignment, Create a custom model for a heater to heat the given mixture of compounds for different Inlet stream conditions.
Watch the video available at following link. It summarizes the Spoken Tutorial project.
The Spoken Tutorial Project Team Conducts workshops and Gives certificates.
For more details, please write to us.
Please post your times queries in this forum.
The FOSSEE team coordinates conversion of existing flow sheets into DWSIM.
We give honorarium and certificates. For more details, please visit this site.
The FOSSEE team coordinates coding of solved examples of popular books.
We give honorarium and certificates. For more details, please visit this site.
The FOSSEE team helps migrate commercial simulator labs to DWSIM.
We give honorarium and certificates. For more details, please visit this site.
Spoken Tutorial and FOSSEE projects are funded by NMEICT, MHRD, Government of India.
This tutorial is contributed by Kaushik Datta and Priyam Nayak. Thanks for joining.