You are on page 1of 27

Introduction

There are several types of the stirred reactors used in chemical or biochemical industry.
Continuous stirred tank reactors (CSTR) are commonly used because of their technological
paramours. Reaction inside flows continuously and we can control this reaction by for example
volumetric flow rate of the reactant. The first step is introducing of the mathematical model
which describes relations between state variable in the mathematical way. This mathematical
model comes from material or heat balances inside the relations is mathematical model the set of
ordinary differential equations (ODE). Simulation usually consists of steady-state analysis which
observes behavior of the system in steady state and dynamic analysis which shows dynamic
behavior after the step change of the input quantity.

Model of the Reactor

Reactor under the consideration is isothermal reactor with complex reaction. Reactions inside the
reactor can be described by following reactions which are shown in following images.
Mathematical description of all variables is of course very complicated. Therefore, there must be
introduced some simplifications before we start to build the mathematical model of the plant. We
expect, that reactant inside the tank is perfectly mixed and volume of the reactant is constant
during the reaction. The mathematical model of the system is then derived from the material
balances inside the reactor. All three reactions are assumed to follow second order kinetics.
Methodology

Step: 1
Import integrate to solve the ODE of unsteady state model of CSTR
Step: 2
Input all the given parameters like:
A0=0.4
B0=0.6
X0=0.0
Y0=0.0
Z0=0.0
k1=5.E-4
k2=5.E-2
k3=2.E-2
nint=500.
tfin=25000.
tau=5000.0
Step: 3
Make the function to solve ODES as follows
def dx_dt(x,t=0):
Step: 4
Return all the array of the ODES model as follows
return array([(A0-x[0])/tau-k1*x[0]*x[1],
(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],
(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],
(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],
(Z0-x[4])/tau+k3*x[1]*x[3]
])

Step: 5
Make the for loop for study of performance of CSTR with change in k1, k2, k3, tau etc. as
follows
for tau in range(1000,11000,1000):

Step: 6
Give the range for time as follows:
t=linspace(0.,tfin,nint)

Step: 7
Give initial values for ODES
x0=([A0,B0,X0,Y0,Z0])

Step: 8
Use the function to solve ODES and print the result for ODES and take the transpose for
solving of all ODES
x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)
print(infodict['message'])
CA,CB,CX,CY,CZ=x.T

Step: 9
Plot the graph using plot command, give title, legend and label the graph and finally run
the program
p.plot(t,CA,label="tau="+str(tau))
p.grid()
p.legend(loc="best")
p.xlabel("time(S)")
p.ylabel("concentration of CA(Kmol/m^3)")
p.title("concentration vs time for different value of tau")
p.savefig("cstrcom,png")
p.show()
Python Code
Dynamic nature of the CSTR:

# Cstrcom using python

from numpy import *

import pylab as p

from scipy import integrate

A0=0.4

B0=0.6

X0=0.0

Y0=0.0

Z0=0.0

k1=5.E-4

k2=5.E-2

k3=2.E-2

nint=500.

tfin=25000.

tau=5000.0

def dx_dt(x,t=0):

return array([(A0-x[0])/tau-k1*x[0]*x[1],

(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],

(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],
(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],

(Z0-x[4])/tau+k3*x[1]*x[3]

])

t=linspace(0.,tfin,nint)

x0=([A0,B0,X0,Y0,Z0])

x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)

print(infodict['message'])

CA,CB,CX,CY,CZ=x.T

f1=p.figure()

p.plot(t,CA,'r--',label="A")

p.plot(t,CB,'b',label='B')

p.plot(t,CX,'g',label='X')

p.plot(t,CY,'k',label="Y")

p.plot(t,CZ,'y',label="Z")

p.grid()

p.legend(loc="best")

p.xlabel("time(S)")

p.ylabel("concentration(Kmol/m^3)")

p.title("concentration vs time")

p.savefig("cstrcom,png")

p.show()
Dynamic Nature of the CSTR Concentration vs time:

Figure 1. Dynamic nature of CSTR

Performance of the reactor with change in residence time (tau):

# Cstrcom using python

from numpy import *

import pylab as p

from scipy import integrate

A0=0.4

B0=0.6

X0=0.0

Y0=0.0

Z0=0.0
k1=5.E-4

k2=5.E-2

k3=2.E-2

nint=500.

tfin=25000.

def dx_dt(x,t=0):

return array([(A0-x[0])/tau-k1*x[0]*x[1],

(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],

(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],

(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],

(Z0-x[4])/tau+k3*x[1]*x[3]

])

for tau in range(1000,11000,1000):

t=linspace(0.,tfin,nint)

x0=([A0,B0,X0,Y0,Z0])

x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)

print(infodict['message'])

CA,CB,CX,CY,CZ=x.T

p.plot(t,CA,label="tau="+str(tau))

p.grid()

p.legend(loc="best")
p.xlabel("time(S)")

p.ylabel("concentration of CA(Kmol/m^3)")

p.title("concentration vs time for different value of tau")

p.savefig("cstrcom,png")

p.show()

Figure 2. Change in concentration component with change in residence time

Change in concentration of component B with change in tau:


# Cstrcom using python

