Skip to content

Commit e29379e

Browse files
committed
make R12 work for industrial applications
checks pass, critical enhancement is WIP
1 parent a809f2a commit e29379e

File tree

5 files changed

+110
-108
lines changed

5 files changed

+110
-108
lines changed

pyXSteam/IAPWS_R12.py

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,25 @@
1515
logger = logging.getLogger(__name__)
1616

1717

18-
def R12_my_dash_0(T: float) -> float:
18+
def R12_my_dash_0(T_dash: float) -> float:
1919
"""eq 11, viscosity in the dilute-gas limit"""
20-
T_dash = T / R12_08.T_STAR
21-
2220
numerator = 100 * math.sqrt(T_dash)
2321
denominator = 0
2422
for i, H in enumerate(R12_08.Table1_H):
2523
denominator += H / T_dash**i
2624
return numerator / denominator
2725

2826

29-
def R12_my_dash_1(rho: float, T: float) -> float:
27+
def R12_my_dash_1(rho_dash: float, T_dash: float) -> float:
3028
"""eq 12, contribution to viscosity due to finite density"""
31-
rho_dash = rho / R12_08.P_STAR
32-
T_dash = T / R12_08.T_STAR
33-
29+
coeff_t = (1 / T_dash) - 1
30+
sum_ij = 0.0
3431
H = R12_08.Table2_H()
35-
36-
sum = 0
37-
for i, _ in enumerate(H): # i
38-
sum_T_i = ((1 / T_dash) - 1) ** i
39-
40-
sum_rho_ij = 0
41-
for j, _ in enumerate(H[0]): # j
42-
print(i, j, H[i][j])
43-
sum_rho_ij += H[i][j] * ((rho_dash - 1) ** j)
44-
sum += sum_T_i * sum_rho_ij
45-
46-
return math.exp(rho_dash * sum)
32+
for j, _ in enumerate(H[0]):
33+
for i, _ in enumerate(H):
34+
if H[i][j] != 0.0:
35+
sum_ij += math.pow(coeff_t, i) * H[i][j] * math.pow((rho_dash - 1), j)
36+
return math.exp(rho_dash * sum_ij)
4737

4838

4939
def R12_helpereq_rhoT(rho: float, T: float):
@@ -133,12 +123,15 @@ def R12_my_dash_2(rho: float, T: float) -> float:
133123
return 1.0
134124

135125

136-
def my_rhoT(rho: float, T: float, industrial_use: bool = False) -> float:
126+
def my_rhoT(rho: float, T: float, industrial_application: bool = False) -> float:
137127
"""eq 10, viscosity"""
138128

139-
my_dash = R12_my_dash_0(T)
140-
my_dash = my_dash * R12_my_dash_1(rho, T)
141-
if not industrial_use:
129+
rho_dash = rho / R12_08.RHO_STAR
130+
T_dash = T / R12_08.T_STAR
131+
132+
my_dash = R12_my_dash_0(T_dash) * R12_my_dash_1(rho_dash, T_dash)
133+
134+
if not industrial_application:
142135
my_dash = my_dash * R12_my_dash_2(rho, T)
143136

144137
return my_dash * R12_08.MU_STAR

pyXSteam/XSteam.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,24 +2373,23 @@ def psubl_t(self, t: float) -> float:
23732373
self.logger.warning("temperature %f out of range", T)
23742374
return float("NaN")
23752375

