Skip to main content

Crate seuif97

Crate seuif97 

Source
Expand description

§SEUIF97

docs.rs Build test Crates.io Version Crates.io Total Downloads Crates.io Downloads (recent)

This is the Rust implementation of the high-speed IAPWS-IF97 package SEUIF97 with C, Python and WASM bindings. It is designed for computation-intensive tasks, such as simulating non-stationary processes, on-line process monitoring, and optimization.

SEUIF97 achieves a 5-20x speedup over naive implementations that use the Rust standard library’s powi() in for loops for the basic equations of Regions 1, 2, and 3.

This package supports 12 distinct input state pairs for calculating 36 thermodynamic, transport, and derived properties (see Properties), and thermodynamic process functions (see Thermodynamic Process Functions).

§What’s New in the Rust Version

The Rust version of SEUIF97 is a major upgrade over the original C implementation, delivering significant improvements in performance, functionality, and ecosystem support.

FeatureC VersionRust Version
Calculation SpeedBaseline~2× speedup
Supported Properties30 properties36 properties (+6 new)
Package DistributionPyPI onlyCrates.io, PyPI, npm
Direct Property Functions (new)

For detailed comparison and key improvements, see Rust vs C.

§Acceleration Methods

  • Profiling-guided loop tiling partitions polynomial summation into cache-friendly tiles with empirically determined boundaries, enabling more effective SIMD vectorization.
  • Shared-power scaling exploits the mathematical relationship between Gibbs/Helmholtz free energy polynomials and their partial derivatives to compute them simultaneously in a single pass, eliminating redundant power calculations.

For more details on these algorithms, see: code snippets of the acceleration methods.

§Performance Comparison with CoolProp IF97

SEUIF97 achieves 3.4 - 7.6x speedups over CoolProp IF97. See Performance Comparison for detailed benchmark results.

§Property Calculation Functions

The package provides two types of API for property calculation.

§Universal Property Functions

The following 12 input pairs are implemented:

  (p,t), (p,h), (p,s), (p,v)
  (h,s)
  (t,h), (t,s), (t,v)
  (h,x), (t,x), (v,x), (s,x)

Each function accepts an input pair, an output property ID (o_id), and an optional region parameter for faster computation. For example: the input pair (p,t): pt(p,t,o_id), pt(p,t,(o_id,region))

Note:

  • The region parameter is Rust-only. C, Python and WASM bindings support the o_id form only.
  • Only linearly related thermodynamic properties are calculable in the wet steam region.

§Direct Property Functions

Function naming convention: {input1}{input2}2{output}.

InputOutputsInputOutputsInputOutputs
(p,t)h,s,v,x(t,h)p,s,v,x(p,x)t,h,s,v
(p,h)t,s,v,x(t,s)p,h,v,x(t,x)p,h,s,v
(p,s)t,h,v,x(t,v)p,h,s,x(h,x)p,t,s,v
(p,v)t,h,s,x(h,s)p,t,v,x(s,x)p,t,h,v

Total: 48 functions(e.g. pt2h(p,t), ph2t(p,h), hs2p(h,s))

§Thermodynamic Process Functions

The following thermodynamic process functions are implemented:

  • ishd(pi, ti, pe): isentropic enthalpy drop for steam expansion (kJ/kg)
  • ief(pi, ti, pe, te): isentropic efficiency for superheated steam expansion (%)

§Install the crate

cargo add seuif97

§Usage

use seuif97::*;
fn main() {    
    let p: f64 = 3.0;
    let t: f64 = 300.0-273.15;
    // universal property functions with o_id parameter only
    let h = pt(p,t,OH);   
    // universal property functions with explicit region for faster calculation
    let s = pt(p,t,(OS,1)); 
    // direct property functions
    let v = pt2v(p,t);

    println!("p={p:.6} t={t:.6} h={h:.6} s={s:.6} v={v:.6}");   

    // thermodynamic process functions
    let pi: f64 = 16.0;
    let ti: f64 = 535.1;
    let pe: f64 = 5.0;
    let delta_h = ishd(pi, ti, pe);
    println!("ishd: pi={pi} ti={ti} pe={pe} delta_h={delta_h:.3}");
}

