#example 1
#work done during different processes
import math
P1=200 #initial pressure inside cylinder in kPa
V2=0.1 #in m^3
V1=0.04 #initial volume of gas in m^3
W1=P1*(V2-V1) #work done in isobaric process in kJ
print"\n hence,the work done during the isobaric process is",round(W1,2),"kJ. \n"
W2=P1*V1*math.log(V2/V1) #work done in isothermal process in kJ
print"\n hence,the work done in isothermal process is",round(W2,2),"kJ. \n"
P2=P1*(V1/V2)**(1.3) #final pressure according to the given process
W3=(P2*V2-P1*V1)/(1-1.3)
print"\n hence,the work done during the described process is",round(W3,2),"kJ. \n"
W4=0 #work done in isochoric process
print"\n hence,the work done in the isochoric process is",round(W4,3),"kJ. \n"
#example 3
#work produced
Psat=190.2 #in kPa
P1=Psat #saturation pressure in state 1
vf=0.001504 #in m^3/kg
vfg=0.62184 #in m^3/kg
x1=0.25 #quality
v1=vf+x1*vfg #specific volume at state 1 in m^3/kg
v2=1.41*v1 #specific volume at state 2 in m^3/kg
P2=600 #pressure in state 2 in kPa from Table B.2.2
m=0.5 #mass of ammonia in kg
W=m*(P1+P2)*(v2-v1)/2 #woork produced by ammonia in kJ
print "The final pressure is",round(P2),"kPa\n"
print "hence,work produced by ammonia is",round(W,2),"kJ"
#example 4
#calculating work done
v1=0.35411 #specific volume at state 1 in m^3/kg
v2=v1/2
m=0.1 #mass of water in kg
P1=1000 #pressure inside cylinder in kPa
W=m*P1*(v2-v1) #in kJ
print "the work in the overall process is",round(W,1),"kJ"
#example 7
#heat transfer
k=1.4 #conductivity of glass pane in W/m-K
A=0.5 #total surface area of glass pane
dx=0.005 #thickness of glasspane in m
dT1=20-12.1 #temperature difference between room air and outer glass surface temperature in celsius
Q=-k*A*dT1/dx #conduction through glass slab in W
h=100 #convective heat transfer coefficient in W/m^2-K
dT=12.1-(-10) #temperature difference between warm room and colder ambient in celsius
Q2=h*A*dT #heat transfer in convective layer in W
#result
print "the rate of heat transfer in the glass and convective layer is",round(Q2),"kW."