Crate xsteamrs

Crate xsteamrs 

Source
Expand description

IAPWS-IF97 water/steam properties (Rust)

This crate provides two ways to call into the implementation:

  • IF97 low-level functions: region-based *_p_t / *_rho_t functions, using IF97 conventional SI units (p: MPa, T: K, h/u: kJ/kg, s: kJ/(kg·K), v: m³/kg).
  • Public string-dispatch API: props / props_si, dispatching by a function name string (e.g. "h_pT", "T_ph").
    • props: XSteam.m-style default units (p: bar, T: °C, most others follow IF97 SI units)
    • props_si: SI inputs (p: Pa, T: K, others follow IF97 SI units); temperature outputs in K and pressure outputs in Pa

§Quick start: XSteam-style API

  • Function names are case-insensitive; the implementation applies trim() + to_ascii_lowercase().
  • Input units depend on the selected function name (the table below shows the most common subset).
use xsteamrs::props;

fn rel_close(a: f64, b: f64, rel: f64) -> bool {
    if b == 0.0 { (a - b).abs() <= rel } else { ((a - b) / b).abs() <= rel }
}

// Example 1: p(bar) + T(°C) -> h(kJ/kg)
let h = props("h_pT", 1.0, 100.0).unwrap();
assert!(rel_close(h, 2_675.0, 1e-3));

// Example 2: p(bar) + h(kJ/kg) -> T(°C)
let t_c = props("T_ph", 1.0, 100.0).unwrap();
assert!(t_c.is_finite());

§XSteam-style units (common subset)

  • *_p*: p in bar
  • *_T* / *_t*: T in °C (note: low-level IF97 functions use K)
  • h/ukJ/kg
  • skJ/(kg·K)
  • vm³/kg
  • rhokg/m³
  • Cp/CvkJ/(kg·K)
  • wm/s
  • my (dynamic viscosity): XSteam.m default output (typically Pa·s)
  • tc (thermal conductivity): XSteam.m default output (typically W/(m·K))
  • st (surface tension): XSteam.m default output (typically N/m)

The supported function names match the public interface in XSteam.m. See the fun list in XSteam.m#L3826-L3829.

§Using low-level IF97 functions (more explicit types/units)

Low-level functions typically use parameter names like p_mpa and t_k to avoid unit confusion:

  • If you only know (p, T): call region_from_p_t and then h1_p_t / h2_p_t / h3_p_t / h5_p_t, etc.
  • If you only know (p, h): call [region_from_p_h] and then t1_p_h / t2_p_h / t3_p_h / t5_p_h, etc.
  • If you only know (p, s): call [region_from_p_s] and then t1_p_s / t2_p_s / t3_p_s / t5_p_s, etc.
use xsteamrs::{h1_p_t, psat_mpa_from_t_k};

// Saturation pressure: input T(K), output p(MPa)
let p_sat = psat_mpa_from_t_k(373.15).unwrap();
assert!(p_sat > 0.0);

// Region 1: input p(MPa), T(K), output h(kJ/kg)
let h = h1_p_t(0.101_325, 373.15).unwrap();
assert!(h.is_finite());

§Error handling

Prefer handling errors explicitly via If97Result returned by props / props_si.

Enums§

If97Error
Errors that may occur during IF97 calculations.
Region

Functions§

b23_p_mpa_from_t_k
b23_t_k_from_p_mpa
cp1_p_t
cp2_p_t
cp3_p_t
cp3_rho_t
cp5_p_t
cv1_p_t
cv2_p_t
cv3_p_t
cv3_rho_t
cv5_p_t
h1_p_t
h2_p_t
h3_p_t
h3_rho_t
h5_p_t
p1_h_s
p2_h_s
p3_h_s
p3_rho_t
props
Public string-dispatch API (XSteam units: bar / °C).
props_si
psat_bar_from_t_c
XSteam-style: given temperature T (°C), compute saturation pressure psat (bar).
psat_mpa_from_t_k
Given temperature T (K), compute saturation pressure psat (MPa).
region_from_p_t
rho3_p_t
s1_p_t
s2_p_t
s3_p_t
s3_rho_t
s5_p_t
t1_p_h
t1_p_rho
t1_p_s
t2_p_h
t2_p_rho
t2_p_s
t3_p_h
t3_p_s
t5_p_h
t5_p_s
tsat_c_from_p_bar
XSteam-style: given saturation pressure p (bar), compute saturation temperature Tsat (°C).
tsat_k_from_p_mpa
Given saturation pressure p (MPa), compute saturation temperature Tsat (K).
u1_p_t
u2_p_t
u3_p_t
u3_rho_t
u5_p_t
v1_p_t
v2_p_t
v3_p_h
v3_p_s
v3_p_t
v5_p_t
w1_p_t
w2_p_t
w3_p_t
w3_rho_t
w5_p_t

Type Aliases§

If97Result
IF97 result type.