Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Fluegas enthalpy calculation

Flue gas emitted from the stack of fired heaters are the main target for recovery of wasted heat. Energy engineers should calculate the amount of flue gas recoverable energy and decide whether to pursue investment projects. At this time, what energy engineers need is the flue gas enthalpy calculation library.

If know the composition of nitrogen, oxygen, argon, carbon dioxide, and water at atmospheric pressure and the discharge temperature, it is a simple procedure to calculate the enthalpy of each component in the mixed component state using the mixing rule.

Python code of flue gas enthalpy


The following Python code calculates the fluegas entalpy emitted at 500 degC with compositions of 70.0 mol% N2, 15.0 mole% O2, 5.0 mole% Ar, 5.0 mole% CO2, and 5.0 mole% H2O.

def fluegas(temp_given, temp_base, mol_n2, mol_o2, mol_arg, mol_co2, mol_h2o):
    if temp_given < 0 or temp_base < 0 or temp_base > temp_given: return -1
    coeff_a = [6.921525928892, 6.905598931009, 4.964694915254, 8.44682086499, 7.967187267909]
    coeff_b = [0.000264324135, 0.00156659667, 0, 0.00575849121, 0.000876904142]
    coeff_c = [0.000000433542006, -0.000000453431059, 0, -0.00000215927489, 0.000000575161121]
    coeff_d = [-1.17644032E-10, 5.37208504E-11, 0, 3.05898491E-10, -1.47239368E-10]
    mw = [28.0134, 31.9988, 39.948, 44.01, 18.0152]
    wt = [0, 0, 0, 0, 0] 
    temp_given = temp_given * 1.8 + 32
    temp_base = temp_base * 1.8 + 32
    sum_mol = mol_n2 + mol_o2 + mol_arg + mol_co2 + mol_h2o
    mol_n2 = mol_n2 / sum_mol
    mol_o2 = mol_o2 / sum_mol
    mol_arg = mol_arg / sum_mol
    mol_co2 = mol_co2 / sum_mol
    mol_h2o = mol_h2o / sum_mol
    sum_mw = mw[0] * mol_n2 + mw[1] * mol_o2 + mw[2] * mol_arg + mw[3] * mol_co2 + mw[4] * mol_h2o
    wt[0] = mw[0] * mol_n2 / sum_mw
    wt[1] = mw[1] * mol_o2 / sum_mw
    wt[2] = mw[2] * mol_arg / sum_mw
    wt[3] = mw[3] * mol_co2 / sum_mw
    wt[4] = mw[4] * mol_h2o / sum_mw
    sum_h = 0
    for comp in range(5):
        each_ha = coeff_a[comp] * (temp_given - temp_base)
        each_hb = coeff_b[comp] / 2 * (pow(temp_given, 2) - pow(temp_base, 2))
        each_hc = coeff_c[comp] / 3 * (pow(temp_given, 3) - pow(temp_base, 3))
        each_hd = coeff_d[comp] / 4 * (pow(temp_given, 4) - pow(temp_base, 4))
        each_h = (each_ha + each_hb + each_hc + each_hd) / mw[comp] * wt[comp] * 0.556
        sum_h = sum_h + each_h
    return sum_h
enthalpy = fluegas(500,15,0.70, 0.15, 0.05, 0.05, 0.05) 
print("flue gas enthalpy = ", enthalpy, "kcal/kg")

When run the code, you will receive the following results.

flue gas enthalpy =  121.0 kcal/kg

Pump power calculation

A pump is a kind of equipment that consumes a considerable amount of energy in the industrial process. It is mainly driven by a motor, and in many cases, a kW meter or ampere meter is installed so that the power consumption can be calculated, but in many cases, this is not possible.

If know the pumping flow rate and pressure difference, user can calculate the amount of work required by the pump. Of course, the power usage of the motor requires assumptions.

The hydraulic power that drives the pump depends on mass flow rate, liquid density and height difference.

Formula of pump power consumption


Pump power equation is as follows.

W = ρ*Q*h*g/η

where
W = power (kg•m2/s3, ft-lbf/s)
ρ : density of fluid (kg/m3, lbm/ft3)
Q = volumetric flow (m3/s, gpm)
h = head (m or ft) the fluid has to be lifted
g : acceleration of gravity (9.8 m/s2, 32.174 ft/s2)
η = total efficiency (%, η of pump, η of motor)
1. In case of MKS (m/kg/sec/°C/bar/W) units
W = ρ*Q*h*g/η = (1000 kg/m3 * 1000 m3/s * 25 m * 9.8 m/s2) / (3600 * 1000 * 0.8) = 85.1 kW

where,
W : power (W)
ρ : density of fluid (kg/m3)
Q : flow (m3/h)
h : differential head (m)
g : acceleration of gravity (9.8 m/s2)
η : friver efficiency (%)
2. In case of FLS (ft/lb/sec/°F/psi/bt) units
W = ρ*Q*h/η = (62.4 lbm/ft3 * 1000 gpm * 106 ft) / (7.481 gal/ft3 * 33,000 ft-lb/min-hp * 70%) = 38.3 hp

