thermo-utils 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thermo_utils-0.2.0/LICENSE +21 -0
- thermo_utils-0.2.0/PKG-INFO +143 -0
- thermo_utils-0.2.0/README.md +112 -0
- thermo_utils-0.2.0/pyproject.toml +50 -0
- thermo_utils-0.2.0/src/thermo_utils/__init__.py +1 -0
- thermo_utils-0.2.0/src/thermo_utils/activity.py +118 -0
- thermo_utils-0.2.0/src/thermo_utils/calcs.py +269 -0
- thermo_utils-0.2.0/src/thermo_utils/chemical_equilibrium.py +218 -0
- thermo_utils-0.2.0/src/thermo_utils/cli.py +357 -0
- thermo_utils-0.2.0/src/thermo_utils/devices.py +39 -0
- thermo_utils-0.2.0/src/thermo_utils/equations.py +157 -0
- thermo_utils-0.2.0/src/thermo_utils/heat.py +72 -0
- thermo_utils-0.2.0/src/thermo_utils/mixtures.py +465 -0
- thermo_utils-0.2.0/src/thermo_utils/plots.py +32 -0
- thermo_utils-0.2.0/src/thermo_utils/properties.py +312 -0
- thermo_utils-0.2.0/src/thermo_utils/pure.py +400 -0
- thermo_utils-0.2.0/src/thermo_utils/reactions.py +150 -0
- thermo_utils-0.2.0/src/thermo_utils/result.py +27 -0
- thermo_utils-0.2.0/src/thermo_utils/substances.py +151 -0
- thermo_utils-0.2.0/src/thermo_utils/surface.py +347 -0
- thermo_utils-0.2.0/src/thermo_utils/units.py +154 -0
- thermo_utils-0.2.0/src/thermo_utils/vle.py +208 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dspavier
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: thermo-utils
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A thermodynamics calculator for chemical engineering, from homework to plant design
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: thermodynamics,chemical engineering,equation of state,phase equilibrium,calculator
|
|
8
|
+
Author: Dspavier
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: CoolProp (>=7.0.0)
|
|
19
|
+
Requires-Dist: chemicals (>=1.5.0)
|
|
20
|
+
Requires-Dist: matplotlib (>=3.9.0)
|
|
21
|
+
Requires-Dist: numpy (>=2.0.0)
|
|
22
|
+
Requires-Dist: pytest (>=8.0.0) ; extra == "dev"
|
|
23
|
+
Requires-Dist: rich (>=13.0.0)
|
|
24
|
+
Requires-Dist: scipy (>=1.16.3,<2.0.0)
|
|
25
|
+
Requires-Dist: thermo (>=0.6.0)
|
|
26
|
+
Requires-Dist: typer (>=0.20.0,<1.0.0)
|
|
27
|
+
Project-URL: Homepage, https://github.com/eggplanta/thermo-utils
|
|
28
|
+
Project-URL: Issues, https://github.com/eggplanta/thermo-utils/issues
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
|
|
33
|
+
<picture>
|
|
34
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/logo-dark.png">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/logo-light.png" alt="thermo-utils" width="560">
|
|
36
|
+
</picture>
|
|
37
|
+
|
|
38
|
+

|
|
39
|
+

