Skip to content

Commit

Permalink
fixed px_reg4
Browse files Browse the repository at this point in the history
  • Loading branch information
thermalogic committed Sep 4, 2023
1 parent e891461 commit 289f2b5
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "seuif97"
version = "1.1.3"
version = "1.1.4"
edition = "2021"
authors = ["Cheng Maohua <[email protected]>"]
description = "The high-speed IAPWS-IF97 package with C and Python binding"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
println!("hs: h={h:.6} s={s:.6} p={p:.6} t={t:.6}");

p = 0.5;
let x=0.5;
let x = 0.5;
t = px(p, x, OT);
println!("px: p={p:.6} x={x:.6} t={t:.6}");
}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = seuif97
version = 2.1.9
version = 2.2.0
author=Cheng Maohua
author_email[email protected]
keywords = IAPWS-IF97, IF97
Expand Down
2 changes: 1 addition & 1 deletion src/cdecl_c_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub unsafe extern "C" fn px(p: f64, x: f64, o_id: i32) -> f64 {
match o_id {
OP => return p,
OX => return x,
OT => return px_reg4(p, x, o_id)-273.15,
OT => return px_reg4(p, x, o_id),
_ => return px_reg4(p, x, o_id),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/python_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn px(p: f64, x: f64, o_id: i32) -> f64 {
match o_id {
OP => return p,
OX => return x,
OT => return px_reg4(p, x, o_id)-273.15,
OT => return px_reg4(p, x, o_id),
_ => return px_reg4(p, x, o_id),
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/r4/region4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn ph_reg4(p: f64, h: f64, o_id: i32) -> f64 {
if o_id == OX {
return x;
}
px_reg4(p, x, o_id)
px_reg4(p, x, o_id)
}

pub fn ps_reg4(p: f64, s: f64, o_id: i32) -> f64 {
Expand All @@ -43,6 +43,7 @@ pub fn ps_reg4(p: f64, s: f64, o_id: i32) -> f64 {
return x;
}
px_reg4(p, x, o_id)

}

pub fn hs_reg4(h: f64, s: f64, o_id: i32) -> f64 {
Expand All @@ -63,8 +64,12 @@ pub fn hs_reg4(h: f64, s: f64, o_id: i32) -> f64 {
if o_id == OX {
return x;
}

px_reg4(p, x, o_id)
// T is k
if o_id == OT {
px_reg4(p, x, o_id) - 273.15
} else {
px_reg4(p, x, o_id)
}
}

/// Region 4 - The extended input pair
Expand Down
10 changes: 6 additions & 4 deletions src/r4/region4_pTx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ use crate::r3::*;
use crate::r4::region4_sat_pT::*;

/// saturation water include :region3 pT2v_sat_reg
// t is °C
pub fn p2sat_water(p: f64, o_id: i32) -> f64 {
if o_id == OP {
return p;
}

let T: f64 = T_saturation(p);
if o_id == OT {
return T;
return T-273.15;
}

if p >= P_MIN && p <= Ps_623 {
Expand All @@ -46,7 +47,7 @@ pub fn p2sat_water(p: f64, o_id: i32) -> f64 {
}
}

/// saturation steam
/// saturation steam, t is °C
pub fn p2sat_steam(p: f64, o_id: i32) -> f64 {
if o_id == OP {
return p;
Expand Down Expand Up @@ -163,7 +164,8 @@ pub fn T2sat_steam(T: f64, o_id: i32) -> f64 {
return Td_reg3(T, d, o_id);
}
}
// T is k

// px_reg4 ,t is °C
pub fn px_reg4(p: f64, x: f64, o_id: i32) -> f64 {
// x= 0 or 1, return all properties
if x == 0.0 {
Expand All @@ -174,7 +176,7 @@ pub fn px_reg4(p: f64, x: f64, o_id: i32) -> f64 {
let mut r: f64 = 0.0;
let T: f64 = T_saturation(p);
match o_id {
OT => return T,
OT => return T-273.15,
OH | OS | OV | OD | OU | OF | OG | OE => {
// region 4 x(0,1) return v,h,s only
let mut rl: f64 = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/rust_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn px(p: f64, x: f64, o_id: i32) -> f64 {
match o_id {
OP => return p,
OX => return x,
OT => return px_reg4(p, x, o_id)-273.15,
OT => return px_reg4(p, x, o_id),
_ => return px_reg4(p, x, o_id),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/stdcall_c_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub unsafe extern "stdcall" fn px(p: f64, x: f64, o_id: i32) -> f64 {
match o_id {
OP => return p,
OX => return x,
OT => return px_reg4(p, x, o_id)-273.15,
OT => return px_reg4(p, x, o_id),
_ => return px_reg4(p, x, o_id),
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ph_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ fn test_region4_ph() {
let mut h: f64 = 0.0;
let mut h1: f64 = 0.0;
let mut h2: f64 = 0.0;
let mut x: f64 = 0.0;
let mut x: f64 = 0.35;
for i in 0..3 {
let p: f64 = r4_sat_Tp[i][1];
x = 0.35;
h = px(p, x, OH);
assert_approx_eq!(x, ph(p, h, OX));
assert_approx_eq!(r4_sat_Tp[i][0]-273.15, ph(p, h, OT));
}

for i in 0..3 {
let p: f64 = r4_sat_pT[i][0];
x = 0.55;
h = px(p, x, OH);
assert_approx_eq!(x, ph(p, h, OX));
assert_approx_eq!(r4_sat_pT[i][1]-273.15, ph(p, h, OT));
}
}
5 changes: 4 additions & 1 deletion tests/ps_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ fn test_region4_ps() {
let mut s: f64 = 0.0;
let mut s1: f64 = 0.0;
let mut s2: f64 = 0.0;
let mut x: f64 = 0.0;
let mut x: f64 = 0.35;
for i in 0..3 {
let p: f64 = r4_sat_Tp[i][1];
s = px(p, x, OS);
assert_approx_eq!(x, ps(p, s, OX));
assert_approx_eq!(r4_sat_Tp[i][0]-273.15, ps(p, s, OT));
}

for i in 0..3 {
let p: f64 = r4_sat_pT[i][0];
x = 0.35;
s = px(p, x, OS);
assert_approx_eq!(x, ps(p, s, OX));
assert_approx_eq!(r4_sat_pT[i][1]-273.15, ps(p, s, OT));
}
}
8 changes: 8 additions & 0 deletions tests/pv_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ fn test_pv_region4() {
let p: f64 = r4_sat_Tp[i][1];
v = px(p, x, OV);
assert_approx_eq!(x, pv(p, v, OX));
assert_approx_eq!(r4_sat_Tp[i][0]-273.15, pv(p, v, OT));
}

for i in 0..3 {
let p: f64 = r4_sat_pT[i][0];
v= px(p, x, OV);
assert_approx_eq!(x, pv(p, v, OX));
assert_approx_eq!(r4_sat_pT[i][1]-273.15, pv(p, v, OT));
}
}

Expand Down

0 comments on commit 289f2b5

Please sign in to comment.