vle-units
Dimensional analysis and unit conversion for vapor-liquid equilibrium (VLE) and thermodynamic calculations.
Works standalone. Designed as the unit layer for
vle-thermo but useful in any Rust
project that needs thermodynamic-flavored units (gauge pressure, °C / °F,
kJ/kmol, barg, psig, mmHg, etc.).
Features
- Compile-time typed quantities via
uom— zero runtime cost, full dimension safety. Canonical quantity aliases match VLE conventions (VleTemperature,VlePressure,VleMolarEnergy, …). - Runtime unit registry — parse user-supplied strings like
"25 degC","3.5 barg","1 atm"at the FFI boundary. - Gauge ↔ absolute conversion with a runtime-configurable atmospheric pressure (never hardcoded). Default: 101.325 kPa.
- Extensible — define custom units and derived dimensions at runtime (TOML or direct API) without recompiling.
Install
[]
= "0.1"
Example
use UnitRegistry;
let mut reg = with_vle_defaults;
// Parse user input in arbitrary units.
let t = reg.parse?;
let p = reg.parse?;
assert!;
assert!; // gauge + P_atm
// Configure atmospheric pressure for a different location / altitude.
reg.set_atmospheric_pressure?;
# Ok::
Full API docs: https://docs.rs/vle-units.
Why a separate crate?
Thermodynamics code needs a few things that generic unit libraries don't handle cleanly:
- Gauge pressure (
barg,psig,kPag) where absolute = gauge + P_atm, and P_atm is a runtime parameter the operator can set. - Temperature differences vs. absolute temperatures (
ΔT in K vs. T in °C—uommodels these as distinct dimensions to prevent misuse). - Molar units (
kJ/kmol,cm³/mol) that map to the canonical internal units used by cubic-EOS codebases going back to the 1980s.
See docs/en/units/dimensional-analysis.md
for the full design rationale.
License
MIT. See LICENSE.