Modelling Steady Flow Energy Equation in Python


Steady Flow Energy Equation (SFEE) is the application of conservation of energy on to an open system. Figure shown below is a schematic of open system in which fluid enters at 𝑖 and exits at 𝑒. The red broken line represents the control surface (CS) of the control volume (CV).


The inlet and exit parameters are mentioned in the table shown below −

Parameter Inlet Exit
Pressure pi pe
Velocity Vi Ve
Density Pi Pe
Specific volume vi ve
Enthalpy hi he
Area Ai Ae
Datum zi ze

For single input and exist systems (as shown above) the SFEE can be written as −

$$\mathrm{\dot{E}_I+\dot{Q}=\dot{E}_e+\dot{W}_{shaft}}$$

where, $\mathrm{\dot{Q}}$ and $\mathrm{\dot{W}_{shaft}}$ shaft represents the rate of heat transfer to and shaft work from the CS of the CV. The $\mathrm{\dot{E}_𝑖}$ and $\mathrm{\dot{E}_𝑒}$ represents the energies which are flowing into and out of the CV with mass. The expanded form of the Eq. 1 is shown in Eq. 2.

$$\mathrm{\dot{m}_I(h_i+\frac{v^{2}_i}{2}+gzi)+\dot{m}=m_e(h_e+\frac{v^{2}_e}{2}+gz_e)\dot{W}_{shaft}}$$

Equations 1 and 2 are for single input and output but if more than one input output are there along with more than one heat interactions then the equations becomes −

$$\mathrm{\sum \dot{E}_I+\sum\dot Q=\sum \dot{E}_e+\dot{W}_{Shaft}}$$

$$\mathrm{\sum(\dot{m}_I(h_i+\frac{v^{2}_i}{2}+))+\sum\dot Q=\sum(\dot{m}_e(h_e+\frac{v^{2}_e}{2}+gze))+\dot{W}_{shaft}}$$

Apart from these equations the mass conservation has to be solved. In fact mass conservation has to be solved first then the energy equation. So for multi input output control volume the net mass entering the system should be equal to the net mass exiting the system.

$$\mathrm{\sum m_i=\sum m_e}$$

There is no straightforward way in which the above equations can be modelled in Python hence, they will be modelled based on the problem in hand. We will make a case type structure of a program in which we will make functions for each missing entry in the equation.

Following functions are developed for single inlet and outlet &mainus;

For the Evaluation of Enthalpy

def Enthaply(T,c):
   """
   Enter temperature in deg C
   """
   return c*(T+273) 

Discharge/mass Flow

def mass_flow(ρ,a,v):
   return ρ*a*v

Inlet Enthalpy

def SFEE_hi(he,vi,ve,zi,ze,Q,W,mi,me):
   """
   h: in kJ/kg
   v: m/s
   z: m/s
   Q: kW
   W: kW
   m: kg/s
   """
   return (me*(he+1.E-3*ve**2/c+1.E-3*g*ze)+W-Q)/mi-(1.E-3*vi**2/2+1.E3*g*zi) 

Exit Enthalpy

def SFEE_he(hi,vi,ve,zi,ze,Q,W,mi,me):
   """
   h: in kJ/kg
   v: m/s
   z: m/s
   Q: kW
   W: kW
   m: kg/s
   """
   return (mi*(hi+1.E-3*vi**2/2+1.E-3*g*zi)-W+Q)/me-(1.E-3*ve**2/2+1.E3*g*ze) 

Heat Transfer

def SFEE_Q(hi,he,vi,ve,zi,ze,W,mi,me):
   """
   h: in kJ/kg
   v: m/s
   z: m/s
   W: kW
   m: kg/s
   """
   return me*(he+1.E-3*ve**2/2+1.E-3*g*ze)-mi*(hi+1.E-3*vi**2/2+1.E3*g*zi)+W 

Shaft Work

def SFEE_W(hi,he,vi,ve,zi,ze,Q,mi,me):
   """
   h: in kJ/kg
   v: m/s
   z: m/s
   Q: kW
   m: kg/s
   """
   return mi*(hi+1.E-3*vi**2/2+1.E-3*g*zi)-me*(he+1.E-3*ve**2/2+1.E3*g*ze)+Q 

Inlet Velocity

def SFEE_vi(hi,he,ve,zi,ze,Q,W,mi,me):
   """
   h: in kJ/kg
   v: m/s
   z: m/s
   Q: kW
   W: kW
   m: kg/s
   W: kW
   """
   a= (me*(he+1.E-3*ve**2/2+1.E-3*g*ze)+W-Q)/mi
   return sqrt(2000*(a-(hi+1.E-3*g*zi))) 

