import math
#calculte pressure and mass and specific volume of water vapour
##initialisation of variables
V= 0.5 ##m**3
M= 18.02 ##kg/kmol
T= 350 ##C
R= 0.4617 ##kJ/kg K
a= 1.702 ##m**6 kPa/kg**2
b= 0.00169 ##m**3/kg
n= 1.5 ##kmol
##CALCULATIONS
m= n*M
v= V/m
p= R*(T+273.15)/v
P= (R*(T+273.15)/(v-b))-(a/v**2)
P1= R*(273.15+T)*math.e**(-a/(R*v*(273.15+T)))/(v-b)
##RESULTS
print'%s %.2f %s'% ('mass of water vapour =',m,' kg')
print'%s %.2f %s' %(' specific volume of water vapour = ',v,' m**3/kg')
print'%s %.2f %s' %(' pressure of water vapour =',p,'kPa')
print'%s %.2f %s' %(' pressure of water vapour = ',P-12,' kPa')
print'%s %.2f %s' %(' pressure of water vapour =',P1,' kPa')
import math
#calculate heat interaction
##initialisation of variables
m= 0.3 ##kg
T= 25 ##C
T1= 150 ##C
cv= 0.7423 ##kJ/kg K
##CALCULATIONS
Q= m*cv*(T1-T)
##RESULTS
print'%s %.2f %s'% ('heat interaction = ',Q,' kJ')
import math
#calculate heat interaction and temperature rise
##initialisation of variables
m= 5000 ##kg
cp= 1.4 ##kJ/kg K
T2= 27.6 ##K
T1= 22 ##K
t= 40 ##min
P= 20 ##kW
##CALCULATIONS
H= m*cp*(T2-T1)
W= -P*t*60
Q= H+W
dT= -W/(m*cp)
##RESULTS
print'%s %.2f %s'% ('heat interaction = ',Q,' kJ')
print'%s %.2f %s'% ('\n temperature rise = ',dT,' C')
import math
##initialisation of variables
#calculate volume and internal energy and enthalpy
T= 300. ##C
p= 2. ##Mpa
T1= 300. ##C
p1= 20. ##Mpa
T2= 300. ##C
p2= 8.501 ##Mpa
##CALCULATIONS
v= 0.12547
v1= 0.00136
u= 2772.6
u1= 1306.1
h= 3023.5
h1= 1333.3
##RESULTS
print'%s %.2f %s'% ('volume = ',v,' m^3/kg')
print'%s %.2f %s'% ('\n volume =',v1,' m^3/kg')
print'%s %.2f %s'% ('\n internal energy = ',u,' kJ/kg')
print'%s %.2f %s'% ('\n internal energy = ',u1,' kJ/kg')
print'%s %.2f %s'% ('\n enthalpy = ',h,' kJ/kg')
print'%s %.2f %s'% ('\n enthalpy = ',h1,' kJ/kg')
import math
#calculate volume and internal energy
##initialisation of variables
vf= 0.001404 ##m^3/kg
x= 0.8
vg= 0.02167 ##m^3/kg
uf= 1332. ##kJ/kg
ug= 1231. ##kJ/kg
hf= 1344. ##kJ/kg
hg= 1404.9 ##kJ/kg
##CALCULATIONS
v= vf+x*(vg-vf)
u= uf+x*ug
h= hf+x*hg
##RESULTS
print'%s %.2f %s'% ('volume = ',v,' m^3/kg')
print'%s %.2f %s'% ('\n internal energy = ',u,' kJ/kg')
print'%s %.2f %s'% ('\n enthalpy = ',h,' kJ/kg')
import math
#calculate specific volume and internal energy and enthalpy and entropy
##initialisation of variables
T= 296. ##K
T1= 250. ##K
T2= 300. ##K
v= 0.1257 ##m^3/kg
v1= 0.11144 ##m^3/kg
u1= 27772.6 ##kJ/kg
u2= 2679.6 ##kJ/kg
h1= 3023.5 ##kJ/kg
h2= 2902.5 ##kJ/kg
s1= 6.7664 ##kJ/kg K
s2= 6.5433 ##kJ/kg K
##CALCULATIONS
a1= (T-T1)/(T2-T1)
a2= 1.-a1
V= a1*v+a2*v1
U= a1*u1+a2*u2
H= a1*h1+a2*h2
S= a1*s1+a2*s2
##RESULTS
print'%s %.2f %s'% ('a2 = ',a2,'')
print'%s %.2f %s'% ('\n specific volume = ',V,' m^3/kg')
print'%s %.2f %s'% ('\n internal energy = ',U,' kJ/kg')
print'%s %.2f %s'% ('\n enthalpy = ',H,' kJ/kg')
print'%s %.2f %s'% ('\n Entropy = ',S,' kJ/kg')
import math
#calculate a2 and internal energy
##initialisation of variables
v= 0.15 ##m^3/kg
v1= 0.13857 ##m^3/kg
v2= 0.1512 ##m^3/kg
v3= 0.050 ##m^3##kg
vf= 0.001177 ##m^3/kg
vg= 0.09963 ##m^3/kg
uf= 906.44 ##kJ/kg
ufg= 1693.8 ##kJ/kg
##CALCULATIONS
a1= (v-v1)/(v2-v1)
a2= 1-a1
x= (v3-vf)/(vg-vf)
u= uf+x*ufg
##RESULTS
print'%s %.2f %s'% ('a2 = ',a2,'')
print'%s %.2f %s'% ('\n internal energy = ',u,' kJ/kg')
import math
#calculate pressure and temperature
##initialisation of variables
T= 250. ##C
T2= 300. ##C
v300= 0.6548 ##m^3/kg
v250= 0.591 ##m^3/kg
v= 0.6 ##m^3/kg
u= 3000. ##kJ/kg
u250= 2726.1 ##kJ/kg
u300= 2804.8 ##kJ/kg
T2= 510.30
u2= 3145.26 ##kJ/kg
p= 0.4 ##Mpa
p2= 0.2 ##Mpa
##CALCULATIONS
T1= T+((v-v250)/(v300-v250))*(T2-T)
u1= u250+((v-v250)/(v300-v250))*(u300-u250)
du= u1-u
p1= p+((u-u1)/(u2-u1))*p2
##RESULTS
print'%s %.2f %s'% ('pressure = ',p1,' Mpa')
print'%s %.2f %s'% ('\n temperature = ',T2,' C')
import math
#calculate mass and specific volume
##initialisation of variables
n= 1.5 ##kmol
V= 0.5 ##m^3
M= 18.02 ##kg
##CALCULATIONS
m= n*M
v= V/m
##RESULTS
print'%s %.2f %s'% ('mass = ',m,' kg')
print'%s %.2f %s'% ('\n sepcific volume = ',v,' m^3/kg')
import math
#calculate work and heat interaction
##initialisation of variables
V= 0.2 ##m^3
v1= 0.02995 ##m^3/kg
u2= 2826.7 ##kJ/kg
u1= 2747.7 ##kJ/kg
h2= 3092.5 ##kJ/kg
h1= 2987.3 ##kJ/kg
p= 4. ##Mpa
v2= 0.06645 ##m^3/kg
v1= 0.02995 ##m^3/kg
##CALCULATIONS
m= V/v1
U= m*(u2-u1)
H= m*(h2-h1)
W= m*p*10**3*(v2-v1)
Q= U+W
##RESULTS
print'%s %.2f %s'% (' work = ',W,' kJ')
print'%s %.2f %s'% ('\n heat interaction = ',Q,' kJ')
import math
#calculate work and heat interaction
##initialisation of variables
m= 6.678 ##kg
u2= 2826.7 ##kJ/kg
u1= 2747.7 ##kJ/kg
p1= 8. ##Mpa
p2= 7. ##Mpa
p3= 6. ##Mpa
p4= 5. ##Mpa
p5= 4. ##Mpa
v1= 29.95 ##L/kg
v2= 35.24 ##L/kg
v3= 42.23 ##L/kg
v4= 51.94 ##L/kg
v5= 66.45 ##L/kg
##CALCULATIONS
U= m*(u2-u1)
W= m*0.5*((p1+p2)*(v2-v1)+(p2+p3)*(v3-v2)+(p3+p4)*(v4-v3)+(p4+p5)*(v5-v4))
Q=U+W
##RESULTS
print'%s %.2f %s'% (' work = ',W,' kJ')
print'%s %.2f %s'% ('\n heat interaction = ',Q,' kJ')
import math
#calculate final pressure and enthalpy and piston rise
##initialisation of variables
p0= 100. ##kpa
A= 0.1 ##m^2
F= 20. ##kN
m3= 0.8873 ##kg
m1= 1.1384 ##kg
m2= 0.2511 ##kg
u1= 3116.2 ##kJ/kg
u2= 2728.7 ##kJ/kg
v3= 0.9942 ##m^3/kg
##CALCULATIONS
pe= (p0+(F/A))/1000.
h3= (m1*u1-m2*u2)/m3
z3= m3*v3/A
##RESULTS
print'%s %.2f %s'% (' final pressure = ',pe,' Mpa')
print'%s %.2f %s'% (' \n enthalpy = ',h3,' kJ/kg')
print'%s %.2f %s'% ('\n piston rise = ',z3,' m')