refprop-rs
Safe Rust bindings for NIST REFPROP -- thermodynamic and transport properties of refrigerants, pure fluids, and mixtures.
Features
- Pure fluids --
Fluid::new("R134A"),Fluid::new("CO2"), ... - Predefined mixtures --
Fluid::new("R410A")(auto-loaded from.MIXfiles) - Custom mixtures --
Fluid::mixture(&[("R32", 0.5), ("R125", 0.5)]) - CoolProp-style
get()--fluid.get("D", "T", 0.0, "Q", 1.0) - Configurable units -- work in °C + bar + kg/m³ + kJ/kg, or K + kPa, or any mix
- Flash calculations -- TP, TD, TH, TS, TQ, PD, PH, PS, PQ, DH, DS, HS
- Saturation, transport, critical point, fluid info
- Thread-safe -- global mutex with automatic fluid re-setup
- Dynamic loading -- no compile-time linking, just point to your REFPROP installation
Prerequisites
A licensed REFPROP installation (v9.1 or v10).
Installation
Add to your Cargo.toml:
[]
= { = "https://github.com/math-dev-24/refprop-rs" }
The library name is refprop, so you import it as:
use ;
Configuration
Tell the library where REFPROP is installed. Create a .env file at
the project root (or set the environment variable directly):
REFPROP_PATH='C:\Program Files (x86)\REFPROP'
The library also checks standard install locations automatically.
Quick start
Engineering units (°C, bar, kg/m³, kJ/kg)
use ;
REFPROP native units (K, kPa, mol/L, J/mol)
use Fluid;
Unit system
Choose your preferred units at construction time. All inputs and outputs are automatically converted.
Presets
| Preset | T | P | D | H | S | Viscosity | Conductivity |
|---|---|---|---|---|---|---|---|
UnitSystem::refprop() |
K | kPa | mol/L | J/mol | J/(mol·K) | µPa·s | W/(m·K) |
UnitSystem::engineering() |
°C | bar | kg/m³ | kJ/kg | kJ/(kg·K) | µPa·s | W/(m·K) |
UnitSystem::si() |
K | Pa | kg/m³ | J/kg | J/(kg·K) | Pa·s | W/(m·K) |
Custom builder
Pick only the units you care about; the rest stay at REFPROP defaults:
use ;
let units = new
.temperature
.pressure;
// density stays mol/L, energy stays J/mol, etc.
let fluid = with_units?;
let sat = fluid.saturation_t?; // 0 °C directly
println!;
Available unit choices
| Property | Options |
|---|---|
| Temperature | Kelvin, Celsius, Fahrenheit |
| Pressure | KPa, Bar, MPa, Pa, Atm, Psi |
| Density | MolPerL, KgPerM3 |
| Energy/Enthalpy | JPerMol, KJPerKg, JPerKg |
| Entropy/Cv/Cp | JPerMolK, KJPerKgK, JPerKgK |
| Viscosity | MicroPaS, MilliPaS, PaS |
| Conductivity | WPerMK, MilliWPerMK |
Mixtures
use ;
// Predefined mixture (from .MIX file)
let r410a = with_units?;
// Custom composition
let r454c = mixture_with_units?;
let p = r454c.get?;
println!;
get() -- generic property lookup
// get(output, key1, val1, key2, val2) -> f64
let density = fluid.get?;
Input pairs (order-independent)
| Pair | Description |
|---|---|
T, P |
Temperature + Pressure |
P, H |
Pressure + Enthalpy |
P, S |
Pressure + Entropy |
T, Q |
Temperature + Quality |
P, Q |
Pressure + Quality |
T, D |
Temperature + Density |
T, H |
Temperature + Enthalpy |
T, S |
Temperature + Entropy |
P, D |
Pressure + Density |
D, H |
Density + Enthalpy |
D, S |
Density + Entropy |
H, S |
Enthalpy + Entropy |
Output keys
| Key | Property |
|---|---|
T |
Temperature |
P |
Pressure |
D |
Density |
H |
Enthalpy |
S |
Entropy |
Q |
Quality (vapor frac.) |
Cv |
Heat capacity (v) |
Cp |
Heat capacity (p) |
W |
Speed of sound |
E |
Internal energy |
ETA |
Dynamic viscosity |
TCX |
Thermal conductivity |
Units depend on the UnitSystem you chose at construction time.
Flash & saturation methods
All methods respect the configured unit system.
let props = fluid.props_tp?; // TP flash
let props = fluid.props_ph?; // PH flash
let props = fluid.props_ps?; // PS flash
let props = fluid.props_tq?; // TQ flash (saturation)
let props = fluid.props_pq?; // PQ flash (saturation)
let props = fluid.props_td?; // TD flash
let props = fluid.props_th?; // TH flash
let props = fluid.props_ts?; // TS flash
let props = fluid.props_pd?; // PD flash
let props = fluid.props_dh?; // DH flash
let props = fluid.props_ds?; // DS flash
let props = fluid.props_hs?; // HS flash
let sat = fluid.saturation_t?; // saturation at T
let sat = fluid.saturation_p?; // saturation at P
let crit = fluid.critical_point?; // Tc, Pc, Dc
let trn = fluid.transport?; // viscosity, conductivity
let info = fluid.info?; // molar mass, Ttrp, Tnbp, ...
Project structure
refprop-rs/
├── Cargo.toml single crate: refprop-rs
├── src/
│ ├── lib.rs public API & re-exports
│ ├── fluid.rs Fluid struct (high-level API)
│ ├── converter.rs UnitSystem + Converter
│ ├── sys.rs low-level FFI (libloading)
│ ├── error.rs error types
│ ├── properties.rs result structs
│ └── backend/
│ └── refprop.rs REFPROP backend (flash, sat, etc.)
└── examples/
├── demo.rs engineering units showcase
├── simple.rs pure fluid, native units
└── mixture.rs predefined & custom mixtures
| Module | Role |
|---|---|
sys |
Dynamic DLL loading + raw FFI function wrappers |
converter |
UnitSystem + Converter (unit conversion) |
fluid |
High-level API: Fluid, get(), flash, units |
backend::refprop |
Core REFPROP calls, global state management |
License
MIT