"Limited Pressure Cycle  Supercharging.  Intercooling."
"Air Engine."

"Half of heat added at constant volume, half at constant pressure."

f_cv = 0.5
f_cp = 1-f_cv

"Engine Properties"

r_c = 9
V_d = 3.277*convert(liter,m^3)
V_2 = 0.410*convert(liter,m^3)
V_1 = V_2 + V_d

"Fuel properties"

Q_LHV = 44300					"[kJ/lg]"
AF = 15.0

"Start with atmospheric air at supercharger inlet- Point a on our PV diagram"

P_a = 103.4								"[kPa]"
T_a = 333									"[K]"
sv_a = VOLUME(Air,T=T_a,P=P_a)
s_a = ENTROPY(Air,T=T_a,P=P_a)
h_a = ENTHALPY(Air, T=T_a)
u_a =INTENERGY(Air,T=T_a)

"The air is compressed by supercharging to 137.9 kPa. Isentropically"

P_b = 137.9							"[kPa]"
sv_b = VOLUME(Air,T=T_b,P=P_b)
s_b = ENTROPY(Air,T=T_b,P=P_b)
h_b = ENTHALPY(Air, T=T_b) 
s_b = s_a
u_b =INTENERGY(Air,T=T_b)

"Inlet Conditions - Point 1.  We get there by removing heat in intercooler"

P_1 = P_b						"[kPa]"
T_1 = T_a						"[K]"
sv_1 = volume(Air,T=T_1,P=P_1)
s_1 = entropy(Air,T=T_1,P=P_1)
u_1 = intenergy(Air,T=T_1)
h_1 = enthalpy(Air,T=T_1)
gamma_1 = CP(Air,T=T_1)/CV(Air,T=T_1)
q_remove = h_b - h_a				"Heat removed"
m_1 = V_1/sv_1					"mass of charge"

"Point 2 Conditions"

s_2 = entropy(Air,T=T_2,P=P_2)
s_2= s_1
sv_2 = sv_1/r_c
sv_2 = volume(Air,T=T_2,P=P_2)
u_2 = intenergy(Air,T=T_2)
h_2 = enthalpy(Air,T=T_2)
gamma_2 = CP(Air,T=T_2)/CV(Air,T=T_2)

"Heat Added per Kg mixture - const vol - Point 3a Conditions"

{x_r = 0.05}
mfm = (1-x_r)/( 1+AF)
q_cv = f_cv*mfm*Q_LHV
u_3a = intenergy(Air,T=T_3a)
h_3a = enthalpy(Air,T=T_3a)
s_3a = entropy(Air,T=T_3a,P=P_3a)
q_cv = u_3a - u_2
P_3a/P_2 = T_3a/T_2
sv_3a = sv_2
gamma_3a = CP(Air,T=T_3a)/CV(Air,T=T_3a)

"Heat Added per Kg mixture - constant press - Point 3b Conditions"

q_cp = f_cp*mfm*Q_LHV
h_3b = enthalpy(Air,T=T_3b)
s_3b = entropy(Air,T=T_3b,P=P_3b)
u_3b = intenergy(Air,T=T_3b)
q_cp = h_3b - h_3a
P_3b = P_3a
P_3b*sv_3b = R*T_3b
sv_3b/sv_3a = T_3b/T_3a
gamma_3b = CP(Air,T=T_3b)/CV(Air,T=T_3b)

"Point 4 Conditions.  Get there with an isentropic expansion"

sv_4 = sv_1
sv_4 = volume(Air,T=T_4,P=P_4)
s_4 = entropy(Air,T=T_4,P=P_4)
s_3b=s_4
h_4 = enthalpy(Air,T=T_4)
gamma_4 = CP(Air,T=T_4)/CV(Air,T=T_4)
u_4 = intenergy(Air,T=T_4)

"Now the gas that remains after blowdown expands to fill the cylinder at BC.
 This is point 5.  The expansion is isentropic"

P_e = 103.4
P_5 = P_e
s_5 = entropy(Air,T=T_5, P=P_5)
s_5 = s_4
sv_5 = volume(Air,T=T_5,P=P_5)
h_5 = enthalpy(Air,T=T_5)
u_5 = intenergy(Air,T=T_5)
m_5 = V_1/sv_5					"Mass remaining after blowdown"

		

"Point 6.  We now move the piston to TC.  EV is open.  There is no change in the
  properties, just force some more gas to leave."

T_6 = T_5
P_6 = P_5
sv_6 = sv_5
m_res = V_2/sv_6
x_r = m_res/m_1
h_6 = h_5
s_6 = s_5
x_r1 =(sv_4/sv_5)/r_c

"At this point we have all that is necessary to do some estimates of engine performance.
  We will assume an operating speed of 4000 rpm"

N = 4000/60						"[1/s]"

"Totals of Heat Added and work done"

"Heat"

Q_add = m_1*(q_cv+q_cp)

"Work and Power at the Piston - Indicated"

W_12 = m_1*(u_2-u_1)
W_exp =    m_1*(p_3b*(sv_3b-sv_3a) + u_3b - u_4)
W_cg =    W_exp - W_12
W_pump = (P_1 - P_e)*(V_1-V_2)
W_cn = W_cg + W_pump
Pow_i = W_cn * N / 2
P_hp = Pow_i * convert(kW,hp)

"Work and Power to drive supercharger"

W_super = (1-x_r)*m_1*(h_b-h_a)
Pow_super = W_super * N /2

"Work and Power available in exhaust"

"There are two approaches.  There is a first law analysis.  Then there is an availability analysis.  It is the second of these which is most restrictive."

m_exh = m_1 - m_5
W_exh = m_1*u_4 - m_5*u_5 - m_exh*h_6
W_avail = m_1*u_4 -m_5*u_4 + P_e*m_5*sv_5 - m_exh*h_6
Pow_exh = W_exh * N/2
Pow_avail = W_avail * N /2
Pow_exhp = Pow_exh*convert(kW,hp)
Pow_avhp = Pow_avail*convert(kW,hp)

"Fuel Conversion Efficiency"

eta_fn = W_cn/Q_add					"Net"
eta_fg = W_cg/Q_add					"Gross"

"Imep"

imep_n = W_cn/V_d					"Net"
imep_g = W_cg/V_d					"Gross"