Skip to main content

refprop/
properties.rs

1// ── Thermodynamic properties from a flash calculation ───────────────
2
3/// Result of a TP-flash or PH-flash calculation.
4///
5/// **Default REFPROP units (molar basis):**
6///
7/// | Field            | Unit       |
8/// |------------------|------------|
9/// | temperature      | K          |
10/// | pressure         | kPa        |
11/// | density          | mol/L      |
12/// | enthalpy         | J/mol      |
13/// | entropy          | J/(mol·K)  |
14/// | cv               | J/(mol·K)  |
15/// | cp               | J/(mol·K)  |
16/// | sound_speed      | m/s        |
17/// | quality          | molar vapor fraction (0–1, >1 or <0 = single phase) |
18/// | internal_energy  | J/mol      |
19#[derive(Debug, Clone, PartialEq)]
20pub struct ThermoProp {
21    pub temperature: f64,
22    pub pressure: f64,
23    pub density: f64,
24    pub enthalpy: f64,
25    pub entropy: f64,
26    pub cv: f64,
27    pub cp: f64,
28    pub sound_speed: f64,
29    pub quality: f64,
30    pub internal_energy: f64,
31}
32
33impl std::fmt::Display for ThermoProp {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        writeln!(f, "T  = {:.4} K", self.temperature)?;
36        writeln!(f, "P  = {:.4} kPa", self.pressure)?;
37        writeln!(f, "D  = {:.6} mol/L", self.density)?;
38        writeln!(f, "H  = {:.4} J/mol", self.enthalpy)?;
39        writeln!(f, "S  = {:.4} J/(mol·K)", self.entropy)?;
40        writeln!(f, "Cv = {:.4} J/(mol·K)", self.cv)?;
41        writeln!(f, "Cp = {:.4} J/(mol·K)", self.cp)?;
42        writeln!(f, "W  = {:.4} m/s", self.sound_speed)?;
43        write!(f, "Q  = {:.6}", self.quality)
44    }
45}
46
47// ── Saturation properties ───────────────────────────────────────────
48
49/// Saturation-line properties returned by `SATPdll` / `SATTdll`.
50///
51/// Densities are in **mol/L**.
52#[derive(Debug, Clone, PartialEq)]
53pub struct SaturationProps {
54    /// Saturation temperature (K)
55    pub temperature: f64,
56    /// Saturation pressure (kPa)
57    pub pressure: f64,
58    /// Saturated-liquid density (mol/L)
59    pub density_liquid: f64,
60    /// Saturated-vapor density (mol/L)
61    pub density_vapor: f64,
62}
63
64impl std::fmt::Display for SaturationProps {
65    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66        writeln!(f, "T_sat  = {:.4} K ({:.2} °C)", self.temperature, self.temperature - 273.15)?;
67        writeln!(f, "P_sat  = {:.4} kPa", self.pressure)?;
68        writeln!(f, "D_liq  = {:.6} mol/L", self.density_liquid)?;
69        write!(f, "D_vap  = {:.6} mol/L", self.density_vapor)
70    }
71}
72
73// ── Transport properties ────────────────────────────────────────────
74
75/// Viscosity and thermal conductivity at a given (T, D) state point.
76#[derive(Debug, Clone, PartialEq)]
77pub struct TransportProps {
78    /// Dynamic viscosity (µPa·s)
79    pub viscosity: f64,
80    /// Thermal conductivity (W/(m·K))
81    pub thermal_conductivity: f64,
82}
83
84impl std::fmt::Display for TransportProps {
85    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86        writeln!(f, "eta = {:.6} µPa·s", self.viscosity)?;
87        write!(f, "tcx = {:.6} W/(m·K)", self.thermal_conductivity)
88    }
89}
90
91// ── Critical point ──────────────────────────────────────────────────
92
93#[derive(Debug, Clone, PartialEq)]
94pub struct CriticalProps {
95    /// Critical temperature (K)
96    pub temperature: f64,
97    /// Critical pressure (kPa)
98    pub pressure: f64,
99    /// Critical density (mol/L)
100    pub density: f64,
101}
102
103impl std::fmt::Display for CriticalProps {
104    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
105        writeln!(f, "Tc = {:.4} K ({:.2} °C)", self.temperature, self.temperature - 273.15)?;
106        writeln!(f, "Pc = {:.4} kPa ({:.4} bar)", self.pressure, self.pressure / 100.0)?;
107        write!(f, "Dc = {:.6} mol/L", self.density)
108    }
109}
110
111// ── Fluid information ───────────────────────────────────────────────
112
113/// Static information about a pure component (from `INFOdll`).
114#[derive(Debug, Clone, PartialEq)]
115pub struct FluidInfo {
116    /// Molar mass (g/mol)
117    pub molar_mass: f64,
118    /// Triple-point temperature (K)
119    pub triple_point_temp: f64,
120    /// Normal boiling point (K)
121    pub normal_boiling_point: f64,
122    /// Critical temperature (K)
123    pub critical_temperature: f64,
124    /// Critical pressure (kPa)
125    pub critical_pressure: f64,
126    /// Critical density (mol/L)
127    pub critical_density: f64,
128    /// Critical compressibility factor Z_c
129    pub compressibility_factor: f64,
130    /// Acentric factor
131    pub acentric_factor: f64,
132    /// Dipole moment (debye)
133    pub dipole_moment: f64,
134    /// Gas constant R for this fluid (J/(mol·K))
135    pub gas_constant: f64,
136}
137
138impl std::fmt::Display for FluidInfo {
139    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
140        writeln!(f, "M     = {:.4} g/mol", self.molar_mass)?;
141        writeln!(f, "T_trp = {:.4} K", self.triple_point_temp)?;
142        writeln!(f, "T_nbp = {:.4} K ({:.2} °C)", self.normal_boiling_point, self.normal_boiling_point - 273.15)?;
143        writeln!(f, "Tc    = {:.4} K ({:.2} °C)", self.critical_temperature, self.critical_temperature - 273.15)?;
144        writeln!(f, "Pc    = {:.4} kPa", self.critical_pressure)?;
145        writeln!(f, "Dc    = {:.6} mol/L", self.critical_density)?;
146        writeln!(f, "Zc    = {:.6}", self.compressibility_factor)?;
147        writeln!(f, "omega = {:.6}", self.acentric_factor)?;
148        writeln!(f, "dip   = {:.4} debye", self.dipole_moment)?;
149        write!(f, "R     = {:.6} J/(mol·K)", self.gas_constant)
150    }
151}