16
16
import Region1
17
17
import Region2
18
18
import Region3
19
+ import Region4
19
20
import Region5
20
21
21
22
h0 = np .array ([0.5132047 , 0.3205656 , 0.0 , 0.0 , - 0.7782567 , 0.1885447 ])
@@ -53,7 +54,6 @@ def my_allregions_pT(pressure, temperature):
53
54
54
55
rhos = density / 317.63
55
56
ts = temperature / 647.226
56
- ps = pressure / 22.115
57
57
58
58
my_0 = ts ** 0.5 / (1.0 + 0.978197 / ts + 0.579829 / (ts ** 2.0 ) - 0.202354 / (ts ** 3.0 ))
59
59
total = 0.0
@@ -64,63 +64,53 @@ def my_allregions_pT(pressure, temperature):
64
64
my_1 = math .exp (rhos * total )
65
65
return my_0 * my_1 * 0.000055071
66
66
67
- #Rem
68
- #Rem Private Function my_AllRegions_ph(ByVal p As Double, ByVal h As Double) As Double
69
- #Rem Dim h0, h1, h2, h3, h4, h5, h6 As Variant, rho, T, Ts, ps, my0, sum, my1, rhos, v4V, v4L, xs As Double, i As Integer
70
- #Rem h0 = Array(0.5132047, 0.3205656, 0, 0, -0.7782567, 0.1885447)
71
- #Rem h1 = Array(0.2151778, 0.7317883, 1.241044, 1.476783, 0, 0)
72
- #Rem h2 = Array(-0.2818107, -1.070786, -1.263184, 0, 0, 0)
73
- #Rem h3 = Array(0.1778064, 0.460504, 0.2340379, -0.4924179, 0, 0)
74
- #Rem h4 = Array(-0.0417661, 0, 0, 0.1600435, 0, 0)
75
- #Rem h5 = Array(0, -0.01578386, 0, 0, 0, 0)
76
- #Rem h6 = Array(0, 0, 0, -0.003629481, 0, 0)
77
- #Rem
78
- #Rem 'Calcualte density.
79
- #Rem Select Case region_ph(p, h)
80
- #Rem Case 1
81
- #Rem Ts = T1_ph(p, h)
82
- #Rem T = Ts
83
- #Rem rho = 1 / v1_pT(p, Ts)
84
- #Rem Case 2
85
- #Rem Ts = T2_ph(p, h)
86
- #Rem T = Ts
87
- #Rem rho = 1 / v2_pT(p, Ts)
88
- #Rem Case 3
89
- #Rem rho = 1 / v3_ph(p, h)
90
- #Rem T = T3_ph(p, h)
91
- #Rem Case 4
92
- #Rem xs = x4_ph(p, h)
93
- #Rem If p < 16.529 Then
94
- #Rem v4V = v2_pT(p, T4_p(p))
95
- #Rem v4L = v1_pT(p, T4_p(p))
96
- #Rem Else
97
- #Rem v4V = v3_ph(p, h4V_p(p))
98
- #Rem v4L = v3_ph(p, h4L_p(p))
99
- #Rem End If
100
- #Rem rho = 1 / (xs * v4V + (1 - xs) * v4L)
101
- #Rem T = T4_p(p)
102
- #Rem Case 5
103
- #Rem Ts = T5_ph(p, h)
104
- #Rem T = Ts
105
- #Rem rho = 1 / v5_pT(p, Ts)
106
- #Rem Case Else
107
- #Rem my_AllRegions_ph = CVErr(xlErrValue)
108
- #Rem Exit Function
109
- #Rem End Select
110
- #Rem rhos = rho / 317.763
111
- #Rem Ts = T / 647.226
112
- #Rem ps = p / 22.115
113
- #Rem 'Check valid area
114
- #Rem If T > 900 + 273.15 Or (T > 600 + 273.15 And p > 300) Or (T > 150 + 273.15 And p > 350) Or p > 500 Then
115
- #Rem my_AllRegions_ph = CVErr(xlErrValue)
116
- #Rem Exit Function
117
- #Rem End If
118
- #Rem my0 = Ts ^ 0.5 / (1 + 0.978197 / Ts + 0.579829 / (Ts ^ 2) - 0.202354 / (Ts ^ 3))
119
- #Rem
120
- #Rem sum = 0
121
- #Rem For i = 0 To 5
122
- #Rem sum = sum + h0(i) * (1 / Ts - 1) ^ i + h1(i) * (1 / Ts - 1) ^ i * (rhos - 1) ^ 1 + h2(i) * (1 / Ts - 1) ^ i * (rhos - 1) ^ 2 + h3(i) * (1 / Ts - 1) ^ i * (rhos - 1) ^ 3 + h4(i) * (1 / Ts - 1) ^ i * (rhos - 1) ^ 4 + h5(i) * (1 / Ts - 1) ^ i * (rhos - 1) ^ 5 + h6(i) * (1 / Ts - 1) ^ i * (rhos - 1) ^ 6
123
- #Rem Next i
124
- #Rem my1 = Exp(rhos * sum)
125
- #Rem my_AllRegions_ph = my0 * my1 * 0.000055071
126
- #Rem End Function
67
+ def my_allregions_ph (pressure , enthalpy ):
68
+ '''Viscosity (IAPWS formulation 1985, Revised 2003)'''
69
+ region = Regions .region_ph (pressure , enthalpy )
70
+ if region is None : return Constants ._errorValue
71
+
72
+ temperature = Constants ._errorValue
73
+ density = Constants ._errorValue
74
+
75
+ if region == 1 :
76
+ temperature = Region1 .t1_ph (pressure , enthalpy )
77
+ density = 1.0 / Region1 .v1_pt (pressure , temperature )
78
+ elif region == 2 :
79
+ temperature = Region2 .t2_ph (pressure , enthalpy )
80
+ density = 1.0 / Region2 .v2_pt (pressure , temperature )
81
+ elif region == 3 :
82
+ temperature = Region3 .t3_ph (pressure , enthalpy )
83
+ density = 1.0 / Region3 .v3_ph (pressure , enthalpy )
84
+ elif region == 4 :
85
+ quality = Region4 .x4_ph (pressure , enthalpy )
86
+ specificVolumeVapor , specificVolumeLiquid = Constants ._errorValue , Constants ._errorValue
87
+ temperature = Region4 .t4_p (pressure )
88
+ if pressure < Constants ._pressureSubDomain :
89
+ specificVolumeVapor = Region2 .v2_pt (pressure , temperature )
90
+ specificVolumeLiquid = Region1 .v1_pt (pressure , temperature )
91
+ else :
92
+ specificVolumeVapor = Region3 .v3_ph (pressure , Region4 .h4_p (pressure , 'vap' ))
93
+ specificVolumeLiquid = Region3 .v3_ph (pressure , Region4 .h4_p (pressure , 'liq' ))
94
+ density = 1.0 / (quality * specificVolumeVapor + (1.0 - quality )* specificVolumeLiquid )
95
+ elif region == 5 :
96
+ temperature = Region5 .t5_ph (pressure , enthalpy )
97
+ density = 1.0 / Region5 .v5_pt (pressure , temperature )
98
+
99
+ # Check valid area
100
+ if temperature > 900.0 + 273.15 or \
101
+ (temperature > 600.0 + 273.15 and pressure > 300.0 ) or \
102
+ (temperature > 150.0 + 273.15 and pressure > 350.0 ) or \
103
+ pressure > 500.0 :
104
+ return Constants ._errorValue
105
+
106
+ rhos = density / 317.63
107
+ ts = temperature / 647.226
108
+
109
+ my_0 = ts ** 0.5 / (1.0 + 0.978197 / ts + 0.579829 / (ts ** 2.0 ) - 0.202354 / (ts ** 3.0 ))
110
+ total = 0.0
111
+ a , b = 1.0 / ts - 1.0 , rhos - 1.0
112
+ for i in range (6 ):
113
+ total += h0 [i ]* a ** i + h1 [i ]* a ** i * b + h2 [i ]* a ** i * b ** 2 + h3 [i ]* a ** i * b ** 3 + h4 [i ]* a ** i * b ** 4 + h5 [i ]* a ** i * b ** 5 + h6 [i ]* a ** i * b ** 6
114
+
115
+ my_1 = math .exp (rhos * total )
116
+ return my_0 * my_1 * 0.000055071
0 commit comments