Programming series
Material Balance in
Multicomponent
Distillation
Just using Python
Swipe
Naufal Hadi 1
Overview
Material balance is an essential part in process
engineering calculation. This calculation can be
done analytically by writing down it on a paper or
using computer simulation programs such Matlab,
Aspen Hysys, Aspen Plus, and DWSIM. But in this
case I will perform the calculation only using
python, a multipurpose programming language to
solve material balance on multicomponent
distillation.
Swipe
Naufal Hadi 2
The Problem
A hydrocarbon mixture that consisting 35 % xylene, 45 % styrene, 15,5 %
benzene, 4 % toluene, and the rest are moisture content to be separate at
10.000 kg-mole/h in multicomponent distillation. The feed initially entering
dryer (D1) to removing moisture content up to 0,01 % moisture that leaving
from the dryer. Then stream are entering distillation column (D1). Styrene
considering as a main product that flowing from side stream of the column
consisting 98,5 % concentration. The top product consisting as xylene with 96
% concentration. Excess water content are removed that flowing
simultaneously with top stream using partial condenser. The detail are shown
on this picture.
Total Vapor,VTot
V2
Top stream
V1 (Light End)
CONDENSER
96 % styrene
4 % benzene
Feed, F
Side stream
F1 (Distillate)
10000 kmol/h
0,01 % 0,5 % xylene
35 % xylene 98,5 % styrene
45 % styrene moisture
1 % benzene
15,5 % benzene D1
4 % toluene ( Dryer)
(Heavy End)
0,5 % moisture
99,5 % benzene
0,5 % toluene
D2
( 1st Distillation)
D3
Bottom ( 2 nd Distillation)
(F2)
Residu
100 % toluene
Naufal Hadi 3
The Problem
Now calculate the unknown stream F1, F2, V1, V2, Vtot, LE (Light End), Dist
(Distillate), HE (Heavy End) and Res (Residu) in kg-mol/h. Also calculate the
concentration of component in F2.
Solution
Naufal Hadi 4
The Solution
This problem can be solved easily using matrix since the
system are linear equation. It’s yielding 5 equations and 5
unknown variables that giving us 0 degrees of freedom. The
concentration of each flow can we write as a matrix then
multiply it as a vector. Calculation are done using python
programming language. Let’s write the code !
The code
Naufal Hadi 5
The Code
[Link]
# This program are perform basic mass balance calculations using python
# Author : Naufal Hadi
# June 30 2020
# Import modules
import numpy as np
import [Link]
# Define the constant
F = 10000 # feed flow,kg-mole/h
F_cont = [Link]([0.35, 0.45, 0.155, 0.04, 0.005]) #concentration of the
feed, mole percent
# compute feed flow
comp_flow = F*F_cont # flow each component, kg/h
# compute mass balance on the dryer first
F1 = (1-F_cont[4])*F/(1-0.001) #stream that flow leaving dryer
V1 = F - F1 # vapor stream that leaving dryer
# new concentration leaving on dryer
xy = comp_flow[0]/F1 # new xylene concentration leaving dryer
sy = comp_flow[1]/F1 # new styrene concentration leaving dryer
be = comp_flow[2]/F1 # new benzene concentration leaving dryer
to = comp_flow[3]/F1 # new toluene concentration leaving dryer
wa = (comp_flow[4]-V1)/F1 # new water concentration leaving dryer
# construct an array that store new concentration of F1
# this is necessary since we will solve the problem from F1, not as initial
feed
new_cont = [Link]([xy, sy, be, to, wa])
# hence the flow each component in stream leaving dryer
F1_comp = F1*new_cont
# now define the concentration each unknown streams in an arrays
xylene = [Link] ([0, 0.96, 0.05, 0, 0]) #mole percent
styrene = [Link] ([0, 0.04, 0.985, 0, 0]) #mole percent
benzene = [Link] ([0, 0, 0.01, 0.995, 0])#mole percent
toluene = [Link] ([0, 0, 0, 0.005, 1])#mole percent
water = [Link] ([1, 0, 0, 0, 0])#mole percent
x = [Link]([xylene, styrene, benzene, toluene, water]) # construct an array
# compute the unknown flow of the streams
flows =[Link](x,F1_comp) # main solver that solve linear eqn
Naufal Hadi 6
The Code (cont.)
[Link]
# store and print the results each stream
V2 = flows[0]
LE = flows[1]
Dist = flows[2]
HE = flows[3]
Res = flows[4]
print('Flow water contain leaving from dyer, V1 =', V1, 'kgmole/h')
print('Flow excess water vapor from condenser, V2 =', V2, 'kgmole/h')
print('Flow distillate in top stream, LE =', LE, 'kgmole/h')
print('Flow distillate in side stream, Dist =', Dist, 'kgmole/h')
print('Flow top stream in D3, HE =', HE, 'kgmole/h')
print('Flow bottom stream in D3, Res =', Res, 'kgmole/h')
# optionally compute the intermediate streams and concentrations
F2 = HE + Res # Bottom stream of D2
V = V2 + LE # Top stream of D2 before entering condenser that consist water vapor
and Light end
Vtot = V1 + V2 # Total water vapored
print('Flow of bottom stream entering D3, F2 =', F2, 'kg/h')
print('Flow of vapor stream in top D2 before entering condenser, V =', V, 'kg/h')
print('Total water removed, Vtot =', Vtot, 'kg/h')
x_benz = (benzene[3]*HE + benzene[4]*Res)/F2 # benzene concentration in F2, mole
percent
x_tol = (toluene[3]*HE + toluene[4]*Res)/F2 # toluene concentration in F2, mole
percent
print('Benzene concentration in F2 (mole percent) =' ,x_benz)
print('Toluene concentration in F2 (mole percent) =' ,x_tol)
The script above are written using python version 3.7.3 and the
editor are Visual Studio Code (VS Code). We already write the
script and now let’s find out the result by simply typing this
command on terminal :
python [Link]
Result
Naufal Hadi 7
Result
Out
> Flow water contain leaving from dyer, V1 = 40,404040 kgmole/h
> Flow excess water vapor from condenser, V2 = 9.95995995996054 kgmole/h
> Flow distillate in top stream, LE = 3415.112335735482 kgmole/h
> Flow distillate in side stream, Dist = 4429.843153878763 kgmole/h
> Flow top stream in D3, HE = 1513.2679080012185 kgmole/h
> Flow bottom stream in D3, Res = 392.4336604599939 kgmole/h
> Flow of bottom stream entering D3, F2 = 1905.7015684612124 kgmole/h
> Flow of vapor stream in top D2 before entering condenser, V =
3425.0722956954423 kgmole/h
> Total water removed, Vtot = 50.0 kgmole/h
> Benzene concentration in F2 (mole percent) = 0.7901035468407648
> Toluene concentration in F2 (mole percent) = 0.20989645315923525
then we obtain :
V1 = 40,4040 kgmole/h
V2 = 9,9595 kgmole/h
LE =3415.112335735482 kgmole/h
Dist = 4429.843153878763 kgmole/h
HE = 1513.2679080012185 kgmole/h
Res = 392.4336604599939 kgmole/h
F2 = 1905.7015684612124 kgmole/h
V = 3425.0722956954423 kgmole/h
Vtot = 50.0 kgmole/h
Benzene concentration in F2 (mole percent) = 0.79
Toluene concentration in F2 (mole percent) = 0.21
Naufal Hadi 8
Thank You
Let me know your thought on
comment !
Tools :
Script : Python 3.7.3
Editor : Visual Studio Code
Layouting : Libreoffice Draw
End
Naufal Hadi 9