Skip to content
ktwywPublic

About

Chemical engineering thermodynamics in Python: validated methods, an 18-notebook course with worked solutions

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

engthermo

Chemical engineering thermodynamics - readable, validated Python, with an 18-notebook course.

tests validation notebooks python license ORCID

Peng-Robinson isotherms of CO2 sweeping through the critical point, with the two-phase dome and saturation tie lines from the equal-fugacity condition

engthermo covers an undergraduate course in chemical engineering thermodynamics, from the first law and steam power cycles through real fluids, mixtures and phase equilibria to reaction equilibrium, combustion and electrochemistry - with examples from chemical and materials engineering and energy technologies. Every method is checked against reference formulations (IAPWS-IF97), independent implementations (CoolProp, thermo) and textbook examples, and a course of executed notebooks with worked solutions teaches the ideas.

from engthermo import cycles, reaction, steam, vle

steam.state(p=3e6, s=6.7e3)                                 # IAPWS-IF97: any state from two properties
cycles.rankine(p_boiler=15e6, p_condenser=10e3, T_inlet=873.15, reheat=(4e6, 873.15))["efficiency"]
vle.bubble_T(["ethanol", "water"], [0.5, 0.5], p=101325.0)  # Raoult's law (add gamma=... for real mixtures)
reaction.equilibrium_constant({"N2": -1, "H2": -3, "NH3": 2}, T=723.15)