§C Shared Library

Pre-compiled dynamic link libraries for Windows, Linux and macOS are available in GitHub Releases.

Note: GitHub Releases builds produce library names with platform-specific suffixes. Example: seuif97-windows-x86_64-cdecl.dll. Linux and macOS follow the same naming pattern. Rename them to seuif97.dll / libseuif97.so / libseuif97.dylib before use to match the local build naming convention.

Interfaces and examples are provided in the ./demo_using_lib/ directory, supporting a wide range of languages and environments.

  • C/C++, Python, C#, Java, Excel VBA, Rust, Fortran, Golang, JavaScript/TypeScript
#include <stdlib.h>
#include <stdio.h>

#define OH 4

extern double pt(double p,double t,short o_id);
extern double pt2s(double p,double t);

int main(void)
{
    double p = 16.0;
    double t = 530.0;
    // universal property functions with o_id parameter only
    double h = pt(p, t, OH);
    // direct property functions
    double s = pt2s(p, t);
    printf("p,t %f,%f h= %f s= %f\n", p, t, h, s);
    return EXIT_SUCCESS;
}

Comprehensive Cross-language Examples

§Python binding

Install from PyPI

pip install seuif97
from seuif97 import *

OH=4

p=16.0
t=535.1
# universal property functions with o_id parameter only
h=pt(p,t,OH)
# direct property functions
s=pt2s(p,t)
print(f"p={p}, t={t} h={h:.3f} s={s:.3f}")

Comprehensive Examples in Python

T-S Diagram

§WASM binding

Install from npm:

npm install seuif97
import init, { pt, pt2s } from 'seuif97';

await init();

const p = 16.0;  // MPa
const t = 535.1; // °C
// universal property functions (with o_id parameter only)
const h = pt(p, t, 4);     // kJ/kg
// direct property functions
const s = pt2s(p, t);      // kJ/(kg·K)

console.log('Properties at p = 16.0 MPa, t = 535.1 °C:');
console.log(`H: ${h.toFixed(3)} kJ/kg`);
console.log(`S: ${s.toFixed(5)} kJ/(kg·K)`);

§Properties

PropertyUnitSymbolo_ido_id(i32)
PressureMPapOP0
Temperature°CtOT1
Densitykg/m³ρOD2
Specific Volumem³/kgvOV3
Specific enthalpykJ/kghOH4
Specific entropykJ/(kg·K)sOS5
Specific exergykJ/kgeOE6
Specific internal energykJ/kguOU7
Specific isobaric heat capacitykJ/(kg·K)cpOCP8
Specific isochoric heat capacitykJ/(kg·K)cvOCV9
Speed of soundm/swOW10
Isentropic exponentkOKS11
Specific Helmholtz free energykJ/kgfOF12
Specific Gibbs free energykJ/kggOG13
Compressibility factorzOZ14
Steam qualityxOX15
RegionrOR16
Isobaric cubic expansion coefficient1/KɑvOEC17
Isothermal compressibility1/MPakTOKT18
Partial derivative (∂v/∂T)pm³/(kg·K)(∂v/∂T)pODVDT19
Partial derivative (∂v/∂p)Tm³/(kg·MPa)(∂v/∂p)TODVDP20
Partial derivative (∂p/∂T)vMPa/K(∂p/∂T)vODPDT21
Isothermal throttling coefficientkJ/(kg·MPa)δtOIJTC22
Joule-Thomson coefficientK/MPaμOJTC23
Dynamic viscosityPa·sηODV24
Kinematic viscositym²/sνOKV25
Thermal conductivityW/(m.K)λOTC26
Thermal diffusivitym²/saOTD27
Prandtl numberPrOPR28
Surface tensionN/mσOST29
Static Dielectric ConstantεOSDC30
Isochoric pressure coefficient1/KβOPC31
Isothermal stress coefficientkg/m³βpOBETAP32
Fugacity coefficientφOFI33
FugacityMPafOFU34
Relative pressure coefficient1/KαpOAFLAP35

