##Part A Chapter 6 Example 1 pg no 192
##find the change in entropy
import math
p1=5.;##bar
T1=27.+273.;##K
p2=2.;##bar
cp_air=1.004;##kJ/kgK
R=0.287;##kJ/kgK
T2=T1;##K(as cp*T1=cp*T2)
delta_s=cp_air*math.log(T2/T1)-R*math.log(p2/p1);##kJ/kgK
print"%s %.2f %s"%("Change in entropy = ",delta_s," kJ/kgK");
##Part A Chapter 6 Example 2 pg no 192
##find the total change in entropy
import math
import scipy
from scipy import integrate
T1=27.+273.;##K
T2=100.+273.;##K
T3=400.+273.;##K
m=5.;##kg
cp=4.2;##kJ/kgK
cp2=2260.;##kJ/kg
delta_T=100.-27.;##degree C
Q1=m*cp*delta_T;##kJ/K
delta_S1=Q1/T1##kJ/K
Q2=m*cp2;##kJ/K
delta_S2=Q2/T2##kJ/K
R=8.314/34.;##kJ/kgK
##cp_steam=R*(3.5+1.2*T+0.14*T^2)*10^-3;##kJ/kgK
##delta_S3=m*cp_steam/T*dT
def fun(T):
y=m*R*(((3.5/T)+1.2+0.14*T)*10**-3)
return y;
delta_S3=scipy.integrate.quad(fun,373,673);##kJ/K
delta_s3=delta_S3[0]
delta_S=delta_S1+delta_S2+delta_s3;##kJ/K
print"%s %.2f %s"%("Total entropy change = ",delta_S," kJ/K");
##Answer in the book is not accurate.
##Part A Chapter 6 Example 3 pg no 194
##find the change in entropy
import math
R=8.314/32.;##kJ/kgK
p1=125.;##kPa
p2=375.;##kPa
T1=27.+273.;##K
T2=T1;##K
delta_S=-R*math.log(p2/p1);##kJ/K;##kJ/kgK
print"%s %.2f %s"%("Change in entropy = ",delta_S," kJ/K");
##Part A Chapter 6 Example 4 pg no 194
##find the change in entropy universe
T1=150.+273.;##K
T2=25.+273.;##K
m=1;##kg
cp=0.393;##kJ/kgK
import math
deltaS_block=-m*cp*math.log(T1/T2);##kJ/kgK
HeatLost_block=-m*cp*(T1-T2);##kJ
deltaS_water=-HeatLost_block/T2;##kJ/K
deltaS_universe=deltaS_block+deltaS_water;##kJ/K
deltaS_universe=deltaS_universe*1000.;##J/K
print"%s %.2f %s"%("Change in entropy of universe = ",deltaS_universe," J/K");
##unit of answer is wrong in the book.
##Part A Chapter 6 Example 5 pg no 195
##find the change in entropy
m=1.;##kg
g=9.81;##gravity constant
h=200.;##m
T1=27.+273.;##K
cp=0.393;##kJ/kgK
deltaPE=m*g*h;##J
Q=deltaPE;##J
deltaS_SeaWater=Q/T1;##J/kgK
deltaS_universe=deltaS_SeaWater;##J/kgK(because of same temperature)
print"%s %.2f %s"%("Change in entropy of universe = ",deltaS_universe," J/kgK");
##Part A Chapter 6 Example 6 pg no 195
##find the change in entropy
import math
m1=1.;##kg
m2=0.5;##kg
T1=150.+273.;##K
T2=0.+273.;##K
cp1=0.393;##kJ/kgK
cp2=0.381;##kJ/kgK
##m1*cp1*(T1-Tf)=m2*cp2*(Tf-T2);
Tf=(m1*cp1*T1+m2*cp2*T2)/(m2*cp2+m1*cp1);##K
delta_S1=m1*cp1*math.log(Tf/T1);##kJ/K
delta_S2=m2*cp2*math.log(Tf/T2);##kJ/K
deltaS_universe=delta_S1+delta_S2;##kJ/K
print"%s %.2f %s"%("Change in entropy of universe = ",deltaS_universe," kJ/K");
##Part A Chapter 6 Example 8 pg no 197
##find the work lost
T1=1800.;##K
T2=300.;##K
W=2.;##MW
Q1=5.;##MW
Q2=Q1-W;##MW
deltaS=(-Q1/T1+Q2/T2);##MW/K
W_lost=T2*deltaS;##MW
print"%s %.2f %s"%("Work lost = ",W_lost," MW");
##Part A Chapter 6 Example 9 pg no 198
##find the change entropy
import math
import scipy
from scipy import integrate
T1_HE=2000.;##K
T2_HE=300.;##K
T1=500.;##K
T2=300.;##K
def fun(T):
y=0.05*T**2+0.10*T+0.085
return y
Q1=scipy.integrate.quad(fun,500,300);##J
Q11=Q1[0]
def fun(T):
y=0.05*T+0.10+0.085/T
return y
deltaS_system=scipy.integrate.quad(fun,500,300);##J/K
deltaS_system1=deltaS_system[0]
##Putting deltaS_system+deltaS_reservoir>=0
##deltaS_reservoir=(Q1-W)/T2
W=deltaS_system1*T2-Q11;##J
print"%s %.2f %s"%("Maximum Work = ",W/1000," kJ");
##Part A Chapter 6 Example 10 pg 199
##find the entropy change
import math
import scipy
from scipy import integrate
p1=3.;##MPa
V1=0.05;##m^3
V2=0.3;##m^3
p2=p1*V1**1.4/V2**1.4;##Mpa
deltaS=0;##for reversible process
def fun(P):
y=(p1*V1**1.4/P)**(1/1.4)
return y
deltaH=scipy.integrate.quad(fun,p2,p1);##MJ
deltaH1=deltaH[0]
print"%s %.2f %s"%("Enthalpy change = ",deltaH1*1000," kJ");
print"%s %.f %s"%("Entropy change = ",deltaS,"");
##Part A Chapter 6 Example 11 pg no 200
##find the entropy change
import math
m=2.;##kg
V1=1.;##m^3
V2=10.;##m^3
R=287.;##consant
deltaS_air=m*R*math.log(V2/V1);##J/K
print"%s %.2f %s"%("Entropy change of air = ",deltaS_air," J/K");
deltaS_surr=0;##for free expansion
print"%s %.2f %s"%("Entropy change of surrounding = ",deltaS_surr,"");
deltaS_uni=deltaS_air+deltaS_surr;##J/K
print"%s %.2f %s"%("Entropy change of universe = ",deltaS_uni," J/K");