Home
Generals
Unit converter
Periodic table
Molecular weight
Properties
Hydrocarbon properties
Steam properties
Psychrometric properties
Fuel gas LHV
Flue gas enthalpy
Dynamics
Equation of state
Flow convert (mass - volume)
Energy to emission
Flow rate
Darcy friction factor
Mean pressure
Flow compensation
Orifice sizing
Bernoulli equation
Steam pinhone
Control valve CV
Sizing
LMTD
Flash steam
Pump BHP
Performance
Cooling tower capability
Heater efficiency
Compressor efficiency
Turbine efficiency
About
ID
Name
Title
Keyword
Description
<p style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;">Energy engineers frequently calculate the equation of state for gases. The Python example below is an example of calculating the value of an unknown variable using the ideal equation of state and the Van der waals equation of state.</p><h2 style="margin: 0px; position: relative; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-weight: bold; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "Trebuchet MS", Trebuchet, sans-serif; color: rgb(0, 0, 0);"><span style="font-family: Consolas;">Ideal equation of state</span></h2><p style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><b> P = 0.082*T/V</b></p><h2 style="margin: 0px; position: relative; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-weight: bold; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "Trebuchet MS", Trebuchet, sans-serif; color: rgb(0, 0, 0);"><span style="font-family: Consolas;">Van Der Waals equation of state</span></h2><p style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><b> P = (0.082 * T) / (V - b) - a / V^2<br><br></b><b> a = (27 * 0.082^2 * Tc^2) / (64 * Pc)<br></b><b> b = (0.082 * Tc) / (8 * Pc)</b></p><div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><br></div><h2 style="margin: 0px; position: relative; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-weight: bold; font-stretch: normal; font-size: 14px; line-height: normal; font-family: "Trebuchet MS", Trebuchet, sans-serif; color: rgb(0, 0, 0);"><b><span style="font-family: Consolas;">Python code of equation of state </span></b></h2><div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><b><br></b></div><p style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><span style="color: rgb(43, 0, 254);">import numpy as np</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);">def eos(p, v, t, pc, tc, EOS, PVT):</span><br><span style="color: rgb(43, 0, 254);"> </span><br><span style="color: rgb(43, 0, 254);"> delta = 99999; </span><br><span style="color: rgb(43, 0, 254);"> delta_result = 99999; </span><br><span style="color: rgb(43, 0, 254);"> </span><br><span style="color: rgb(43, 0, 254);"> if EOS == "Ideal":</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> if (PVT == 'P'):</span><br><span style="color: rgb(43, 0, 254);"> p = 0.082 * t / v</span><br><span style="color: rgb(43, 0, 254);"> result = p</span><br><span style="color: rgb(43, 0, 254);"> elif PVT == 'V':</span><br><span style="color: rgb(43, 0, 254);"> v = 0.082 * t / p</span><br><span style="color: rgb(43, 0, 254);"> result = v</span><br><span style="color: rgb(43, 0, 254);"> elif PVT == 'T':</span><br><span style="color: rgb(43, 0, 254);"> t = p * v / 0.082</span><br><span style="color: rgb(43, 0, 254);"> result = t</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> elif EOS == "VanderWaals":</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> a = 27*(pow(0.082,2)*pow(tc,2))/(64*pc)</span><br><span style="color: rgb(43, 0, 254);"> b = 0.082*tc/(8*pc)</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> if PVT == 'P':</span><br><span style="color: rgb(43, 0, 254);"> p = (0.082*t)/(v-b)-a/pow(v,2)</span><br><span style="color: rgb(43, 0, 254);"> result = p</span><br><span style="color: rgb(43, 0, 254);"> </span><br><span style="color: rgb(43, 0, 254);"> elif PVT == 'V':</span><br><span style="color: rgb(43, 0, 254);"> v = 0.082 * t / p</span><br><span style="color: rgb(43, 0, 254);"> v_start = v*1-(v*0.5)</span><br><span style="color: rgb(43, 0, 254);"> v_end = v*1+(v*0.5)</span><br><span style="color: rgb(43, 0, 254);"> v_interval = v*1/2000</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> Iteration = np.arange(v_start, v_end, v_interval)</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> for v_temp in Iteration:</span><br><span style="color: rgb(43, 0, 254);"> </span><br><span style="color: rgb(43, 0, 254);"> p1 = p</span><br><span style="color: rgb(43, 0, 254);"> p2 = (0.082*t)/(v_temp-b)-a/pow(v_temp,2)</span><br><span style="color: rgb(43, 0, 254);"> </span><br><span style="color: rgb(43, 0, 254);"> delta = abs(p1 - p2)</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> if (delta < delta_result):</span><br><span style="color: rgb(43, 0, 254);"> delta_result = delta</span><br><span style="color: rgb(43, 0, 254);"> v_result = v_temp </span><br><span style="color: rgb(43, 0, 254);"> </span><br><span style="color: rgb(43, 0, 254);"> v_result = round(v_result*1000)/1000</span><br><span style="color: rgb(43, 0, 254);"> result = v_result</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> elif PVT == 'T':</span><br><span style="color: rgb(43, 0, 254);"> t = (p*1+a/pow(v,2))*(v-b)/0.082</span><br><span style="color: rgb(43, 0, 254);"> result = t</span><br><span style="color: rgb(43, 0, 254);"> else:</span><br><span style="color: rgb(43, 0, 254);"> pass</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);"> return result</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);">P = 10 # Pressure (P, atm) = 10</span><br><span style="color: rgb(43, 0, 254);">V = 2.403 # Volume/mole (V, L/gmol) = 2.403</span><br><span style="color: rgb(43, 0, 254);">T = 298.15 # Temperature (T, K) = 298.15</span><br><span style="color: rgb(43, 0, 254);">Pc = 45.80 # Critical Pressure (Pc, atm) = 45.80</span><br><span style="color: rgb(43, 0, 254);">Tc = 190.7 # Critical Temperature (Tc, K) = 190.7</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);">print(eos(P, V, T, Pc, Tc, 'Ideal', 'P'))</span><br><span style="color: rgb(43, 0, 254);">print(eos(P, V, T, Pc, Tc, 'Ideal', 'V'))</span><br><span style="color: rgb(43, 0, 254);">print(eos(P, V, T, Pc, Tc, 'Ideal', 'T'))</span><br><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);">print(eos(P, V, T, Pc, Tc, 'VanderWaals', 'P'))</span><br><span style="color: rgb(43, 0, 254);">print(eos(P, V, T, Pc, Tc, 'VanderWaals', 'V'))<br></span><span style="color: rgb(43, 0, 254);">print(eos(P, V, T, Pc, Tc, 'VanderWaals', 'T'))</span></p><div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><br></div><div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;">When run the code, you will receive the following results.</div><p style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><span style="color: rgb(43, 0, 254);"><br></span><span style="color: rgb(43, 0, 254);">10.174</span><br><span style="color: rgb(43, 0, 254);">2.445</span><br><span style="color: rgb(43, 0, 254);">293.049</span><br><span style="color: rgb(43, 0, 254);">9.968</span><br><span style="color: rgb(43, 0, 254);">2.395</span><br></p><div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><br></div><div style="color: rgb(68, 68, 68); font-family: Consolas; font-size: 15px;"><span style="color: rgb(43, 0, 254);"><br></span></div>