Why engthermo?

  • Data you can trust. The IAPWS-IF97 coefficient tables and the UNIFAC group tables are transcribed programmatically from their published sources, never typed; critical constants, heat capacities and Antoine vapour pressures are taken or fitted from CoolProp's reference equations, with fit errors recorded; every source is named in the code.
  • Validated, not just tested. 150 checks in docs/VALIDATION.md, rerun in CI: the IAPWS verification tables to nine figures, cubic equations and mixture fugacities against CoolProp to 1e-6, UNIFAC against the thermo package to 1e-8, textbook cycles (Cengel & Boles) and mixtures (Smith, Van Ness & Abbott), exact identities (Gibbs-Duhem, van 't Hoff, element balances), and known azeotropes, eutectics and cell voltages.
  • Robust where textbooks are silent. Trivial-solution detection and pressure scanning in equation-of-state VLE, spinodal-bracketed liquid-liquid solvers, continuation near critical points, and a Gibbs minimiser that raises rather than returning a composition that violates element balances.
  • Lightweight. Only NumPy and SciPy are required; CoolProp, iapws and thermo are used for validation only.

What's inside

Module Methods
steam IAPWS-IF97 regions 1-5: any state from (T, p), (p, h), (p, s), (p, x); saturation; two-phase states
components, idealgas 32 species with sourced data; ideal-gas Cp, H, S, isentropic processes, mixtures
tables, cycles refrigerant tables (R134a, ammonia, propane); Carnot, Rankine (reheat, efficiencies), Brayton, vapour-compression
eos virial (Pitzer-Abbott); van der Waals, RK, SRK, Peng-Robinson: roots, departure functions, fugacity; mixtures with k_ij
vapor Clausius-Clapeyron, Antoine (fitted, with ranges), saturation from an equation of state
mixtures, activity partial molar and excess properties; Margules, van Laar, Wilson, NRTL, UNIQUAC; fitting, azeotropes, consistency test
unifac original UNIFAC (Hansen et al. 1991 tables), group assignments for common molecules
vle Raoult and modified Raoult: bubble/dew points, Rachford-Rice flash, diagrams; phi-phi bubble and dew points with an EOS
lle, sle binary liquid-liquid equilibria; Flory-Huggins theory; solubility, eutectics, lens diagrams
reaction Delta H, Delta S, Delta G and K(T); single-reaction extent; Gibbs minimisation for many reactions
combustion, electrochem heating values, flue gas, adiabatic flame temperature, Ellingham diagram; cell potentials, Nernst, fuel-cell and electrolyser limits
datasets 11 bundled data files (property tables and course data) with sources

Learn: the course

Eighteen executed notebooks, each built around engineering problems, with learning objectives, an "Inside the algorithm" section and exercises (including an "Implement it yourself" task); every exercise has a worked solution in solutions/. They open in Google Colab and install engthermo automatically.

# Notebook Applications
00 Python for thermodynamics units, tables, root finding, property diagrams
01 The first law and energy balances furnaces, compressors with intercooling, turbines, valves
02 Steam and power cycles Rankine cycles, reheat, plant sizing
03 Entropy, refrigeration and heat pumps exergy, vapour-compression cycles, refrigerants, heat pumps
04 Real gases and equations of state CO2 pipelines, hydrogen tanks
05 Departure functions and fugacity real-gas compressors, fugacity
06 Vapour pressure and phase change Antoine, saturation from an EOS, LPG storage
07 Mixture fundamentals partial molar volumes, ideal mixing, Gibbs-Duhem
08 Raoult's law and flash calculations T-x-y diagrams, flash drums, relative volatility
09 Activity-coefficient models ethanol-water, fitting, consistency, the bioethanol azeotrope
10 UNIFAC prediction prediction without data, solvent screening
11 High-pressure phase equilibria natural-gas dew points, CO2 mixtures, interaction parameters
12 Liquid-liquid equilibria and polymer solutions extraction, Flory-Huggins, UCST
13 Solid-liquid equilibria and alloy phase diagrams solubility, antifreeze, Bi-Cd and Cu-Ni diagrams
14 Chemical reaction equilibrium ammonia, methanol, hydrogen by steam reforming
15 High-temperature thermochemistry fuels and CO2, flame temperatures, Ellingham diagram, green steel
16 Electrochemical thermodynamics fuel cells, electrolysers, batteries
17 From messy laboratory data to a model data repair, consistency, fitting with uncertainties, reporting

Gallery

Every image is computed by the library; python tools/make_images.py regenerates them.


Steam T-s diagram (IAPWS-IF97) with a reheat Rankine cycle

Peng-Robinson isotherms of CO2 through the critical point

Ethanol-water: UNIFAC finds the azeotrope Raoult's law cannot

Ammonia synthesis: the Haber-Bosch compromise

Ellingham diagram: which oxides carbon and hydrogen can reduce

Cu-Ni lens diagram from two melting points and two enthalpies

Install

pip install "engthermo @ git+https://github.com/ktwyw/engthermo"
# or, for development (adds CoolProp, iapws and thermo for the validation suite):
git clone https://github.com/ktwyw/engthermo && cd engthermo && pip install -e ".[dev]"

Validation at a glance

Reference What is checked Agreement
IAPWS-IF97 verification tables; CoolProp; iapws steam properties in all five regions, saturation line, two-phase and inverse states 1e-8
CoolProp reference equations critical constants, ideal-gas Cp (fitted), Antoine vapour pressures, refrigerant tables ≤ 1 %; tables 2e-4
CoolProp cubic backends Z, departure functions, fugacity, saturation (PR, SRK); mixture fugacities and a mixture bubble point (PR) ≤ 1e-6
thermo package UNIFAC activity coefficients (binary, ternary, negative deviations) 1e-8
Cengel & Boles; Smith, Van Ness & Abbott Rankine, reheat and Brayton cycles; Redlich-Kwong volumes ≤ 0.3 %
Exact identities van 't Hoff, Gibbs-Duhem, G = H - TS, element balances, Rachford-Rice, energy balances ≤ 1e-6
Experiment / literature ethanol-water azeotrope, Bi-Cd eutectic, naphthalene solubility, fuel-cell voltage and its temperature coefficient within stated tolerances

Citing

If engthermo helps your work, please cite it using CITATION.cff (GitHub shows a "Cite this repository" button).

Author

Yanwei Wang - personal open-source project. GitHub @ktwyw · ORCID 0000-0002-8488-9833 · wangyanwei@gmail.com

Also by the author: engmath (numerical methods), engstat (engineering statistics), fluidmech (fluid mechanics) and engrheo (rheology).

License

MIT - see LICENSE. Contributions welcome: see CONTRIBUTING.md.

About

Chemical engineering thermodynamics in Python: validated methods, an 18-notebook course with worked solutions

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages