thermolib 0.7.7__tar.gz → 0.8.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {thermolib-0.7.7 → thermolib-0.8.1}/Cargo.lock +1 -1
  2. {thermolib-0.7.7 → thermolib-0.8.1}/Cargo.toml +2 -2
  3. {thermolib-0.7.7 → thermolib-0.8.1}/PKG-INFO +39 -124
  4. {thermolib-0.7.7 → thermolib-0.8.1}/README.md +38 -123
  5. {thermolib-0.7.7/tests → thermolib-0.8.1/scripts}/plot_ceos.py +26 -36
  6. {thermolib-0.7.7 → thermolib-0.8.1}/src/algorithms.rs +28 -0
  7. thermolib-0.8.1/src/ideal_gas.rs +52 -0
  8. thermolib-0.8.1/src/lib.rs +55 -0
  9. {thermolib-0.7.7 → thermolib-0.8.1}/src/liquid_metal/eta.rs +4 -5
  10. {thermolib-0.7.7 → thermolib-0.8.1}/src/liquid_metal/lambda.rs +4 -5
  11. {thermolib-0.7.7 → thermolib-0.8.1}/src/liquid_metal/rho.rs +4 -5
  12. {thermolib-0.7.7 → thermolib-0.8.1}/src/liquid_metal.rs +6 -8
  13. thermolib-0.8.1/src/pc_saft/disp_term.rs +329 -0
  14. thermolib-0.8.1/src/pc_saft/pc_saft_gly.rs +1940 -0
  15. thermolib-0.8.1/src/pc_saft/pc_saft_mix.rs +396 -0
  16. thermolib-0.8.1/src/pc_saft/pc_saft_pure.rs +1918 -0
  17. thermolib-0.8.1/src/pc_saft/pc_saft_ygl.rs +1932 -0
  18. thermolib-0.8.1/src/pc_saft.rs +25 -0
  19. thermolib-0.8.1/src/pr.rs +247 -0
  20. thermolib-0.8.1/src/pr_mix.rs +178 -0
  21. {thermolib-0.7.7 → thermolib-0.8.1}/src/python.rs +6 -0
  22. thermolib-0.8.1/src/rk.rs +218 -0
  23. thermolib-0.8.1/src/srk.rs +225 -0
  24. thermolib-0.8.1/src/vdw.rs +211 -0
  25. thermolib-0.7.7/src/lib.rs +0 -34
  26. thermolib-0.7.7/src/pc_saft.rs +0 -2015
  27. thermolib-0.7.7/src/pr.rs +0 -259
  28. thermolib-0.7.7/src/rk.rs +0 -249
  29. thermolib-0.7.7/src/srk.rs +0 -254
  30. thermolib-0.7.7/src/vdw.rs +0 -250
  31. {thermolib-0.7.7 → thermolib-0.8.1}/.gitignore +0 -0
  32. {thermolib-0.7.7 → thermolib-0.8.1}/LICENSE +0 -0
  33. {thermolib-0.7.7 → thermolib-0.8.1}/pyproject.toml +0 -0
  34. {thermolib-0.7.7 → thermolib-0.8.1}/res/22DimethylButane.json +0 -0
  35. {thermolib-0.7.7 → thermolib-0.8.1}/res/23DimethylButane.json +0 -0
  36. {thermolib-0.7.7 → thermolib-0.8.1}/res/3MethylPentane.json +0 -0
  37. {thermolib-0.7.7 → thermolib-0.8.1}/res/C4F10.json +0 -0
  38. {thermolib-0.7.7 → thermolib-0.8.1}/res/C5F12.json +0 -0
  39. {thermolib-0.7.7 → thermolib-0.8.1}/res/C6F14.json +0 -0
  40. {thermolib-0.7.7 → thermolib-0.8.1}/res/NH3.json +0 -0
  41. {thermolib-0.7.7 → thermolib-0.8.1}/res/SO2.json +0 -0
  42. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz/alpha.rs +0 -0
  43. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz/alpha_i.rs +0 -0
  44. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz/alpha_r.rs +0 -0
  45. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz/anc_eqn.rs +0 -0
  46. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz/assoc.rs +0 -0
  47. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz/rho_ini.rs +0 -0
  48. {thermolib-0.7.7 → thermolib-0.8.1}/src/helmholtz.rs +0 -0
  49. {thermolib-0.7.7 → thermolib-0.8.1}/src/liquid_metal/metals.md +0 -0
  50. {thermolib-0.7.7 → thermolib-0.8.1}/tests/test_fluids.rs +0 -0