Structs§

o_id_region_args
the parameters:
o_id: the property of id;
region: the region in the IAPWS-IF97,optional

Constants§

OALFAP
αp - Relative pressure coefficient 1/K
OBETAP
βp - Isothermal stress coefficient, kg/m³
OCP
cp - Specific isobaric heat capacity kJ/(kg·K)
OCV
cv - Specific isochoric heat capacity kJ/(kg·K)
OD
ρ - Density kg/m³
ODPDT
(∂p/∂t)v - Partial derivative MPa/K
ODV
η - Dynamic viscosity Pa.s dv
ODVDP
(∂V/∂P)T - Partial derivative m³/(kg·MPa)
ODVDT
(∂V/∂T)p - Partial derivative m³/(kg·K)
OE
e - Specific exergy kJ/kg
OEC
δt - Isobaric cubic expansion coefficient 1/K
OF
f - Specific Helmholtz free energy kJ/kg
OFI
fi- Fugacity coefficient
OFU
f* - Fugacity MPa
OG
g - Specific Gibbs free energy kJ/kg
OH
h - Specific enthalpy kJ/kg
OIJTC
δt - Isothermal throttling coefficient kJ/(kg·MPa)
OJTC
μ - Joule-Thomson coefficient K/MPa joule
OKS
k - Isentropic exponent
OKT
kT - Isothermal compressibility 1/MPa
OKV
ν - Kinematic viscosity m²/s
OP
p - Pressure MPa
OPC
β - Isochoric pressure coefficient 1/K
OPR
Pr - Prandtl number
OR
r - Region
OS
s - Specific entropy kJ/(kg·K) )
OSDC
ε - Static Dielectric Constant
OST
σ - Surface tension N/m
OT
t - Temperature °C
OTC
λ - Thermal conductivity W/(m.K) tc
OTD
a - Thermal diffusivity m²/s
OU
u - Specific internal energy kJ/kg
OV
v - Specific Volume m³/kg
OW
w - Speed of sound m/s
OX
x - Steam quality
OZ
z - Compressibility factor

Functions§

