#cal of mean effective pressure
#intiation of all variables
# Chapter 9
import math
print"Example 9.1, Page:334 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 1")
Cp=1;#specific heat at constant pressure in KJ/kg K
Cv=0.71;#specific heat at constant volume in KJ/kg K
P1=98;#pressure at begining of compression in KPa
T1=(60+273.15);#temperature at begining of compression in K
Q23=150;#heat supplied in KJ/kg
r=6;#compression ratio
R=0.287;#gas constant in KJ/kg K
print("SI engine operate on otto cycle.consider working fluid to be perfect gas.")
print("here,y=Cp/Cv")
y=Cp/Cv
y=1.4;#approx.
print("Cp-Cv=R in KJ/kg K")
R=Cp-Cv
print("compression ratio,r=V1/V2=(0.15+V2)/V2")
print("so V2=0.15/(r-1) in m^3")
V2=0.15/(r-1)
print("so V2=0.03 m^3")
print("total cylinder volume=V1=r*V2 m^3")
V1=r*V2
print("from perfect gas law,P*V=m*R*T")
print("so m=P1*V1/(R*T1) in kg")
m=P1*V1/(R*T1)
m=0.183;#approx.
print("from state 1 to 2 by P*V^y=P2*V2^y")
print("so P2=P1*(V1/V2)^y in KPa")
P2=P1*(V1/V2)**y
print("also,P1*V1/T1=P2*V2/T2")
print("so T2=P2*V2*T1/(P1*V1)in K")
T2=P2*V2*T1/(P1*V1)
print("from heat addition process 2-3")
print("Q23=m*CV*(T3-T2)")
print("T3=T2+(Q23/(m*Cv))in K")
T3=T2+(Q23/(m*Cv))
print("also from,P3*V3/T3=P2*V2/T2")
print("P3=P2*V2*T3/(V3*T2) in KPa")
V3=V2;#constant volume process
P3=P2*V2*T3/(V3*T2)
print("for adiabatic expansion 3-4,")
print("P3*V3^y=P4*V4^y")
print("and V4=V1")
V4=V1;
print("hence,P4=P3*V3^y/V1^y in KPa")
P4=P3*V3**y/V1**y
print("and from P3*V3/T3=P4*V4/T4")
print("T4=P4*V4*T3/(P3*V3) in K")
T4=P4*V4*T3/(P3*V3)
print("entropy change from 2-3 and 4-1 are same,and can be given as,")
print("S3-S2=S4-S1=m*Cv*log(T4/T1)")
print("so entropy change,deltaS_32=deltaS_41 in KJ/K")
deltaS_32=m*Cv*math.log(T4/T1)
deltaS_41=deltaS_32;
print("heat rejected,Q41=m*Cv*(T4-T1) in KJ")
Q41=m*Cv*(T4-T1)
W=Q23-Q41
print("net work(W) in KJ="),round(W,2)
n=W/Q23
print("efficiency(n)="),round(W/Q23,2)
print("in percentage"),round(n*100,2)
mep=W/0.15
print("mean effective pressure(mep)=work/volume change in KPa="),round(W/0.15,2)
print("so mep=511.67 KPa")
#cal of compression ratio,air standard efficiency,fuel consumption,bhp/hr
#intiation of all variables
# Chapter 9
print"Example 9.2, Page:336 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 2")
Pa=138;#pressure during compression at 1/8 of stroke in KPa
Pb=1.38*10**3;#pressure during compression at 7/8 of stroke in KPa
n_ite=0.5;#indicated thermal efficiency
n_mech=0.8;#mechanical efficiency
C=41800;#calorific value in KJ/kg
y=1.4;#expansion constant
print("as given")
print("Va=V2+(7/8)*(V1-V2)")
print("Vb=V2+(1/8)*(V1-V2)")
print("and also")
print("Pa*Va^y=Pb*Vb^y")
print("so (Va/Vb)=(Pb/Pa)^(1/y)")
(Pb/Pa)**(1/y)
print("also substituting for Va and Vb")
print("(V2+(7/8)*(V1-V2))/(V2+(1/8)*(V1-V2))=5.18")
r=1+(4.18*8/1.82)
print("so V1/V2=r=1+(4.18*8/1.82)"),round(r,2)
print("it gives r=19.37 or V1/V2=19.37,compression ratio=19.37")
print("as given;cut off occurs at(V1-V2)/15 volume")
print("V3=V2+(V1-V2)/15")
print("cut off ratio,rho=V3/V2")
rho=1+(r-1)/15
n_airstandard=1-(1/(r**(y-1)*y))*((rho**y-1)/(rho-1))
print("air standard efficiency for diesel cycle(n_airstandard)="),round(n_airstandard,2)
print("in percentage"),round(n_airstandard*100,2)
n_airstandard=0.6325;
n_overall=n_airstandard*n_ite*n_mech
print("overall efficiency(n_overall)=n_airstandard*n_ite*n_mech"),round(n_overall,3)
print("in percentage"),round(n_overall*100,2)
n_overall=0.253;
75*60*60/(n_overall*C*100)
print("fuel consumption,bhp/hr in kg="),round(75*60*60/(n_overall*C*100),2)
print("so compression ratio=19.37")
print("air standard efficiency=63.25%")
print("fuel consumption,bhp/hr=0.255 kg")
#cal of comparing efficiency of two cycles
#intiation of all variables
# Chapter 9
print"Example 9.3, Page:338 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 3")
T1=(100+273.15);#temperature at beginning of compresssion in K
P1=103;#pressure at beginning of compresssion in KPa
Cp=1.003;#specific heat at constant pressure in KJ/kg K
Cv=0.71;#specific heat at constant volume in KJ/kg K
Q23=1700;#heat added during combustion in KJ/kg
P3=5000;#maximum pressure in cylinder in KPa
print("1-2-3-4=cycle a")
print("1-2_a-3_a-4_a-5=cycle b")
print("here Cp/Cv=y")
y=Cp/Cv
y=1.4;#approx.
print("and R=0.293 KJ/kg K")
R=0.293;
print("let us consider 1 kg of air for perfect gas,")
m=1;#mass of air in kg
print("P*V=m*R*T")
print("so V1=m*R*T1/P1 in m^3")
V1=m*R*T1/P1
print("at state 3,")
print("P3*V3=m*R*T3")
print("so T3/V2=P3/(m*R)")
P3/(m*R)
print("so T3=17064.8*V2............eq1")
print("for cycle a and also for cycle b")
print("T3_a=17064.8*V2_a.............eq2")
print("a> for otto cycle,")
print("Q23=Cv*(T3-T2)")
print("so T3-T2=Q23/Cv")
Q23/Cv
print("and T2=T3-2394.36.............eq3")
print("from gas law,P2*V2/T2=P3*V3/T3")
print("here V2=V3 and using eq 3,we get")
print("so P2/(T3-2394.36)=5000/T3")
print("substituting T3 as function of V2")
print("P2/(17064.8*V2-2394.36)=5000/(17064.8*V2)")
print("P2=5000*(17064.8*V2-2394.36)/(17064.8*V2)")
print("also P1*V1^y=P2*V2^y")
print("or 103*(1.06)^1.4=(5000*(17064.8*V2-2394.36)/(17064.8*V2))*V2^1.4")
print("upon solving it yields")
print("381.4*V2=17064.8*V2^2.4-2394.36*V2^1.4")
print("or V2^1.4-0.140*V2^0.4-.022=0")
print("by hit and trial it yields,V2=0.18 ")
V2=0.18;
print("thus compression ratio,r=V1/V2")
r=V1/V2
print("otto cycle efficiency,n_otto=1-(1/r)^(y-1)")
n_otto=1-(1/r)**(y-1)
print("in percentage")
n_otto=n_otto*100
print("b> for mixed or dual cycle")
print("Cp*(T4_a-T3_a)=Cv*(T3_a-T2_a)=1700/2=850")
print("or T3_a-T2_a=850/Cv")
850/Cv
print("or T2_a=T3_a-1197.2 .............eq4 ")
print("also P2_a*V2_a/T2_a=P3_a*V3_a/T3_a")
print("P2_a*V2_a/(T3_a-1197.2)=5000*V2_a/T3_a")
print("or P2_a/(T3_a-1197.2)=5000/T3_a")
print("also we had seen earlier that T3_a=17064.8*V2_a")
print("so P2_a/(17064.8*V2_a-1197.2)=5000/(17064.8*V2_a)")
print("so P2_a=5000*(17064.8*V2_a-1197.2)/(17064.8*V2_a).....................eq5")
print("or for adiabatic process,1-2_a")
print("P1*V1^y=P2*V2^y")
print("so 1.3*(1.06)^1.4=V2_a^1.4*(5000-(359.78/V2_a))")
print("or V2_a^1.4-0.07*V2_a^0.4-0.022=0")
print("by hit and trial ")
print("V2_a=0.122 m^3")
V2_a=0.122;
print("therefore upon substituting V2_a,")
print("by eq 5,P2_a in KPa")
P2_a=5000*(17064.8*V2_a-1197.2)/(17064.8*V2_a)
print("by eq 2,T3_a in K")
T3_a=17064.8*V2_a
print("by eq 4,T2_a in K")
T2_a=T3_a-1197.2
print("from constant pressure heat addition")
print("Cp*(T4_a-T3_a)=850")
print("so T4_a=T3_a+(850/Cp) in K")
T4_a=T3_a+(850/Cp)
print("also P4_a*V4_a/T4_a= P3_a*V3_a/T3_a")
print("so V4_a=P3_a*V3_a*T4_a/(T3_a*P4_a) in m^3 ")
print("here P3_a=P4_a and V2_a=V3_a")
V4_a=V2_a*T4_a/(T3_a)
print("using adiabatic formulations V4_a=0.172 m^3")
print("(V5/V4_a)^(y-1)=(T4_a/T5),here V5=V1")
V5=V1;
print("so T5=T4_a/(V5/V4_a)^(y-1) in K")
T5=T4_a/(V5/V4_a)**(y-1)
print("heat rejected in process 5-1,Q51=Cv*(T5-T1) in KJ")
Q51=Cv*(T5-T1)
n_mixed=(Q23-Q51)/Q23
print("efficiency of mixed cycle(n_mixed)="),round(n_mixed,2)
print("in percentage"),round(n_mixed*100,2)
("NOTE=>In this question temperature difference (T3-T2) for part a> in book is calculated wrong i.e 2328.77,which is corrected above and comes to be 2394.36,however it doesnt effect the efficiency of any part of this question.")
#cal of thermal efficiency,turbine and compressor work
#intiation of all variables
# Chapter 9
print"Example 9.4, Page:341 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 4")
T3=1200;#maximum temperature in K
T1=300;#minimum temperature in K
y=1.4;#expansion constant
Cp=1.005;#specific heat at constant pressure in KJ/kg K
print("optimum pressure ratio for maximum work output,")
print("rp=(T_max/T_min)^((y)/(2*(y-1)))")
T_max=T3;
T_min=T1;
rp=(T_max/T_min)**((y)/(2*(y-1)))
print("so p2/p1=11.3,For process 1-2, T2/T1=(p2/p1)^(y/(y-1))")
print("so T2=T1*(p2/p1)^((y-1)/y)in K")
T2=T1*(rp)**((y-1)/y)
print("For process 3-4,")
print("T3/T4=(p3/p4)^((y-1)/y)=(p2/p1)^((y-1)/y)")
print("so T4=T3/(rp)^((y-1)/y)in K")
T4=T3/(rp)**((y-1)/y)
print("heat supplied,Q23=Cp*(T3-T2)in KJ/kg")
Q23=Cp*(T3-T2)
Wc=Cp*(T2-T1)
print("compressor work,Wc in KJ/kg="),round(Wc,2)
Wt=Cp*(T3-T4)
print("turbine work,Wt in KJ/kg="),round(Wt,2)
(Wt-Wc)/Q23
print("thermal efficiency=net work/heat supplied="),round((Wt-Wc)/Q23,2)
print("so compressor work=301.5 KJ/kg,turbine work=603 KJ/kg,thermal efficiency=50%")
#cal of thermal efficiency,turbine and compressor work
#intiation of all variables
# Chapter 9
print"Example 9.5, Page:342 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 5")
P1=1*10**5;#initial pressure in Pa
P4=P1;#constant pressure process
T1=300;#initial temperature in K
P2=6.2*10**5;#pressure after compression in Pa
P3=P2;#constant pressure process
k=0.017;#fuel to air ratio
n_compr=0.88;#compressor efficiency
q=44186;#heating value of fuel in KJ/kg
n_turb=0.9;#turbine internal efficiency
Cp_comb=1.147;#specific heat of combustion at constant pressure in KJ/kg K
Cp_air=1.005;#specific heat of air at constant pressure in KJ/kg K
y=1.4;#expansion constant
n=1.33;#expansion constant for polytropic constant
print("gas turbine cycle is shown by 1-2-3-4 on T-S diagram,")
print("for process 1-2 being isentropic,")
print("T2/T1=(P2/P1)^((y-1)/y)")
print("so T2=T1*(P2/P1)^((y-1)/y) in K")
T2=T1*(P2/P1)**((y-1)/y)
print("considering compressor efficiency,n_compr=(T2-T1)/(T2_a-T1)")
print("so T2_a=T1+((T2-T1)/n_compr)in K")
T2_a=T1+((T2-T1)/n_compr)
print("during process 2-3 due to combustion of unit mass of compressed the energy balance shall be as under,")
print("heat added=mf*q")
print("=((ma+mf)*Cp_comb*T3)-(ma*Cp_air*T2)")
print("or (mf/ma)*q=((1+(mf/ma))*Cp_comb*T3)-(Cp_air*T2_a)")
print("so T3=((mf/ma)*q+(Cp_air*T2_a))/((1+(mf/ma))*Cp_comb)in K")
T3=((k)*q+(Cp_air*T2_a))/((1+(k))*Cp_comb)
print("for expansion 3-4 being")
print("T4/T3=(P4/P3)^((n-1)/n)")
print("so T4=T3*(P4/P3)^((n-1)/n) in K")
T4=T3*(P4/P3)**((n-1)/n)
print("actaul temperature at turbine inlet considering internal efficiency of turbine,")
print("n_turb=(T3-T4_a)/(T3-T4)")
print("so T4_a=T3-(n_turb*(T3-T4)) in K")
T4_a=T3-(n_turb*(T3-T4))
Wc=Cp_air*(T2_a-T1)
print("compressor work,per kg of air compressed(Wc) in KJ/kg of air="),round(Wc,2)
print("so compressor work=234.42 KJ/kg of air")
Wt=Cp_comb*(T3-T4_a)
print("turbine work,per kg of air compressed(Wt) in KJ/kg of air="),round(Wt,2)
print("so turbine work=414.71 KJ/kg of air")
W_net=Wt-Wc
print("net work(W_net) in KJ/kg of air="),round(W_net,2)
Q=k*q
print("heat supplied(Q) in KJ/kg of air="),round(Q,2)
n=W_net/Q
print("thermal efficiency(n)="),round(n,2)
print("in percentage"),round(n*100,2)
print("so thermal efficiency=24%")
#cal of overall optimum pressure ratio
#intiation of all variables
# Chapter 9
print"Example 9.6, Page:343 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 6")
T1=300;#minimum temperature in brayton cycle in K
T5=1200;#maximum temperature in brayton cycle in K
n_isen_c=0.85;#isentropic efficiency of compressor
n_isen_t=0.9;#isentropic efficiency of turbine
y=1.4;#expansion constant
print("NOTE=>In this question formula for overall pressure ratio is derived,which cannot be done using scilab,so using this formula we proceed further.")
rp=(T1/(T5*n_isen_c*n_isen_t))**((2*y)/(3*(1-y)))
print("overall pressure ratio(rp)="),round(rp,2)
print("so overall optimum pressure ratio=13.6")
#cal of state of air at exit of compressor,polytropic efficiency,efficiency of each sate,power
#intiation of all variables
# Chapter 9
import math
print"Example 9.7, Page:346 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 7")
T1=313.;#air entering temperature in K
P1=1*10**5;#air entering pressure in Pa
m=50.;#flow rate through compressor in kg/s
R=0.287;#gas constant in KJ/kg K
print("i> theoretically state of air at exit can be determined by the given stage pressure ratio of 1.35.Let pressure at inlet to first stage P1 and subsequent intermediate pressure be P2,P3,P4,P5,P6,P7,P8 and exit pressure being P9.")
print("therefore,P2/P1=P3/P2=P4/P3=P5/P4=P6/P5=P7/P6=P8/P7=P9/P8=r=1.35")
r=1.35;#compression ratio
k=(1.35)**8
print("or P9/P1=k=(1.35)^8"),round(k,2)
k=11.03;#approx.
print("or theoretically,the temperature at exit of compressor can be predicted considering isentropic compression of air(y=1.4)")
y=1.4;#expansion constant
print("T9/T1=(P9/P1)^((y-1)/y)")
T9=T1*(k)**((y-1)/y)
print("so T9 in K="),round(T9,2)
print("considering overall efficiency of compression 82% the actual temperature at compressor exit can be obtained")
print("(T9-T1)/(T9_actual-T1)=0.82")
T9_actual=T1+((T9-T1)/0.82)
print("so T9_actual=T1+((T9-T1)/0.82) in K"),round(T9_actual,2)
print("let the actual index of compression be n, then")
print("(T9_actual/T1)=(P9/P1)^((n-1)/n)")
print("so n=log(P9/P1)/(log(P9/P1)-log(T9-actual/T1))")
n=math.log(k)/(math.log(k)-math.log(T9_actual/T1))
print("so state of air at exit of compressor,pressure=11.03 bar and temperature=689.18 K")
print("ii> let polytropic efficiency be n_polytropic for compressor then,")
print("(n-1)/n=((y-1)/y)*(1/n_polytropic)")
n_polytropic=((y-1)/y)/((n-1)/n)
print("so n_polytropic="),round(n_polytropic,2)
print("in percentage"),round(n_polytropic*100,2)
print("so ploytropic efficiency=86.88%")
print("iii> stage efficiency can be estimated for any stage.say first stage.")
print("ideal state at exit of compressor stage=T2/T1=(P2/P1)^((y-1)/y)")
print("so T2=T1*(P2/P1)^((y-1)/y) in K")
T2=T1*(r)**((y-1)/y)
print("actual temperature at exit of first stage can be estimated using polytropic index 1.49.")
print("T2_actual/T1=(P2/P1)^((n-1)/n)")
print("so T2_actual=T1*(P2/P1)^((n-1)/n) in K")
T2_actual=T1*(r)**((n-1)/n)
ns_1=(T2-T1)/(T2_actual-T1)
print("stage efficiency for first stage,ns_1="),round(ns_1,2)
print("in percentage"),round(ns_1*100,2)
print("actual temperature at exit of second stage,")
print("T3_actual/T2_actual=(P3/P2)^((n-1)/n)")
print("so T3_actual=T2_actual*(P3/P2)^((n-1)/n) in K")
T3_actual=T2_actual*(r)**((n-1)/n)
print("ideal temperature at exit of second stage")
print("T3/T2_actual=(P3/P2)^((n-1)/n)")
print("so T3=T2_actual*(P3/P2)^((y-1)/y) in K")
T3=T2_actual*(r)**((y-1)/y)
ns_2=(T3-T2_actual)/(T3_actual-T2_actual)
print("stage efficiency for second stage,ns_2="),round(ns_2,2)
print("in percentage"),round(ns_2*100,2)
print("actual rtemperature at exit of third stage,")
print("T4_actual/T3_actual=(P4/P3)^((n-1)/n)")
T4_actual=T3_actual*(r)**((n-1)/n)
print("so T4_actual in K="),round(T4_actual,2)
print("ideal temperature at exit of third stage,")
print("T4/T3_actual=(P4/P3)^((n-1)/n)")
T4=T3_actual*(r)**((y-1)/y)
print("so T4 in K="),round(T4,2)
ns_3=(T4-T3_actual)/(T4_actual-T3_actual)
print("stage efficiency for third stage,ns_3="),round(ns_3,2)
ns_3=ns_3*100
print("in percentage="),round(ns_3*100,2)
print("so stage efficiency=86.4%")
print("iv> from steady flow energy equation,")
print("Wc=dw=dh and dh=du+p*dv+v*dp")
print("dh=dq+v*dp")
print("dq=0 in adiabatic process")
print("dh=v*dp")
print("Wc=v*dp")
print("here for polytropic compression ")
print("P*V^1.49=constant i.e n=1.49")
n=1.49;
Wc=(n/(n-1))*m*R*T1*(((k)**((n-1)/n))-1)
print("Wc in KJ/s="),round(Wc,2)
Wc_actual=Wc*0.9
print("due to overall efficiency being 90% the actual compressor work(Wc_actual) in KJ/s="),round(Wc*0.9,2)
print("so power required to drive compressor =14777.89 KJ/s")
#intiation of all variables
# Chapter 9
print"Example 9.8, Page:349 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 8")
print("In question no.8,expression for air standard cycle efficiency is derived which cannot be solve using python software.")
#cal of cycle efficiency,work ratio,specific work output
#intiation of all variables
# Chapter 9
print"Example 9.9, Page:350 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 9")
y=1.4;#expansion constant
n_poly_c=0.85;#ploytropic efficiency of compressor
n_poly_T=0.90;#ploytropic efficiency of Turbine
r=8.;#compression ratio
T1=(27.+273.);#temperature of air in compressor in K
T3=1100.;#temperature of air leaving combustion chamber in K
epsilon=0.8;#effectiveness of heat exchanger
Cp=1.0032;#specific heat at constant pressure in KJ/kg K
print("using polytropic efficiency the index of compression and expansion can be obtained as under,")
print("let compression index be nc,")
print("(nc-1)/nc=(y-1)/(y*n_poly_c)")
print("so nc=1/(1-((y-1)/(y*n_poly_c)))")
nc=1/(1-((y-1)/(y*n_poly_c)))
print("let expansion index be nt,")
print("(nt-1)/nt=(n_poly_T*(y-1))/y")
print("so nt=1/(1-((n_poly_T*(y-1))/y))")
nt=1/(1-((n_poly_T*(y-1))/y))
print("For process 1-2")
print("T2/T1=(p2/p1)^((nc-1)/nc)")
print("so T2=T1*(p2/p1)^((nc-1)/nc)in K")
T2=T1*(r)**((nc-1)/nc)
print("also T4/T3=(p4/p3)^((nt-1)/nt)")
print("so T4=T3*(p4/p3)^((nt-1)/nt)in K")
T4=T3*(1/r)**((nt-1)/nt)
print("using heat exchanger effectivenesss,")
print("epsilon=(T5-T2)/(T4-T2)")
print("so T5=T2+(epsilon*(T4-T2))in K")
T5=T2+(epsilon*(T4-T2))
print("heat added in combustion chamber,q_add=Cp*(T3-T5)in KJ/kg")
q_add=Cp*(T3-T5)
print("compressor work,Wc=Cp*(T2-T1)in ")
Wc=Cp*(T2-T1)
print("turbine work,Wt=Cp*(T3-T4)in KJ/kg")
Wt=Cp*(T3-T4)
(Wt-Wc)/q_add
print("cycle efficiency="),round((Wt-Wc)/q_add,2)
print("in percentage"),round((Wt-Wc)*100/q_add,2)
(Wt-Wc)/Wt
print("work ratio="),round((Wt-Wc)/Wt,2)
print("specific work output in KJ/kg="),round(Wt-Wc,2)
print("so cycle efficiency=32.79%,work ratio=0.334,specific work output=152.56 KJ/kg")
#cal of isentropic efficiency of turbine
#intiation of all variables
# Chapter 9
print"Example 9.10, Page:351 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 10")
T1=(27+273);#temperature of air in compressor in K
p1=1*10**5;#pressure of air in compressor in Pa
p2=5*10**5;#pressure of air after compression in Pa
p3=p2-0.2*10**5;#pressure drop in Pa
p4=1*10**5;#pressure to which expansion occur in turbine in Pa
nc=0.85;#isentropic efficiency
T3=1000;#temperature of air in combustion chamber in K
n=0.2;#thermal efficiency of plant
y=1.4;#expansion constant
Cp=1.0032;#specific heat at constant pressure in KJ/kg K
print("for process 1-2_a")
print("T2_a/T1=(p2_a/p1)^((y-1)/y)")
print("so T2_a=T1*(p2_a/p1)^((y-1)/y) in K")
T2_a=T1*(p2/p1)**((y-1)/y)
print("nc=(T2_a-T1)/(T2-T1)")
print("so T2=T1+((T2_a-T1)/nc) in K")
T2=T1+((T2_a-T1)/nc)
print("for process 3-4_a,")
print("T4_a/T3=(p4/p3)^((y-1)/y)")
print("so T4_a=T3*(p4/p3)^((y-1)/y)in K")
T4_a=T3*(p4/p3)**((y-1)/y)
print("Compressor work per kg,Wc=Cp*(T2-T1) in KJ/kg")
Wc=Cp*(T2-T1)
print("Turbine work per kg,Wt=Cp*(T3-T4)in KJ/kg")
print("net output,W_net=Wt-Wc={Wc-(Cp*(T3-T4))} in KJ/kg")
print("heat added,q_add=Cp*(T3-T2) in KJ/kg")
q_add=Cp*(T3-T2)
print("thermal efficiency,n=W_net/q_add")
print("n={Wc-(Cp*(T3-T4))}/q_add")
print("so T4=T3-((Wc-(n*q_add))/Cp)in K")
T4=T3-((Wc-(n*q_add))/Cp)
nt=(T3-T4)/(T3-T4_a)
print("therefore,isentropic efficiency of turbine,nt=(T3-T4)/(T3-T4_a)"),round((T3-T4)/(T3-T4_a),3)
print("in percentage"),round(nt*100,2)
print("so turbine isentropic efficiency=29.69%")
#cal of thermal efficiency,net output,A/F ratio
#intiation of all variables
# Chapter 9
import math
print"Example 9.11, Page:352 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 11")
P1=1.*10**5;#initial pressure in Pa
T1=(27.+273.);#initial temperature in K
T3=T1;
r=10.;#pressure ratio
T5=1000.;#maximum temperature in cycle in K
P6=3.*10**5;#first stage expansion pressure in Pa
T7=995.;#first stage reheated temperature in K
C=42000.;#calorific value of fuel in KJ/kg
Cp=1.0032;#specific heat at constant pressure in KJ/kg K
m=30.;#air flow rate in kg/s
nc=0.85;#isentropic efficiency of compression
ne=0.9;#isentropic efficiency of expansion
y=1.4;#expansion constant
print("for perfect intercooling the pressure ratio of each compression stage(k)")
print("k=sqrt(r)")
k=math.sqrt(r)
k=3.16;#approx.
print("for process 1-2_a,T2_a/T1=(P2/P1)^((y-1)/y)")
print("so T2_a=T1*(k)^((y-1)/y)in K")
T2_a=T1*(k)**((y-1)/y)
print("considering isentropic efficiency of compression,")
print("nc=(T2_a-T1)/(T2-T1)")
print("so T2=T1+((T2_a-T1)/nc)in K")
T2=T1+((T2_a-T1)/nc)
print("for process 3-4,")
print("T4_a/T3=(P4/P3)^((y-1)/y)")
print("so T4_a=T3*(P4/P3)^((y-1)/y) in K")
T4_a=T3*(k)**((y-1)/y)
print("again due to compression efficiency,nc=(T4_a-T3)/(T4-T3)")
print("so T4=T3+((T4_a-T3)/nc)in K")
T4=T3+((T4_a-T3)/nc)
print("total compressor work,Wc=2*Cp*(T4-T3) in KJ/kg")
Wc=2*Cp*(T4-T3)
print("for expansion process 5-6_a,")
print("T6_a/T5=(P6/P5)^((y-1)/y)")
print("so T6_a=T5*(P6/P5)^((y-1)/y) in K")
P5=10.*10**5;#pressure in Pa
T6_a=T5*(P6/P5)**((y-1)/y)
print("considering expansion efficiency,ne=(T5-T6)/(T5-T6_a)")
print("T6=T5-(ne*(T5-T6_a)) in K")
T6=T5-(ne*(T5-T6_a))
print("for expansion in 7-8_a")
print("T8_a/T7=(P8/P7)^((y-1)/y)")
print("so T8_a=T7*(P8/P7)^((y-1)/y) in K")
P8=P1;#constant pressure process
P7=P6;#constant pressure process
T8_a=T7*(P8/P7)**((y-1)/y)
print("considering expansion efficiency,ne=(T7-T8)/(T7-T8_a)")
print("so T8=T7-(ne*(T7-T8_a))in K")
T8=T7-(ne*(T7-T8_a))
print("expansion work output per kg of air(Wt)=Cp*(T5-T6)+Cp*(T7-T8) in KJ/kg")
Wt=Cp*(T5-T6)+Cp*(T7-T8)
print("heat added per kg air(q_add)=Cp*(T5-T4)+Cp*(T7-T6) in KJ/kg")
q_add=Cp*(T5-T4)+Cp*(T7-T6)
mf=q_add/C
print("fuel required per kg of air,mf=q_add/C"),round(q_add/C,2)
print("air-fuel ratio=1/mf"),round(1/mf,2)
W=Wt-Wc
print("net output(W) in KJ/kg="),round(Wt-Wc,2)
print("output for air flowing at 30 kg/s,=W*m in KW"),round(W*m,2)
W/q_add
print("thermal efficiency="),round(W/q_add,2)
print("in percentage"),round(W*100/q_add,2)
print("so thermal efficiency=27.87%,net output=6876.05 KW,A/F ratio=51.07")
print("NOTE=>In this question,expansion work is calculated wrong in book,so it is corrected above and answers vary accordingly.")
#cal of fuel-air ratio in two combustion chambers,total turbine work,cycle thermal efficiency
#intiation of all variables
# Chapter 9
print"Example 9.12, Page:354 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 12")
P1=1.*10**5;#initial pressure in Pa
P9=P1;
T1=300.;#initial temperature in K
P2=4.*10**5;#pressure of air in intercooler in Pa
P3=P2;
T3=290.;#temperature of air in intercooler in K
T6=1300.;#temperature of combustion chamber in K
P4=8.*10**5;#pressure of air after compression in Pa
P6=P4;
T8=1300.;#temperature after reheating in K
P8=4.*10**5;#pressure after expansion in Pa
P7=P8;
C=42000.;#heating value of fuel in KJ/kg
y=1.4;#expansion constant
ne=0.8;#effectiveness of regenerator
Cp=1.0032;#specific heat at constant pressure in KJ/kg K
print("for process 1-2,")
print("T2/T1=(P2/P1)^((y-1)/y)")
print("so T2=T1*(P2/P1)^((y-1)/y) in K")
T2=T1*(P2/P1)**((y-1)/y)
print("for process 3-4,")
print("T4/T3=(P4/P3)^((y-1)/y)")
print("so T4=T3*(P4/P3)^((y-1)/y) in K")
T4=T3*(P4/P3)**((y-1)/y)
print("for process 6-7,")
print("T7/T6=(P7/P6)^((y-1)/y)")
print("so T7=T6*(P7/P6)^((y-1)/y) in K")
T7=T6*(P7/P6)**((y-1)/y)
print("for process 8-9,")
print("T9/T8=(P9/P8)^((y-1)/y)")
print("T9=T8*(P9/P8)^((y-1)/y) in K")
T9=T8*(P9/P8)**((y-1)/y)
print("in regenerator,effectiveness=(T5-T4)/(T9-T4)")
print("T5=T4+(ne*(T9-T4))in K")
T5=T4+(ne*(T9-T4))
print("compressor work per kg air,Wc=Cp*(T2-T1)+Cp*(T4-T3) in KJ/kg")
Wc=Cp*(T2-T1)+Cp*(T4-T3)
Wt=Cp*(T6-T7)+Cp*(T8-T9)
print("turbine work per kg air,Wt in KJ/kg="),round(Wt,2)
q_add=Cp*(T6-T5)+Cp*(T8-T7)
print("heat added per kg air,q_add in KJ/kg="),round(q_add,2)
q_add/C
print("total fuel required per kg of air="),round(q_add/C,2)
W_net=Wt-Wc
print("net work,W_net in KJ/kg="),round(W_net,2)
n=W_net/q_add
print("cycle thermal efficiency,n="),round(n,2)
print("in percentage"),round(n*100,2)
print("fuel required per kg air in combustion chamber 1,Cp*(T8-T7)/C="),round(Cp*(T8-T7)/C,4)
print("fuel required per kg air in combustion chamber2,Cp*(T6-T5)/C="),round(Cp*(T6-T5)/C,4)
print("so fuel-air ratio in two combustion chambers=0.0126,0.0056")
print("total turbine work=660.85 KJ/kg")
print("cycle thermal efficiency=58.9%")
print("NOTE=>In this question,fuel required per kg air in combustion chamber 1 and 2 are calculated wrong in book,so it is corrected above and answers vary accordingly. ")
#cal of brake output,stroke volume
#intiation of all variables
# Chapter 9
import math
print"Example 9.13, Page:356 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 13")
T2=700.;#highest temperature of stirling engine in K
T1=300.;#lowest temperature of stirling engine in K
r=3.;#compression ratio
q_add=30.;#heat addition in KJ/s
epsilon=0.9;#regenerator efficiency
P=1*10**5;#pressure at begining of compression in Pa
n=100.;#number of cycle per minute
Cv=0.72;#specific heat at constant volume in KJ/kg K
R=29.27;#gas constant in KJ/kg K
print("work done per kg of air,W=R*(T2-T1)*log(r) in KJ/kg")
W=R*(T2-T1)*math.log(r)
print("heat added per kg of air,q=R*T2*log(r)+(1-epsilon)*Cv*(T2-T1) in KJ/kg")
q=R*T2*math.log(r)+(1-epsilon)*Cv*(T2-T1)
print("for 30 KJ/s heat supplied,the mass of air/s(m)=q_add/q in kg/s")
m=q_add/q
print("mass of air per cycle=m/n in kg/cycle")
m/n
print("brake output in KW="),round(W*m,2)
m=1.33*10**-4;#mass of air per cycle in kg/cycle
T=T1;
V=m*R*T*1000/P
print("stroke volume,V in m^3="),round(V,4)
print("brake output=17.11 KW")
print("stroke volume=0.0116 m^3")
#cal of compression ratio,air standard efficiency,fuel consumption,bhp/hr
#intiation of all variables
# Chapter 9
print"Example 9.14, Page:357 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 14")
print("In question no.14,various expression is derived which cannot be solved using python software.")
#cal of overall efficiency,steam per kg of air
#intiation of all variables
# Chapter 9
print"Example 9.15, Page:361 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 15")
r=10.;#pressure ratio
Cp=1.0032;#specific heat of air in KJ/kg K
y=1.4;#expansion constant
T3=1400.;#inlet temperature of gas turbine in K
T1=(17.+273.);#ambient temperature in K
P1=1.*10**5;#ambient pressure in Pa
Pc=15.;#condensor pressure in KPa
Pg=6.*1000;#pressure of steam in generator in KPa
T5=420.;#temperature of exhaust from gas turbine in K
print("In gas turbine cycle,T2/T1=(P2/P1)^((y-1)/y)")
print("so T2=T1*(P2/P1)^((y-1)/y)in K")
T2=T1*(r)**((y-1)/y)
print("T4/T3=(P4/P3)^((y-1)/y)")
print("so T4=T3*(P4/P3)^((y-1)/y) in K")
T4=T3*(1/r)**((y-1)/y)
print("compressor work per kg,Wc=Cp*(T2-T1) in KJ/kg")
Wc=Cp*(T2-T1)
print("turbine work per kg,Wt=Cp*(T3-T4) in KJ/kg ")
Wt=Cp*(T3-T4)
print("heat added in combustion chamber per kg,q_add=Cp*(T3-T2) in KJ/kg ")
q_add=Cp*(T3-T2)
print("net gas turbine output,W_net_GT=Wt-Wc in KJ/kg air")
W_net_GT=Wt-Wc
print("heat recovered in HRSG for steam generation per kg of air")
print("q_HRGC=Cp*(T4-T5)in KJ/kg")
q_HRGC=Cp*(T4-T5)
print("at inlet to steam in turbine,")
print("from steam table,ha=3177.2 KJ/kg,sa=6.5408 KJ/kg K")
ha=3177.2;
sa=6.5408;
print("for expansion in steam turbine,sa=sb")
sb=sa;
print("let dryness fraction at state b be x")
print("also from steam table,at 15KPa, sf=0.7549 KJ/kg K,sfg=7.2536 KJ/kg K,hf=225.94 KJ/kg,hfg=2373.1 KJ/kg")
sf=0.7549;
sfg=7.2536;
hf=225.94;
hfg=2373.1;
print("sb=sf+x*sfg")
print("so x=(sb-sf)/sfg ")
x=(sb-sf)/sfg
print("so hb=hf+x*hfg in KJ/kg K")
hb=hf+x*hfg
print("at exit of condenser,hc=hf ,vc=0.001014 m^3/kg from steam table")
hc=hf;
vc=0.001014;
print("at exit of feed pump,hd=hd-hc")
print("hd=vc*(Pg-Pc)*100 in KJ/kg")
hd=vc*(Pg-Pc)*100
print("heat added per kg of steam =ha-hd in KJ/kg")
ha-hd
print("mass of steam generated per kg of air in kg steam per kg air="),round(q_HRGC/(ha-hd),3)
W_net_ST=(ha-hb)-(hd-hc)
print("net steam turbine cycle output,W_net_ST in KJ/kg="),round(W_net_ST,2)
W_net_ST=W_net_ST*0.119
print("steam cycle output per kg of air(W_net_ST) in KJ/kg air="),round(W_net_ST,2)
(W_net_GT+W_net_ST)
print("total combined cycle output in KJ/kg air= "),round((W_net_GT+W_net_ST),2)
n_cc=(W_net_GT+W_net_ST)/q_add
print("combined cycle efficiency,n_cc=(W_net_GT+W_net_ST)/q_add"),round(n_cc,2)
print("in percentage"),round(n_cc*100,2)
n_GT=W_net_GT/q_add
print("In absence of steam cycle,gas turbine cycle efficiency,n_GT="),round(n_GT,2)
print("in percentage"),round(n_GT*100,2)
print("thus ,efficiency is seen to increase in combined cycle upto 57.77% as compared to gas turbine offering 48.21% efficiency.")
print("overall efficiency=57.77%")
print("steam per kg of air=0.119 kg steam per/kg air")
#cal of air standard thermal efficiency
#intiation of all variables
# Chapter 9
print"Example 9.16, Page:363 \n \n"
print("Engineering Thermodynamics by Onkar Singh Chapter 9 Example 16")
T1=(27+273);#temperature at begining of compression in K
k=70;#ration of maximum to minimum pressures
r=15;#compression ratio
y=1.4;#expansion constant
print("here P4/P1=P3/P1=70............eq1")
print("compression ratio,V1/V2=V1/V3=15.............eq2")
print("heat added at constant volume= heat added at constant pressure")
print("Q23=Q34")
print("m*Cv*(T3-T2)=m*Cp*(T4-T3)")
print("(T3-T2)=y*(T4-T3)")
print("for process 1-2;")
print("T2/T1=(P2/P1)^((y-1)/y)")
print("T2/T1=(V1/V2)^(y-1)")
print("so T2=T1*(V1/V2)^(y-1) in K")
T2=T1*(r)**(y-1)
print("and (P2/P1)=(V1/V2)^y")
print("so P2=P1*(V1/V2)^y in Pa...........eq3")
print("for process 2-3,")
print("P2/P3=T2/T3")
print("so T3=T2*P3/P2")
print("using eq 1 and 3,we get")
print("T3=T2*k/r^y in K")
T3=T2*k/r**y
print("using equal heat additions for processes 2-3 and 3-4,")
print("(T3-T2)=y*(T4-T3)")
print("so T4=T3+((T3-T2)/y) in K")
T4=T3+((T3-T2)/y)
print("for process 3-4,")
print("V3/V4=T3/T4")
print("(V3/V1)*(V1/V4)=T3/T4")
print("so (V1/V4)=(T3/T4)*r")
(T3/T4)*r
print("so V1/V4=11.88 and V5/V4=11.88")
print("for process 4-5,")
print("P4/P5=(V5/V4)^y,or T4/T5=(V5/V4)^(y-1)")
print("so T5=T4/((V5/V4)^(y-1))")
T5=T4/(11.88)**(y-1)
print("air standard thermal efficiency(n)=1-(heat rejected/heat added)")
print("n=1-(m*Cv*(T5-T1)/(m*Cp*(T4-T3)+m*Cv*(T3-T2)))")
n=1-((T5-T1)/(y*(T4-T3)+(T3-T2)))
print("n="),round(n,2)
print("air standard thermal efficiency=0.6529")
print("in percentage"),round(n*100,2)
print("so air standard thermal efficiency=65.29%")
print("Actual thermal efficiency may be different from theoretical efficiency due to following reasons")
print("a> Air standard cycle analysis considers air as the working fluid while in actual cycle it is not air throughtout the cycle.Actual working fluid which are combustion products do not behave as perfect gas.")
print("b> Heat addition does not occur isochorically in actual process.Also combustion is accompanied by inefficiency such as incomplete combustion,dissociation of combustion products,etc.")
print("c> Specific heat variation occurs in actual processes where as in air standard cycle analysis specific heat variation neglected.Also during adiabatic process theoretically no heat loss occur while actually these processes are accompanied by heat losses.")