@@ -210,7 +210,7 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
210
210
 
211
211
  [[package]]
212
212
  name = "thermolib"
213
- version = "0.7.7"
213
+ version = "0.8.1"
214
214
  dependencies = [
215
215
  "anyhow",
216
216
  "pyo3",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "thermolib"
3
- version = "0.7.7"
3
+ version = "0.8.1"
4
4
  edition = "2021"
5
5
  license = "MIT"
6
6
  description = "An open-source library for the calculation of fluid properties"
@@ -19,7 +19,7 @@ features = ["derive"]
19
19
 
20
20
  [dependencies.pyo3]
21
21
  version = "0.22.6"
22
- features = ["anyhow", "extension-module"]
22
+ features = ["extension-module", "abi3-py39", "anyhow"]
23
23
 
24
24
  [lib]
25
25
  name = "thermolib"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: thermolib
3
- Version: 0.7.7
3
+ Version: 0.8.1
4
4
  License-File: LICENSE
5
5
  Summary: An open-source library for the calculation of fluid properties
6
6
  License: MIT
@@ -14,147 +14,62 @@ thermolib
14
14
 
15
15
  An open-source library for the calculation of fluid properties.
16
16
 
17
- # Vdw
17
+ # Cubic EOS {Vdw, Rk, Srk, Pr}
18
18
 
19
19
  | Flash Calculation | Get Corresponding Properties |
20
20
  | :---: | :---: |
21
21
  | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
22
22
  | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
23
23
 
24
- ```rust
25
- use thermolib::Vdw;
26
-
27
- let Tc = 430.64; // K
28
- let pc = 7886600.0; // Pa
29
- let M = 0.064064; // kg/mol
30
- let mut SO2 = Vdw::new_fluid(Tc, pc, M);
31
- let _ = SO2.set_molar_unit();
32
-
33
- if let Ok(_) = SO2.t_flash(273.15) {
34
- println!("T_s={}", SO2.T_s().unwrap());
35
- println!("p_s={}", SO2.p_s().unwrap());
36
- println!("rho_v={}", SO2.rho_v().unwrap());
37
- println!("rho_l={}", SO2.rho_l().unwrap());
38
- }
39
-
40
- SO2.tp_flash(273.15, 0.1e6);
41
- println!("T={}", SO2.T().unwrap());
42
- println!("p={}", SO2.p().unwrap());
43
- println!("rho={}", SO2.rho().unwrap());
44
-
45
- ```
46
-
47
- ```python
48
- from thermolib import Vdw
49
-
50
- Tc = 430.64
51
- pc = 7886600
52
- M = 0.064064
53
- SO2 = Vdw(Tc, pc, M)
54
- SO2.set_molar_unit()
55
-
56
- SO2.t_flash(273.15)
57
- print("T_s =", SO2.T_s())
58
- print("p_s =", SO2.p_s())
59
- print("rho_v =", SO2.rho_v())
60
- print("rho_l =", SO2.rho_l())
61
-
62
- SO2.tp_flash(273.15, 0.1e6)
63
- print("T =", SO2.T())
64
- print("p =", SO2.p())
65
- print("rho =", SO2.rho())
66
-
67
- ```
68
-
69
- # Rk
70
-
71
- | Flash Calculation | Get Corresponding Properties |
72
- | :---: | :---: |
73
- | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
74
- | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
75
-
76
- ```rust
77
- use thermolib::Rk;
78
-
79
- let Tc = 430.64; // K
80
- let pc = 7886600.0; // Pa
81
- let M = 0.064064; // kg/mol
82
- let mut SO2 = Rk::new_fluid(Tc, pc, M);
83
- let _ = SO2.set_molar_unit();
84
-
85
- ```
86
-
87
- ```python
88
- from thermolib import Rk
89
-
90
- Tc = 430.64
91
- pc = 7886600
92
- M = 0.064064
93
- SO2 = Rk(Tc, pc, M)
94
- SO2.set_molar_unit()
95
-
96
- ```
97
-
98
- # Srk
99
-
100
- | Flash Calculation | Get Corresponding Properties |
101
- | :---: | :---: |
102
- | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
103
- | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
24
+ ## Flash Calculation
104
25
 
105
26
  ```rust
106
- use thermolib::Srk;
107
-
108
- let Tc = 430.64; // K
109
- let pc = 7886600.0; // Pa
110
- let omega = 0.256;
111
- let M = 0.064064; // kg/mol
112
- let mut SO2 = Srk::new_fluid(Tc, pc, omega, M);
113
- let _ = SO2.set_molar_unit();
114
-
27
+ use thermolib::{Vdw, Rk, Srk, Pr};
28
+ let crit_t = 430.64; // critical temperature of sulfur dioxide // K
29
+ let crit_p = 7886600.0; // critical pressure of sulfur dioxide // Pa
30
+ let acentric_factor = 0.256;
31
+ let mut fluid_vdw = Vdw::new_fluid(crit_t, crit_p);
32
+ let mut fluid_rk = Rk::new_fluid(crit_t, crit_p);
33
+ let mut fluid_srk = Srk::new_fluid(crit_t, crit_p, acentric_factor);
34
+ let mut fluid_pr = Pr::new_fluid(crit_t, crit_p, acentric_factor);
115
35
  ```
116
36
 
117
37
  ```python
118
- from thermolib import Srk
119
-
120
- Tc = 430.64
121
- pc = 7886600
122
- omega = 0.256
123
- M = 0.064064
124
- SO2 = Srk(Tc, Pc, omega, M)
125
- SO2.set_molar_unit()
126
-
38
+ from thermolib import Vdw, Rk, Srk, Pr
39
+ TC = 430.64
40
+ PC = 7886600
41
+ OMEGA = 0.256
42
+ fluid_vdw = Vdw(TC, PC)
43
+ fluid_rk = Rk(TC, PC)
44
+ fluid_srk = Srk(TC, PC, OMEGA)
45
+ fluid_pr = Pr(TC, PC, OMEGA)
127
46
  ```
128
47
 
129
- # Pr
130
-
131
- | Flash Calculation | Get Corresponding Properties |
132
- | :---: | :---: |
133
- | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
134
- | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
48
+ ## Get Corresponding Properties
135
49
 
136
50
  ```rust
137
- use thermolib::Pr;
138
-
139
- let Tc = 430.64; // K
140
- let pc = 7886600.0; // Pa
141
- let omega = 0.256;
142
- let M = 0.064064; // kg/mol
143
- let mut SO2 = Pr::new_fluid(Tc, pc, omega, M);
144
- let _ = SO2.set_molar_unit();
145
-
51
+ if let Ok(_) = fluid.t_flash(273.15) {
52
+ println!("T_s={}", fluid.T_s().unwrap());
53
+ println!("p_s={}", fluid.p_s().unwrap());
54
+ println!("rho_v={}", fluid.rho_v().unwrap());
55
+ println!("rho_l={}", fluid.rho_l().unwrap());
56
+ }
57
+ fluid.tp_flash(273.15, 0.1e6);
58
+ println!("T={}", fluid.T().unwrap());
59
+ println!("p={}", fluid.p().unwrap());
60
+ println!("rho={}", fluid.rho().unwrap());
146
61
  ```
147
62
 
148
63
  ```python
149
- from thermolib import Pr
150
-
151
- Tc = 430.64
152
- pc = 7886600
153
- omega = 0.256
154
- M = 0.064064
155
- SO2 = Pr(Tc, Pc, omega, M)
156
- SO2.set_molar_unit()
157
-
64
+ fluid.t_flash(273.15)
65
+ print("T_s =", fluid.T_s())
66
+ print("p_s =", fluid.p_s())
67
+ print("rho_v =", fluid.rho_v())
68
+ print("rho_l =", fluid.rho_l())
69
+ SO2.tp_flash(273.15, 0.1e6)
70
+ print("T =", fluid.T())
71
+ print("p =", fluid.p())
72
+ print("rho =", fluid.rho())
158
73
  ```
159
74
 
160
75
  # Helmholtz
@@ -4,147 +4,62 @@ thermolib
4
4
 
5
5
  An open-source library for the calculation of fluid properties.
6
6
 
7
- # Vdw
7
+ # Cubic EOS {Vdw, Rk, Srk, Pr}
8
8
 
9
9
  | Flash Calculation | Get Corresponding Properties |
10
10
  | :---: | :---: |
11
11
  | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
12
12
  | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
13
13
 
14
- ```rust
15
- use thermolib::Vdw;
16
-
17
- let Tc = 430.64; // K
18
- let pc = 7886600.0; // Pa
19
- let M = 0.064064; // kg/mol
20
- let mut SO2 = Vdw::new_fluid(Tc, pc, M);
21
- let _ = SO2.set_molar_unit();
22
-
23
- if let Ok(_) = SO2.t_flash(273.15) {
24
- println!("T_s={}", SO2.T_s().unwrap());
25
- println!("p_s={}", SO2.p_s().unwrap());
26
- println!("rho_v={}", SO2.rho_v().unwrap());
27
- println!("rho_l={}", SO2.rho_l().unwrap());
28
- }
29
-
30
- SO2.tp_flash(273.15, 0.1e6);
31
- println!("T={}", SO2.T().unwrap());
32
- println!("p={}", SO2.p().unwrap());
33
- println!("rho={}", SO2.rho().unwrap());
34
-
35
- ```
36
-
37
- ```python
38
- from thermolib import Vdw
39
-
40
- Tc = 430.64
41
- pc = 7886600
42
- M = 0.064064
43
- SO2 = Vdw(Tc, pc, M)
44
- SO2.set_molar_unit()
45
-
46
- SO2.t_flash(273.15)
47
- print("T_s =", SO2.T_s())
48
- print("p_s =", SO2.p_s())
49
- print("rho_v =", SO2.rho_v())
50
- print("rho_l =", SO2.rho_l())
51
-
52
- SO2.tp_flash(273.15, 0.1e6)
53
- print("T =", SO2.T())
54
- print("p =", SO2.p())
55
- print("rho =", SO2.rho())
56
-
57
- ```
58
-
59
- # Rk
60
-
61
- | Flash Calculation | Get Corresponding Properties |
62
- | :---: | :---: |
63
- | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
64
- | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
65
-
66
- ```rust
67
- use thermolib::Rk;
68
-
69
- let Tc = 430.64; // K
70
- let pc = 7886600.0; // Pa
71
- let M = 0.064064; // kg/mol
72
- let mut SO2 = Rk::new_fluid(Tc, pc, M);
73
- let _ = SO2.set_molar_unit();
74
-
75
- ```
76
-
77
- ```python
78
- from thermolib import Rk
79
-
80
- Tc = 430.64
81
- pc = 7886600
82
- M = 0.064064
83
- SO2 = Rk(Tc, pc, M)
84
- SO2.set_molar_unit()
85
-
86
- ```
87
-
88
- # Srk
89
-
90
- | Flash Calculation | Get Corresponding Properties |
91
- | :---: | :---: |
92
- | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
93
- | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
14
+ ## Flash Calculation
94
15
 
95
16
  ```rust
96
- use thermolib::Srk;
97
-
98
- let Tc = 430.64; // K
99
- let pc = 7886600.0; // Pa
100
- let omega = 0.256;
101
- let M = 0.064064; // kg/mol
102
- let mut SO2 = Srk::new_fluid(Tc, pc, omega, M);
103
- let _ = SO2.set_molar_unit();
104
-
17
+ use thermolib::{Vdw, Rk, Srk, Pr};
18
+ let crit_t = 430.64; // critical temperature of sulfur dioxide // K
19
+ let crit_p = 7886600.0; // critical pressure of sulfur dioxide // Pa
20
+ let acentric_factor = 0.256;
21
+ let mut fluid_vdw = Vdw::new_fluid(crit_t, crit_p);
22
+ let mut fluid_rk = Rk::new_fluid(crit_t, crit_p);
23
+ let mut fluid_srk = Srk::new_fluid(crit_t, crit_p, acentric_factor);
24
+ let mut fluid_pr = Pr::new_fluid(crit_t, crit_p, acentric_factor);
105
25
  ```
106
26
 
107
27
  ```python
108
- from thermolib import Srk
109
-
110
- Tc = 430.64
111
- pc = 7886600
112
- omega = 0.256
113
- M = 0.064064
114
- SO2 = Srk(Tc, Pc, omega, M)
115
- SO2.set_molar_unit()
116
-
28
+ from thermolib import Vdw, Rk, Srk, Pr
29
+ TC = 430.64
30
+ PC = 7886600
31
+ OMEGA = 0.256
32
+ fluid_vdw = Vdw(TC, PC)
33
+ fluid_rk = Rk(TC, PC)
34
+ fluid_srk = Srk(TC, PC, OMEGA)
35
+ fluid_pr = Pr(TC, PC, OMEGA)
117
36
  ```
118
37
 
119
- # Pr
120
-
121
- | Flash Calculation | Get Corresponding Properties |
122
- | :---: | :---: |
123
- | `t_flash(Ts)` | `T_s()` <br> `p_s()` <br> `rho_v()` <br> `rho_l()` <br> |
124
- | `tp_flash(T,p)` | `T()` <br> `p()` <br> `rho()` <br> |
38
+ ## Get Corresponding Properties
125
39
 
126
40
  ```rust
127
- use thermolib::Pr;
128
-
129
- let Tc = 430.64; // K
130
- let pc = 7886600.0; // Pa
131
- let omega = 0.256;
132
- let M = 0.064064; // kg/mol
133
- let mut SO2 = Pr::new_fluid(Tc, pc, omega, M);
134
- let _ = SO2.set_molar_unit();
135
-
41
+ if let Ok(_) = fluid.t_flash(273.15) {
42
+ println!("T_s={}", fluid.T_s().unwrap());
43
+ println!("p_s={}", fluid.p_s().unwrap());
44
+ println!("rho_v={}", fluid.rho_v().unwrap());
45
+ println!("rho_l={}", fluid.rho_l().unwrap());
46
+ }
47
+ fluid.tp_flash(273.15, 0.1e6);
48
+ println!("T={}", fluid.T().unwrap());
49
+ println!("p={}", fluid.p().unwrap());
50
+ println!("rho={}", fluid.rho().unwrap());
136
51
  ```
137
52
 
138
53
  ```python
139
- from thermolib import Pr
140
-
141
- Tc = 430.64
142
- pc = 7886600
143
- omega = 0.256
144
- M = 0.064064
145
- SO2 = Pr(Tc, Pc, omega, M)
146
- SO2.set_molar_unit()
147
-
54
+ fluid.t_flash(273.15)
55
+ print("T_s =", fluid.T_s())
56
+ print("p_s =", fluid.p_s())
57
+ print("rho_v =", fluid.rho_v())
58
+ print("rho_l =", fluid.rho_l())
59
+ SO2.tp_flash(273.15, 0.1e6)
60
+ print("T =", fluid.T())
61
+ print("p =", fluid.p())
62
+ print("rho =", fluid.rho())
148
63
  ```
149
64
 
150
65
  # Helmholtz
@@ -1,40 +1,31 @@
1
- """
2
- plot ceos
3
- """
1
+ """plot ceos"""
4
2
 
5
3
  import math
6
4
  import numpy as np
7
5
  import matplotlib.pyplot as plt
6
+ from thermolib import hello, Vdw, Rk, Srk, Pr # pylint: disable=no-name-in-module
8
7
 
9
- # pylint: disable=E
10
- from thermolib import hello, Vdw, Rk, Srk, Pr
11
8
 
12
9
  print("test_hello:", hello())
13
10
 
11
+
14
12
  TC = 430.64
15
13
  PC = 7886600
16
14
  OMEGA = 0.256
17
- M = 0.064064
18
-
19
- vdw = Vdw(TC, PC, M)
20
- vdw.set_mass_unit()
21
-
22
- rk = Rk(TC, PC, M)
23
- rk.set_mass_unit()
24
-
25
- srk = Srk(TC, PC, OMEGA, M)
26
- srk.set_mass_unit()
15
+ vdw = Vdw(TC, PC)
16
+ rk = Rk(TC, PC)
17
+ srk = Srk(TC, PC, OMEGA)
18
+ pr = Pr(TC, PC, OMEGA)
27
19
 
28
- pr = Pr(TC, PC, OMEGA, M)
29
- pr.set_mass_unit()
30
20
 
31
21
  fig, (ax1, ax2) = plt.subplots(2, 1)
32
22
 
23
+
33
24
  t_s = []
34
25
  p_s = []
35
26
  rho_v = []
36
27
  rho_l = []
37
- for T in range(math.floor(0.7 * TC), math.ceil(TC)):
28
+ for T in range(math.floor(0.6 * TC), math.ceil(TC)):
38
29
  vdw.t_flash(T)
39
30
  t_s.append(vdw.T_s())
40
31
  p_s.append(vdw.p_s())
@@ -44,16 +35,16 @@ t_s = np.array(t_s)
44
35
  p_s = np.array(p_s)
45
36
  rho_v = np.array(rho_v)
46
37
  rho_l = np.array(rho_l)
38
+ ax1.plot(t_s, p_s, color="r", label="Vdw")
39
+ ax2.plot(rho_v, p_s, color="r", label="Vdw")
40
+ ax2.plot(rho_l, p_s, color="r")
47
41
 
48
- ax1.plot(t_s, p_s, color="red", label="Vdw")
49
- ax2.plot(rho_v, p_s, color="red", label="Vdw")
50
- ax2.plot(rho_l, p_s, color="red")
51
42
 
52
43
  t_s = []
53
44
  p_s = []
54
45
  rho_v = []
55
46
  rho_l = []
56
- for T in range(math.floor(0.7 * TC), math.ceil(TC)):
47
+ for T in range(math.floor(0.6 * TC), math.ceil(TC)):
57
48
  rk.t_flash(T)
58
49
  t_s.append(rk.T_s())
59
50
  p_s.append(rk.p_s())
@@ -63,16 +54,16 @@ t_s = np.array(t_s)
63
54
  p_s = np.array(p_s)
64
55
  rho_v = np.array(rho_v)
65
56
  rho_l = np.array(rho_l)
57
+ ax1.plot(t_s, p_s, color="g", label="Rk")
58
+ ax2.plot(rho_v, p_s, color="g", label="Rk")
59
+ ax2.plot(rho_l, p_s, color="g")
66
60
 
67
- ax1.plot(t_s, p_s, color="yellow", label="Rk")
68
- ax2.plot(rho_v, p_s, color="yellow", label="Rk")
69
- ax2.plot(rho_l, p_s, color="yellow")
70
61
 
71
62
  t_s = []
72
63
  p_s = []
73
64
  rho_v = []
74
65
  rho_l = []
75
- for T in range(math.floor(0.7 * TC), math.ceil(TC)):
66
+ for T in range(math.floor(0.6 * TC), math.ceil(TC)):
76
67
  srk.t_flash(T)
77
68
  t_s.append(srk.T_s())
78
69
  p_s.append(srk.p_s())
@@ -82,16 +73,16 @@ t_s = np.array(t_s)
82
73
  p_s = np.array(p_s)
83
74
  rho_v = np.array(rho_v)
84
75
  rho_l = np.array(rho_l)
76
+ ax1.plot(t_s, p_s, color="b", label="Srk")
77
+ ax2.plot(rho_v, p_s, color="b", label="Srk")
78
+ ax2.plot(rho_l, p_s, color="b")
85
79
 
86
- ax1.plot(t_s, p_s, color="blue", label="Srk")
87
- ax2.plot(rho_v, p_s, color="blue", label="Srk")
88
- ax2.plot(rho_l, p_s, color="blue")
89
80
 
90
81
  t_s = []
91
82
  p_s = []
92
83
  rho_v = []
93
84
  rho_l = []
94
- for T in range(math.floor(0.7 * TC), math.ceil(TC)):
85
+ for T in range(math.floor(0.6 * TC), math.ceil(TC)):
95
86
  pr.t_flash(T)
96
87
  t_s.append(pr.T_s())
97
88
  p_s.append(pr.p_s())
@@ -101,19 +92,18 @@ t_s = np.array(t_s)
101
92
  p_s = np.array(p_s)
102
93
  rho_v = np.array(rho_v)
103
94
  rho_l = np.array(rho_l)
95
+ ax1.plot(t_s, p_s, color="y", label="Pr")
96
+ ax2.plot(rho_v, p_s, color="y", label="Pr")
97
+ ax2.plot(rho_l, p_s, color="y")
104
98
 
105
- ax1.plot(t_s, p_s, color="green", label="Pr")
106
- ax2.plot(rho_v, p_s, color="green", label="Pr")
107
- ax2.plot(rho_l, p_s, color="green")
108
99
 
109
100
  ax1.set_xlabel("temperature K")
110
101
  ax1.set_ylabel("pressure Pa")
111
102
  ax1.legend()
112
-
113
- ax2.set_xlabel("density kg/m3")
103
+ ax2.set_xlabel("density mol/m3")
114
104
  ax2.set_ylabel("pressure Pa")
115
105
  ax2.legend()
116
106
 
117
- plt.tight_layout()
118
107
 
108
+ plt.tight_layout()
119
109
  plt.show()
@@ -97,6 +97,34 @@ where
97
97
  }
