#ques1
# pressure required to make diamonds from graphite
import math
T=25 # temp in degree C
ggrp= 0 # g for fraphite
gdiamnd=2867.8 # g for diamond in kJ/mol
vgrp=0.000444 # specific volume of graphite in m^3/kg
vdiamnd=0.000284 # specific volume of graphite in m^3/kg
BetaTgrp=0.304e-6 # beta for graphite in 1/MPa
BetaTdiamnd=0.016e-6 # beta for diamond in 1/MPa
P=-(-2*(vgrp-vdiamnd)+math.sqrt((2*vgrp-2*vdiamnd)**2-4*(vgrp*BetaTgrp-vdiamnd*BetaTdiamnd)*(2*gdiamnd/(12.011*1000))))/(2*(vgrp*BetaTgrp-vdiamnd*BetaTdiamnd))
print int(P)," MPa is the pressure at which possibility exists for conversion from graphite to diamonds"
#ques2
#to determine change in gibbs free energy
#1-H2
#2-O2
#3-H2O
#at T=298 K
T1=298.0;#K
Hf1=0;#Enthalpy of formation of H2 at 298 K
Hf2=0;#Enthalpy of formation of O2 at 298 K
Hf3=-241826;#enthalpy of formation of H2O at 298 K in kJ
dH=2*Hf1+Hf2-2*Hf3;#Change in enthalpy in kJ
Sf1=130.678;#Entropy of H2 at 298 K n kJ/K
Sf2=205.148;#Entropy of O2 at 298 K in kJ/K
Sf3=188.834;#entropy of H2O at 298 K in kJ/K
dS=2*Sf1+Sf2-2*Sf3;#Change in entropy in kJ/K
dG1=dH-T1*dS;#change n gibbs free energy in kJ
print" Change in gibbs free energy at",T1,"kelvin is",round(dG1),"kJ "
#at T=2000 K
T2=2000.0;#K
Hf1=52942-0;#Enthalpy of formation of H2 at 2000 K
Hf2=59176-0;#Enthalpy of formation of O2 at 2000 K
Hf3=-241826+72788;#enthalpy of formation of H2O at 2000 K in kJ
dH=2*Hf1+Hf2-2*Hf3;#Change in enthalpy in kJ
Sf1=188.419;#Entropy of H2 at 2000 K n kJ/K
Sf2=268.748;#Entropy of O2 at 2000 K in kJ/K
Sf3=264.769;#entropy of H2O at 2000 K in kJ/K
dS=2*Sf1+Sf2-2*Sf3;#Change in entropy in kJ/K
dG2=dH-(T2*dS);#change n gibbs free energy in kJ
print" Change in gibbs free energy at",T2,"kelvin is",round(dG2)," kJ "
#ques3
#calculating equilibrium constant
dG1=-457.166;#change in gibbs free energy at temp 298 K from example2 in kJ
dG2=-271.040;#change in gibbs free energy at temp 2000 K from example2 n kJ
T1=298;#K
T2=2000;#K
R=8.3145;#gas constant
K1=dG1*1000/(R*T1);
K2=dG2*1000/(R*T2);
print" Equilibrium constant at ",T1,"K = ",round(K1,2)
print" Equilibrium constant at ",T2,"K = ",round(K2,3)
# The example is about proving that Equlibrium constant can be found using table hence doesn't require solution in python
# ques 5
# To determine Heat Transfer
# The process is two step as:
# Combustion: C + O2--->CO2
# Dissociation reaction: 2CO2---->2CO + O2
# overall process : C + O2 → 0.5622 CO2 + 0.4378 CO + 0.2189 O2
nCO2=0.5622 # moles of CO2
nCO=0.4378 # moles of CO
nO2=0.2189 # moles of NO2
# from Table A.9:
hfCO2=0 # enthalpy of formation
hfC=0 # enthalpy of formation
hfCO=0 # enthalpy of formation
hfO2=0 # enthalpy of formation
hfCO23000=-393522 # enthalpy @ 3000K
hfCO3000=-110527 # enthalpy @ 3000K
hfO23000=0 # enthalpy @ 3000K
hfCO2298=-152853 # enthalpy @ 298K
hfCO298=-93504 # enthalpy @ 298K
hfO2298=-98013 # enthalpy @ 298K
Hr=hfC+hfO2 # enthalpy of reactants
Hp=nCO2*(hfCO2+hfCO23000-hfCO2298)+nCO*(hfCO+hfCO3000-hfCO298)+nO2*(hfO2+hfO23000-hfO2298)
Qcv=Hp-Hr # using first law
print round(Qcv),"kJ/kmol C is the heat transfer "
# ques 6
# to determine the composition
# the standard equation is C + 2O2 → CO2 + O2
# from equilibrium C + 2O2 → (1 − 2z)CO2 + 2zCO + (1 + z)O2
T=3000 # temp in K
P=0.1 # prssure in MPa
z = 0.1553 # from equilibrium equation using table
yCO2=(1-2*z)/(2+z) # mole fraction of CO2
yCO = 2*z/(2+z) # mole fraction of CO
yO2=(1+z)/(2+z) # mole fraction of O2
print "The mole fraction is ",round(yCO2,3)," for CO2 \n"
print "The mole fraction is ",round(yCO,3)," for CO \n"
print "The mole fraction is ",round(yO2,3)," for O2 \n"
# ques 7
# to determine the equilibrium composition
# The reaction equation is:
# (1): 2.H2O -->2H2 + O2
# (2): 2 H2O -->H2 + 2OH
# the equilibrium equation is
# H2O → (1 − 2a − 2b)H2O + (2a + b)H2 + aO2 + 2bOH
P= 0.1 # pressure in MPa
T=3000 # temp in Kelvin
a=0.0534 # using value of K from Table A.11 @ 3000k
b=0.0551 # using value of K from Table A.11 @ 3000k
nH2O= (1-2*a-b) # moles of H2O
nH2=2*a+b# moles of H2
nO2=a# moles of O2
nOH= 2*b# moles of OH
X=nH2O+nH2+nO2+nOH
yH2O=nH2O/X # mole fraction
yH2=nH2/X # mole fraction
yO2=nO2/X # mole fraction
yOH=nOH/X # mole fraction
print "The mole fraction of H2O is",round(yH2O,2),"\n"
print "The mole fraction of H2 is",round(yH2,2),"\n"
print "The mole fraction of O2 is",round(yO2,2),"\n"
print "The mole fraction of OH is",round(yOH,2),"\n"
# the answers are slightly different due to approximation in textbook while here the answers are precise
# ques 8
# determine the the equilibrium composition
P= 1 # pressure in Kpa
T=10000 # temp in Kelvin
z=0.2008 # using k from table
# the chemical equation is Ar -->Ar^(+) + e−
yAr=(1-z)/(1 + z) # mole fraction of Ar
yArpositive= z/(1+z) # mole fraction of Ar(+)
yenegative=z/(1+z) # mole fraction of ye-
print "The mole fraction of Ar is",round(yAr,3),"\n"
print "The mole fraction of Ar+ is",round(yArpositive,3),"\n"
print "The mole fraction of e- is",round(yenegative,3),"\n"