Where,
W : power (hp)
ρ : density of fluid (kg/m3 or lbm/ft3)
Q : flow (gpm)
h : differential head (ft)
g : acceleration of gravity (32.174 ft/s2)
η : friver efficiency (%)

Python code of pump power consumption


The following is a Python example that calculates the pump power.

def pumpower(unit, d, q, h, n):
    if unit == "MKS" and n > 0:
        W = (d * q * h * 9.8) / (3600 * 1000 * n) # kW
    elif unit == "FLS" and n > 0:
        W = (d * q * h) / (7.481 * 33000 * n) # hp
    else:
        pass
    return W

pumppowerMKS = pumpower("MKS", 1000, 1000, 25, 0.8) # 1000 kg/m3, 1000 m3/hr, 25 m, 80%
pumppowerFLS = pumpower("FLS", 62.4, 1000, 106, 0.7) # 62.4 lbm/ft3, 1000 gpm, 106 ft, 70%

print("Pump power = ", pumppowerMKS, " kW")
print("Pump power = ", pumppowerFLS, " hp")

When run the code, you get the results below.

Pump power =  85.069 kW
Pump power =  38.275 hp

Steam properties library

The steam properties library is one of the most important tools used by energy engineers. In the past, we used to refer to Steam tables books, but now there are tools available for multiple platforms, including Windows programs and Excel addins.

IAPWS?