98
98
  fx[N_DIM - 1][N_DIM - 1]
99
99
  }
100
+ /// shengjin
101
+ #[allow(non_snake_case)]
102
+ pub fn shengjin_roots(b: f64, c: f64, d: f64) -> (f64, f64) {
103
+ let A = b.powi(2) - 3.0 * c;
104
+ let B = b * c - 9.0 * d;
105
+ let C = c.powi(2) - 3.0 * b * d;
106
+ let Delta = B.powi(2) - 4.0 * A * C;
107
+ if Delta.is_sign_positive() {
108
+ let Y1 = A * b + 1.5 * (-B + Delta.sqrt());
109
+ let Y2 = A * b + 1.5 * (-B - Delta.sqrt());
110
+ ((-b - (Y1.cbrt() + Y2.cbrt())) / 3.0, 0.0)
111
+ } else {
112
+ let SQRT_A = A.sqrt();
113
+ let SQRT_3 = 3_f64.sqrt();
114
+ let theta3 = ((2.0 * A * b - 3.0 * B) / (2.0 * A * SQRT_A)).acos() / 3.0;
115
+ let theta3cos = theta3.cos();
116
+ let x1 = (-b - 2.0 * SQRT_A * theta3cos) / 3.0;
117
+ let x2 = (-b + SQRT_A * (theta3cos + SQRT_3 * theta3.sin())) / 3.0;
118
+ let x3 = (-b + SQRT_A * (theta3cos - SQRT_3 * theta3.sin())) / 3.0;
119
+ let Zv = x1.max(x2).max(x3);
120
+ let Zl = x1.min(x2).min(x3);
121
+ if Zl.is_sign_positive() {
122
+ (Zv, Zl)
123
+ } else {
124
+ (Zv, 0.0)
125
+ }
126
+ }
127
+ }
100
128
  /// unit test
