Skip to main content

refprop/
lib.rs

1//! # refprop
2//!
3//! Safe, ergonomic Rust bindings for
4//! [NIST REFPROP](https://www.nist.gov/srd/refprop) — thermodynamic and
5//! transport properties of refrigerants, pure fluids, and mixtures.
6//!
7//! ## Highlights
8//!
9//! * **Pure fluids** — `Fluid::new("R134A")`
10//! * **Predefined mixtures** — `Fluid::new("R410A")` (loaded from `.MIX`)
11//! * **Custom mixtures** — `Fluid::mixture(&[("R32", 0.5), ("R125", 0.5)])`
12//! * **CoolProp-style `get()`** — `fluid.get("D", "T", 0.0, "Q", 100.0)`
13//! * **Configurable units** — work in °C + bar, K + kPa, or any combination
14//! * **Thread-safe** — global mutex prevents data races on REFPROP's singleton state
15//! * **[`FluidApi`] trait** — common interface for [`Fluid`] and
16//!   [`ParallelFluid`](pool::ParallelFluid), write generic code that works
17//!   with either backend
18//!
19//! ## Quick example
20//!
21//! ```no_run
22//! use refprop::{Fluid, UnitSystem};
23//!
24//! // Engineering units: °C, bar, kg/m³, kJ/kg
25//! let co2 = Fluid::with_units("CO2", UnitSystem::engineering())?;
26//!
27//! let p = co2.get("P", "T", -5.0, "Q", 100.0)?;
28//! println!("Psat(-5 °C) = {p:.2} bar");
29//!
30//! let d = co2.get("D", "T", -5.0, "Q", 100.0)?;
31//! println!("D_vap(-5 °C) = {d:.2} kg/m³");
32//! # Ok::<(), refprop::RefpropError>(())
33//! ```
34//!
35//! ## Generic code with `FluidApi`
36//!
37//! ```no_run
38//! use refprop::{FluidApi, Fluid, UnitSystem, Result};
39//!
40//! fn density(f: &impl FluidApi, t: f64, p: f64) -> Result<f64> {
41//!     f.get("D", "T", t, "P", p)
42//! }
43//!
44//! let fluid = Fluid::with_units("R134A", UnitSystem::engineering())?;
45//! let d = density(&fluid, 25.0, 10.0)?;
46//! # Ok::<(), refprop::RefpropError>(())
47//! ```
48//!
49//! ## Unit system
50//!
51//! Choose units at construction time with [`UnitSystem`] presets
52//! ([`refprop()`](UnitSystem::refprop), [`engineering()`](UnitSystem::engineering),
53//! [`si()`](UnitSystem::si)) or the builder:
54//!
55//! ```
56//! use refprop::{UnitSystem, TempUnit, PressUnit};
57//!
58//! let units = UnitSystem::new()
59//!     .temperature(TempUnit::Celsius)
60//!     .pressure(PressUnit::Bar);
61//! ```
62//!
63//! ## Mixtures
64//!
65//! ```no_run
66//! use refprop::{Fluid, UnitSystem};
67//!
68//! // Predefined (from .MIX file)
69//! let r410a = Fluid::with_units("R410A", UnitSystem::engineering())?;
70//!
71//! // Custom composition
72//! let r454c = Fluid::mixture_with_units(
73//!     &[("R32", 0.215), ("R1234YF", 0.785)],
74//!     UnitSystem::engineering(),
75//! )?;
76//! # Ok::<(), refprop::RefpropError>(())
77//! ```
78
79// ── Internal modules ─────────────────────────────────────────────────
80mod backend;
81pub mod converter;
82pub mod error;
83pub mod sys;
84pub mod fluid;
85pub mod properties;
86pub mod traits;
87
88#[cfg(feature = "parallel")]
89pub mod pool;
90
91// ── Public re-exports ────────────────────────────────────────────────
92pub use error::{RefpropError, Result};
93pub use fluid::Fluid;
94pub use traits::FluidApi;
95pub use properties::{
96    CriticalProps, FluidInfo, SaturationProps, ThermoProp, TransportProps,
97};
98
99pub use converter::{
100    Converter, UnitSystem,
101    TempUnit, PressUnit, DensityUnit, EnergyUnit, EntropyUnit,
102    ViscosityUnit, ConductivityUnit,
103};
104
105#[cfg(feature = "parallel")]
106pub use pool::ParallelFluid;