rfluids
🦀 Rusty CoolProp wrapper
Overview
rfluids provides a safe, idiomatic Rust interface to CoolProp —
a comprehensive C++ library for thermophysical property calculations.
Built with type safety and ergonomics in mind, it enables precise fluid property
calculations for engineering and scientific applications.
Key Features
- Rich substance library: pure fluids, incompressible fluids, predefined mixtures, binary mixtures, and custom mass- or volume-based mixtures
- Comprehensive property calculations: thermodynamic (e.g., density, enthalpy, entropy, etc.) and transport properties (e.g., viscosity, thermal conductivity, etc.)
- Psychrometric calculations: based on ASHRAE RP-1485 standard
- Flexible backends: choose between
HEOS,IF97, and otherCoolPropbackends, which determine the underlying equation of state or calculation method used for thermophysical property calculations - Type-safe API: leverages Rust's type system with the Typestate Pattern to prevent invalid operations at compile time
- Configuration management: flexible control over
CoolPropconfiguration via type-safe builder, with optionalserdesupport for loading from configuration files - Batteries included: pre-compiled
CoolPropdynamic libraries for all supported platforms
Modules
fluid– thermophysical properties of substances (pure fluids and mixtures)humid_air– thermophysical properties of real humid airsubstance– types representingCoolPropsubstancesio– input/output parameter types for fluid and humid air calculationsnative– low-level and high-levelCoolPropAPI bindingsconfig– global configuration management forCoolPropprelude– convenient re-exports of commonly used types and traits
Feature Flags
regen-bindings– regenerates FFI bindings toCoolProp(requireslibclang)serde– enables serialization and deserialization support forConfig, allowing integration with configuration management crates and file-based configuration
Supported platforms
Linux x86-64macOS AArch64macOS x86-64Windows AArch64Windows x86-64
MSRV
rfluids requires rustc 1.85.0 or later.
How to install
Add this to your Cargo.toml:
[]
= "0.3"
Or via command line:
cargo add rfluids
🎁 It comes with native CoolProp dynamic libraries for supported platforms. The library
required for your platform will be automatically copied to the target directory during build.
It also includes pre-generated FFI bindings, so libclang is not required for normal builds.
Regenerating bindings
If you need to regenerate the FFI bindings (requires libclang), enable the
regen-bindings feature.
Add this to your Cargo.toml:
[]
= { = "0.3", = ["regen-bindings"] }
Or via command line:
cargo add rfluids --features regen-bindings
Examples
| ℹ️ All calculations are performed in SI units |
|---|
Specific heat [J/kg/K] of saturated water vapor at 1 atm:
use assert_relative_eq;
use *;
let mut water_vapor = from
.in_state?;
assert_relative_eq!;
Dynamic viscosity [Pa·s] of propylene glycol aqueous solution with 60 % mass fraction at 100 kPa and -20 °C:
use assert_relative_eq;
use *;
let mut propylene_glycol = from
.in_state?;
assert_relative_eq!;
Density [kg/m³] of ethanol aqueous solution (with ethanol 40 % mass fraction) at 200 kPa and 4 °C:
use assert_relative_eq;
use *;
let mut mix =
try_from?
.in_state?;
assert_relative_eq!;
Wet-bulb temperature [K] of humid air at 300 m above sea level, 30 °C and 50 % relative humidity:
use assert_relative_eq;
use *;
let mut humid_air = new.in_state?;
assert_relative_eq!;
Fluid
and HumidAir
implement the PartialEq trait.
Equality is checked by the thermodynamic state:
use *;
let mut humid_air = new.in_state?;
let mut another_humid_air = new.in_state?;
assert_eq!;
another_humid_air.update?;
assert_ne!;
You can also specify a CoolProp backend for
Fluid
instead of the default one using
Fluid::builder:
use *;
let mut water = from
.in_state?;
let mut if97_water = builder
.substance
.with_backend
.build?
.in_state?;
// Same fluids with different backends are never equal
assert_ne!;
// Different backends may yield slightly different results for the same property
assert!;