2376-
# def R12_my_rhot(self, rho: float, t: float, industrial_application: bool = True) -> float:
2377-
# """shear viscosity of pure water substance over an extensive range of fluid states
2376+
def R12_my_rhot(self, rho: float, t: float, industrial_application: bool = True) -> float:
2377+
"""shear viscosity of pure water substance over an extensive range of fluid states
23782378
2379-
# Release on the IAPWS Formulation 2008 for the Viscosity of Ordinary Water Substance
2380-
# IAPWS R12-08
2381-
# http://www.iapws.org/relguide/visc.pdf
2379+
Release on the IAPWS Formulation 2008 for the Viscosity of Ordinary Water Substance
2380+
IAPWS R12-08
2381+
http://www.iapws.org/relguide/visc.pdf
23822382
2383-
# :param rho: density
2384-
# :param t: temperature
2385-
# :param industrial_application: select if simple or detailes approximation should be used
2383+
:param rho: density
2384+
:param t: temperature
2385+
:param industrial_application: select if simple or detailes approximation should be used
23862386
2387-
# :return: shear viscosity
2388-
# """
2389-
# self.logger.warning("this function is still experimental, use at your own risk!")
2387+
:return: shear viscosity
2388+
"""
2389+
self.logger.warning("this function is still experimental, use at your own risk!")
23902390

2391-
# T = self._unit_converter.toSIunit_T(t)
2391+
T = self._unit_converter.toSIunit_T(t)
23922392

2393-
# my_my = my_rhoT(rho, T)
2394-
# my = my_my * 10e5
2393+
my = my_rhoT(rho, T, industrial_application)
23952394

2396-
# return self._unit_converter.fromSIunit_my(my)
2395+
return self._unit_converter.fromSIunit_my(my)

pyXSteam/tables/R12_08.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class R12_08:
1616
T_STAR = 647.096 # reference temperature [K], eq 1
1717
RHO_STAR = 322.0 # reference density [kg / m^3], eq 2
1818
P_STAR = 22.064 # reference pressure [Pa], eq 3
19-
MU_STAR = 1.00e-6 # reference viscosity [Pa s], eq 4
19+
MU_STAR = 1.0e-6 # reference viscosity [Pa s], eq 4
2020

2121
# table 1: Coefficients H_i for my_dash_0
2222
Table1_H = [
@@ -66,34 +66,34 @@ def Table2_H():
6666
Table3_Gamma_0 = 0.06
6767
Table3_T_dash_R = 1.5
6868

69-
# Tabel 4: Sample points for computer-program verification of the correlating equation, Eq. (10), with µ_2 =1.
70-
Tabel4_T = [298.15, 298.15, 373.15, 433.15, 433.15, 873.15, 873.15, 873.15, 1173.15, 1173.15, 1173.15]
69+
# Table 4: Sample points for computer-program verification of the correlating equation, Eq. (10), with µ_2 =1.
70+
Table4_T = [298.15, 298.15, 373.15, 433.15, 433.15, 873.15, 873.15, 873.15, 1173.15, 1173.15, 1173.15]
7171
Table4_rho = [998, 1200, 1000, 1, 1000, 1, 100, 600, 1, 100, 400]
72-
Tabel4_my = [
73-
889.735100,
74-
1437.649467,
75-
307.883622,
76-
14.538324,
77-
217.685358,
78-
32.619287,
79-
35.802262,
80-
77.430195,
81-
44.217245,
82-
47.640433,
83-
64.154608,
72+
Table4_my = [
73+
889.735100e-6,
74+
1437.649467e-6,
75+
307.883622e-6,
76+
14.538324e-6,
77+
217.685358e-6,
78+
32.619287e-6,
79+
35.802262e-6,
80+
77.430195e-6,
81+
44.217245e-6,
82+
47.640433e-6,
83+
64.154608e-6,
8484
]
8585

8686
# Table 5: Sample points for computer-program verification of the correlating equation, Eq. (10), in the region near the critical point.
87-
Tabel5_T = [647.35, 647.35, 647.35, 647.35, 647.35] # in K
88-
Tabel5_rho = [122, 222, 272, 322, 372, 422] # in kg / m^3
87+
Table5_T = [647.35, 647.35, 647.35, 647.35, 647.35, 647.35] # in K
88+
Table5_rho = [122, 222, 272, 322, 372, 422] # in kg / m^3
8989
Table5_xi = [
9090
0.309247,
9191
1.571405,
9292
5.266522,
9393
16.590209,
9494
5.603768,
9595
1.876244,
96-
] # in nm
96+
] # in nm
9797
Table5_my2dash = [
9898
1.00000289, # Correlation length ξ < 0.3817016416 nm so Y is evaluated with Eq. (15).
9999
1.00375120,
@@ -102,4 +102,4 @@ def Table2_H():
102102
1.03665871,
103103
1.00596332,
104104
]
105-
Tabel5_my = [25.520677e-6, 31.337589e-6, 36.228143e-6, 42.961579e-6, 45.688204e-6, 49.436256e-6] # Pa*s
105+
Table5_my = [25.520677e-6, 31.337589e-6, 36.228143e-6, 42.961579e-6, 45.688204e-6, 49.436256e-6] # Pa*s

tests/test_R12.py

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99

1010
class R12_FunctionTester(unittest.TestCase):
1111
def setUp(self):
12-
self.max_error = 1e-8
12+
self.max_error = 1e-7
1313

1414
def tearDown(self):
1515
pass
1616

17-
# def test_R12_industrial(self):
17+
def test_R12_industrial(self):
1818

19-
# res = numpy.zeros(len(R12_08.Tabel4_my))
20-
# for i, (T, rho) in enumerate(zip(R12_08.Tabel4_T, R12_08.Table4_rho)):
21-
# res[i] = IAPWS_R12.my_rhoT(T, rho, industrial_use=True)
19+
res = numpy.zeros(len(R12_08.Table4_my))
20+
for i, (T, rho) in enumerate(zip(R12_08.Table4_T, R12_08.Table4_rho)):
21+
res[i] = IAPWS_R12.my_rhoT(rho, T, industrial_application=True)
2222

23-
# error = numpy.sum(numpy.absolute((res - R12_08.Tabel4_my) / R12_08.Tabel4_my))
24-
# self.assertLess(error, self.max_error, "Test of correlation function for T and rho in R12 failed")
23+
error = numpy.sum(numpy.absolute((res - R12_08.Table4_my) / R12_08.Table4_my))
24+
self.assertLess(error, self.max_error, "Test of simplifyed viscosity function for rho and T in R12 failed")
2525

2626
# def test_R12(self):
2727
# values = list()
@@ -47,45 +47,54 @@ def tearDown(self):
4747
# },
4848
# )
4949

50-
# def test_R12_internal(self):
51-
# in_T = [647.35] * 6 # K
52-
# in_rho = [
53-
# 122.0,
54-
# 222.0,
55-
# 272.0,
56-
# 322.0,
57-
# 372.0,
58-
# 422.0,
59-
# ] # kg / m^3
60-
61-
# ref_xi = [
62-
# 0.309247,
63-
# 1.571405,
64-
# 5.266522,
65-
# 16.590209,
66-
# 5.603768,
67-
# 1.876244,
68-
# ] # nm
69-
70-
# res = numpy.zeros(len(ref_xi))
71-
# for i, (rho, T) in enumerate(zip(in_rho, in_T)):
72-
# res[i] = IAPWS_R12.R12_xi(rho, T)
73-
74-
# error = numpy.sum(numpy.absolute((res - ref_xi) / ref_xi))
75-
# self.assertLess(error, self.max_error * 2, "Test of internal function R12_xi(rho,T) Function failed")
76-
77-
# ref_my_dash_2 = [
78-
# 1.00000289,
79-
# 1.00375120,
80-
# 1.03416789,
81-
# 1.09190440,
82-
# 1.03665871,
83-
# 1.00596332,
84-
# ]
85-
86-
# res = numpy.zeros(len(ref_my_dash_2))
87-
# for i, (rho, T) in enumerate(zip(in_rho, in_T)):
88-
# res[i] = IAPWS_R12.R12_my_dash_2(rho, T)
89-
90-
# error = numpy.sum(numpy.absolute((res - ref_my_dash_2) / ref_my_dash_2))
91-
# self.assertLess(error, self.max_error * 2, "Test of internal function R12_my_dash_2(rho,T) Function failed")
50+
def test_R12_internal(self):
51+
52+
res = numpy.zeros(len(R12_08.Table5_xi))
53+
for i, (T, rho) in enumerate(zip(R12_08.Table5_T, R12_08.Table5_rho)):
54+
print(IAPWS_R12.R12_xi(rho, T))
55+
res[i] = IAPWS_R12.R12_xi(rho, T)
56+
57+
error = numpy.sum(numpy.absolute((res - R12_08.Table5_xi) / R12_08.Table5_xi))
58+
self.assertLess(error, self.max_error, "Test of internal calculation of correlation length ξ failed")
59+
60+
# in_T = [647.35] * 6 # K
61+
# in_rho = [
62+
# 122.0,
63+
# 222.0,
64+
# 272.0,
65+
# 322.0,
66+
# 372.0,
67+
# 422.0,
68+
# ] # kg / m^3
69+
70+
# ref_xi = [
71+
# 0.309247,
72+
# 1.571405,
73+
# 5.266522,
74+
# 16.590209,
75+
# 5.603768,
76+
# 1.876244,
77+
# ] # nm
78+
79+
# res = numpy.zeros(len(ref_xi))
80+
# for i, (rho, T) in enumerate(zip(in_rho, in_T)):
81+
# res[i] = IAPWS_R12.R12_xi(rho, T)
82+
83+
# error = numpy.sum(numpy.absolute((res - ref_xi) / ref_xi))
84+
# self.assertLess(error, self.max_error * 2, "Test of internal function R12_xi(rho,T) Function failed")
85+
86+
# ref_my_dash_2 = [
87+
# 1.00000289,
88+
# 1.00375120,
89+
# 1.03416789,
90+
# 1.09190440,
91+
# 1.03665871,
92+
# 1.00596332,
93+
# ]
94+
95+
# res = numpy.zeros(len(ref_my_dash_2))
96+
# for i, (rho, T) in enumerate(zip(in_rho, in_T)):
97+
# res[i] = IAPWS_R12.R12_my_dash_2(rho, T)
98+
99+
# error = numpy.sum(numpy.absolute((res - ref_my_dash_2) / ref_my_dash_2))
100+
# self.assertLess(error, self.max_error * 2, "Test of internal function R12_my_dash_2(rho,T) Function failed")

tests/test_R15.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# -*- coding: utf-8 -*-
22

33
import unittest
4-
import numpy
5-
from pyXSteam import IAPWS_R15
4+
5+
# import numpy
6+
# from pyXSteam import IAPWS_R15
67

78

89
class TransportTester(unittest.TestCase):

0 commit comments

Comments
 (0)