engineeringkit.thermodynamics#
Ideal, van der Waals and Peng-Robinson gases, the compressibility factor,
Pitzer’s acentric factor and the Joule-Thomson coefficient; Dalton’s
ideal-gas mixtures and Maxwell’s relations; Joule’s first law for closed
systems and steady-flow devices, with isentropic efficiencies, and
Clausius’s entropy; the Carnot bound, the Otto, Diesel, dual, Brayton,
Stirling and Rankine cycles, Rankine plants with reheat and feedwater
heating, gas turbines with regeneration, intercooling and reheat, and the
Curzon-Ahlborn efficiency at maximum power; refrigerator and heat-pump COPs
and the vapour-compression cycle on R-134a; Gouy-Stodola lost work and the
exergy of heat; vapour pressure by Clausius-Clapeyron and Antoine; water and
steam properties from all five regions of IAPWS-IF97 (inverted for entropy
and enthalpy with scipy.optimize.brentq); Carrier’s psychrometrics and
air-conditioning processes; and combustion stoichiometry, heating values and
the adiabatic flame temperature.
engineeringkit.thermodynamics: gases, the two laws, cycles, refrigeration, exergy, steam, moist air and combustion.
Ideal, van der Waals and Peng-Robinson gases, the compressibility factor and
Pitzer’s acentric factor, the Joule-Thomson coefficient, Dalton’s ideal-gas
mixtures and Maxwell’s relations; Joule’s first law for closed systems and
steady-flow devices, with isentropic efficiencies, and Clausius’s entropy;
Carnot, Otto, Diesel, dual, Brayton, Stirling and Rankine cycles, Rankine
plants with reheat and feedwater heating, gas turbines with regeneration,
intercooling and reheat, and the Curzon-Ahlborn efficiency at maximum power;
refrigerator and heat-pump COPs and the vapour-compression cycle on R-134a;
Gouy-Stodola lost work and the exergy of heat; vapour pressure by
Clausius-Clapeyron and Antoine; water and steam properties from IAPWS-IF97
(all five regions); Carrier’s psychrometrics and air-conditioning processes;
and combustion stoichiometry, heating values and the adiabatic flame
temperature. Models are hand-written closed forms; SciPy’s brentq
inverts the property equations.
- class engineeringkit.thermodynamics.BraytonResult(labels, T, p, s, efficiency, compressor_work, turbine_work, heat_in, heat_regenerated, cp)[source]#
Bases:
objectOutput of
engineeringkit.thermodynamics.brayton_cycle().Energies are per kilogram of air (air-standard, constant specific heats).
- Parameters:
labels (tuple)
T (ndarray)
p (ndarray)
s (ndarray)
efficiency (float)
compressor_work (float)
turbine_work (float)
heat_in (float)
heat_regenerated (float)
cp (float)
- T: ndarray#
Temperature of each state [K].
- Type:
ndarray
- property back_work_ratio#
Compressor work over turbine work [-].
- Type:
float
- compressor_work: float#
Work of all compressor stages [J/kg].
- Type:
float
- cp: float#
Isobaric specific heat used [J/(kg K)].
- Type:
float
- efficiency: float#
Thermal efficiency, net work over heat added [-].
- Type:
float
- heat_in: float#
Heat added in the combustor and reheaters [J/kg].
- Type:
float
- property heat_out#
Heat rejected in the exhaust and intercoolers [J/kg].
- Type:
float
- heat_regenerated: float#
Heat passed from the exhaust to the compressed air [J/kg].
- Type:
float
- labels: tuple#
Name of each state, in the order the air meets them.
- Type:
tuple of str
- property net_work#
Turbine work less compressor work [J/kg].
- Type:
float
- p: ndarray#
Pressure of each state [Pa].
- Type:
ndarray
- plot(ax=None)[source]#
Draw the cycle on T-s axes; return
(fig, ax).Constant-pressure processes follow \(s = c_p\ln T + \text{const}\); compressor and turbine stages are straight lines.
- s: ndarray#
Entropy of each state relative to the compressor inlet [J/(kg K)].
- Type:
ndarray
- turbine_work: float#
Work of all turbine stages [J/kg].
- Type:
float
- class engineeringkit.thermodynamics.CubicFluid(name, Tc, pc, omega, molar_mass, cp0)[source]#
Bases:
objectA pure fluid described by the Peng-Robinson equation of state.
- Parameters:
name (
str) – Display name.Tc (
float) – Critical temperature [K].pc (
float) – Critical pressure [Pa].omega (
float) – Pitzer’s acentric factor [-].molar_mass (
float) – Molar mass [kg/mol].cp0 (
float) – Ideal-gas isobaric specific heat [J/(kg K)], taken as constant.
- Tc: float#
- cp0: float#
- molar_mass: float#
- name: str#
- omega: float#
- pc: float#
- class engineeringkit.thermodynamics.OttoCycle(compression_ratio, gamma=1.4)[source]#
Bases:
objectAir-standard Otto cycle with a given compression ratio.
- Parameters:
compression_ratio (
float) – Volumetric compression ratio [-], at least one.gamma (
float) – Ratio of specific heats [-], greater than one.
- compression_ratio: float#
- property efficiency#
Air-standard thermal efficiency [-].
- Type:
float
- gamma: float = 1.4#
- class engineeringkit.thermodynamics.RankineResult(labels, states, efficiency, turbine_work, pump_work, heat_in, heat_out, bleed_fraction)[source]#
Bases:
objectOutput of
engineeringkit.thermodynamics.rankine_cycle().Energies are per kilogram of steam through the boiler.
- Parameters:
labels (tuple)
states (tuple)
efficiency (float)
turbine_work (float)
pump_work (float)
heat_in (float)
heat_out (float)
bleed_fraction (float)
- property back_work_ratio#
Pump work over turbine work [-].
- Type:
float
- bleed_fraction: float#
Fraction of the boiler flow bled to the open feedwater heater [-]; zero without one.
- Type:
float
- efficiency: float#
Thermal efficiency, net work over heat added [-].
- Type:
float
- heat_in: float#
Heat added in the boiler and reheater [J/kg].
- Type:
float
- heat_out: float#
Heat rejected in the condenser [J/kg].
- Type:
float
- labels: tuple#
Name of each state, in the order the water meets them.
- Type:
tuple of str
- property net_work#
Turbine work less pump work [J/kg].
- Type:
float
- plot(ax=None)[source]#
Draw the cycle on the T-s diagram over the water dome; return
(fig, ax).Heat exchanges follow their isobar; pumps and turbine stages are drawn as straight lines between their end states.
- pump_work: float#
Work of all pumps [J/kg].
- Type:
float
- states: tuple#
The state points, matching
labels.- Type:
tuple of SteamState
- summary()[source]#
Efficiency, energies per kilogram, back-work ratio, bleed fraction and exit quality.
- property turbine_exit_quality#
Vapour quality at the condenser inlet [-]; NaN if the steam is still superheated.
- Type:
float
- turbine_work: float#
Turbine work [J/kg], counting the bled steam only up to its bleed point.
- Type:
float
- class engineeringkit.thermodynamics.RefrigerantState(p, T, v, h, s, x, phase)[source]#
Bases:
objectOutput of
engineeringkit.thermodynamics.refrigerant_properties().- Parameters:
p (float)
T (float)
v (float)
h (float)
s (float)
x (float)
phase (str)
- T: float#
Temperature [K].
- Type:
float
- h: float#
Specific enthalpy [J/kg], 200 kJ/kg for saturated liquid at 0 °C (IIR reference).
- Type:
float
- p: float#
Pressure [Pa].
- Type:
float
- phase: str#
"liquid","vapour","mixture"or"supercritical".- Type:
str
- s: float#
Specific entropy [J/(kg K)], 1 kJ/(kg K) for saturated liquid at 0 °C (IIR reference).
- Type:
float
- v: float#
Specific volume [m^3/kg].
- Type:
float
- x: float#
Vapour quality [-] inside the dome; NaN for a single-phase state.
- Type:
float
- class engineeringkit.thermodynamics.SteamState(p, T, v, h, s, u, cp, x, region)[source]#
Bases:
objectOutput of
engineeringkit.thermodynamics.steam_properties().Each field is a float for a scalar call and an array of the broadcast input shape for an array call.
- Parameters:
p (float)
T (float)
v (float)
h (float)
s (float)
u (float)
cp (float)
x (float)
region (int)
- T: float#
Temperature [K].
- Type:
float or ndarray
- cp: float#
Isobaric specific heat [J/(kg K)]; NaN inside the two-phase dome.
- Type:
float or ndarray
- h: float#
Specific enthalpy [J/kg], zero for liquid at the triple point.
- Type:
float or ndarray
- p: float#
Pressure [Pa].
- Type:
float or ndarray
- region: int#
IF97 region, 1 (compressed liquid), 2 (vapour), 3 (near-critical), 4 (wet mixture) or 5 (above 1073.15 K).
- Type:
int or ndarray
- s: float#
Specific entropy [J/(kg K)], zero for liquid at the triple point.
- Type:
float or ndarray
- u: float#
Specific internal energy [J/kg].
- Type:
float or ndarray
- v: float#
Specific volume [m^3/kg].
- Type:
float or ndarray
- x: float#
Vapour quality [-] inside the dome; NaN for a single-phase state.
- Type:
float or ndarray
- class engineeringkit.thermodynamics.VaporCompressionResult(fluid, labels, states, q_evaporator, q_condenser, compressor_work)[source]#
Bases:
objectOutput of
engineeringkit.thermodynamics.vapor_compression_cycle().Energies are per kilogram of refrigerant.
- Parameters:
fluid (CubicFluid)
labels (tuple)
states (tuple)
q_evaporator (float)
q_condenser (float)
compressor_work (float)
- compressor_work: float#
Compressor work [J/kg].
- Type:
float
- property cop_heat_pump#
Condenser heat over compressor work [-], one more than the refrigerator COP.
- Type:
float
- property cop_refrigerator#
Refrigerating effect over compressor work [-].
- Type:
float
- fluid: CubicFluid#
The refrigerant.
- Type:
- labels: tuple#
Compressor inlet, compressor outlet, condenser outlet and evaporator inlet.
- Type:
tuple of str
- plot(ax=None)[source]#
Draw the cycle on the pressure-enthalpy diagram over the fluid’s dome; return
(fig, ax).
- q_condenser: float#
Heat rejected in the condenser [J/kg].
- Type:
float
- q_evaporator: float#
Heat absorbed in the evaporator (refrigerating effect) [J/kg].
- Type:
float
- states: tuple#
The four state points, matching
labels.- Type:
tuple of RefrigerantState
- engineeringkit.thermodynamics.adiabatic_flame_temperature(c, h, o=0.0, *, h_f_fuel, excess_air=0.0, T_air=298.15)[source]#
Temperature of the products of complete, adiabatic, constant-pressure combustion.
- Parameters:
c (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
h (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
o (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
h_f_fuel (float) – Standard enthalpy of formation of the fuel at 298.15 K [J/mol].
excess_air (float, optional) – Excess air as a fraction of the stoichiometric amount [-], nonnegative.
T_air (float, optional) – Temperature of the combustion air [K], 298.15 K to 1500 K; the fuel enters at 298.15 K.
- Returns:
Adiabatic flame temperature [K].
- Return type:
float
Notes
Solves \(\sum_p n_i[h_{f,i} + \Delta h_i(T)] = h_f^{fuel} + \sum_r n_j\Delta h_j(T_{air})\) by Brent’s method, with water as vapour and no dissociation. Above about 2000 K real flames dissociate CO2 and H2O, so the measured temperature is lower (methane in air: about 2230 K at equilibrium against 2327 K here). Every parameter is scalar-only: the balance is solved for one fuel and mixture. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Y. A. Çengel and M. A. Boles, Thermodynamics: An Engineering Approach, 9th ed., New York: McGraw-Hill (2019), Ch. 15.
Examples
>>> round(adiabatic_flame_temperature(1, 4, h_f_fuel=-74.87e3)) 2327
- engineeringkit.thermodynamics.adiabatic_mixing(m_a1, T1, w1, m_a2, T2, w2)[source]#
Adiabatic mixing of two moist-air streams.
- Parameters:
m_a1 (float or array_like) – Dry-air mass flow of each stream [kg/s], nonnegative, not both zero.
m_a2 (float or array_like) – Dry-air mass flow of each stream [kg/s], nonnegative, not both zero.
T1 (float or array_like) – Dry-bulb temperature of each stream [K], positive.
T2 (float or array_like) – Dry-bulb temperature of each stream [K], positive.
w1 (float or array_like) – Humidity ratio of each stream [kg/kg], nonnegative.
w2 (float or array_like) – Humidity ratio of each stream [kg/kg], nonnegative.
- Returns:
Outlet temperature [K] and humidity ratio [kg/kg]. A relative humidity above one at the outlet means fog forms.
- Return type:
tuple of float or ndarray
Notes
Dry air, water and enthalpy are conserved, so the outlet lies on the straight line between the inlets on the psychrometric chart: \(w_3\) and \(h_3\) are the dry-air-weighted means. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> T3, w3 = adiabatic_mixing(1.0, 305.15, 0.015, 3.0, 287.15, 0.006) >>> round(T3 - 273.15, 2), round(w3, 5) (18.55, 0.00825)
- engineeringkit.thermodynamics.adiabatic_saturation_temperature(T, w, p=101325.0)[source]#
Temperature reached by air saturated adiabatically with liquid water at that temperature.
- Parameters:
T (float) – Dry-bulb temperature [K], above 273.15 K.
w (float) – Humidity ratio [kg/kg], nonnegative and at most saturation.
p (float, optional) – Total pressure [Pa], positive.
- Returns:
Adiabatic saturation temperature [K], between the dew point and the dry-bulb temperature; for air-water it is practically the wet-bulb temperature.
- Return type:
float
Notes
Solves \(h(T, w) + (w_s - w)\,h_f(T_{as}) = h(T_{as}, w_s)\) with \(w_s\) the saturated humidity ratio at \(T_{as}\), by Brent’s method. Raises
ValueErrorwhen \(T_{as}\) falls below 0 °C. Every parameter is scalar-only: the search runs for one air state. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.Examples
>>> round(adiabatic_saturation_temperature(303.15, 0.01) - 273.15, 2) 19.6
- engineeringkit.thermodynamics.antoine_vapor_pressure(T, A, B, C)[source]#
Antoine’s vapour-pressure equation, \(\log_{10} p = A - B/(C + T)\).
- Parameters:
T (float or array_like) – Absolute temperature [K], with \(C + T > 0\).
A (float) – Constant [-] for
pin Pa.B (float) – Constant [K].
C (float) – Constant [K] for
Tin kelvin.
- Returns:
Vapour pressure [Pa].
- Return type:
float or ndarray
Notes
Tabulated constants are often for mmHg and °C. To convert, add \(\log_{10} 133.322 = 2.12490\) to \(A\) and subtract 273.15 from \(C\); \(B\) is unchanged. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
C. Antoine, “Tensions des vapeurs; nouvelle relation entre les tensions et les températures,” C. R. Acad. Sci. 107 (1888) 681-684, 778-780, 836-837.
Examples
>>> round(float(antoine_vapor_pressure(373.15, 8.07131 + 2.12490, 1730.63, 233.426 - 273.15)), -1) 101340.0
- engineeringkit.thermodynamics.brayton_cycle(pressure_ratio, T_min, T_max, *, compressor_efficiency=1.0, turbine_efficiency=1.0, regenerator_effectiveness=0.0, compressor_stages=1, turbine_stages=1, cp=1005.0, gamma=1.4, p_min=101325.0)[source]#
Air-standard gas-turbine cycle with regeneration, intercooling and reheat.
- Parameters:
pressure_ratio (float) – Overall compressor pressure ratio [-], greater than one.
T_min (float) – Compressor inlet temperature [K], positive; every intercooler returns the air to it.
T_max (float) – Turbine inlet temperature [K], above the compressor outlet temperature; every reheater returns the gas to it.
compressor_efficiency (float, optional) – Isentropic efficiency of each stage [-] in (0, 1].
turbine_efficiency (float, optional) – Isentropic efficiency of each stage [-] in (0, 1].
regenerator_effectiveness (float, optional) – Regenerator effectiveness [-] in [0, 1]; zero for no regenerator. It heats the compressed air by \(\varepsilon(T_{exhaust} - T_{compressor})\) when the exhaust is the hotter stream and does nothing otherwise.
compressor_stages (int, optional) – Number of compressor stages (with an intercooler between each pair) and turbine stages (with a reheater between each pair), each with the same pressure ratio \(r_p^{1/N}\).
turbine_stages (int, optional) – Number of compressor stages (with an intercooler between each pair) and turbine stages (with a reheater between each pair), each with the same pressure ratio \(r_p^{1/N}\).
cp (float, optional) – Isobaric specific heat [J/(kg K)], positive.
gamma (float, optional) – Ratio of specific heats [-], greater than one.
p_min (float, optional) – Compressor inlet pressure [Pa], positive; it only sets the pressure labels of the states.
- Returns:
State temperatures, pressures and entropies; efficiency; compressor and turbine work, heat added and heat regenerated per kilogram.
- Return type:
Notes
With ideal components and a perfect regenerator the efficiency is \(1 - (T_{min}/T_{max})\,r_p^{(\gamma-1)/\gamma}\), which falls with pressure ratio; with many intercooled and reheated stages it approaches the Ericsson cycle and Carnot’s bound. Pressure losses in the heat exchangers are neglected. Every parameter is scalar-only: one cycle is built with its list of states. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Y. A. Çengel and M. A. Boles, Thermodynamics: An Engineering Approach, 9th ed., New York: McGraw-Hill (2019), Ch. 9.
Examples
>>> res = brayton_cycle(8.0, 300.0, 1300.0, compressor_efficiency=0.8, turbine_efficiency=0.85) >>> round(res.efficiency, 3), round(res.back_work_ratio, 3) (0.274, 0.615)
- engineeringkit.thermodynamics.brayton_efficiency(pressure_ratio, gamma=1.4)[source]#
Ideal Brayton (Joule) cycle efficiency, \(1 - r_p^{(1-\gamma)/\gamma}\).
- Parameters:
pressure_ratio (float or array_like) – Compressor pressure ratio \(r_p\) [-], at least one.
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
- Returns:
Thermal efficiency [-].
- Return type:
float or ndarray
Notes
Heat is added and rejected at constant pressure; compression and expansion are isentropic. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Brayton, “Improvement in gas-engines,” U.S. Patent 125,166 (1872).
- engineeringkit.thermodynamics.carnot_cop_heat_pump(T_hot, T_cold)[source]#
Coefficient of performance of a reversible heat pump, \(T_h/(T_h - T_c)\).
- Parameters:
T_hot (float) – Absolute temperatures of the heated space and the heat source [K], with \(T_h > T_c > 0\).
T_cold (float) – Absolute temperatures of the heated space and the heat source [K], with \(T_h > T_c > 0\).
- Returns:
Maximum heat delivered per unit work [-], one more than the refrigerator COP between the same temperatures.
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
W. Thomson, “On the economy of the heating or cooling of buildings by means of currents of air,” Proc. Phil. Soc. Glasgow 3 (1852) 269-272.
- engineeringkit.thermodynamics.carnot_cop_refrigerator(T_hot, T_cold)[source]#
Coefficient of performance of a reversible refrigerator, \(T_c/(T_h - T_c)\).
- Parameters:
T_hot (float) – Absolute temperatures of the heat sink and the cooled space [K], with \(T_h > T_c > 0\).
T_cold (float) – Absolute temperatures of the heat sink and the cooled space [K], with \(T_h > T_c > 0\).
- Returns:
Maximum heat removed per unit work [-].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.carnot_efficiency(T_hot, T_cold)[source]#
Efficiency of a reversible engine between two reservoirs, \(1 - T_c/T_h\).
- Parameters:
T_hot (float) – Absolute reservoir temperatures [K], with \(T_h > T_c > 0\).
T_cold (float) – Absolute reservoir temperatures [K], with \(T_h > T_c > 0\).
- Returns:
Thermal efficiency [-].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
S. Carnot, Réflexions sur la puissance motrice du feu, Paris: Bachelier (1824).
Examples
>>> carnot_efficiency(600.0, 300.0) 0.5
- engineeringkit.thermodynamics.clausius_clapeyron_pressure(T, T_ref, p_ref, h_fg, R_gas)[source]#
Vapour pressure from the integrated Clausius-Clapeyron relation.
\[p = p_{ref}\exp\left[-\frac{h_{fg}}{R}\left(\frac{1}{T} - \frac{1}{T_{ref}}\right)\right]\]- Parameters:
T (float or array_like) – Absolute temperature [K], positive.
T_ref (float) – Absolute temperature of a known saturation state [K], positive.
p_ref (float) – Saturation pressure at
T_ref[Pa], positive.h_fg (float) – Latent heat of vaporization [J/kg], positive, taken as constant.
R_gas (float) – Specific gas constant of the vapour [J/(kg K)], positive (461.5 for water).
- Returns:
Saturation pressure [Pa].
- Return type:
float or ndarray
Notes
Assumes the vapour is an ideal gas, the liquid volume is negligible and \(h_{fg}\) does not vary with temperature. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
É. Clapeyron, “Mémoire sur la puissance motrice de la chaleur,” J. École Polytechnique 14 (1834) 153-190; R. Clausius, “Über die bewegende Kraft der Wärme,” Ann. Phys. 79 (1850) 368-397, 500-524.
Examples
>>> round(float(clausius_clapeyron_pressure(363.15, 373.15, 101325.0, 2.257e6, 461.5)), -2) 70600.0
- engineeringkit.thermodynamics.clausius_inequality(cyclic_heat_over_temperature)[source]#
Whether a discretized cycle satisfies Clausius’s inequality \(\sum \delta Q/T \le 0\).
- Parameters:
cyclic_heat_over_temperature (array_like) – The terms \(\delta Q_i/T_i\) [J/K] around one cycle, heat into the system positive and \(T_i\) the temperature at the boundary where it crosses.
- Returns:
Trueif the sum is at most \(10^{-12}\) J/K (zero within rounding for a reversible cycle, negative for an irreversible one).- Return type:
bool
Notes
The function checks a supplied sum and does not construct a path. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
R. Clausius, “Über eine veränderte Form des zweiten Hauptsatzes der mechanischen Wärmetheorie,” Ann. Phys. 93 (1854) 481-506.
- engineeringkit.thermodynamics.combustion_products(c, h, o=0.0, excess_air=0.0)[source]#
Moles of each product of complete combustion per mole of fuel.
- Parameters:
c (float or array_like) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
h (float or array_like) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
o (float or array_like) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
excess_air (float or array_like, optional) – Air beyond the stoichiometric amount, as a fraction [-], nonnegative (0.5 is 150% theoretical air).
- Returns:
Moles of
"CO2","H2O","O2"and"N2"[mol/mol fuel].- Return type:
dict
Notes
Rich mixtures, which also produce CO and H2, are not covered. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> {k: round(float(v), 2) for k, v in combustion_products(1, 4).items()} {'CO2': 1.0, 'H2O': 2.0, 'O2': 0.0, 'N2': 7.52}
- engineeringkit.thermodynamics.compressibility_factor(p, T, v)[source]#
Compressibility factor \(Z = pv/(RT)\).
- Parameters:
p (float or array_like) – Pressure [Pa], positive.
T (float or array_like) – Absolute temperature [K], positive.
v (float or array_like) – Molar volume [m^3/mol], positive.
- Returns:
\(Z\) [-]: one for an ideal gas, below one where attraction dominates, above one where the molecules’ own volume does.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(compressibility_factor(101325.0, 273.15, 0.022414)), 4) 1.0
- engineeringkit.thermodynamics.compression_outlet_enthalpy(h_in, h_out_s, efficiency)[source]#
Actual outlet enthalpy of a compressor or pump, \(h_2 = h_1 + (h_{2s} - h_1)/\eta\).
- Parameters:
h_in (float or array_like) – Inlet enthalpy [J/kg].
h_out_s (float or array_like) – Isentropic outlet enthalpy [J/kg].
efficiency (float or array_like) – Isentropic efficiency [-] in (0, 1].
- Returns:
Actual outlet enthalpy [J/kg].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(compression_outlet_enthalpy(300e3, 540e3, 0.8)), 6) 600000.0
- engineeringkit.thermodynamics.compressor_isentropic_efficiency(h_in, h_out, h_out_s)[source]#
Isentropic efficiency of a compressor or pump, \((h_{2s} - h_1)/(h_2 - h_1)\).
- Parameters:
h_in (float or array_like) – Inlet enthalpy [J/kg].
h_out (float or array_like) – Actual outlet enthalpy [J/kg], above
h_in.h_out_s (float or array_like) – Outlet enthalpy of an isentropic compression to the same pressure [J/kg].
- Returns:
Isentropic work over actual work [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(compressor_isentropic_efficiency(300e3, 600e3, 540e3)), 6) 0.8
- engineeringkit.thermodynamics.cooling_coil(T_in, phi_in, T_out, p=101325.0)[source]#
Cooling (and dehumidifying) coil: heat and condensate per kilogram of dry air.
- Parameters:
T_in (float or array_like) – Inlet dry-bulb temperature [K], 273.15 K to 647 K.
phi_in (float or array_like) – Inlet relative humidity [-] in [0, 1].
T_out (float or array_like) – Outlet temperature [K], at least 273.15 K and at most
T_in.p (float, optional) – Total pressure [Pa], positive.
- Returns:
Outlet humidity ratio [kg/kg], heat removed [J/kg dry air] and condensate [kg/kg dry air].
- Return type:
tuple of float or ndarray
Notes
Above the dew point the air is cooled at constant humidity ratio; below it, it leaves saturated at
T_outand the excess water drains as liquid atT_out: \(q = h_1 - h_2 - (w_1 - w_2)h_f(T_2)\). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.Examples
>>> w2, q, water = cooling_coil(303.15, 0.8, 287.15) >>> round(w2, 5), round(q / 1e3, 1), round(water, 5) (0.00997, 45.3, 0.0116)
- engineeringkit.thermodynamics.cooling_tower(m_water, T_water_in, T_water_out, T_air_in, phi_air_in, T_air_out, phi_air_out=1.0, p=101325.0)[source]#
Wet cooling tower: dry-air flow needed and make-up water evaporated.
- Parameters:
m_water (float or array_like) – Warm water flow entering the tower [kg/s], positive.
T_water_in (float or array_like) – Water temperature entering (warm) and leaving (cooled) [K], with
T_water_out < T_water_in, both at least 273.15 K.T_water_out (float or array_like) – Water temperature entering (warm) and leaving (cooled) [K], with
T_water_out < T_water_in, both at least 273.15 K.T_air_in (float or array_like) – Inlet air temperature [K] and relative humidity [-].
phi_air_in (float or array_like) – Inlet air temperature [K] and relative humidity [-].
T_air_out (float or array_like, optional) – Outlet air temperature [K] and relative humidity [-]; the air usually leaves saturated.
phi_air_out (float or array_like, optional) – Outlet air temperature [K] and relative humidity [-]; the air usually leaves saturated.
p (float, optional) – Total pressure [Pa], positive.
- Returns:
Dry-air mass flow [kg/s] and make-up water flow, the water evaporated into the air [kg/s].
- Return type:
tuple of float or ndarray
Notes
From the water balance \(\dot m_{evap} = \dot m_a(w_2 - w_1)\) and the energy balance \(\dot m_a(h_2 - h_1) = \dot m_w h_{f,in} - (\dot m_w - \dot m_{evap})h_{f,out}\), with liquid enthalpies from IF97. The air must gain enthalpy and moisture. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Y. A. Çengel and M. A. Boles, Thermodynamics: An Engineering Approach, 9th ed., New York: McGraw-Hill (2019), Ch. 14.
Examples
>>> m_air, makeup = cooling_tower(100.0, 308.15, 295.15, 293.15, 0.6, 303.15) >>> round(m_air, 1), round(makeup, 2) (97.6, 1.8)
- engineeringkit.thermodynamics.cp_minus_cv(T, v, beta, kappa_T)[source]#
Difference of the specific heats, \(c_p - c_v = Tv\beta^2/\kappa_T\).
- Parameters:
T (float or array_like) – Absolute temperature [K], positive.
v (float or array_like) – Specific volume [m^3/kg], positive.
beta (float or array_like) – Volume expansivity \((1/v)(\partial v/\partial T)_p\) [1/K].
kappa_T (float or array_like) – Isothermal compressibility \(-(1/v)(\partial v/\partial p)_T\) [1/Pa], positive.
- Returns:
\(c_p - c_v\) [J/(kg K)]: never negative, the gas constant \(R\) for an ideal gas, and zero for water at 4 °C where \(\beta = 0\).
- Return type:
float or ndarray
Notes
Follows from \((\partial s/\partial v)_T = (\partial p/\partial T)_v\) and \((\partial s/\partial p)_T = -(\partial v/\partial T)_p\). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Maxwell, Theory of Heat, London: Longmans, Green (1871), Ch. 9.
Examples
>>> round(float(cp_minus_cv(300.0, 287.0 * 300.0 / 1e5, 1 / 300.0, 1 / 1e5)), 6) 287.0
- engineeringkit.thermodynamics.curzon_ahlborn_efficiency(T_hot, T_cold)[source]#
Efficiency of an endoreversible engine at maximum power, \(1 - \sqrt{T_c/T_h}\).
- Parameters:
T_hot (float or array_like) – Absolute reservoir temperatures [K], with \(T_h > T_c > 0\).
T_cold (float or array_like) – Absolute reservoir temperatures [K], with \(T_h > T_c > 0\).
- Returns:
Thermal efficiency at maximum power output [-], independent of the two heat-transfer conductances.
- Return type:
float or ndarray
Notes
The engine is a Carnot cycle that exchanges heat with its reservoirs through finite conductances, \(\dot Q = K\,\Delta T\). Run reversibly it gives Carnot efficiency at zero power; run fast it gives no work at all. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
F. L. Curzon and B. Ahlborn, “Efficiency of a Carnot engine at maximum power output,” Am. J. Phys. 43 (1975) 22-24.
Examples
>>> round(float(curzon_ahlborn_efficiency(838.15, 298.15)), 3) 0.404
- engineeringkit.thermodynamics.dew_point(w, p=101325.0)[source]#
Dew-point temperature: where air of humidity ratio
wsaturates on cooling.- Parameters:
w (float or array_like) – Humidity ratio [kg/kg], positive.
p (float, optional) – Total pressure [Pa], positive.
- Returns:
Dew point [K], the saturation temperature of the vapour’s partial pressure. Dew points below 0 °C (frost points) are not covered.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(dew_point(humidity_ratio(298.15, 0.5))) - 273.15, 2) 13.86
- engineeringkit.thermodynamics.diesel_efficiency(r, cutoff, gamma=1.4)[source]#
Air-standard Diesel cycle efficiency.
\[\eta = 1 - \frac{r_c^\gamma - 1}{\gamma\, r^{\gamma-1}(r_c - 1)}\]- Parameters:
r (float or array_like) – Compression ratio [-].
cutoff (float or array_like) – Cutoff ratio \(r_c = V_3/V_2\) [-], with \(1 \le r_c \le r\).
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
- Returns:
Thermal efficiency [-]; the Otto value at \(r_c = 1\).
- Return type:
float or ndarray
Notes
Heat is added at constant pressure.
expm1keeps cutoffs near one accurate. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
R. Diesel, Theorie und Konstruktion eines rationellen Wärmemotors, Berlin: Springer (1893).
- engineeringkit.thermodynamics.dual_efficiency(r, pressure_ratio, cutoff, gamma=1.4)[source]#
Air-standard dual (limited-pressure) cycle efficiency.
\[\eta = 1 - \frac{\alpha r_c^\gamma - 1}{r^{\gamma-1}[(\alpha - 1) + \gamma\alpha(r_c - 1)]}\]- Parameters:
r (float or array_like) – Compression ratio [-], at least one.
pressure_ratio (float or array_like) – Pressure ratio of the constant-volume heat addition \(\alpha = p_3/p_2\) [-], at least one.
cutoff (float or array_like) – Cutoff ratio of the constant-pressure heat addition \(r_c = V_4/V_3\) [-], with \(1 \le r_c \le r\).
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
- Returns:
Thermal efficiency [-]: the Otto value at \(r_c = 1\) and the Diesel value at \(\alpha = 1\).
- Return type:
float or ndarray
Notes
Heat is added first at constant volume, then at constant pressure, as in a fast diesel engine whose peak pressure is limited. At \(\alpha = r_c = 1\) no heat is added and the Otto limit is returned. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Y. A. Çengel and M. A. Boles, Thermodynamics: An Engineering Approach, 9th ed., New York: McGraw-Hill (2019), Ch. 9.
Examples
>>> round(float(dual_efficiency(18.0, 1.5, 1.2)), 4) 0.6798
- engineeringkit.thermodynamics.entropy_change_isothermal_ideal_gas(n, T, V1, V2)[source]#
Entropy change of an ideal gas at constant temperature, \(nR\ln(V_2/V_1)\).
- Parameters:
n (float or array_like) – Amount of gas [mol], positive.
T (float or array_like) – Absolute temperature [K], positive (it does not enter the result).
V1 (float or array_like) – Initial and final volumes [m^3], positive.
V2 (float or array_like) – Initial and final volumes [m^3], positive.
- Returns:
Entropy change [J/K].
- Return type:
float or ndarray
Notes
Entropy is a state function, so the result holds for any process between the two states, reversible or not. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.entropy_of_mixing(mole_fractions, n=1.0)[source]#
Entropy generated by mixing ideal gases at equal temperature and pressure, \(-nR\sum y_i\ln y_i\).
- Parameters:
mole_fractions (array_like) – Mole fraction of each component in the mixture [-], nonnegative, summing to one.
n (float, optional) – Total amount [mol], positive.
- Returns:
Entropy increase [J/K]; zero for a pure gas, \(nR\ln 2\) for equal amounts of two gases.
- Return type:
float
Notes
Each gas expands from its own volume into the whole at constant temperature, from \(p\) to its partial pressure \(y_i p\). Mixing a gas with itself generates nothing (Gibbs’s paradox). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(entropy_of_mixing([0.5, 0.5]), 4) 5.7631
- engineeringkit.thermodynamics.exergy_destruction(T0, entropy_generation)[source]#
Lost work by the Gouy-Stodola theorem, \(T_0 S_{gen}\).
- Parameters:
T0 (float or array_like) – Absolute environment temperature [K], positive.
entropy_generation (float or array_like) – Entropy generated by the irreversibility [J/K or W/K], nonnegative.
- Returns:
Exergy destroyed [J or W].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
G. Gouy, “Sur l’énergie utilisable,” J. Phys. Théor. Appl. 8 (1889) 501-518; A. Stodola, Die Dampfturbinen, 3rd ed., Berlin: Springer (1905).
- engineeringkit.thermodynamics.exergy_heat(Q, T_source, T0)[source]#
Exergy of heat \(Q\) available at \(T_s\), \(Q(1 - T_0/T_s)\).
- Parameters:
Q (float or array_like) – Heat [J or W].
T_source (float or array_like) – Absolute temperature at which the heat is available [K], positive.
T0 (float or array_like) – Absolute environment (dead-state) temperature [K], positive.
- Returns:
Maximum work obtainable from the heat [J or W, as
Q]; negative for a source colder than the environment.- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Z. Rant, “Exergie, ein neues Wort für ‘technische Arbeitsfähigkeit’,” Forsch. Ingenieurwes. 22 (1956) 36-37.
- engineeringkit.thermodynamics.expansion_outlet_enthalpy(h_in, h_out_s, efficiency)[source]#
Actual outlet enthalpy of a turbine, \(h_2 = h_1 - \eta(h_1 - h_{2s})\).
- Parameters:
h_in (float or array_like) – Inlet enthalpy [J/kg].
h_out_s (float or array_like) – Isentropic outlet enthalpy [J/kg].
efficiency (float or array_like) – Isentropic efficiency [-] in (0, 1].
- Returns:
Actual outlet enthalpy [J/kg].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(expansion_outlet_enthalpy(3000e3, 2500e3, 0.8)), 6) 2600000.0
- engineeringkit.thermodynamics.first_law_heat(delta_u, work_by_system)[source]#
Heat supplied to a closed system, \(Q = \Delta U + W\).
- Parameters:
delta_u (float or array_like) – Change of internal energy [J].
work_by_system (float or array_like) – Work done by the system [J]; negative when work is done on it.
- Returns:
Heat added to the system [J]; negative when heat leaves it.
- Return type:
float or ndarray
Notes
Kinetic and potential energy changes need their own terms. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
J. P. Joule, “On the mechanical equivalent of heat,” Phil. Trans. R. Soc. 140 (1850) 61-82.
- engineeringkit.thermodynamics.fuel_molar_mass(c, h, o=0.0)[source]#
Molar mass of a fuel \(\mathrm{C}_c\mathrm{H}_h\mathrm{O}_o\).
- Parameters:
c (float) – Atoms of carbon, hydrogen and oxygen per molecule [-], nonnegative.
h (float) – Atoms of carbon, hydrogen and oxygen per molecule [-], nonnegative.
o (float) – Atoms of carbon, hydrogen and oxygen per molecule [-], nonnegative.
- Returns:
Molar mass [kg/mol].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(fuel_molar_mass(1, 4), 5) 0.01604
- engineeringkit.thermodynamics.heat_engine_work(Qin, Qout)[source]#
Net work of a heat engine, \(W = Q_{in} - Q_{out}\).
- Parameters:
Qin (float) – Heat absorbed and heat rejected per cycle [J], nonnegative, with \(Q_{in} \ge Q_{out}\).
Qout (float) – Heat absorbed and heat rejected per cycle [J], nonnegative, with \(Q_{in} \ge Q_{out}\).
- Returns:
Net work [J].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.heat_pump_cop(q_hot, work_input)[source]#
Heat-pump coefficient of performance, \(Q_h/W\).
- Parameters:
q_hot (float) – Heat delivered to the warm space [J or W], at least
work_input.work_input (float) – Work (or power) supplied [J or W, as
q_hot], positive.
- Returns:
COP [-], at least one.
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.heating_value(c, h, o=0.0, *, h_f_fuel, water='vapour')[source]#
Heating value of a fuel from enthalpies of formation (Hess’s law).
- Parameters:
c (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
h (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
o (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-].
h_f_fuel (float) – Standard enthalpy of formation of the fuel at 298.15 K [J/mol], in the phase in which it is burned (e.g. -74.87e3 for methane gas, -249.95e3 for liquid octane).
water ({"vapour", "liquid"}, optional) – Phase of the product water: vapour for the lower heating value, liquid for the higher.
- Returns:
Heat released per kilogram of fuel burned at 25 °C with its products cooled back to 25 °C [J/kg].
- Return type:
float
Notes
\(HV = [h_f^{fuel} - c\,h_f^{CO_2} - (h/2)\,h_f^{H_2O}]/M_{fuel}\); the excess air drops out because oxygen and nitrogen have zero enthalpy of formation. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
G. H. Hess, “Thermochemische Untersuchungen,” Ann. Phys. 126 (1840) 385-404, doi:10.1002/andp.18401260620.
Examples
>>> round(heating_value(1, 4, h_f_fuel=-74.87e3) / 1e6, 2) 50.01
- engineeringkit.thermodynamics.humidity_ratio(T, phi, p=101325.0)[source]#
Humidity ratio of moist air, \(w = 0.622\,\phi p_s/(p - \phi p_s)\).
- Parameters:
T (float or array_like) – Dry-bulb temperature [K], 273.15 K to 647 K.
phi (float or array_like) – Relative humidity [-] in [0, 1].
p (float, optional) – Total pressure [Pa], positive; sea level by default.
- Returns:
Mass of water vapour per mass of dry air [kg/kg].
- Return type:
float or ndarray
Notes
The saturation pressure \(p_s(T)\) over liquid water comes from
saturation_pressure()(IF97). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
W. H. Carrier, “Rational psychrometric formulae,” Trans. ASME 33 (1911) 1005-1053.
Examples
>>> round(float(humidity_ratio(298.15, 0.5)), 5) 0.00988
- engineeringkit.thermodynamics.ideal_gas_pressure(n, T, V)[source]#
Ideal-gas pressure \(p = nRT/V\).
- Parameters:
n (float or array_like) – Amount of gas [mol], positive.
T (float or array_like) – Absolute temperature [K], positive.
V (float or array_like) – Volume [m^3], positive.
- Returns:
Pressure [Pa].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
É. Clapeyron, “Mémoire sur la puissance motrice de la chaleur,” J. École Polytechnique 14 (1834) 153-190.
Examples
>>> round(float(ideal_gas_pressure(1.0, 273.15, 0.022414)), 0) 101325.0
- engineeringkit.thermodynamics.ideal_gas_temperature(P, V, n)[source]#
Ideal-gas temperature \(T = pV/(nR)\).
- Parameters:
P (float or array_like) – Pressure [Pa], positive.
V (float or array_like) – Volume [m^3], positive.
n (float or array_like) – Amount of gas [mol], positive.
- Returns:
Absolute temperature [K].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.isentropic_pressure_volume(p1, v1, v2, gamma=1.4)[source]#
Pressure after a reversible adiabatic change of volume, \(p_1(v_1/v_2)^\gamma\).
- Parameters:
p1 (float or array_like) – Initial pressure [Pa], positive.
v1 (float or array_like) – Initial and final volumes in consistent units (e.g. m^3/kg), positive.
v2 (float or array_like) – Initial and final volumes in consistent units (e.g. m^3/kg), positive.
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
- Returns:
Final pressure [Pa].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.isentropic_temperature_ratio(pressure_ratio, gamma=1.4)[source]#
Temperature ratio across an isentropic pressure change, \(T_2/T_1 = (p_2/p_1)^{(\gamma-1)/\gamma}\).
- Parameters:
pressure_ratio (float or array_like) – \(p_2/p_1\) [-], positive.
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
- Returns:
\(T_2/T_1\) [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.joule_thomson_coefficient(T, v, beta, cp)[source]#
Joule-Thomson coefficient of any fluid, \(\mu_{JT} = v(T\beta - 1)/c_p\).
- Parameters:
T (float or array_like) – Absolute temperature [K], positive.
v (float or array_like) – Specific volume [m^3/kg], positive.
beta (float or array_like) – Volume expansivity [1/K].
cp (float or array_like) – Isobaric specific heat [J/(kg K)], positive.
- Returns:
\((\partial T/\partial p)_h\) [K/Pa]: zero for an ideal gas (\(T\beta = 1\)), positive where throttling cools.
- Return type:
float or ndarray
Notes
From \(dh = c_p\,dT + [v - T(\partial v/\partial T)_p]\,dp\), whose second term comes from the Maxwell relation \((\partial s/\partial p)_T = -(\partial v/\partial T)_p\). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Maxwell (1871), as above.
Examples
>>> float(joule_thomson_coefficient(300.0, 0.861, 1 / 300.0, 1005.0)) 0.0
- engineeringkit.thermodynamics.joule_thomson_coefficient_vdw(T, a, b, cp_molar)[source]#
Low-pressure Joule-Thomson coefficient of a van der Waals gas, \((2a/RT - b)/c_{p,m}\).
- Parameters:
T (float or array_like) – Absolute temperature [K], positive.
a (float) – Attraction constant [Pa m^6/mol^2], nonnegative.
b (float) – Excluded volume [m^3/mol], nonnegative.
cp_molar (float) – Molar isobaric heat capacity [J/(mol K)], positive.
- Returns:
\(\mu_{JT} = (\partial T/\partial p)_h\) [K/Pa]. Positive values mean the gas cools when throttled; the sign changes at the inversion temperature \(2a/(Rb)\).
- Return type:
float or ndarray
Notes
This is the zero-pressure limit of \(\mu_{JT} = [T(\partial v/\partial T)_p - v]/c_p\) for the van der Waals equation; at higher pressures the inversion temperature falls. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
J. P. Joule and W. Thomson, “On the thermal effects experienced by air in rushing through small apertures,” Phil. Mag. 4 (1852) 481-492.
Examples
>>> round(float(joule_thomson_coefficient_vdw(300.0, 0.137, 3.87e-5, 29.1)) * 1e5, 3) 0.244
- engineeringkit.thermodynamics.mass_fractions(mole_fractions, molar_masses)[source]#
Mass fractions from mole fractions, \(x_i = y_i M_i/\sum_j y_j M_j\).
- Parameters:
mole_fractions (array_like) – Mole fraction of each component [-], nonnegative, summing to one.
molar_masses (array_like) – Molar mass of each component [kg/mol], positive, same length.
- Returns:
Mass fractions [-].
- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> mass_fractions([0.79, 0.21], [0.028013, 0.031999]).round(4).tolist() [0.7671, 0.2329]
- engineeringkit.thermodynamics.mixing_chamber(mass_flows, enthalpies)[source]#
Adiabatic mixing of several streams: total mass flow and mixed enthalpy.
- Parameters:
mass_flows (array_like) – Mass flow of each inlet stream [kg/s], nonnegative, not all zero.
enthalpies (array_like) – Specific enthalpy of each inlet stream [J/kg], same length.
- Returns:
Outlet mass flow \(\sum \dot m_i\) [kg/s] and outlet enthalpy \(\sum \dot m_i h_i / \sum \dot m_i\) [J/kg].
- Return type:
tuple of float
Notes
No work, no heat and negligible kinetic and potential energy. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> mixing_chamber([1.0, 3.0], [100e3, 300e3]) (4.0, 250000.0)
- engineeringkit.thermodynamics.mixture_molar_mass(mole_fractions, molar_masses)[source]#
Apparent molar mass of a mixture, \(M = \sum y_i M_i\).
- Parameters:
mole_fractions (array_like) – Mole fraction of each component [-], nonnegative, summing to one.
molar_masses (array_like) – Molar mass of each component [kg/mol], positive, same length.
- Returns:
Molar mass [kg/mol]; the mixture’s gas constant is \(R_u/M\) [J/(kg K)].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(mixture_molar_mass([0.79, 0.21], [0.028013, 0.031999]), 5) 0.02885
- engineeringkit.thermodynamics.moist_air_enthalpy(T, w)[source]#
Enthalpy of moist air per kilogram of dry air, \(h = c_{p,a}t + w(h_{g,0} + c_{p,v}t)\).
- Parameters:
T (float or array_like) – Dry-bulb temperature [K], positive.
w (float or array_like) – Humidity ratio [kg/kg], nonnegative.
- Returns:
Enthalpy [J/kg dry air], zero for dry air at 0 °C, with \(c_{p,a} = 1005\), \(c_{p,v} = 1820\) J/(kg K) and \(h_{g,0} = 2501\) kJ/kg, \(t\) in °C.
- Return type:
float or ndarray
Notes
Liquid water at 0 °C has zero enthalpy on this scale, as in IF97, so condensate enthalpies come from
steam_properties(). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.Examples
>>> round(float(moist_air_enthalpy(298.15, 0.01)) / 1e3, 3) 50.59
- engineeringkit.thermodynamics.mole_fractions(mass_fractions, molar_masses)[source]#
Mole fractions from mass fractions, \(y_i = (x_i/M_i)/\sum_j (x_j/M_j)\).
- Parameters:
mass_fractions (array_like) – Mass fraction of each component [-], nonnegative, summing to one.
molar_masses (array_like) – Molar mass of each component [kg/mol], positive, same length.
- Returns:
Mole fractions [-].
- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> mole_fractions([0.5, 0.5], [0.002, 0.032]).round(4).tolist() [0.9412, 0.0588]
- engineeringkit.thermodynamics.nozzle_exit_velocity(h_in, h_out, V_in=0.0)[source]#
Exit velocity of an adiabatic nozzle, \(V_2 = \sqrt{V_1^2 + 2(h_1 - h_2)}\).
- Parameters:
h_in (float or array_like) – Specific enthalpy at the inlet and the exit [J/kg].
h_out (float or array_like) – Specific enthalpy at the inlet and the exit [J/kg].
V_in (float or array_like, optional) – Inlet velocity [m/s], nonnegative.
- Returns:
Exit velocity [m/s].
- Return type:
float or ndarray
Notes
No work and no heat; raises
ValueErrorif the enthalpy rise exceeds the inlet kinetic energy. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.Examples
>>> round(float(nozzle_exit_velocity(3000e3, 2950e3)), 6) 316.227766
- engineeringkit.thermodynamics.nozzle_isentropic_efficiency(h_in, h_out, h_out_s, V_in=0.0)[source]#
Isentropic efficiency of a nozzle, the ratio of exit kinetic energies \(V_2^2/V_{2s}^2\).
- Parameters:
h_in (float or array_like) – Inlet enthalpy [J/kg].
h_out (float or array_like) – Actual exit enthalpy [J/kg].
h_out_s (float or array_like) – Exit enthalpy of an isentropic expansion to the same pressure [J/kg].
V_in (float or array_like, optional) – Inlet velocity [m/s], nonnegative.
- Returns:
Actual over isentropic exit kinetic energy [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(nozzle_isentropic_efficiency(3000e3, 2955e3, 2950e3)), 6) 0.9
- engineeringkit.thermodynamics.otto_efficiency(compression_ratio, gamma=1.4)[source]#
Air-standard Otto cycle efficiency, \(1 - r^{1-\gamma}\).
- Parameters:
compression_ratio (float or array_like) – Volumetric compression ratio \(r = V_1/V_2\) [-], at least one.
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
- Returns:
Thermal efficiency [-].
- Return type:
float or ndarray
Notes
Heat is added and rejected at constant volume. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
Otto, “Gas motor engine,” U.S. Patent 194,047 (1877).
- engineeringkit.thermodynamics.partial_pressures(mole_fractions, p)[source]#
Dalton’s partial pressures, \(p_i = y_i p\).
- Parameters:
mole_fractions (array_like) – Mole fraction of each component [-], nonnegative, summing to one.
p (float) – Total pressure [Pa], positive.
- Returns:
Partial pressure of each component [Pa], summing to
p.- Return type:
ndarray
Notes
Each component behaves as if it alone filled the volume at the mixture temperature. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
J. Dalton, “Experimental essays on the constitution of mixed gases,” Mem. Lit. Phil. Soc. Manchester 5 (1802) 535-602.
Examples
>>> partial_pressures([0.79, 0.21], 100e3).round(1).tolist() [79000.0, 21000.0]
- engineeringkit.thermodynamics.peng_robinson_compressibility(T, p, Tc, pc, omega, phase='vapour')[source]#
Compressibility factor \(Z = pv/(RT)\) from the Peng-Robinson cubic.
- Parameters:
T (float) – Absolute temperature [K], positive.
p (float) – Pressure [Pa], positive.
Tc (float) – Critical temperature [K], critical pressure [Pa] and acentric factor [-].
pc (float) – Critical temperature [K], critical pressure [Pa] and acentric factor [-].
omega (float) – Critical temperature [K], critical pressure [Pa] and acentric factor [-].
phase ({"vapour", "liquid"}, optional) – Which root to return where the cubic has three: the largest (vapour) or the smallest (liquid). With one real root it is returned for either.
- Returns:
Compressibility factor [-].
- Return type:
float
Notes
The cubic \(Z^3 - (1 - B)Z^2 + (A - 3B^2 - 2B)Z - (AB - B^2 - B^3) = 0\) with \(A = a\alpha p/(RT)^2\) and \(B = bp/(RT)\) is solved with
numpy.roots(). Which root is the stable phase is decided by the saturation pressure (peng_robinson_saturation_pressure()). Every parameter is scalar-only: a root is chosen for one state. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
D.-Y. Peng and D. B. Robinson (1976), as above.
Examples
>>> round(peng_robinson_compressibility(300.0, 101325.0, 190.56, 4.599e6, 0.011), 4) 0.9978
- engineeringkit.thermodynamics.peng_robinson_pressure(T, v, Tc, pc, omega)[source]#
Peng-Robinson pressure from temperature and molar volume.
- Parameters:
T (float or array_like) – Absolute temperature [K], positive.
v (float or array_like) – Molar volume [m^3/mol], larger than the co-volume \(b = 0.07780\,RT_c/p_c\).
Tc (float) – Critical temperature [K], positive.
pc (float) – Critical pressure [Pa], positive.
omega (float) – Acentric factor [-], in [-0.5, 1.5].
- Returns:
Pressure [Pa].
- Return type:
float or ndarray
Notes
At the critical point the critical isotherm has a horizontal inflection and the critical compressibility is 0.3074, nearer real fluids than van der Waals’s 3/8. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
D.-Y. Peng and D. B. Robinson, “A new two-constant equation of state,” Ind. Eng. Chem. Fundam. 15 (1976) 59-64.
Examples
>>> round(float(peng_robinson_pressure(300.0, 0.024, 190.56, 4.599e6, 0.011)), -1) 103700.0
- engineeringkit.thermodynamics.peng_robinson_saturation_pressure(T, Tc, pc, omega)[source]#
Vapour pressure from the Peng-Robinson equation: equal liquid and vapour fugacities.
- Parameters:
T (float) – Absolute temperature [K], from \(0.45\,T_c\) to \(0.9999\,T_c\).
Tc (float) – Critical temperature [K], critical pressure [Pa] and acentric factor [-].
pc (float) – Critical temperature [K], critical pressure [Pa] and acentric factor [-].
omega (float) – Critical temperature [K], critical pressure [Pa] and acentric factor [-].
- Returns:
Saturation pressure [Pa].
- Return type:
float
Notes
Between the two spinodal pressures, where \((\partial p/\partial v)_T = 0\), the cubic has a liquid and a vapour root; Brent’s method finds the pressure where their fugacity coefficients are equal. That is Maxwell’s equal-area rule in another form. Every parameter is scalar-only: the search runs on one isotherm. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
D.-Y. Peng and D. B. Robinson (1976), as above.
Examples
>>> round(peng_robinson_saturation_pressure(0.7 * 190.56, 190.56, 4.599e6, 0.011) / 4.599e6, 4) 0.0981
- engineeringkit.thermodynamics.pitzer_acentric_factor(p_sat_07, pc)[source]#
Pitzer’s acentric factor, \(\omega = -\log_{10}[p_s(0.7\,T_c)/p_c] - 1\).
- Parameters:
p_sat_07 (float or array_like) – Vapour pressure at \(0.7\,T_c\) [Pa], positive.
pc (float or array_like) – Critical pressure [Pa], positive.
- Returns:
Acentric factor [-]: zero for the simple fluids argon, krypton and xenon, whose reduced vapour pressure at \(T_r = 0.7\) is 0.1, and larger for less spherical molecules.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
K. S. Pitzer, D. Z. Lippmann, R. F. Curl, C. M. Huggins and D. E. Petersen, “The volumetric and thermodynamic properties of fluids. II. Compressibility factor, vapor pressure and entropy of vaporization,” J. Am. Chem. Soc. 77 (1955) 3433-3440.
Examples
>>> round(float(pitzer_acentric_factor(0.1 * 4.86e6, 4.86e6)), 12) 0.0
- engineeringkit.thermodynamics.pitzer_virial_compressibility(T, p, Tc, pc, omega)[source]#
Generalized second-virial compressibility, \(Z = 1 + (B^0 + \omega B^1)\,p_r/T_r\).
- Parameters:
T (float or array_like) – Absolute temperature [K], positive.
p (float or array_like) – Pressure [Pa], positive.
Tc (float) – Critical temperature [K], positive.
pc (float) – Critical pressure [Pa], positive.
omega (float) – Acentric factor [-].
- Returns:
Compressibility factor [-].
- Return type:
float or ndarray
Notes
Abbott’s fits \(B^0 = 0.083 - 0.422/T_r^{1.6}\) and \(B^1 = 0.139 - 0.172/T_r^{4.2}\) of the Pitzer correlation for the second virial coefficient. Truncated after the second virial coefficient, it holds for gases at low to moderate reduced pressure (roughly \(v_r > 2\)), not for liquids. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
J. M. Smith, H. C. Van Ness and M. M. Abbott, Introduction to Chemical Engineering Thermodynamics, 7th ed., New York: McGraw-Hill (2005), Sec. 3.7.
Examples
>>> round(float(pitzer_virial_compressibility(510.0, 2.5e6, 425.1, 3.796e6, 0.2)), 4) 0.8789
- engineeringkit.thermodynamics.rankine_cycle(p_boiler, p_condenser, T_turbine_inlet=None, *, reheat_pressure=None, T_reheat=None, feedwater_pressure=None, turbine_efficiency=1.0, pump_efficiency=1.0)[source]#
Rankine steam cycle with optional superheat, reheat and an open feedwater heater.
- Parameters:
p_boiler (float) – Boiler (turbine inlet) pressure [Pa], at most 100 MPa.
p_condenser (float) – Condenser pressure [Pa], from 611.213 Pa to below
p_boiler.T_turbine_inlet (float, optional) – Turbine inlet temperature [K], above saturation (or above the critical temperature for a supercritical boiler). Omitted, the turbine takes saturated vapour, which needs a subcritical boiler.
reheat_pressure (float, optional) – Pressure [Pa] at which the steam leaves the high-pressure turbine for the reheater, between the condenser and boiler pressures.
T_reheat (float, optional) – Reheater outlet temperature [K]; given with
reheat_pressure.feedwater_pressure (float, optional) – Pressure [Pa] of an open (direct-contact) feedwater heater, between the condenser and boiler pressures and not equal to
reheat_pressure. Steam is bled from the turbine at this pressure; the heater delivers saturated liquid.turbine_efficiency (float, optional) – Isentropic efficiencies [-] in (0, 1], applied to every turbine section and every pump.
pump_efficiency (float, optional) – Isentropic efficiencies [-] in (0, 1], applied to every turbine section and every pump.
- Returns:
State points, efficiency, turbine, pump, boiler and condenser energies per kilogram of boiler steam, and the bleed fraction.
- Return type:
Notes
The condenser delivers saturated liquid. The bleed fraction \(y\) follows from the heater’s energy balance, \(y h_{bleed} + (1 - y) h_{pump\,1} = h_f(p_{fwh})\). Each turbine section between two of the pressures (boiler, reheat, bleed, condenser) is expanded with
turbine_efficiencyfrom its own inlet state. Properties come fromsteam_properties()(IAPWS-IF97). Every parameter is scalar-only: one plant is solved state by state. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
Y. A. Çengel and M. A. Boles, Thermodynamics: An Engineering Approach, 9th ed., New York: McGraw-Hill (2019), Ch. 10; M. J. Moran et al., Fundamentals of Engineering Thermodynamics, 9th ed., Wiley (2018), Ch. 8.
Examples
>>> res = rankine_cycle(15e6, 10e3, 873.15, reheat_pressure=4e6, T_reheat=873.15) >>> round(res.efficiency, 3), round(res.turbine_exit_quality, 3) (0.45, 0.896)
- engineeringkit.thermodynamics.rankine_ideal_efficiency(h1, h2, h3, h4)[source]#
Ideal Rankine cycle efficiency from the four state enthalpies.
- Parameters:
h1 (float) – Pump outlet (boiler inlet) enthalpy [J/kg].
h2 (float) – Boiler outlet (turbine inlet) enthalpy [J/kg].
h3 (float) – Turbine outlet (condenser inlet) enthalpy [J/kg].
h4 (float) – Condenser outlet (pump inlet) enthalpy [J/kg].
- Returns:
\([(h_2 - h_3) - (h_1 - h_4)]/(h_2 - h_1)\) [-].
- Return type:
float
Notes
The enthalpies can come from
steam_properties(). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
W. J. M. Rankine, A Manual of the Steam Engine and Other Prime Movers, London: Griffin (1859).
- engineeringkit.thermodynamics.refrigerant_properties(fluid, p, T=None, *, x=None, s=None, h=None)[source]#
State of a Peng-Robinson fluid from pressure and one other property.
- Parameters:
fluid (CubicFluid) – The fluid, e.g.
R134A.p (float) – Pressure [Pa], positive.
T (Exactly one of) – Temperature [K], from \(0.45\,T_c\) to \(2.5\,T_c\), for a single-phase state.
x (float, optional) – Vapour quality [-] in [0, 1] for a saturated mixture; needs
pon the saturation line between \(0.45\,T_c\) and \(0.9999\,T_c\) (up to about \(0.999\,p_c\)).s (float, optional) – Specific entropy [J/(kg K)], e.g. after an isentropic compressor.
h (float, optional) – Specific enthalpy [J/kg], e.g. after an expansion valve.
T
x
given. (s and h is)
- Returns:
Pressure, temperature, specific volume, enthalpy, entropy, quality (NaN outside the dome) and phase.
- Return type:
Notes
Enthalpy and entropy are the ideal gas with constant
fluid.cp0plus the Peng-Robinson departure functions\[h - h^{ig} = RT(Z - 1) + \frac{T\,d(a\alpha)/dT - a\alpha}{2\sqrt2\,b} \ln\frac{Z + (1 + \sqrt2)B}{Z + (1 - \sqrt2)B},\]\[s - s^{ig} = R\ln(Z - B) + \frac{d(a\alpha)/dT}{2\sqrt2\,b} \ln\frac{Z + (1 + \sqrt2)B}{Z + (1 - \sqrt2)B},\]shifted to the IIR reference (200 kJ/kg and 1 kJ/(kg K) for saturated liquid at 0 °C). Given
T, the phase is liquid at or above the saturation pressure and vapour below it. Givensorh, the temperature is found by Brent’s method. Peng-Robinson liquid volumes are typically 5-15% off; enthalpy differences are good to a few percent. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
D.-Y. Peng and D. B. Robinson (1976), as above.
Examples
>>> st = refrigerant_properties(R134A, 0.14e6, x=1.0) >>> round(st.T - 273.15, 1), st.phase (-18.7, 'mixture')
- engineeringkit.thermodynamics.refrigeration_cop(q_cold, work_input)[source]#
Refrigerator coefficient of performance, \(Q_c/W\).
- Parameters:
q_cold (float) – Heat removed from the cold space [J or W], nonnegative.
work_input (float) – Work (or power) supplied [J or W, as
q_cold], positive.
- Returns:
COP [-].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
J. Perkins, “Apparatus and means for producing ice, and in cooling fluids,” British Patent 6662 (1834).
- engineeringkit.thermodynamics.relative_humidity(T, w, p=101325.0)[source]#
Relative humidity \(\phi = p_v/p_s(T)\) from the humidity ratio.
- Parameters:
T (float or array_like) – Dry-bulb temperature [K], 273.15 K to 647 K.
w (float or array_like) – Humidity ratio [kg/kg], nonnegative.
p (float, optional) – Total pressure [Pa], positive.
- Returns:
Relative humidity [-]; above one the air is supersaturated and condensate (fog) forms.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.reversible_isothermal_work_ideal_gas(n, T, V1, V2)[source]#
Work done by an ideal gas in a reversible isothermal process, \(nRT\ln(V_2/V_1)\).
- Parameters:
n (float or array_like) – Amount of gas [mol], positive.
T (float or array_like) – Absolute temperature [K], positive.
V1 (float or array_like) – Initial and final volumes [m^3], positive.
V2 (float or array_like) – Initial and final volumes [m^3], positive.
- Returns:
Work done by the gas [J], equal to the heat absorbed, \(T\Delta S\).
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.saturation_pressure(T)[source]#
Saturation (vapour) pressure of water, IF97 region 4.
- Parameters:
T (float or array_like) – Absolute temperature [K], from 273.15 K to the critical 647.096 K.
- Returns:
Saturation pressure [Pa].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
W. Wagner et al., “The IAPWS Industrial Formulation 1997 for the thermodynamic properties of water and steam,” J. Eng. Gas Turbines Power 122 (2000) 150-182.
Examples
>>> round(float(saturation_pressure(373.15)), 1) 101418.0
- engineeringkit.thermodynamics.saturation_temperature(p)[source]#
Saturation temperature of water, IF97 region 4.
- Parameters:
p (float or array_like) – Pressure [Pa], from 611.213 Pa (0 °C) to the critical 22.064 MPa.
- Returns:
Saturation (boiling) temperature [K].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(saturation_temperature(101325.0)) - 273.15, 3) 99.974
- engineeringkit.thermodynamics.specific_enthalpy_ideal_gas(T, cp)[source]#
Specific enthalpy \(h = c_p T\) of a calorically perfect gas.
- Parameters:
T (float or array_like) – Absolute temperature [K], nonnegative.
cp (float or array_like) – Isobaric specific heat [J/(kg K)], positive.
- Returns:
Specific enthalpy [J/kg], referred to zero at 0 K. With the same reference, \(h - u = (c_p - c_v)T = RT\).
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.specific_internal_energy_ideal_gas(T, cv)[source]#
Specific internal energy \(u = c_v T\) of a calorically perfect gas.
- Parameters:
T (float or array_like) – Absolute temperature [K], nonnegative.
cv (float or array_like) – Isochoric specific heat [J/(kg K)], positive.
- Returns:
Specific internal energy [J/kg], referred to zero at 0 K.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.steady_flow_work(h_in, h_out, *, q=0.0, V_in=0.0, V_out=0.0, z_in=0.0, z_out=0.0)[source]#
Shaft work per unit mass of a steady-flow device from its energy balance.
\[w = q + (h_{in} - h_{out}) + \tfrac12(V_{in}^2 - V_{out}^2) + g(z_{in} - z_{out})\]- Parameters:
h_in (float or array_like) – Specific enthalpy at the inlet and the outlet [J/kg].
h_out (float or array_like) – Specific enthalpy at the inlet and the outlet [J/kg].
q (float or array_like, optional) – Heat added per unit mass [J/kg]; negative for heat lost.
V_in (float or array_like, optional) – Mean flow velocity at the inlet and the outlet [m/s], nonnegative.
V_out (float or array_like, optional) – Mean flow velocity at the inlet and the outlet [m/s], nonnegative.
z_in (float or array_like, optional) – Elevation of the inlet and the outlet [m].
z_out (float or array_like, optional) – Elevation of the inlet and the outlet [m].
- Returns:
Work done by the fluid per unit mass [J/kg]: positive for a turbine, negative for a compressor or pump.
- Return type:
float or ndarray
Notes
One inlet, one outlet, steady state. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(steady_flow_work(3000e3, 2500e3)), 6) 500000.0
- engineeringkit.thermodynamics.steam_properties(p, T=None, *, x=None, s=None, h=None)[source]#
State of water or steam from pressure and one other property (IAPWS-IF97).
- Parameters:
p (float or array_like) – Pressure [Pa], positive and at most 100 MPa (50 MPa above 1073.15 K).
T (Exactly one of) – Temperature [K], 273.15 K to 2273.15 K, for a single-phase state.
x (float or array_like, optional) – Vapour quality [-] in [0, 1] for a saturated mixture; needs 611.213 Pa <=
p<= 22.064 MPa (the critical pressure).s (float or array_like, optional) – Specific entropy [J/(kg K)], e.g. after an isentropic turbine.
h (float or array_like, optional) – Specific enthalpy [J/kg], e.g. after a throttling valve.
T
x
broadcast (s and h is given. Arrays)
p. (against)
- Returns:
Pressure, temperature, specific volume, enthalpy, entropy, internal energy, isobaric heat capacity (NaN in the dome), quality (NaN outside it) and the IF97 region. Scalar inputs give float fields; array inputs give arrays of the broadcast shape, one state per element.
- Return type:
Notes
Given
T, the phase is liquid ifpis at or above the saturation pressure and vapour below it; a state exactly on the saturation line needsx. Region 3 (above 350 °C and above the B23 boundary pressure) is a Helmholtz function of density and temperature, so its density is found by Brent’s method on the isotherm, taking the liquid or vapour root of its van der Waals loop below the critical temperature. Region 5 (above 1073.15 K) is a Gibbs function like region 2, valid to 50 MPa. Givensorh, the temperature is found by Brent’s method, since both rise monotonically with temperature at fixed pressure. Array inputs are evaluated element by element. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
W. Wagner et al., “The IAPWS Industrial Formulation 1997 for the thermodynamic properties of water and steam,” J. Eng. Gas Turbines Power 122 (2000) 150-182; IAPWS, Revised Release on the IAPWS Industrial Formulation 1997, R7-97 (2007, 2012), for region 5 to 50 MPa.
Examples
>>> st = steam_properties(10e6, 773.15) >>> round(st.h / 1e3, 1), round(st.s / 1e3, 4), st.region (3375.1, 6.5993, 2) >>> steam_properties(1e5, [300.0, 400.0, 1500.0]).region.tolist() [1, 2, 5]
- engineeringkit.thermodynamics.stirling_efficiency(T_hot, T_cold, compression_ratio, gamma=1.4, regenerator_effectiveness=1.0)[source]#
Ideal-gas Stirling cycle efficiency with an imperfect regenerator.
\[\eta = \frac{(T_h - T_c)\ln r}{T_h \ln r + (1 - \varepsilon)(T_h - T_c)/(\gamma - 1)}\]- Parameters:
T_hot (float or array_like) – Temperatures of the isothermal expansion and compression [K], with \(T_h > T_c > 0\).
T_cold (float or array_like) – Temperatures of the isothermal expansion and compression [K], with \(T_h > T_c > 0\).
compression_ratio (float or array_like) – Volume ratio \(r = V_{max}/V_{min}\) [-], greater than one.
gamma (float or array_like, optional) – Ratio of specific heats [-], greater than one.
regenerator_effectiveness (float or array_like, optional) – Fraction \(\varepsilon\) [-] in [0, 1] of the constant-volume heat rejected on cooling that the regenerator returns on heating.
- Returns:
Thermal efficiency [-]; Carnot’s \(1 - T_c/T_h\) for a perfect regenerator, whatever the compression ratio.
- Return type:
float or ndarray
Notes
Two isotherms joined by two constant-volume processes. The work is \(R(T_h - T_c)\ln r\) per unit mass; the external heat is the isothermal heat \(RT_h\ln r\) plus the part of the constant-volume heating \(c_v(T_h - T_c)\) that the regenerator does not supply. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
R. Stirling, “Improvements for diminishing the consumption of fuel,” British Patent 4081 (1816).
Examples
>>> round(float(stirling_efficiency(900.0, 300.0, 3.0)), 4) # Carnot's 1 - 300/900 0.6667 >>> round(float(stirling_efficiency(900.0, 300.0, 3.0, regenerator_effectiveness=0.0)), 4) 0.2649
- engineeringkit.thermodynamics.stoichiometric_air_fuel_ratio(c, h, o=0.0)[source]#
Mass of air per mass of fuel for complete combustion with no excess air.
- Parameters:
c (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-], nonnegative, needing some oxygen.
h (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-], nonnegative, needing some oxygen.
o (float) – Atoms of carbon, hydrogen and oxygen per fuel molecule [-], nonnegative, needing some oxygen.
- Returns:
\(4.76\,a\,M_{air}/M_{fuel}\) [kg air/kg fuel], with \(a = c + h/4 - o/2\) mol of oxygen per mol of fuel.
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(stoichiometric_air_fuel_ratio(8, 18), 2) # octane 15.09
- engineeringkit.thermodynamics.thermal_efficiency(Qin, Qout)[source]#
Thermal efficiency from the heat flows, \(1 - Q_{out}/Q_{in}\).
- Parameters:
Qin (float) – Heat absorbed [J], positive.
Qout (float) – Heat rejected [J], nonnegative and at most
Qin.
- Returns:
Thermal efficiency [-].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
- engineeringkit.thermodynamics.throttle_steam(state, p_out)[source]#
State of water or steam after a throttling valve: same enthalpy, lower pressure.
- Parameters:
state (SteamState) – Inlet state, e.g. from
steam_properties().p_out (float) – Outlet pressure [Pa], positive and at most the inlet pressure.
- Returns:
Outlet state with \(h_2 = h_1\); its temperature drop is the Joule-Thomson effect and its entropy rise the lost work.
- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> out = throttle_steam(steam_properties(1e6, x=0.0), 1e5) >>> round(out.x, 4) 0.1529
- engineeringkit.thermodynamics.turbine_isentropic_efficiency(h_in, h_out, h_out_s)[source]#
Isentropic efficiency of a turbine, \((h_1 - h_2)/(h_1 - h_{2s})\).
- Parameters:
h_in (float or array_like) – Inlet enthalpy [J/kg].
h_out (float or array_like) – Actual outlet enthalpy [J/kg].
h_out_s (float or array_like) – Outlet enthalpy of an isentropic expansion to the same pressure [J/kg], below
h_in.
- Returns:
Actual work over isentropic work [-].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> round(float(turbine_isentropic_efficiency(3000e3, 2600e3, 2500e3)), 6) 0.8
- engineeringkit.thermodynamics.van_der_waals_critical_point(a, b)[source]#
Critical temperature, pressure and molar volume of a van der Waals gas.
- Parameters:
a (float) – Attraction constant [Pa m^6/mol^2], positive.
b (float) – Excluded volume [m^3/mol], positive.
- Returns:
\(T_c = 8a/(27Rb)\) [K], \(p_c = a/(27b^2)\) [Pa] and \(v_c = 3b\) [m^3/mol], the point where the critical isotherm has a horizontal inflection.
- Return type:
tuple of float
Notes
The critical compressibility \(p_c v_c/(RT_c) = 3/8\) is the same for every van der Waals gas; real gases are nearer 0.27-0.29. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
Examples
>>> Tc, pc, vc = van_der_waals_critical_point(0.3640, 4.267e-5) >>> round(Tc, 1), round(pc / 1e6, 2) (304.0, 7.4)
- engineeringkit.thermodynamics.van_der_waals_pressure(n, T, V, a, b)[source]#
Van der Waals pressure \(p = nRT/(V - nb) - an^2/V^2\).
- Parameters:
n (float or array_like) – Amount of gas [mol], positive.
T (float or array_like) – Absolute temperature [K], positive.
V (float or array_like) – Volume [m^3], larger than the excluded volume \(nb\).
a (float) – Attraction constant [Pa m^6/mol^2], nonnegative.
b (float) – Excluded (co-)volume [m^3/mol], nonnegative.
- Returns:
Pressure [Pa]. With
a = b = 0this is the ideal-gas pressure.- Return type:
float or ndarray
Notes
Below the critical temperature an isotherm has a loop in which \(\partial p/\partial V > 0\); those states are unstable, and the real fluid splits into liquid and vapour at the pressure given by Maxwell’s equal-area rule. Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.
References
J. D. van der Waals, Over de continuïteit van den gas- en vloeistoftoestand, thesis, Leiden (1873).
Examples
>>> round(float(van_der_waals_pressure(1.0, 300.0, 1e-3, 0.3640, 4.267e-5)), -2) 2241500.0
- engineeringkit.thermodynamics.vapor_compression_cycle(p_evaporator, p_condenser, *, fluid=CubicFluid(name='R-134a', Tc=374.2, pc=4059000.0, omega=0.327, molar_mass=0.10203, cp0=852.0), superheat=0.0, subcooling=0.0, compressor_efficiency=1.0)[source]#
Vapour-compression refrigeration cycle on a Peng-Robinson refrigerant.
- Parameters:
p_evaporator (float) – Evaporator pressure [Pa], positive and below
p_condenser.p_condenser (float) – Condenser pressure [Pa], below the fluid’s critical pressure.
fluid (CubicFluid, optional) – Refrigerant;
R134Aby default.superheat (float, optional) – Superheat of the vapour leaving the evaporator [K], nonnegative.
subcooling (float, optional) – Subcooling of the liquid leaving the condenser [K], nonnegative.
compressor_efficiency (float, optional) – Isentropic efficiency of the compressor [-] in (0, 1].
- Returns:
The four states (compressor inlet and outlet, condenser outlet, evaporator inlet), the heat absorbed and rejected and the compressor work per kilogram, and both COPs.
- Return type:
Notes
Perkins’s cycle: the vapour is compressed, condensed, throttled through an expansion valve at constant enthalpy and evaporated. Heat exchangers have no pressure drop. Properties come from
refrigerant_properties(). Inputs are raw SI numbers with no dimensional metadata; see Thermodynamics: total versus specific quantities and cycle states.References
Y. A. Çengel and M. A. Boles, Thermodynamics: An Engineering Approach, 9th ed., New York: McGraw-Hill (2019), Ch. 11.
Examples
>>> res = vapor_compression_cycle(0.14e6, 0.8e6) >>> round(res.cop_refrigerator, 2) 3.94
Utilities#
IAPWS-IF97 basic equations for regions 1 to 5, in reduced variables.
The coefficients are those of the IAPWS release (Lucerne 2007 revision of
the 1997 formulation): region 1 is compressed liquid, region 2 superheated
vapour, region 3 the near-critical fluid, region 4 the saturation line and
region 5 the high-temperature steam of gas turbines. Regions 1, 2 and 5 are dimensionless Gibbs free energies
\(\gamma(\pi, \tau)\) and region 3 a dimensionless Helmholtz free
energy \(\phi(\delta, \tau)\); every property follows from the
function and its derivatives. Pressures are in MPa and temperatures in
K inside this module, as in the release; the public wrappers in
engineeringkit.thermodynamics.systems.steam convert to Pa and J.
- engineeringkit.thermodynamics.utils.if97.P_CRIT = 22064000.0#
Critical pressure of water [Pa].
- engineeringkit.thermodynamics.utils.if97.R_WATER = 461.526#
Specific gas constant of water used by IF97 [J/(kg K)].
- engineeringkit.thermodynamics.utils.if97.T_CRIT = 647.096#
Critical temperature of water [K].
- engineeringkit.thermodynamics.utils.if97.b23_pressure_mpa(T)[source]#
Pressure on the boundary between regions 2 and 3.
- Parameters:
T (float or array_like) – Temperature [K], 623.15 K to 863.15 K.
- Returns:
Boundary pressure [MPa].
- Return type:
float or ndarray
- engineeringkit.thermodynamics.utils.if97.b23_temperature_k(p_mpa)[source]#
Temperature on the boundary between regions 2 and 3, the inverse of
b23_pressure_mpa().- Parameters:
p_mpa (float or array_like) – Pressure [MPa], 16.529 MPa to 100 MPa.
- Returns:
Boundary temperature [K].
- Return type:
float or ndarray
- engineeringkit.thermodynamics.utils.if97.region1(T, p_mpa)[source]#
Region 1 (compressed liquid) properties from the IF97 Gibbs function.
- Parameters:
T (float or array_like) – Temperature [K], 273.15 K to 623.15 K.
p_mpa (float or array_like) – Pressure [MPa], above saturation and at most 100 MPa.
- Returns:
Specific volume
v[m^3/kg], enthalpyh[J/kg], internal energyu[J/kg], entropys[J/(kg K)] and isobaric heat capacitycp[J/(kg K)], broadcast overTandp_mpa.- Return type:
dict of ndarray
- engineeringkit.thermodynamics.utils.if97.region2(T, p_mpa)[source]#
Region 2 (vapour) properties from the IF97 Gibbs function.
- Parameters:
T (float or array_like) – Temperature [K], 273.15 K to 1073.15 K.
p_mpa (float or array_like) – Pressure [MPa], positive and below saturation (and below the region 2-3 boundary above 623.15 K).
- Returns:
Specific volume
v[m^3/kg], enthalpyh[J/kg], internal energyu[J/kg], entropys[J/(kg K)] and isobaric heat capacitycp[J/(kg K)], broadcast overTandp_mpa.- Return type:
dict of ndarray
- engineeringkit.thermodynamics.utils.if97.region3(rho, T)[source]#
Region 3 (near-critical) properties from the IF97 Helmholtz function.
- Parameters:
rho (float or array_like) – Density [kg/m^3], positive.
T (float or array_like) – Temperature [K], 623.15 K to 863.15 K.
- Returns:
Pressure
p[Pa] and, as forregion1(),v,h,u,sandcp, broadcast overrhoandT.- Return type:
dict of ndarray
- engineeringkit.thermodynamics.utils.if97.region3_density(T, p_mpa, phase)[source]#
Density at which the region 3 pressure equals
p_mpaon the isothermT.Below the critical temperature an isotherm of the Helmholtz function has a van der Waals loop, so up to three densities share a pressure; the largest is the liquid and the smallest the vapour.
- Parameters:
T (float) – Temperature [K], 623.15 K to 863.15 K.
p_mpa (float) – Pressure [MPa].
phase ({"liquid", "vapour"}) – Which root to return when there are several.
- Returns:
Density [kg/m^3].
- Return type:
float
- Raises:
ValueError – If no density between 100 and 800 kg/m^3 gives that pressure.
Notes
Region 3 spans about 113 to 765 kg/m^3. The search stops at 800 kg/m^3 because the fit, extrapolated to denser states, turns back down and would give a spurious liquid root.
- engineeringkit.thermodynamics.utils.if97.region5(T, p_mpa)[source]#
Region 5 (high-temperature steam) properties from the IF97 Gibbs function.
- Parameters:
T (float or array_like) – Temperature [K], 1073.15 K to 2273.15 K.
p_mpa (float or array_like) – Pressure [MPa], positive and at most 50 MPa.
- Returns:
Specific volume
v[m^3/kg], enthalpyh[J/kg], internal energyu[J/kg], entropys[J/(kg K)] and isobaric heat capacitycp[J/(kg K)], broadcast overTandp_mpa.- Return type:
dict of ndarray
- engineeringkit.thermodynamics.utils.if97.saturation_pressure_mpa(T)[source]#
Region 4 saturation pressure.
- Parameters:
T (float or array_like) – Temperature [K], 273.15 K to 647.096 K.
- Returns:
Saturation pressure [MPa].
- Return type:
float or ndarray
- engineeringkit.thermodynamics.utils.if97.saturation_temperature_k(p_mpa)[source]#
Region 4 saturation temperature, the inverse of
saturation_pressure_mpa().- Parameters:
p_mpa (float or array_like) – Pressure [MPa], 611.213 Pa to 22.064 MPa.
- Returns:
Saturation temperature [K].
- Return type:
float or ndarray
Ideal-gas enthalpies of the combustion gases from NIST’s Shomate equations.
Each species has one coefficient set per temperature range; with \(t = T/1000\),
Coefficients and standard enthalpies of formation are those of the NIST Chemistry WebBook (Chase, NIST-JANAF Thermochemical Tables, 1998; CODATA key values, Cox, Wagman and Medvedev, 1984).
- engineeringkit.thermodynamics.utils.shomate.FORMATION_ENTHALPY = {'CO2': -393510.0, 'H2O': -241826.0, 'N2': 0.0, 'O2': 0.0}#
Standard enthalpy of formation at 298.15 K [J/mol], water as vapour (CODATA).
- Type:
dict
- engineeringkit.thermodynamics.utils.shomate.LIQUID_WATER_FORMATION_ENTHALPY = -285830.0#
Standard enthalpy of formation of liquid water at 298.15 K [J/mol] (CODATA).
- Type:
float
- engineeringkit.thermodynamics.utils.shomate.SPECIES = ('CO2', 'H2O', 'N2', 'O2')#
Species with Shomate data: CO2, H2O (gas), N2 and O2.
- Type:
tuple of str
- engineeringkit.thermodynamics.utils.shomate.sensible_enthalpy(species, T)[source]#
Ideal-gas enthalpy above 298.15 K, \(H^\circ(T) - H^\circ(298.15)\) [J/mol].
- Parameters:
species (str) – One of
SPECIES.T (float or array_like) – Temperature [K], 298.15 K to 6000 K.
- Returns:
Sensible enthalpy [J/mol].
- Return type:
float or ndarray
Visualizers#
Matplotlib visualizers for engineeringkit.thermodynamics.
- engineeringkit.thermodynamics.visualizers.plot_pv_diagram(v, p, ax=None, label=None)[source]#
Plot a process path on pressure-volume axes.
- Parameters:
v (array_like) – Specific (or total) volumes along the path [m^3/kg or m^3].
p (array_like) – Matching pressures [Pa], drawn in kPa.
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label.
- Return type:
matplotlib.axes.Axes
- engineeringkit.thermodynamics.visualizers.plot_saturation_dome(ax=None, T_min=273.16, T_max=647.096, n=120)[source]#
Draw the saturated-liquid and saturated-vapour lines of water on T-s axes.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
T_min (float, optional) – Temperature range [K] of the dome, within 273.16 K and the critical 647.096 K.
T_max (float, optional) – Temperature range [K] of the dome, within 273.16 K and the critical 647.096 K.
n (int, optional) – Number of points on each line.
- Return type:
matplotlib.axes.Axes
- engineeringkit.thermodynamics.visualizers.plot_ts_diagram(s, T, ax=None, label=None, dome=True)[source]#
Plot a process path on temperature-entropy axes, optionally over the water dome.
- Parameters:
s (array_like) – Specific entropies along the path [J/(kg K)], drawn in kJ/(kg K).
T (array_like) – Matching temperatures [K], drawn in °C.
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label.
dome (bool, optional) – Draw the saturation dome of water first.
- Return type:
matplotlib.axes.Axes