Skip to content

Commit

Permalink
seuif97 in Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
thermalogic committed Aug 14, 2023
1 parent a075559 commit 02aea18
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "seuif97"
version = "1.0.7"
version = "1.0.8"
edition = "2021"
authors = ["Cheng Maohua <cmh@seu.edu.cn>"]
description = "The high-speed IAPWS-IF97 package with C and Python binding"
Expand All @@ -19,14 +19,13 @@ crate-type = ["rlib", "cdylib"]
[features]
cdecl = []
stdcall = []
python = []
python = ["pyo3"]

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


[dev-dependencies]
assert_approx_eq = "1.1.0"
criterion = { version = "0.5.1", features = ["html_reports"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ print(f"p={p}, t={t} h={h:.3f} s={s:.3f}")

**T-S Diagram**

* code: [./demo_using_lib/Diagram_T-S.py](./demo_using_lib/Diagram_T-S.py)
* [./demo_using_lib/Diagram_T-S.py](./demo_using_lib/Diagram_T-S.py)

![T-S Diagram](./img/T-S.jpg)

Expand Down
3 changes: 2 additions & 1 deletion demo_using_lib/Diagram_H-S.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
plt.grid()

Pt = 611.657e-6
# Isotherm lines to plot, values in ºC
isot = np.array([0, 50, 100, 200, 300, 400, 500, 600, 700, 800])
isop = np.array([Pt, 0.001, 0.01, 0.1, 1, 10, 20, 50, 100])

# Isotherm lines to plot, values in ºC
for t in isot:
h = np.array([pt2h(p, t) for p in isop])
s = np.array([pt2s(p, t) for p in isop])
Expand Down
17 changes: 13 additions & 4 deletions demo_using_lib/Diagram_T-S.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""
import numpy as np
import matplotlib.pyplot as plt
from seuif97 import ph, tx
from seuif97 import ph, tx, px

OT = 1
OS = 5
Expand All @@ -29,18 +29,27 @@
plt.grid()

Pt = 611.657e-6
isoh = np.linspace(200, 3600, 27)
isop = np.array([Pt, 0.001, 0.002,0.004,0.01, 0.02, 0.05, 0.1, 0.2, 0.5,
1.0, 2.0, 5.0, 10.0,15, 20.0, 22, 25, 28, 30, 35, 40, 45, 50.0,60, 80,100.0])
isoh = np.linspace(100, 3600, 27)
isop = np.array([Pt, 0.001, 0.002, 0.004, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5,
1.0, 2.0, 5.0, 10.0, 15, 20.0, 22, 25, 28, 30, 35, 40, 45, 50.0, 60, 80, 100.0])
for h in isoh:
T = np.array([ph(p, h, OT) for p in isop])
S = np.array([ph(p, h, OS) for p in isop])
plt.plot(S, T, 'g', lw=0.5)

for p in isop:
T = np.array([ph(p, h, OT) for h in isoh])
S = np.array([ph(p, h, OS) for h in isoh])
plt.plot(S, T, 'b', lw=0.5)

# saturate water to wet steam
for p in [0.001, 0.002]:
s = ph(p, 100, OS)
t = ph(p, 100, OT)
s_sat_water = px(p, 0.0, OS)
t_sat_water = px(p, 0.0, OT)
plt.plot([s_sat_water, s], [t_sat_water, t], 'b', lw=0.5)

tc = 647.096 - 273.15
T = np.linspace(0.11, tc, 100)

Expand Down
Binary file modified img/T-S.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions src/algo/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ pub const I_MAX: i32 = 100;

/// rtsec1 :fun(x,con_var2): the result is the first x:x,x={x1,x2}
/// the second con_var2 in constant
/// * fr: the value of fun(x,con_var2)
/// * fr: the value of fun(x,con_var2)
/// * fl: fr-fun(x1,con_var2)
/// * f: fr-fun(x2,con_var2)
/// * rts:the solution of x
/// * rts:the solution of x
pub fn rtsec1(
fun: IF97_EQ, con_var2: f64, fr: f64, x1: f64, x2: f64, mut fl: f64, mut f: f64, xacc: f64, i_max: i32,
) -> f64 {
Expand Down Expand Up @@ -51,12 +51,12 @@ pub fn rtsec1(
return rts;
}

/// rtsec2 :fun(con_var1,x),the result is the second x,x={x1,x2}
/// the first con_var1 is constant
/// fr: the value of func(con_var1,x)
/// fl: fr-func(con_var1,x1)
/// f: fr-func(con_var1,x2)
/// rts:the solution of x
/// rtsec2 :fun(con_var1,x),the result is the second x,x={x1,x2}
/// * the first con_var1 is constant
/// * fr: the value of func(con_var1,x)
/// * fl: fr-func(con_var1,x1)
/// * f: fr-func(con_var1,x2)
/// * rts:the solution of x
pub fn rtsec2(
fun: IF97_EQ, con_var1: f64, fr: f64, x1: f64, x2: f64, mut fl: f64, mut f: f64, xacc: f64, i_max: i32,
) -> f64 {
Expand Down
7 changes: 4 additions & 3 deletions src/common/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub const INVALID_H: i32 = -2103;
pub const INVALID_PT: i32 = -2201;
pub const INVALID_HS: i32 = -2202;

/// FLOAT_ERROR for float value with `==`
pub const FLOAT_ERROR: f64 = 1.0e-6;

/// constants
Expand All @@ -34,7 +35,7 @@ pub const ht_water: f64 = 0.611783; // the triple point
// T=623.15 region (1,3)
pub const Ps_623: f64 = 16.5291642526045; // P_MIN3 Ps_623 = _PSat_T(623.15) P Saturation at 623.15 K, boundary region 1-3

pub const P_MIN: f64 = 0.000611212677444; // P_MIN = _PSat_T(273.15) Minimum pressure
pub const P_MIN: f64 = 0.000611212677444; // P_MIN = _PSat_T(273.15) Mininum pressure
pub const V_MAX: f64 = 1.0E+10;
pub const V_MIN: f64 = 0.00095;
pub const H_MAX: f64 = 7376.99;
Expand All @@ -48,7 +49,7 @@ pub const T01: f64 = 1386.0;
pub const T_MAX1: f64 = 623.15;
pub const T_MIN1: f64 = 273.15;
pub const P_MAX1: f64 = 100.00;
pub const P_MIN1: f64 = 0.000611212677444; // t=273.15
pub const P_MIN1: f64 = 0.000611212677444; // T=273.15

/// Region2 boundary constants
pub const T02: f64 = 540.0;
Expand Down Expand Up @@ -82,4 +83,4 @@ pub const P05: f64 = 1.0;
pub const T_MAX5: f64 = 2273.15;
pub const T_MIN5: f64 = 1073.15;
pub const P_MAX5: f64 = 50.0;
pub const P_MIN5: f64 = 0.000611212677444; //1.0E-8;
pub const P_MIN5: f64 = 0.000611212677444;
7 changes: 3 additions & 4 deletions src/common/propertry_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
//! 1. The Basic propertry in IAPWS-IF97 Equation - p,t,v,d,h,s,cp,cv,w
//! * region1_pT.rs, region2_pT.rs, region5_pT.rs
//! * region3_Td.rs
//! 2. Transport propertry
//! * common::transport_further.rs
//! 3. The extended propertry
//! 2. The extended propertry
//! * region1_pT_ext.rs, region2_pT_ext.rs, region5_pT_ext.rs
//! * region3_Td_ext.rs
//!
//! 3. Transport propertry
//! * common::transport_further.rs

/// 0. p - Pressure MPa
pub const OP: i32 = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/common/propertry_pairs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! The computing function of basic and extended Thermodynamic Properties
//! # Input pairs:
//! * (p,t) (p,h) (p,s) (h,s)
//! * (p,t) (p,h) (p,s)
//! * (h,s)
//! * (p,v),(t,v),(t,h),(t,s)
//!
//! # The Basic Thermodynamic Properties
Expand Down

0 comments on commit 02aea18

Please sign in to comment.