The steam property library expresses actual experimental property results in a regression equation. Standardization is managed by the IAPWS organization (http://www.iapws.org). In Python, Among the many Python packages that follow the IAPWS formula, recommend pyXSteam (https://pypi.org/project/pyXSteam).

Use of pyXSteam


pyXSteam provides (mostly) accurate steam and water properties from 0 ~ 1000 bar and from 0 ~ 2000 °C according to the IAPWS release IF-97. Also includes thermal conductivity and viscosity, which are not part of the IF97 release.
There are no requirements for installing pyXSteam with Python 3.6 and up.
When installing the pyXSteam package on a Windows computer, if Python is already installed and you type "pip install pyXSteam" in the command line window, it will be installed immediately if you are connected to the Internet. The steam properties provided by pyXSteam are as follows.

Property Description
t Temperature (°C or °F)
p Pressure (bar or psi)
h Enthalpy (kJ/kg or btu/lb)
v Specific volume (m3/kg or ft^3/lb)
rho Density (kg/m3 or lb/ft^3)
s Specific entropy (kJ/(kg °C) or btu/(lb °F))
u Specific internal energy (kJ/kg or btu/lb)
Cp Specific isobaric heat capacity (kJ/(kg °C) or btu/(lb °F))
Cv Specific isochoric heat capacity (kJ/(kg °C) or btu/(lb °F))
w Speed of sound (m/s or ft/s)
my Viscosity (N s/m^2 or lbm/ft/hr)
tc Thermal Conductivity (W/(m °C) or btu/(h ft °F))
st Surface Tension (N/m or lb/ft)
x Vapor fraction
vx Vapor Volume Fraction

The unit group supports 3 groups as shown below. Please select one of the three.
steamTable = XSteam(XSteam.UNIT_SYSTEM_MKS) # m/kg/sec/°C/bar/W
steamTable = XSteam(XSteam.UNIT_SYSTEM_FLS) # ft/lb/sec/°F/psi/btu
steamTable = XSteam(XSteam.UNIT_SYSTEM_BARE) # m/kg/sec/K/MPa/W


Python code

Please see below for an example of calculating steam properties using pyXSteam.

from pyXSteam.XSteam import XSteam

steamTable = XSteam(XSteam.UNIT_SYSTEM_FLS) # ft/lb/sec/°F/psi/btu

psat = steamTable.psat_t(337)
print("psat : saturation pressure of steam T = 337 degF = ", psat - 14.696, " psig")

tsat = steamTable.tsat_p(100+14.696)
print("tsat : saturation temperature of steam P = 100 psig = ", tsat, " degF")

h_pt = steamTable.h_pt(100+14.696, 400)
print("h_pt : enthalpy a of steam P = 100 psig and T = 400 degF = ", h_pt, " btu/lb")

h_ps = steamTable.h_ps(100+14.696, 1.635)
print("h_ps : enthalpy a of steam P = 100 psig and S = 1.635 btu/lb-F = ", h_ps, " btu/lb")

s_pt = steamTable.s_pt(100+14.696, 400)
print("s_pt : entropy a of steam P = 100 psig and T = 400 degF = ", s_pt, " btu/lb-F")

s_ph = steamTable.s_ph(100+14.696, 1225)
print("s_ph : entropy a of steam P = 100 psig and H = 1225 btu/lb = ", s_ph, " btu/lb-F")

rho_pt = steamTable.rho_pt(100+14.696, 400)
print("rho_pt : density a of steam P = 100 psig and T = 400 degF = ", rho_pt, " lb/ft3")

Cp_pt = steamTable.Cp_pt(100+14.696, 400)
print("Cp_pt : Specific isobaric heat capacity a of steam P = 100 psig and T = 400 degF = ", Cp_pt, " btu/lb-F")

Cv_pt = steamTable.Cv_pt(100+14.696, 400)
print("Cv_pt : Specific isochoric heat capacity a of steam P = 100 psig and T = 400 degF = ", Cv_pt, " btu/lb-F")

When run the code, you get the results below.

psat : saturation pressure of steam T = 337 degF =  98.647  psig
tsat : saturation temperature of steam P = 100 psig =  337.882  degF
h_pt : enthalpy a of steam P = 100 psig and T = 400 degF =  1225.473  btu/lb
h_ps : enthalpy a of steam P = 100 psig and S = 1.635 btu/lb-F =  1225.517  btu/lb
s_pt : entropy a of steam P = 100 psig and T = 400 degF =  1.635  btu/lb-F
s_ph : entropy a of steam P = 100 psig and H = 1225 btu/lb =  1.634  btu/lb-F
rho_pt : density a of steam P = 100 psig and T = 400 degF =  0.234  lb/ft3
Cp_pt : Specific isobaric heat capacity a of steam P = 100 psig and T = 400 degF =  0.544  btu/lb-F
Cv_pt : Specific isochoric heat capacity a of steam P = 100 psig and T = 400 degF =  0.399  btu/lb-F

Isentropic efficiency of steam turbine

In thermodynamics, an isentropic process is an ideal thermodynamic process that is adiabatic and reversible. In this system, the transfer of work is friction less and there is no net transfer of heat or mass. 

Formula of Isentropic efficiency of steam turbine


The isentropic efficiency is the ratio of actual power to the isentropic power and this isentropic efficiency of a steam turbine can be calculated using the following formula:

η = (hi - ho) / (hi - hos)

Here,
hi     : enthalpy of the steam at the inlet of the turbine (btu/lb) 
ho    : enthalpy of the steam at the outlet of the turbine (btu/lb)
hos   : isentropic enthalpy of the steam at the outlet of the turbine (btu/lb)

Python code


The following is a Python example that calculates the isentropic efficiency of a steam turbine when superheated steam at 600 psig, 700 degF operates the turbine and is extracted at 60 psig, 350 degF.

from pyXSteam.XSteam import XSteam

steamTable = XSteam(XSteam.UNIT_SYSTEM_FLS) # ft/lb/sec/°F/psi/btu

def isentropicefficiency(Pi, Ti, Po, To):
    hi = steamTable.h_pt(Pi+14.696, Ti)
    ho = steamTable.h_pt(Po+14.696, To)
    si = steamTable.s_ph(Pi+14.696, hi)
    hos= steamTable.h_ps(Po+14.696, si)
    
    return (hi - ho) / (hi - hos) * 100

# from 600 psig + 700 degF to 60 psig + 350 degF

When run the code, you get the results below.

hi : enthalpy of steam Pi, Ti (btu/lb) = 1350.1
si : entropy  of steam Pi, Ti (btu/lb-F) = 1.584
ho : enthalpy of steam Pi, Ti (btu/lb) = 1205.5
so : entropy  of steam Po, To (btu/lb-F) = 1.657
hos : isentropic enthalpy of steam Po, si (btu/lb) = 1149.6
isentropicefficiency = (1350.1 - 1205.5) / (1350.1 - 1149.6) * 100 = 71.1
isentropicefficiency = 72.1


print("isentropicefficiency = ", isentropicefficiency(600, 700, 60, 350))

Flash steam generation from hot condensate

Hot condensate is a target for energy savings. If the pressure is high, steam can be recovered by installing a flash drum to recover the required steam pressure. The unrecoverable energy is recovered as depressurized condensate.

If it is not recovered with flash steam, it may cause hammering in the condensate pipe at the downstream end, so installing and operating a flash drum is essential.

Formula of LMTD


Amount of flash steam generated by hot condensate can be calculated using the following formula:

mfs = mc*(hc-hfc)/(hfs-hfc)


Here,
mfs : Flash Steam Flow Rate (kg/h)
mc : Condensate Load (kg/h)
hc : enthalpy of condensate (kcal/kg)
hfs : enthalpy of flash steam (kcal/kg)
hfc : enthalpy of saturated water (kcal/kg)

Python code


The following is a Python example where 100 lb/hr of hot condensate is introduced into a flash drum at a pressure of 120 psig and flashed with 60 psig steam, and approximately 4.91 lb/hr is recovered as flash steam.

from pyXSteam.XSteam import XSteam

steamTable = XSteam(XSteam.UNIT_SYSTEM_FLS) # ft/lb/sec/°F/psi/btu

def flash(mc, Phc, Pf):
    
    hc = steamTable.h_pt(Phc+14.696, steamTable.tsat_p(Phc+14.696)-1)
    hfs = steamTable.h_pt(Pf+14.696, steamTable.tsat_p(Pf+14.696)+1)
    hfc = steamTable.h_pt(Pf+14.696, steamTable.tsat_p(Pf+14.696)-1)

    return mc*(hc-hfc)/(hfs-hfc)

print("flash steam flow = ", flash(100, 120, 60)) # 100 lb/hr, 120 psig, 60 psig

When run the code, you get the results below.

flash steam flow =  4.91