refprop-rs 0.3.1

Safe Rust bindings for NIST REFPROP – thermodynamic & transport properties of refrigerants, pure fluids, and mixtures
Documentation
//! Common trait for single-point REFPROP property lookups.
//!
//! [`FluidApi`] is implemented by both [`Fluid`](crate::Fluid) and
//! [`ParallelFluid`](crate::ParallelFluid), allowing generic code
//! to work with either backend:
//!
//! ```no_run
//! use refprop::{FluidApi, Fluid, UnitSystem, Result};
//!
//! fn density(f: &impl FluidApi, t: f64, p: f64) -> Result<f64> {
//!     f.get("D", "T", t, "P", p)
//! }
//!
//! let fluid = Fluid::with_units("R134A", UnitSystem::engineering())?;
//! let d = density(&fluid, 25.0, 10.0)?;
//! # Ok::<(), refprop::RefpropError>(())
//! ```

use crate::converter::Converter;
use crate::error::Result;
use crate::properties::*;

/// Common interface shared by [`Fluid`](crate::Fluid) and
/// [`ParallelFluid`](crate::ParallelFluid).
///
/// Import this trait to write functions that are generic over
/// the concrete backend:
///
/// ```no_run
/// use refprop::{FluidApi, Result};
///
/// fn report(f: &impl FluidApi) -> Result<()> {
///     let cp = f.critical_point()?;
///     println!("Tc = {:.2}", cp.temperature);
///     Ok(())
/// }
/// ```
pub trait FluidApi {
    // ── Generic lookup ──────────────────────────────────────────────

    /// CoolProp-style generic property lookup.
    ///
    /// All values are in the unit system configured at construction.
    fn get(&self, output: &str, key1: &str, val1: f64, key2: &str, val2: f64) -> Result<f64>;

    // ── Flash calculations ──────────────────────────────────────────

    /// Temperature–pressure flash.
    fn props_tp(&self, t: f64, p: f64) -> Result<ThermoProp>;

    /// Pressure–enthalpy flash.
    fn props_ph(&self, p: f64, h: f64) -> Result<ThermoProp>;

    /// Pressure–entropy flash.
    fn props_ps(&self, p: f64, s: f64) -> Result<ThermoProp>;

    /// Temperature–density flash.
    fn props_td(&self, t: f64, d: f64) -> Result<ThermoProp>;

    /// Temperature–enthalpy flash.
    fn props_th(&self, t: f64, h: f64) -> Result<ThermoProp>;

    /// Temperature–entropy flash.
    fn props_ts(&self, t: f64, s: f64) -> Result<ThermoProp>;

    /// Pressure–density flash.
    fn props_pd(&self, p: f64, d: f64) -> Result<ThermoProp>;

    /// Density–enthalpy flash.
    fn props_dh(&self, d: f64, h: f64) -> Result<ThermoProp>;

    /// Density–entropy flash.
    fn props_ds(&self, d: f64, s: f64) -> Result<ThermoProp>;

    /// Enthalpy–entropy flash.
    fn props_hs(&self, h: f64, s: f64) -> Result<ThermoProp>;

    /// Temperature–quality flash.  Quality `q` is in **percent** (0–100).
    fn props_tq(&self, t: f64, q: f64) -> Result<ThermoProp>;

    /// Pressure–quality flash.  Quality `q` is in **percent** (0–100).
    fn props_pq(&self, p: f64, q: f64) -> Result<ThermoProp>;

    // ── Saturation ──────────────────────────────────────────────────

    /// Saturation properties at a given pressure.
    fn saturation_p(&self, p: f64) -> Result<SaturationProps>;

    /// Saturation properties at a given temperature.
    fn saturation_t(&self, t: f64) -> Result<SaturationProps>;

    // ── Transport ───────────────────────────────────────────────────

    /// Transport properties (viscosity, thermal conductivity) at (T, D).
    fn transport(&self, t: f64, d: f64) -> Result<TransportProps>;

    // ── Critical point & info ───────────────────────────────────────

    /// Critical point (Tc, Pc, Dc) in user units.
    fn critical_point(&self) -> Result<CriticalProps>;

    /// Static fluid information (molar mass, triple point, …).
    ///
    /// Values are always in REFPROP-native units regardless of the
    /// configured `UnitSystem`.
    fn info(&self) -> Result<FluidInfo>;

    // ── Converter access ────────────────────────────────────────────

    /// Access the active unit converter.
    fn converter(&self) -> &Converter;
}