101
129
  #[cfg(test)]
102
130
  mod tests {
@@ -0,0 +1,52 @@
1
+ use crate::f64consts::{C, FRAC_H_K, R};
2
+ #[cfg(feature = "with_pyo3")]
3
+ use pyo3::{pyclass, pymethods};
4
+ #[cfg_attr(feature = "with_pyo3", pyclass)]
5
+ pub struct IdealGas {
6
+ c: f64,
7
+ v: Vec<f64>,
8
+ }
9
+ impl IdealGas {
10
+ pub fn new_fluid() -> Self {
11
+ Self {
12
+ c: 1.5, // Translation contribution = 1.5
13
+ v: Vec::new(),
14
+ }
15
+ }
16
+ }
17
+ #[cfg_attr(feature = "with_pyo3", pymethods)]
18
+ #[allow(non_snake_case)]
19
+ impl IdealGas {
20
+ #[cfg(feature = "with_pyo3")]
21
+ #[new]
22
+ pub fn new_py() -> Self {
23
+ Self::new_fluid()
24
+ }
25
+ pub fn set_linear_molecule(&mut self) {
26
+ // Translation contribution = 1.5
27
+ // Rotation contribution = 1.0
28
+ self.c = 2.5;
29
+ }
30
+ pub fn set_nonlinear_molecule(&mut self) {
31
+ // Translation contribution = 1.5
32
+ // Rotation contribution = 1.5
33
+ self.c = 3.0;
34
+ }
35
+ pub fn set_wave_length(&mut self, waves: Vec<f64>) {
36
+ self.v = waves.iter().map(|wave| C * wave * 100.0).collect();
37
+ }
38
+ pub fn calc_cv(&self, T: f64) -> f64 {
39
+ R * (self.c
40
+ + self
41
+ .v
42
+ .iter()
43
+ .map(|vi| {
44
+ let temp = -FRAC_H_K * vi / T;
45
+ temp.exp() * (temp / temp.exp_m1()).powi(2)
46
+ })
47
+ .sum::<f64>())
48
+ }
49
+ pub fn calc_cp(&self, T: f64) -> f64 {
50
+ self.calc_cv(T) + R
51
+ }
52
+ }
@@ -0,0 +1,55 @@
1
+ //!
2
+ //! thermolib
3
+ //! =========
4
+ //!
5
+ //! An open-source library for
6
+ //! the calculation of fluid properties.
7
+ //!
8
+ //!
9
+ /// algorithms
10
+ mod algorithms;
11
+ /// Python wrappers
12
+ #[cfg(feature = "with_pyo3")]
13
+ mod python;
14
+ /// Vdw EOS
15
+ mod vdw;
16
+ pub use vdw::Vdw;
17
+ /// Rk EOS
18
+ mod rk;
19
+ pub use rk::Rk;
20
+ /// Srk EOS
21
+ mod srk;
22
+ pub use srk::Srk;
23
+ /// Pr EOS
24
+ mod pr;
25
+ pub use pr::Pr;
26
+ mod pr_mix;
27
+ pub use pr_mix::PrMix;
28
+ /// Helmholtz EOS
29
+ mod helmholtz;
30
+ pub use helmholtz::Helmholtz;
31
+ /// liquid metals
32
+ mod liquid_metal;
33
+ pub use liquid_metal::LiquidMetal;
34
+ /// PC-SAFT EOS
35
+ mod pc_saft;
36
+ pub use pc_saft::PcSaftGlyPure;
37
+ pub use pc_saft::PcSaftMix;
38
+ pub use pc_saft::PcSaftPure;
39
+ pub use pc_saft::PcSaftYglPure;
40
+ /// Ideal Gas
41
+ mod ideal_gas;
42
+ pub use ideal_gas::IdealGas;
43
+ /// Fundamental Constants
44
+ mod f64consts {
45
+ pub use std::f64::consts::{FRAC_PI_2, FRAC_PI_6, PI, SQRT_2};
46
+ pub const SQRT2ADD1: f64 = SQRT_2 + 1.0;
47
+ pub const SQRT2SUB1: f64 = SQRT_2 - 1.0;
48
+ pub const C: f64 = 299792458.0; // CODATA2018 (speed of light in vacuum) m s^-1
49
+ pub const H: f64 = 6.62607015E-34; // CODATA2018 (Planck constant) J Hz^-1
50
+ pub const K: f64 = 1.380649e-23; // CODATA2018 (Boltzmann constant) J K^-1
51
+ pub const FRAC_H_K: f64 = H / K; // K / Hz
52
+ pub const NA: f64 = 6.02214076E23; // CODATA2018 (Avogadro constant) mol^-1
53
+ pub const FRAC_NA_1E30: f64 = NA / 1E30; // const FRAC_NA_1E30: f64 = 6.02214076E-7;
54
+ pub const R: f64 = 8.314462618; // CODATA2018 (molar gas constant) J mol^-1 K^-1
55
+ }