from numpy import *

import pylab as p

from scipy import integrate

A0=0.4

B0=0.6

X0=0.0

Y0=0.0

Z0=0.0

k1=5.E-4

k2=5.E-2

k3=2.E-2

nint=500.

tfin=25000.

def dx_dt(x,t=0):

return array([(A0-x[0])/tau-k1*x[0]*x[1],

(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],

(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],

(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],

(Z0-x[4])/tau+k3*x[1]*x[3]

])
for tau in range(1000,11000,1000):

t=linspace(0.,tfin,nint)

x0=([A0,B0,X0,Y0,Z0])

x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)

print(infodict['message'])

CA,CB,CX,CY,CZ=x.T

p.plot(t,CB,label="tau="+str(tau))

p.grid()

p.legend(loc="best")

p.xlabel("time(S)")

p.ylabel("concentration of CB(Kmol/m^3)")

p.title("concentration vs time for different value of teu")

p.savefig("cstrcom,png")

p.show()
Figure 3: Change in concentration of component B with respect to change in residence time
(tau)

Change in concentration of component B with change in initial concentration of component


A:

# Cstrcom using python

from numpy import *

import pylab as p

from scipy import integrate

for A0 in range(0,11,1):

B0=0.6

X0=0.0
Y0=0.0

Z0=0.0

k1=5.E-4

k2=5.E-2

k3=2.E-2

nint=500.

tfin=25000.

def dx_dt(x,t=0):

return array([(A0-x[0])/tau-k1*x[0]*x[1],

(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],

(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],

(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],

(Z0-x[4])/tau+k3*x[1]*x[3]

])

t=linspace(0.,tfin,nint)

x0=([A0,B0,X0,Y0,Z0])

x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)

print(infodict['message'])

CA,CB,CX,CY,CZ=x.T

p.plot(t,CB,label="CA0="+str(A0))

p.grid()
p.legend(loc="best")

p.xlabel("time(S)")

p.ylabel("concentration of CB(Kmol/m^3)")

p.title("concentration vs time for different values of CA0")

p.savefig("cstrcom,png")

p.show()

Figure 4. Change in concentration of component B with change in initial concentration of


component A
Change in performance of Reactor with change in initial concentration of component B:

# Cstrcom using python

from numpy import *

import pylab as p

from scipy import integrate

for B0 in range(0,11,1):

A0=0.4

X0=0.0

Y0=0.0

Z0=0.0

k1=5.E-4

k2=5.E-2

k3=2.E-2

nint=500.

tfin=25000.

def dx_dt(x,t=0):

return array([(A0-x[0])/tau-k1*x[0]*x[1],

(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],

(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],

(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],

(Z0-x[4])/tau+k3*x[1]*x[3]
])

t=linspace(0.,tfin,nint)

x0=([A0,B0,X0,Y0,Z0])

x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)

print(infodict['message'])

CA,CB,CX,CY,CZ=x.T

p.plot(t,CA,label="CB0="+str(B0))

p.grid()

p.legend(loc="best")

p.xlabel("time(S)")

p.ylabel("concentration of CA(Kmol/m^3)")

p.title("concentration vs time for different values of CB0")

p.savefig("cstrcom,png")

p.show()
Figure 5. Change in concentration of component A with change in initial concentration of
component B

Change in concentration of component B with value of K1:

# Cstrcom using python

from numpy import *


import pylab as p

from scipy import integrate

for i in range(0,11,1):

A0=0.4

B0=0.6

X0=0.0

Y0=0.0

Z0=0.0

k1=i*0.0001

k2=5.E-2

k3=2.E-2

nint=500.

tfin=25000.

def dx_dt(x,t=0):

return array([(A0-x[0])/tau-k1*x[0]*x[1],

(B0-x[1])/tau-k1*x[0]*x[1]-k2*x[1]*x[2]-
k3*x[1]*x[3],

(X0-x[2])/tau+k1*x[0]*x[1]-k2*x[1]*x[2],

(Y0-x[3])/tau+k2*x[1]*x[2]-k3*x[1]*x[3],

(Z0-x[4])/tau+k3*x[1]*x[3]

])

t=linspace(0.,tfin,nint)
x0=([A0,B0,X0,Y0,Z0])

x, infodict=integrate.odeint(dx_dt,x0,t,full_output=True)

print(infodict['message'])

CA,CB,CX,CY,CZ=x.T

p.plot(t,CB,label="k1="+str(k1))

p.grid()

p.legend(loc="best")

p.xlabel("time(S)")

p.ylabel("concentration of CB(Kmol/m^3)")

p.title("concentration vs time for different values of k1")

p.savefig("cstrcom,png")

p.show()
Figure 6. Change in concentration of component B with value of K1

F-diagram plotting for unit step change:

# Cstrcom using python

from numpy import *

import pylab as p
import matplotlib.pyplot as plt

t=p.arange(0.,30000.,1.)

plt.title('F-Diagram of the CSTR Analyticall')

plt.xlabel('time,t')

plt.ylabel('F(t)')

plt.plot(t,1-exp(-t/5000))

plt.show()

Results

Figure 7. F-diagram of CSTR for unit step change for trace

You might also like