import math
#Variable declaration
thalf=1; #Half life of catalyst in s
F=960; #Feed rate of oil in tons/day
W=50; #Weight of the bed in tons
a=0.5; #Activity after time equal to half life
abar=0.01; #Average activity of the catalyst
#CALCULATION
Ka=-math.log(a)/thalf;#Rate constant is s**-1, assuming I order kinetics from Eqn.(12)
Fs=Ka*W*abar/(1-abar);#Circulation rate of solids from Eqn.(16)
x=(Fs*60*60*24.0)/F; #Circulation rate per feed of oil
#OUTPUT
print '\nSolid recirculation per feed of oil =%ftons of solid circulated/ton feed oil'%x
#Variable declaration
deltaHr1=1260.; #Enthalpy change during endothermic reaction in kJ/kg
deltaHr2=-33900.; #Enthal[y change during exothermic reaction in kJ/kg
H1=703.; #Enthalpy of feed oil in kJ/kg
T1=260.; #Temperature of feed oil in degree celcius
H3=1419.; #Enthalpy of cracked product in kJ/kg
T3=500.; #Temperature of cracked product in degree celcius
Ta=20.; #Temperature of entering air in degree celcius
Cpa=1.09; #Specific heat of entering air in kJ/kg K
Cpf=1.05; #Specific heat of flue gases in kJ/kg K
Cps=1.01; #Specific heat of solids in kJ/kg K
Cpv=3.01; #Specific heat of vaporized feed in kJ/kg K
T4=[520.,540.,560.,580.,600.,620.,640.,660.]; #Temperature of flue gas in degree celcius
V=22.4; #Volume of 1 mole of Carbon dioxide gas in N-m**3
M=12.; #Molecular weight of carbon in kg
rho=1.293; #Density of carbon dioxide gas in kg/N-m**3
xa=0.21; #Mass fraction of oxygen in air
betac=0.07; #Mass fraction of carbon
#CALCULATION
n=len(T4);
i=0;
x1 = [0,0,0,0,0,0,0,0]
x2 = [0,0,0,0,0,0,0,0]
excess_air = [0,0,0,0,0,0,0,0]
x2min=betac*(V*rho/(M*xa));#Minimum amount of air required for complete combustion
while i<n:
x1[i]=(deltaHr1+0.93*H3-H1)/(Cps*(T4[i]-T3));#Fs/F1 by simplifying the overall energy balance
x2[i]=((0.07*(-deltaHr2)-(deltaHr1+0.93*H3-H1))/(Cpf*(T4[i]-Ta)))-0.07;#F2/F1 by simplifying the energy balance for regenerator
if x2[i]>x2min:
excess_air[i]=(x2[i]-x2min)/x2min; #Excess air used
else:
excess_air[i]=0;
i=i+1;
#OUTPUT
print 'T4(degree celcius)',
print '\tFs/F1',
print '\t\tF2/F1',
print '\t\tExcess air(percentage)'
i=0;
while i<n:
print '%f'%T4[i],
print '\t\t%f'%x1[i],
print '\t%f'%x2[i],
print '\t%f'%(excess_air[i]*100);
i=i+1;
#Disclaimer: The values of F2/F1 obtained by manual calculation has close correspondance to the ones obtained as the output, whereas it deviates largely from the values given in textbook.
Fs=100.; #Solid flowrate in kg/s
ephsilon1=0.55;
ephsilon2=0.5;
p1=120.; #Pressure at upper level in kPa
rhos=1000.; #Density of solid in kg/m**3
rhog=1.; #Density of gas in kg/m**3
gc=1.; #Conversion factor
g=9.81; #Acceleration due to gravity in m/s**2
di=0.34; #Diameter of downcomer in m
pi=3.14;
#CALCULATION
x=(ephsilon1/ephsilon2)*((1-ephsilon2)/(1-ephsilon1));#To find pressure at lower level using Eqn.(30)
p2=x*p1;#Pressure at lower level using Eqn.(30)
deltap=p2-p1;
ephsilonbar=0.5*(ephsilon1+ephsilon2);
deltah=(deltap*10**3*gc)/(rhos*(1-ephsilonbar)*g);#Static head height from Eqn.(28)
At=0.25*pi*di**2;#Area of downcomer
Gs=Fs/At;#Flux of solids in downcomer
Gg=Gs*(ephsilon1/(1-ephsilon1))*(rhog/rhos)*(x-1);#Required gas aeration rate from Eqn.(31)
Fg=Gg*At;#Flow rate of gas required
#OUTPUT
print '\nThe required flow rate of gas required for location of %fm below downcomer is %.4fkg/s'%(deltah,Fg)
import math
#Variable declaration
Fs=600;#Solid circulation rate in kg/s
dpbar=60;#Mean size of solids in micrometer
pA=120;#Pressure in vessel A in kPa
pB=180;#Pressure in vessel B in kPa
LfA=8;#Bed height in vessel A in m
LfB=8;#Bed height in vessel B i m
#Bulk densities in kg/m**3
rho12=100;
rho34=400;
rho45=550;
rho67=200;
rho78=200;
rho910=400;
rho1011=400;
rho1112=550;
rho13=100;
deltapdA=7;#Pressure drop across the distributor in regenerator in kPa
deltapdB=8;#Pressure drop across the distributor in reactor in kPa
deltap12=(9+4);#Friction loss and pressure difference required to accelerate the solids in transfer lines in kPa
deltap78=(15+3);#Friction loss and pressure difference required to accelerate the solids in transfer lines in kPa
deltap45=20;#Friction loss across the reactor's stripper downcomer in kPa
deltap1112=4;#Friction loss across the regenerator's downcomer in kPa
deltapvA=5;#Pressure drop assigned for the control valve in regenerator in kPa
deltapvB=15;#Pressure drop assigned for the control valve in reactor in kPa
deltah12=15;#Height of the riser in m
deltah86=30;#Height of the riser in m
deltah1011=7;#Height difference h10-h11 in m
g=9.81;#Acceleration due to gravity in m/s**2
gc=1;#Conversion factor
pi=3.14;
#CALCULATION
Gs=900;#From Fig.(8), to find dt
dt=math.sqrt((4/math.pi)*Fs/Gs);#Diameter of the downcomer
#Height of downcomer A from Eqn.(7)
deltahA=(1/(rho1112*g))*((pB-pA)*gc*(10**3)+(deltap12+deltapdB+deltap1112+deltapvA)*gc*10**3-rho12*g*(-deltah12)-rho34*g*(-LfB)-rho1011*g*deltah1011);
#Height of downcomer B from Eqn.(8)
deltahB=(1/(rho45*g))*(-(pB-pA)*gc*10**3+(deltap45+deltapvB+deltap78+deltapdA)*gc*10**3+rho78*g*deltah86+rho910*g*LfA)
#OUTPUT
print 'Height of downcomer for:'
print '\tRegenerator:%d m'%deltahA
print '\tReactor:%.1f m'%deltahB