hs
hs(h,s,o_id) - the property of o_id (thermodynamic,transport,etc)
hs(h,s,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
hs2p
hs2p(h,s) - Calculate pressure from enthalpy and entropy
hs2t
hs2t(h,s) - Calculate temperature from enthalpy and entropy
hs2v
hs2v(h,s) - Calculate specific volume from enthalpy and entropy
hs2x
hs2x(h,s) - Calculate steam quality from enthalpy and entropy
hx
hx(h,x,o_id) - the property of o_id(thermodynamic)
hx2p
hx2p(h,x) - Calculate pressure from enthalpy and steam quality
hx2s
hx2s(h,x) - Calculate specific entropy from enthalpy and steam quality
hx2t
hx2t(h,x) - Calculate temperature from enthalpy and steam quality
hx2v
hx2v(h,x) - Calculate specific volume from enthalpy and steam quality
ief
ief(pi,ti,pe,te) - Isentropic efficiency (%) for superheated steam expansion
ishd
ishd(pi,ti,pe) - Isentropic enthalpy drop
ph
ph(p,h,o_id) - the property of o_id (thermodynamic,transport,etc)
ph(p,h,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
ph2s
ph2s(p,h) - Calculate specific entropy from pressure and enthalpy
ph2t
ph2t(p,h) - Calculate temperature from pressure and enthalpy
ph2v
ph2v(p,h) - Calculate specific volume from pressure and enthalpy
ph2x
ph2x(p,h) - Calculate steam quality from pressure and enthalpy
ps
ps(p,s,o_id) - the property of o_id (thermodynamic,transport,etc)
ps(p,s,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
ps2h
ps2h(p,s) - Calculate specific enthalpy from pressure and entropy
ps2t
ps2t(p,s) - Calculate temperature from pressure and entropy
ps2v
ps2v(p,s) - Calculate specific volume from pressure and entropy
ps2x
ps2x(p,s) - Calculate steam quality from pressure and entropy
pt
pt(p,t,o_id) - the property of o_id (thermodynamic,transport,etc)
pt(p,t,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
pt2h
pt2h(p,t) - Calculate specific enthalpy from pressure and temperature
pt2s
pt2s(p,t) - Calculate specific entropy from pressure and temperature
pt2v
pt2v(p,t) - Calculate specific volume from pressure and temperature
pt2x
pt2x(p,t) - Calculate steam quality from pressure and temperature
pv
pv(p,v,o_id) - the property of o_id(thermodynamic,transport,etc)
pv(p,v,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
pv2h
pv2h(p,v) - Calculate specific enthalpy from pressure and specific volume
pv2s
pv2s(p,v) - Calculate specific entropy from pressure and specific volume
pv2t
pv2t(p,v) - Calculate temperature from pressure and specific volume
pv2x
pv2x(p,v) - Calculate steam quality from pressure and specific volume
px
px(p,x,o_id) - the property of o_id (thermodynamic)
px2h
px2h(p,x) - Calculate specific enthalpy from pressure and steam quality
px2s
px2s(p,x) - Calculate specific entropy from pressure and steam quality
px2t
px2t(p,x) - Calculate temperature from pressure and steam quality
px2v
px2v(p,x) - Calculate specific volume from pressure and steam quality
sx
sx(s,x,o_id) - the property of o_id(thermodynamic)
sx2h
sx2h(s,x) - Calculate specific enthalpy from entropy and steam quality
sx2p
sx2p(s,x) - Calculate pressure from entropy and steam quality
sx2t
sx2t(s,x) - Calculate temperature from entropy and steam quality
sx2v
sx2v(s,x) - Calculate specific volume from entropy and steam quality
th
th(t,h,o_id) - the property of o_id(thermodynamic,transport,etc)
th(t,h,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
th2p
th2p(t,h) - Calculate pressure from temperature and enthalpy
th2s
th2s(t,h) - Calculate specific entropy from temperature and enthalpy
th2v
th2v(t,h) - Calculate specific volume from temperature and enthalpy
th2x
th2x(t,h) - Calculate steam quality from temperature and enthalpy
ts
ts(t,s,o_id) - the property of o_id(thermodynamic,transport,etc)
ts(t,s,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
ts2h
ts2h(t,s) - Calculate specific enthalpy from temperature and entropy
ts2p
ts2p(t,s) - Calculate pressure from temperature and entropy
ts2v
ts2v(t,s) - Calculate specific volume from temperature and entropy
ts2x
ts2x(t,s) - Calculate steam quality from temperature and entropy
tv
tv(t,v,o_id) - the property of o_id(thermodynamic,transport,etc)
tv(t,v,(o_id,reg)) - the property of o_id in the region of reg(thermodynamic,transport,etc)
tv2h
tv2h(t,v) - Calculate specific enthalpy from temperature and specific volume
tv2p
tv2p(t,v) - Calculate pressure from temperature and specific volume
tv2s
tv2s(t,v) - Calculate specific entropy from temperature and specific volume
tv2x
tv2x(t,v) - Calculate steam quality from temperature and specific volume
tx
tx(t,x,o_id) - the property of o_id (thermodynamic)
tx2h
tx2h(t,x) - Calculate specific enthalpy from temperature and steam quality
tx2p
tx2p(t,x) - Calculate pressure from temperature and steam quality
tx2s
tx2s(t,x) - Calculate specific entropy from temperature and steam quality
tx2v
tx2v(t,x) - Calculate specific volume from temperature and steam quality