|
|
40
|
+
[](LICENSE)
|
|
41
|
+
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
**thermo-utils** is a command-line thermodynamics calculator for chemical engineering.
|
|
45
|
+
It covers pure fluids, heat effects, flow devices, mixtures, phase equilibrium, chemical equilibrium and surface phenomena, and is accurate enough for design work.
|
|
46
|
+
You only type the substance name: Tc, Pc, ω, Cp, ΔHf, Psat and the other data come from built-in databanks.
|
|
47
|
+
|
|
48
|
+
## Screenshots
|
|
49
|
+
|
|
50
|
+
<div align="center">
|
|
51
|
+
|
|
52
|
+
<table>
|
|
53
|
+
<tr>
|
|
54
|
+
<td align="center"><img src="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/screenshots/menu.png" width="420"><br><sub>Main menu</sub></td>
|
|
55
|
+
<td align="center"><img src="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/screenshots/property-change.png" width="420"><br><sub>Property change between two states</sub></td>
|
|
56
|
+
</tr>
|
|
57
|
+
</table>
|
|
58
|
+
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pipx install thermo-utils
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
or `uv tool install thermo-utils`, or `pip install thermo-utils` inside a virtual environment.
|
|
68
|
+
|
|
69
|
+
## Usage
|
|
70
|
+
|
|
71
|
+
Run `thermo-utils` to open the interactive menu (Esc exits; the program closes after showing a result), or run a calculation directly:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
thermo-utils delta water T1=25C P1=1atm T2=300C P2=20bar
|
|
75
|
+
thermo-utils pump water T1=25C P1=1atm P2=50bar efficiency=0.75 flow=10kg/s
|
|
76
|
+
thermo-utils diagram ethanol,water P=1atm --plot --open
|
|
77
|
+
thermo-utils gibbs CH4,H2O,CO,CO2,H2 T=1000 P=1 feed=CH4=2,H2O=3
|
|
78
|
+
thermo-utils list # every calculation and its inputs
|
|
79
|
+
thermo-utils info ammonia # databank values of a substance
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- **Units:** type them with the value (`25C`, `10atm`, `300cm3/mol`, `5kmol/h`), with no space so no quotes are needed. Without a unit the defaults are K, bar, cm³/mol and J/mol. Output units can be changed in the menu (`u`) or with `--T-unit`, `--P-unit`, `--E-unit`, `--V-unit`.
|
|
83
|
+
- **Substances:** English names, formulas or CAS numbers (`water`, `H2O`, `7732-18-5`), right after the calculation name. Mixtures are comma separated (`ethanol,water`).
|
|
84
|
+
- **Devices:** `pump`, `compressor`, `turbine` and `valve` are shortcuts for `device kind=...`.
|
|
85
|
+
- **Plots:** saved as PNG in `./thermo-plots` (or `$THERMO_UTILS_PLOTS`) and opened on request.
|
|
86
|
+
|
|
87
|
+
## Calculations
|
|
88
|
+
|
|
89
|
+
**Pure fluids**
|
|
90
|
+
- PVT with ideal gas, virial, van der Waals, RK, SRK, Peng-Robinson, fitted Peng-Robinson and reference EOS, with a side-by-side comparison
|
|
91
|
+
- State properties: V, Z, H, S, U, G, A, Cp, Cv, φ, fugacity, κ, β, μJT, speed of sound
|
|
92
|
+
- Property changes ΔH, ΔS, ΔU, ΔG, ΔA between two states, including phase change, with the residual-property path
|
|
93
|
+
- Saturation (Psat, Tsat, ΔHvap)
|
|
94
|
+
|
|
95
|
+
**Heat effects**
|
|
96
|
+
- Sensible and latent heats (Riedel, Watson)
|
|
97
|
+
- Adiabatic flame temperature
|
|
98
|
+
|
|
99
|
+
**Flow devices**
|
|
100
|
+
- One-step devices: compressor, pump, turbine and valve, with efficiency and power for a given flow
|
|
101
|
+
|
|
102
|
+
**Mixtures**
|
|
103
|
+
- Fugacity of species in mixtures (PR, SRK, virial) and the Lewis-Randall rule
|
|
104
|
+
- Activity coefficients and excess properties: Margules, van Laar, Wilson, NRTL, UNIQUAC, UNIFAC, UNIFAC-Dortmund
|
|
105
|
+
- Margules and van Laar fits from P-x-y data (CSV)
|
|
106
|
+
|
|
107
|
+
**Phase equilibrium**
|
|
108
|
+
- VLE: bubble/dew P and T and flash, using γ-φ, modified Raoult, Raoult or φ-φ, for multicomponent mixtures
|
|
109
|
+
- Pxy, Txy and xy diagrams with azeotrope detection
|
|
110
|
+
- LLE with the binodal curve, SLE (eutectic), solubility of solids, osmotic pressure
|
|
111
|
+
|
|
112
|
+
**Chemical equilibrium**
|
|
113
|
+
- K(T), ΔG° and ΔH° with rigorous ΔCp integration and the van 't Hoff plot
|
|
114
|
+
- Equilibrium conversion of one reaction: ideal gas, gas with virial φ̂, ideal liquid or UNIFAC
|
|
115
|
+
- Multi-reaction equilibrium by Gibbs energy minimization (no need to write the reactions)
|
|
116
|
+
|
|
117
|
+
**Surface phenomena**
|
|
118
|
+
- Surface tension σ(T) with surface entropy and enthalpy (databank, Brock-Bird, parachor)
|
|
119
|
+
- Kelvin equation (vapor pressure over drops, bubbles and pores)
|
|
120
|
+
- Adsorption isotherms (Langmuir, Freundlich, BET with specific surface area) fitted to CSV data
|
|
121
|
+
- Gibbs adsorption isotherm (Szyszkowski fit), micellization (CMC, ΔG°mic)
|
|
122
|
+
|
|
123
|
+
## Accuracy
|
|
124
|
+
|
|
125
|
+
| Model | Use | Typical error |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| Reference EOS ([CoolProp](https://coolprop.org)) | ~120 common fluids (water, CO₂, hydrocarbons, refrigerants, air gases...) | < 0.1 % in density and enthalpy |
|
|
128
|
+
| Fitted Peng-Robinson (Twu α + volume translation) | any substance in the databank | ~1 % in Psat, ~2 % in liquid density |
|
|
129
|
+
| Peng-Robinson / SRK | any substance in the databank | 1-5 % for gases, 5-30 % for liquid volumes |
|
|
130
|
+
| Virial (Pitzer) | gases at low to moderate pressure | < 1-2 % when Vr > 2 |
|
|
131
|
+
| UNIFAC / NRTL / UNIQUAC (ChemSep) | liquid mixtures | azeotropes within ~0.5 K for common systems |
|
|
132
|
+
|
|
133
|
+
The `auto` model uses the reference EOS when available and the fitted Peng-Robinson otherwise. Its α function and volume shift are fitted to the databank vapor pressure and liquid density of each substance.
|
|
134
|
+
|
|
135
|
+
Every result starts with the equations used in the calculation.
|
|
136
|
+
H, S, U, G and A share one reference state (ideal gas at 298.15 K and 1 bar), so differences between models are meaningful.
|
|
137
|
+
Data come from [chemicals](https://github.com/CalebBell/chemicals), [thermo](https://github.com/CalebBell/thermo) and CoolProp.
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
Contributions are very welcome! thermo-utils still has a lot of room to grow, and I'd be happy to get your help.
|
|
142
|
+
Found a wrong result, a missing substance or a bug? Have an idea for a new calculation? Open an [issue](https://github.com/eggplanta/thermo-utils/issues) or send a pull request.
|
|
143
|
+
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/logo-dark.png">
|
|
5
|
+
<img src="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/logo-light.png" alt="thermo-utils" width="560">
|
|
6
|
+
</picture>
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
**thermo-utils** is a command-line thermodynamics calculator for chemical engineering.
|
|
15
|
+
It covers pure fluids, heat effects, flow devices, mixtures, phase equilibrium, chemical equilibrium and surface phenomena, and is accurate enough for design work.
|
|
16
|
+
You only type the substance name: Tc, Pc, ω, Cp, ΔHf, Psat and the other data come from built-in databanks.
|
|
17
|
+
|
|
18
|
+
## Screenshots
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
|
|
22
|
+
<table>
|
|
23
|
+
<tr>
|
|
24
|
+
<td align="center"><img src="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/screenshots/menu.png" width="420"><br><sub>Main menu</sub></td>
|
|
25
|
+
<td align="center"><img src="https://raw.githubusercontent.com/eggplanta/thermo-utils/main/docs/screenshots/property-change.png" width="420"><br><sub>Property change between two states</sub></td>
|
|
26
|
+
</tr>
|
|
27
|
+
</table>
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pipx install thermo-utils
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
or `uv tool install thermo-utils`, or `pip install thermo-utils` inside a virtual environment.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Run `thermo-utils` to open the interactive menu (Esc exits; the program closes after showing a result), or run a calculation directly:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
thermo-utils delta water T1=25C P1=1atm T2=300C P2=20bar
|
|
45
|
+
thermo-utils pump water T1=25C P1=1atm P2=50bar efficiency=0.75 flow=10kg/s
|
|
46
|
+
thermo-utils diagram ethanol,water P=1atm --plot --open
|
|
47
|
+
thermo-utils gibbs CH4,H2O,CO,CO2,H2 T=1000 P=1 feed=CH4=2,H2O=3
|
|
48
|
+
thermo-utils list # every calculation and its inputs
|
|
49
|
+
thermo-utils info ammonia # databank values of a substance
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- **Units:** type them with the value (`25C`, `10atm`, `300cm3/mol`, `5kmol/h`), with no space so no quotes are needed. Without a unit the defaults are K, bar, cm³/mol and J/mol. Output units can be changed in the menu (`u`) or with `--T-unit`, `--P-unit`, `--E-unit`, `--V-unit`.
|
|
53
|
+
- **Substances:** English names, formulas or CAS numbers (`water`, `H2O`, `7732-18-5`), right after the calculation name. Mixtures are comma separated (`ethanol,water`).
|
|
54
|
+
- **Devices:** `pump`, `compressor`, `turbine` and `valve` are shortcuts for `device kind=...`.
|
|
55
|
+
- **Plots:** saved as PNG in `./thermo-plots` (or `$THERMO_UTILS_PLOTS`) and opened on request.
|
|
56
|
+
|
|
57
|
+
## Calculations
|
|
58
|
+
|
|
59
|
+
**Pure fluids**
|
|
60
|
+
- PVT with ideal gas, virial, van der Waals, RK, SRK, Peng-Robinson, fitted Peng-Robinson and reference EOS, with a side-by-side comparison
|
|
61
|
+
- State properties: V, Z, H, S, U, G, A, Cp, Cv, φ, fugacity, κ, β, μJT, speed of sound
|
|
62
|
+
- Property changes ΔH, ΔS, ΔU, ΔG, ΔA between two states, including phase change, with the residual-property path
|
|
63
|
+
- Saturation (Psat, Tsat, ΔHvap)
|
|
64
|
+
|
|
65
|
+
**Heat effects**
|
|
66
|
+
- Sensible and latent heats (Riedel, Watson)
|
|
67
|
+
- Adiabatic flame temperature
|
|
68
|
+
|
|
69
|
+
**Flow devices**
|
|
70
|
+
- One-step devices: compressor, pump, turbine and valve, with efficiency and power for a given flow
|
|
71
|
+
|
|
72
|
+
**Mixtures**
|
|
73
|
+
- Fugacity of species in mixtures (PR, SRK, virial) and the Lewis-Randall rule
|
|
74
|
+
- Activity coefficients and excess properties: Margules, van Laar, Wilson, NRTL, UNIQUAC, UNIFAC, UNIFAC-Dortmund
|
|
75
|
+
- Margules and van Laar fits from P-x-y data (CSV)
|
|
76
|
+
|
|
77
|
+
**Phase equilibrium**
|
|
78
|
+
- VLE: bubble/dew P and T and flash, using γ-φ, modified Raoult, Raoult or φ-φ, for multicomponent mixtures
|
|
79
|
+
- Pxy, Txy and xy diagrams with azeotrope detection
|
|
80
|
+
- LLE with the binodal curve, SLE (eutectic), solubility of solids, osmotic pressure
|
|
81
|
+
|
|
82
|
+
**Chemical equilibrium**
|
|
83
|
+
- K(T), ΔG° and ΔH° with rigorous ΔCp integration and the van 't Hoff plot
|
|
84
|
+
- Equilibrium conversion of one reaction: ideal gas, gas with virial φ̂, ideal liquid or UNIFAC
|
|
85
|
+
- Multi-reaction equilibrium by Gibbs energy minimization (no need to write the reactions)
|
|
86
|
+
|
|
87
|
+
**Surface phenomena**
|
|
88
|
+
- Surface tension σ(T) with surface entropy and enthalpy (databank, Brock-Bird, parachor)
|
|
89
|
+
- Kelvin equation (vapor pressure over drops, bubbles and pores)
|
|
90
|
+
- Adsorption isotherms (Langmuir, Freundlich, BET with specific surface area) fitted to CSV data
|
|
91
|
+
- Gibbs adsorption isotherm (Szyszkowski fit), micellization (CMC, ΔG°mic)
|
|
92
|
+
|
|
93
|
+
## Accuracy
|
|
94
|
+
|
|
95
|
+
| Model | Use | Typical error |
|
|
96
|
+
|---|---|---|
|
|
97
|
+
| Reference EOS ([CoolProp](https://coolprop.org)) | ~120 common fluids (water, CO₂, hydrocarbons, refrigerants, air gases...) | < 0.1 % in density and enthalpy |
|
|
98
|
+
| Fitted Peng-Robinson (Twu α + volume translation) | any substance in the databank | ~1 % in Psat, ~2 % in liquid density |
|
|
99
|
+
| Peng-Robinson / SRK | any substance in the databank | 1-5 % for gases, 5-30 % for liquid volumes |
|
|
100
|
+
| Virial (Pitzer) | gases at low to moderate pressure | < 1-2 % when Vr > 2 |
|
|
101
|
+
| UNIFAC / NRTL / UNIQUAC (ChemSep) | liquid mixtures | azeotropes within ~0.5 K for common systems |
|
|
102
|
+
|
|
103
|
+
The `auto` model uses the reference EOS when available and the fitted Peng-Robinson otherwise. Its α function and volume shift are fitted to the databank vapor pressure and liquid density of each substance.
|
|
104
|
+
|
|
105
|
+
Every result starts with the equations used in the calculation.
|
|
106
|
+
H, S, U, G and A share one reference state (ideal gas at 298.15 K and 1 bar), so differences between models are meaningful.
|
|
107
|
+
Data come from [chemicals](https://github.com/CalebBell/chemicals), [thermo](https://github.com/CalebBell/thermo) and CoolProp.
|
|
108
|
+
|
|
109
|
+
## Contributing
|
|
110
|
+
|
|
111
|
+
Contributions are very welcome! thermo-utils still has a lot of room to grow, and I'd be happy to get your help.
|
|
112
|
+
Found a wrong result, a missing substance or a bug? Have an idea for a new calculation? Open an [issue](https://github.com/eggplanta/thermo-utils/issues) or send a pull request.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "thermo-utils"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "A thermodynamics calculator for chemical engineering, from homework to plant design"
|
|
5
|
+
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Dspavier" }]
|
|
10
|
+
keywords = ["thermodynamics", "chemical engineering", "equation of state", "phase equilibrium", "calculator"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Environment :: Console",
|
|
13
|
+
"Intended Audience :: Education",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Chemistry",
|
|
18
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
19
|
+
]
|
|
20
|
+
requires-python = ">=3.12"
|
|
21
|
+
dependencies = [
|
|
22
|
+
"typer (>=0.20.0,<1.0.0)",
|
|
23
|
+
"rich (>=13.0.0)",
|
|
24
|
+
"scipy (>=1.16.3,<2.0.0)",
|
|
25
|
+
"numpy (>=2.0.0)",
|
|
26
|
+
"CoolProp (>=7.0.0)",
|
|
27
|
+
"thermo (>=0.6.0)",
|
|
28
|
+
"chemicals (>=1.5.0)",
|
|
29
|
+
"matplotlib (>=3.9.0)"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/eggplanta/thermo-utils"
|
|
34
|
+
Issues = "https://github.com/eggplanta/thermo-utils/issues"
|
|
35
|
+
|
|
36
|
+
[project.optional-dependencies]
|
|
37
|
+
dev = ["pytest (>=8.0.0)"]
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
thermo-utils = "thermo_utils.cli:main"
|
|
41
|
+
|
|
42
|
+
[tool.poetry]
|
|
43
|
+
packages = [{include = "thermo_utils", from = "src"}]
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
47
|
+
build-backend = "poetry.core.masonry.api"
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Excess Gibbs energy models."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from thermo import NRTL, UNIQUAC, IdealSolution
|
|
7
|
+
from thermo.interaction_parameters import IPDB
|
|
8
|
+
from thermo.unifac import DOUFIP2016, DOUFSG, UFIP, UFSG, UNIFAC
|
|
9
|
+
|
|
10
|
+
from thermo_utils.units import R
|
|
11
|
+
|
|
12
|
+
MODELS = {
|
|
13
|
+
"unifac": "UNIFAC (predictive, original)",
|
|
14
|
+
"unifac-do": "Modified UNIFAC (Dortmund)",
|
|
15
|
+
"nrtl": "NRTL (ChemSep parameters or yours)",
|
|
16
|
+
"uniquac": "UNIQUAC (ChemSep parameters)",
|
|
17
|
+
"wilson": "Wilson (binary, your Λ12 and Λ21)",
|
|
18
|
+
"margules": "Margules two-parameter (binary, your A12 and A21)",
|
|
19
|
+
"vanlaar": "van Laar (binary, your A'12 and A'21)",
|
|
20
|
+
"ideal": "Ideal solution (γ = 1, Raoult)",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class GEModel:
|
|
25
|
+
"""Activity coefficients for a fixed set of components."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, subs, name="unifac", params=None):
|
|
28
|
+
self.subs = subs
|
|
29
|
+
self.name = name
|
|
30
|
+
self.params = list(params or [])
|
|
31
|
+
self.notes = []
|
|
32
|
+
n = len(subs)
|
|
33
|
+
if name in ("margules", "vanlaar", "wilson") and n != 2:
|
|
34
|
+
raise ValueError(f"{name} is implemented for binary mixtures.")
|
|
35
|
+
if name in ("margules", "vanlaar", "wilson") and len(self.params) != 2:
|
|
36
|
+
raise ValueError(f"{name} needs two parameters, e.g. params=1.2,0.8")
|
|
37
|
+
if name == "nrtl" and not self.params:
|
|
38
|
+
cas = [s.cas for s in subs]
|
|
39
|
+
self._b = IPDB.get_ip_asymmetric_matrix("ChemSep NRTL", cas, "bij")
|
|
40
|
+
self._alpha = IPDB.get_ip_asymmetric_matrix("ChemSep NRTL", cas, "alphaij")
|
|
41
|
+
if not any(any(r) for r in self._b):
|
|
42
|
+
raise ValueError("No NRTL parameters in the databank for this mixture; give b12,b21,alpha or use UNIFAC.")
|
|
43
|
+
self.notes.append("NRTL parameters from the ChemSep databank (τij = bij/T).")
|
|
44
|
+
elif name == "nrtl":
|
|
45
|
+
if n != 2 or len(self.params) not in (2, 3):
|
|
46
|
+
raise ValueError("Give NRTL params as b12,b21[,alpha] in K (binary).")
|
|
47
|
+
b12, b21 = self.params[:2]
|
|
48
|
+
a = self.params[2] if len(self.params) == 3 else 0.3
|
|
49
|
+
self._b = [[0, b12], [b21, 0]]
|
|
50
|
+
self._alpha = [[0, a], [a, 0]]
|
|
51
|
+
if name == "uniquac":
|
|
52
|
+
cas = [s.cas for s in subs]
|
|
53
|
+
self._b = IPDB.get_ip_asymmetric_matrix("ChemSep UNIQUAC", cas, "bij")
|
|
54
|
+
if not any(any(r) for r in self._b):
|
|
55
|
+
raise ValueError("No UNIQUAC parameters in the databank for this mixture; use UNIFAC.")
|
|
56
|
+
self.notes.append("UNIQUAC parameters from the ChemSep databank.")
|
|
57
|
+
if name.startswith("unifac"):
|
|
58
|
+
for s in subs:
|
|
59
|
+
if not s.unifac_groups:
|
|
60
|
+
raise ValueError(f"No UNIFAC groups for {s.name}.")
|
|
61
|
+
|
|
62
|
+
def _thermo(self, T, xs):
|
|
63
|
+
n = len(xs)
|
|
64
|
+
if self.name == "nrtl":
|
|
65
|
+
return NRTL(T=T, xs=xs, tau_bs=self._b, alpha_cs=self._alpha)
|
|
66
|
+
if self.name == "uniquac":
|
|
67
|
+
return UNIQUAC(T=T, xs=xs, rs=[s.r for s in self.subs], qs=[s.q for s in self.subs], tau_bs=self._b)
|
|
68
|
+
if self.name == "unifac":
|
|
69
|
+
return UNIFAC.from_subgroups(T=T, xs=xs, chemgroups=[s.unifac_groups for s in self.subs],
|
|
70
|
+
version=0, interaction_data=UFIP, subgroups=UFSG)
|
|
71
|
+
if self.name == "unifac-do":
|
|
72
|
+
groups = [s._constants.UNIFAC_Dortmund_groups[0] for s in self.subs]
|
|
73
|
+
return UNIFAC.from_subgroups(T=T, xs=xs, chemgroups=groups, version=1,
|
|
74
|
+
interaction_data=DOUFIP2016, subgroups=DOUFSG)
|
|
75
|
+
return IdealSolution(T=T, xs=xs) if n else None
|
|
76
|
+
|
|
77
|
+
def ln_gammas(self, T, xs):
|
|
78
|
+
xs = [max(float(x), 0.0) for x in xs]
|
|
79
|
+
if self.name == "margules":
|
|
80
|
+
A12, A21 = self.params
|
|
81
|
+
x1, x2 = xs
|
|
82
|
+
return [x2**2 * (A12 + 2 * (A21 - A12) * x1), x1**2 * (A21 + 2 * (A12 - A21) * x2)]
|
|
83
|
+
if self.name == "vanlaar":
|
|
84
|
+
A12, A21 = self.params
|
|
85
|
+
x1, x2 = xs
|
|
86
|
+
d = A12 * x1 + A21 * x2
|
|
87
|
+
return [A12 * (A21 * x2 / d) ** 2, A21 * (A12 * x1 / d) ** 2]
|
|
88
|
+
if self.name == "wilson":
|
|
89
|
+
L12, L21 = self.params
|
|
90
|
+
x1, x2 = xs
|
|
91
|
+
s = L12 / (x1 + x2 * L12) - L21 / (x2 + x1 * L21)
|
|
92
|
+
return [-math.log(x1 + x2 * L12) + x2 * s, -math.log(x2 + x1 * L21) - x1 * s]
|
|
93
|
+
return [math.log(g) for g in self._thermo(T, _safe(xs)).gammas()]
|
|
94
|
+
|
|
95
|
+
def gammas(self, T, xs):
|
|
96
|
+
return [math.exp(v) for v in self.ln_gammas(T, xs)]
|
|
97
|
+
|
|
98
|
+
def GE(self, T, xs):
|
|
99
|
+
return R * T * sum(x * lg for x, lg in zip(xs, self.ln_gammas(T, xs)))
|
|
100
|
+
|
|
101
|
+
def HE(self, T, xs, dT=0.01):
|
|
102
|
+
g = lambda t: self.GE(t, xs) / t
|
|
103
|
+
return -T**2 * (g(T + dT) - g(T - dT)) / (2 * dT)
|
|
104
|
+
|
|
105
|
+
def SE(self, T, xs):
|
|
106
|
+
return (self.HE(T, xs) - self.GE(T, xs)) / T
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _safe(xs):
|
|
110
|
+
xs = [max(x, 1e-12) for x in xs]
|
|
111
|
+
s = sum(xs)
|
|
112
|
+
return [x / s for x in xs]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def binary_curve(model, T, n=101):
|
|
116
|
+
x1 = np.linspace(0, 1, n)
|
|
117
|
+
ln_g = np.array([model.ln_gammas(T, [max(x, 1e-9), max(1 - x, 1e-9)]) for x in x1])
|
|
118
|
+
return x1, ln_g
|