Anda di halaman 1dari 4

###################### Coding Assignment 1 ####################################

# my code runs for all test cases:


# my code is written using Python 2.7.10
# Name: Bikash Gupta
# Entry no. 2014CH70163
import math
global T0,P0,Tc,Pc,w,T1,P1,T2,P2,R,A,B,C,D,Cphm,Cpsm,tau,Prsat71,Prsatr72,tau1,P
r1,tau2,Pr2,Tr1,Tr2,A1,B1,C1
(T0,P0)=273.15,101325.0
# input critical temp,pressure
Tc=562.2
Pc=48.98000
# input temp1,pressure1,temp2,pressure2,Gas constant
T1=4000.0
P1=30.0
T2=4500.0
P2=40.0
R=8.314
# input A,B,C,D,w"omega" virial co-efficients
A=-0.206
B=0.039064
C=-0.000013301
D=0.0
w=0.21

# input A1,B1,C1 for antoine eqn for calc. sat. pressure


A1=45.3
B1=23.3
C1=5.36
#reduced temp and pressure
tau1=T1/T0
Pr1=P1/Pc
tau2=T2/T0
Pr2=P2/Pc
Tr1=T1/Tc
Tr2=T2/Tc
tau=T2/T1
# calc. sat pressure corresponding to Tr=0.7
prsatr7=(math.exp(A1-(B1/((0.7*Tc)+C1))))/Pc
################################################################################
######################################
# All the pitzer co-relations and derivatives
def pitzer():
# mean cp for enthalphy
Cphm1=R*(A+(B/2.0)*T0*(tau1+1.0)+(C/3.0)*(T0**2.0)*((tau1**2.0)+tau1+1.0)+D/
(tau1*(T0**2.0)))
Cphm2=R*(A+(B/2.0)*T0*(tau1+1.0)+(C/3.0)*(T0**2.0)*((tau2**2.0)+tau2+1.0)+D/
(tau2*(T0**2.0)))
Cphm=R*(A+(B/2.0)*T1*(tau+1.0)+(C/3.0)*(T1**2.0)*((tau**2.0)+tau+1.0)+D/(tau
*(T1**2.0)))
# mean cp for entropy
Cpsm1=R*(A+((B*T0)+(C*(T0**2.0)+(D/((tau1*T0)**2.0)))*((tau1+1.0)/2.0))*((ta
u1-1.0)/float(math.log(tau1))))
Cpsm2=R*(A+((B*T0)+(C*(T0**2.0)+(D/((tau2*T0)**2.0)))*((tau2+1.0)/2.0))*((ta
u2-1.0)/float(math.log(tau2))))
Cpsm=R*(A+((B*T1)+(C*(T1**2.0)+(D/((tau*T0)**2.0)))*((tau+1.0)/2.0))*((tau-1
.0)/float(math.log(tau))))
# all the derivatives for temp and pressure 1
B01=0.083-0.422/(Tr1**1.6)
dB01dTr1=0.675/(Tr1**2.6)
B11=0.139-(0.172/(Tr1**4.2))
dB1dTr1=0.722/(Tr1**5.2)

# all the derivatives for temp and pressure 2


B02=0.083-0.422/(Tr2**1.6)
dB02dTr2=0.675/(Tr2**2.6)
B12=0.139-(0.172/(Tr2**4.2))
dB2dTr2=0.722/(Tr2**5.2)

# Enthalpy calculations
H1R=R*Tc*Pr1*(B01-Tr1*(dB01dTr1)+w*(B11-Tr1*(dB1dTr1))) #has to be given o
utput as -H1R
H2R=R*Tc*Pr2*(B02-Tr2*(dB02dTr2)+w*(B12-Tr2*(dB2dTr2))) #has to be given ou
tput as -H2R
# Entropy calculations
S1R=R*(-Pr1*(dB01dTr1+w*dB1dTr1)) #has to be given output as -S1R
S2R=R*(-Pr2*(dB02dTr2+w*dB2dTr2)) #has to be given output as -S2R

# delta H ideal gas


delhig=Cphm*(T2-T1)

# delta S ideal gas


delsig=Cpsm*(math.log(T2/T1))-R*math.log(P2/P1)

# delta H real gas


delH=delhig+H2R-H1R

# delta S real gas


delS=delsig+S2R-S1R
########################################################################
# output work begins:
print "-H1R : ",-H1R
print "-H2R : ",-H2R
print "-S1R : ",-S1R
print "-S2R : ",-S2R
print "Delta Hig : ",delhig
print "Delta Sig : ",delsig
print "Delta H : ",delH
print "Delta S : ",delS

############################################################################
def take():
print"gas seems to form liquid "
print"Tr1,Tr2 are : ",Tr1,Tr2
print"Pr1,Pr2 are : ",Pr1,Pr2
############################################################################
# condition 1
if Tr1>=3.0 and Tr2>=3.0:
print"condition 1 true"
pitzer()
############################################################################
# condition 2
elif Tr1<=0.7 and Tr2<=0.7:
if Prsatr7>Pr1 and Prsatr7>Pr2:
print"condition 2 true"
pitzer()
else:
print"condition 2 fails"
print "Gas became liquid at this pressure"
print"Tr1,Tr2 are : ",Tr1,Tr2
print"Pr1,Pr2 are : ",Pr1,Pr2
###########################################################################
# condition 3
elif Tr1<3.0 and Tr2<3.0:
if Tr1>0.7 and Tr2>0.7:
Prul1=(((Tr1-0.7)/(3.0-0.7))*(3.0-Prsatr7))+Prsatr7
Prul2=(((Tr2-0.7)/(3.0-0.7))*(3.0-Prsatr7))+Prsatr7
print"highest pressure for temp T1 upto which pitzer_relations are valid
is",Prul1
print"highest pressure for temp T2 upto which pitzer_relations are valid
is",Prul2
if Pr1<Prul1 and Pr2<Prul2:
print "condition 3 true"
pitzer()
else:
print"condition 3.1 fails"
print"pressure is way too high thus no pitzer co-relations applied"
else:
print"condition 3.2 fails"
take()
else:
print"condition 3.3 fails"
take()
################################################################################
#

Anda mungkin juga menyukai