Skip to content

Commit

Permalink
the critical point
Browse files Browse the repository at this point in the history
  • Loading branch information
thermalogic committed Aug 10, 2023
1 parent c0dfa4e commit 61bcd2e
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "if97"
version = "1.4.0"
version = "1.4.1"
edition = "2021"
authors = ["Cheng Maohua <cmh@seu.edu.cn>"]
description = "The high-speed IAPWS-IF97 package with C and Python binding"
Expand All @@ -22,7 +22,7 @@ stdcall = []
python = ["pyo3"]

[dependencies.pyo3]
version = "0.15.1"
version = "0.19.2"
features = ["extension-module"]
optional = true

Expand Down
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.0.7
version = 2.0.8
author=Cheng Maohua
author_email=cmh@seu.edu.cn
keywords = IAPWS-IF97, IF97
Expand Down
8 changes: 8 additions & 0 deletions src/cdecl_c_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ pub unsafe extern "C" fn px(p: f64, x: f64, o_id: i32) -> f64 {
/// double tx(double t,double x,short o_id) - the propertry of `o_id` (thermodynamic)
#[no_mangle]
pub unsafe extern "C" fn tx(t: f64, x: f64, o_id: i32) -> f64 {
if (o_id==OT)
{
return t;
}
if (o_id==OX)
{
return x;
}
let T: f64 = t + 273.15;
if T > T_MAX4 || T < T_MIN4 || x > 1.0 || x < 0.0 {
return INVALID_VALUE as f64;
Expand Down
2 changes: 2 additions & 0 deletions src/common/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub const INVALID_H: i32 = -2103;
pub const INVALID_PT: i32 = -2201;
pub const INVALID_HS: i32 = -2202;

pub const FLOAT_ERROR:f64 =1.0e-6;

/// constants
pub const K: f64 = 273.15;
pub const RGAS_WATER: f64 = 0.461526; //gas constant in KJ/(kg K)
Expand Down
10 changes: 9 additions & 1 deletion src/python_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ fn px(p: f64, x: f64, o_id: i32) -> f64 {

#[pyfunction]
fn tx(t: f64, x: f64, o_id: i32) -> f64 {
if (o_id==OT)
{
return t;
}
if (o_id==OX)
{
return x;
}
let T: f64 = t + 273.15;
if T > T_MAX4 || T < T_MIN4 || x > 1.0 || x < 0.0 {
if T>T_MAX4 || T < T_MIN4 || x > 1.0 || x < 0.0 {
return INVALID_VALUE as f64;
}
Tx_reg4(T, x, o_id)
Expand Down
40 changes: 31 additions & 9 deletions src/r4/region4_pTx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn p2sat_water(p: f64, o_id: i32) -> f64 {
} else {
// region3
let mut v: f64 = 0.0;
if p == PC_WATER {
if (p -PC_WATER).abs()<FLOAT_ERROR {
v = 1.0 / 322.0;
} else {
v = pT2v_sat_reg3(p, T, 0.0);
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn p2sat_steam(p: f64, o_id: i32) -> f64 {
} else {
//reg3d =ss
let mut v: f64 = 0.0;
if p == PC_WATER {
if (p -PC_WATER).abs()<FLOAT_ERROR {
let v: f64 = 1.0 / 322.0;
} else {
let v: f64 = pT2v_sat_reg3(p, T, 1.0);
Expand All @@ -85,7 +85,7 @@ pub fn T2sat_water(T: f64, o_id: i32) -> f64 {
}

let mut p: f64 = 0.0;
if T == TC_WATER {
if (T - TC_WATER).abs() < FLOAT_ERROR {
p = PC_WATER;
} else {
p = p_saturation(T);
Expand All @@ -99,7 +99,7 @@ pub fn T2sat_water(T: f64, o_id: i32) -> f64 {
} else {
// region3
let mut v: f64 = 0.0;
if T == TC_WATER {
if (T - TC_WATER).abs() < FLOAT_ERROR {
if o_id == OS {
return SC_WATER;
};
Expand All @@ -126,9 +126,8 @@ pub fn T2sat_steam(T: f64, o_id: i32) -> f64 {
if o_id == OT {
return T;
}

let mut p: f64 = 0.0;
if T == TC_WATER {
if (T - TC_WATER).abs() < FLOAT_ERROR {
p = PC_WATER;
} else {
p = p_saturation(T);
Expand All @@ -142,7 +141,7 @@ pub fn T2sat_steam(T: f64, o_id: i32) -> f64 {
} else {
//region3
let mut v: f64 = 0.0;
if T == TC_WATER {
if (T - TC_WATER).abs() < FLOAT_ERROR {
if o_id == OS {
return SC_WATER;
}
Expand Down Expand Up @@ -201,7 +200,30 @@ pub fn Tx_reg4(T: f64, x: f64, o_id: i32) -> f64 {
let p: f64 = p_saturation(T);
if o_id == OP {
return p;
} else {
return px_reg4(p, x, o_id);
};
if x == 0.0 {
return T2sat_water(T, o_id);
} else if x == 1.0 {
return T2sat_steam(T, o_id);
}
let mut r: f64 = 0.0;
match o_id {
OH | OS | OV | OU | OF | OG | OE => {
// region 4 x(0,1) return v,h,s only
let mut rl: f64 = 0.0;
let mut rv: f64 = 0.0;
if T > 623.15 {
let dl = 1.0 / pT2v_sat_reg3(p, T, 0.0);
rl = Td_reg3(T, dl, o_id);
let dv = 1.0 / pT2v_sat_reg3(p, T, 1.0);
rv = Td_reg3(T, dv, o_id);
} else {
rl = pT_reg1(p, T, o_id);
rv = pT_reg2(p, T, o_id);
}
r = rl + x * (rv - rl);
}
_ => return INVALID_OUTID as f64,
}
r
}
3 changes: 1 addition & 2 deletions src/r4/region4_sat_pT.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const n: [f64; 10] = [
/// saturation pressure, MPa
pub fn p_saturation(T: f64) -> f64 {
let mut ps: f64 = 0.0;
if T < 273.15 || T > 647.096
// TC_WATER=647.096
if T < 273.15 || T> T_MAX4
{
ps = INVALID_VALUE as f64;
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/rust_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ pub fn px(p: f64, x: f64, o_id: i32) -> f64 {
/// ```
///
pub fn tx(t: f64, x: f64, o_id: i32) -> f64 {
if (o_id==OT)
{
return t;
}
if (o_id==OX)
{
return x;
}
let T: f64 = t + 273.15;
if T > T_MAX4 || T < T_MIN4 || x > 1.0 || x < 0.0 {
return INVALID_VALUE as f64;
Expand Down
6 changes: 6 additions & 0 deletions src/stdcall_c_if97.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ pub unsafe extern "stdcall" fn px(p: f64, x: f64, o_id: i32) -> f64 {
/// double tx(double t,double x,short o_id) - the propertry of `o_id` (thermodynamic)
#[no_mangle]
pub unsafe extern "stdcall" fn tx(t: f64, x: f64, o_id: i32) -> f64 {
if (o_id == OT) {
return t;
}
if (o_id == OX) {
return x;
}
let T: f64 = t + 273.15;
if T > T_MAX4 || T < T_MIN4 || x > 1.0 || x < 0.0 {
return INVALID_VALUE as f64;
Expand Down

0 comments on commit 61bcd2e

Please sign in to comment.