Exit Velocity

def SFEE_ve(hi,he,vi,zi,ze,Q,W,mi,me):
   """
   h: in kJ/kg
   v: m/s
   z: m/s
   Q: kW
   W: kW
   m: kg/s
   W: kW
   """
   a= (mi*(hi+1.E-3*vi**2/2+1.E-3*g*zi)-W+Q)/me
   return sqrt(2000*(a-(he+1.E-3*g*ze)))

Let us take some problems to demonstrate the use of these functions.

Example 1

In an adiabatic nozzle the inlet and exit pressures are 31 and 1 bar and the inlet temperature is 527C. The specific heat of gas is 1 kJ/kg-K and 𝛾 = 1.4. If inlet velocity is negligible then estimate the exit velocity.

Solution: In this case, first we have to evaluate the exit temperature. As the nozzle is adiabatic so exit temperature will be evaluated as −

$$\mathrm{T_2=(\frac{p_2}{p_1})^{\frac{y-1}{y}}}$$

Moreover, as this is nozzle, so:$\mathrm{ 𝑊 = 0, z_i = z_e = 1.0, m_i = m_e=1.0}$

The Python code for this problem is as follows −

from math import *
# Adiabatic exponent
γ=1.4

# Specific heat
c= 1

# Heat and work
Q=W=0

# Inlet temperature and pressure
Ti = 800
pi = 31

# Exit pressure
pe = 1

# datum at inlet and exit
zi=ze=1

# mass flow rate at inlet and exit
mi=me=1

# velocity at inlet
vi=0

# Evaluating exit temperature based on adiabatic condition
Te=Ti*(pe/pi)**(1-1/γ) # in Kelvin

# Evaluating inlet and exit enthalpy
hi=Enthaply(Ti,c)
he=Enthaply(Te,c)

# Calling function to evaluate exit velocity
Ve=SFEE_ve(hi,he,vi,zi,ze,Q,W,mi,me)
print(f"Ve = {round(Ve,3)} m/s") 

The program output will be −

Ve = 1000.093 m/s 

Example 2

Air (𝑅 = 0.287 kJ/kg-K, $\mathrm{c_p}$ = 1.005 kJ/kg-K, and 𝛾 = 1.4) flows sequentially through a compressor, a heater and a turbine as shown in the figure. Volume flow rate of air coming out from the compressor is 2.33 $\mathrm{m^3/s}$ when pressure and temperature are 276 kPa and 316 K respectively. Air is then heated at a same pressure to 703 K in a heater. From heater, air flows through a turbine which produces 1860 kW of power. Heat loss from turbine to the surrounding is 90 kW. Air temperature at the turbine exit in K will be?


Solution − Discharge at compressor exit =2.33 $\mathrm{m^3/s}$, $\mathrm{𝑝_1}$ = 276 kPa, $\mathrm{𝑇_1}$ = 316 K, $\mathrm{𝑝_2}$ = 276 kPa, $\mathrm{𝑇_2}$ = 703 K, $\mathrm{𝑊_𝑡}$ = 1860 kW, $\mathrm{𝑄_𝑡}$ = 90 kW. In this problems as nothing is mentioned about velocity and datum so will consider them to be negligible.

As this is a steady problem, so we have to first find the mass flow rate based on the exit conditions of compressor and directly look into turbine and evaluate the exit enthalpy and finally temperature.

The Python program for the problem is as follows −

from math import *
# Adiabatic exponent
γ=1.4

# Specific heat
c= 1.005

# Characteristic gas const.
R=0.287

# Data at compressor exit
disc =2.33 #m^3/s
p1=276 #kPa
T1=316 #K

# Data at heater exit
p2=276 #kPa
T2=703 #K

# Data for turbine
Wt=1860 #kW
Qt=-90 #kW.

# Evaluating mass flow rate
ρ1=p1/(R*T1)
m=ρ1*disc

# Enthalpy at heater exit
h2=Enthaply(T2,c)

# Velocity and pressure at Turbine exit and inlet
v2=v3=0
z2=z3=0

# obtaining enthalpy at turbine exit
h3=SFEE_he(h2,v2,v3,z2,z3,Qt,Wt,m,m)

# Temperature at turbine exit
T3=h3/c
print(f'T3 = {round(T3,3)} K')

The program output will be −

T3 = 429.364 K

Conclusion

In this tutorial, Steady Flow Energy Equation has been modelled in Python. Different functions have been developed and the implementation has been shown with the help of two examples.

Updated on: 04-Oct-2023

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements