-
Notifications
You must be signed in to change notification settings - Fork 64
/
test.py
executable file
·2825 lines (2555 loc) · 138 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Test IAPWS mopdule."""
from math import log
import sys
import unittest
from iapws.iapws97 import (IAPWS97, IAPWS97_Tx, IAPWS97_Px, IAPWS97_Ph,
IAPWS97_Ps, IAPWS97_PT)
from iapws.iapws97 import (_Region1, _Region2, _Region2_meta, _Region3,
_Region5, _Backward1_T_Ph, _Backward1_T_Ps,
_Backward1_P_hs, _Backward2_T_Ph, _Backward2_T_Ps,
_Backward2_P_hs, _h_3ab, _Backward3_T_Ph,
_Backward3_v_Ph, _Backward3_T_Ps, _Backward3_v_Ps,
_PSat_h, _PSat_s, _Backward3_P_hs, _h1_s, _h3a_s,
_h2ab_s, _h2c3b_s, _PSat_T, _TSat_P, _h13_s, _t_hs,
_Backward4_T_hs, _tab_P, _top_P, _twx_P, _tef_P,
_txx_P, _hab_s, _Backward3_v_PT, _P23_T, _t_P,
_P_2bc, _hbc_P)
from iapws.iapws95 import (IAPWS95, IAPWS95_PT, IAPWS95_Tx, IAPWS95_Ph,
IAPWS95_Px, IAPWS95_Ps, D2O)
from iapws.iapws08 import (SeaWater, _ThCond_SeaWater, _Tension_SeaWater,
_solNa2SO4, _critNaCl, _Tb, _Tf, _Triple,
_OsmoticPressure)
from iapws._iapws import (_Ice, _Sublimation_Pressure, _Melting_Pressure,
_Viscosity, _ThCond, _Tension, _Kw, _Liquid,
_D2O_Viscosity, _D2O_ThCond, _D2O_Tension,
_D2O_Sublimation_Pressure, _D2O_Melting_Pressure,
_Conductivity, _Henry, _Kvalue, _Supercooled)
from iapws.humidAir import _virial, _fugacity, Air, HumidAir
from iapws.ammonia import NH3, H2ONH3, Ttr
# Python version detect for new capacities of unittest
major = sys.version_info[0]
minor = sys.version_info[1]
# Test
class Test(unittest.TestCase):
"""
Global unittest for module
Run for python2 and python3 before to release distribution
"""
def test_Helmholtz(self):
"""Table 6 from IAPWS95, pag 14"""
T = 500
rho = 838.025
fluid = IAPWS95()
delta = rho/fluid.rhoc
tau = fluid.Tc/T
ideal = fluid._phi0(tau, delta)
self.assertEqual(round(ideal["fio"], 8), 2.04797733)
self.assertEqual(round(ideal["fiod"], 9), 0.384236747)
self.assertEqual(round(ideal["fiodd"], 9), -0.147637878)
self.assertEqual(round(ideal["fiot"], 8), 9.04611106)
self.assertEqual(round(ideal["fiott"], 8), -1.93249185)
self.assertEqual(round(ideal["fiodt"], 8), 0.0)
res = fluid._phir(tau, delta)
self.assertEqual(round(res["fir"], 8), -3.42693206)
self.assertEqual(round(res["fird"], 9), -0.364366650)
self.assertEqual(round(res["firdd"], 9), 0.856063701)
self.assertEqual(round(res["firt"], 8), -5.81403435)
self.assertEqual(round(res["firtt"], 8), -2.23440737)
self.assertEqual(round(res["firdt"], 8), -1.12176915)
# Revised release of 2018
# Virial coefficient in Table 3
vir = fluid._virial(600)
self.assertEqual(round(vir["B"]/fluid.rhoc, 11), -0.555366808e-2)
self.assertEqual(round(vir["C"]/fluid.rhoc**2, 14), -0.669015050e-5)
def test_phase(self):
"""Table 7 from IAPWS95, pag 14"""
state = IAPWS95(rho=996.556, T=300)
# See footnote for imprecise P value in last significant figures
self.assertEqual(round(state.P*1e3, 7), 99.2418352)
self.assertEqual(round(state.cv, 8), 4.13018112)
self.assertEqual(round(state.w, 5), 1501.51914)
self.assertEqual(round(state.s, 9), 0.393062643)
state = IAPWS95(rho=1005.308, T=300)
self.assertEqual(round(state.P*1e3, 4), 20002.2515)
self.assertEqual(round(state.cv, 8), 4.06798347)
self.assertEqual(round(state.w, 5), 1534.92501)
self.assertEqual(round(state.s, 9), 0.387405401)
state = IAPWS95(rho=1188.202, T=300)
self.assertEqual(round(state.P*1e3, 3), 700004.704)
self.assertEqual(round(state.cv, 8), 3.46135580)
self.assertEqual(round(state.w, 5), 2443.57992)
self.assertEqual(round(state.s, 9), 0.132609616)
state = IAPWS95(rho=0.435, T=500)
self.assertEqual(round(state.P*1e3, 7), 99.9679423)
self.assertEqual(round(state.cv, 8), 1.50817541)
self.assertEqual(round(state.w, 6), 548.314253)
self.assertEqual(round(state.s, 8), 7.94488271)
state = IAPWS95(rho=4.532, T=500)
self.assertEqual(round(state.P*1e3, 6), 999.938125)
self.assertEqual(round(state.cv, 8), 1.66991025)
self.assertEqual(round(state.w, 6), 535.739001)
self.assertEqual(round(state.s, 8), 6.82502725)
state = IAPWS95(rho=838.025, T=500)
self.assertEqual(round(state.P*1e3, 4), 10000.3858)
self.assertEqual(round(state.cv, 8), 3.22106219)
self.assertEqual(round(state.w, 5), 1271.28441)
self.assertEqual(round(state.s, 8), 2.56690919)
state = IAPWS95(rho=1084.564, T=500)
self.assertEqual(round(state.P*1e3, 3), 700000.405)
self.assertEqual(round(state.cv, 8), 3.07437693)
self.assertEqual(round(state.w, 5), 2412.00877)
self.assertEqual(round(state.s, 8), 2.03237509)
state = IAPWS95(rho=358., T=647)
self.assertEqual(round(state.P*1e3, 4), 22038.4756)
self.assertEqual(round(state.cv, 8), 6.18315728)
self.assertEqual(round(state.w, 6), 252.145078)
self.assertEqual(round(state.s, 8), 4.32092307)
state = IAPWS95(rho=0.241, T=900)
self.assertEqual(round(state.P*1e3, 6), 100.062559)
self.assertEqual(round(state.cv, 8), 1.75890657)
self.assertEqual(round(state.w, 6), 724.027147)
self.assertEqual(round(state.s, 8), 9.16653194)
state = IAPWS95(rho=52.615, T=900)
self.assertEqual(round(state.P*1e3, 3), 20000.069)
self.assertEqual(round(state.cv, 8), 1.93510526)
self.assertEqual(round(state.w, 6), 698.445674)
self.assertEqual(round(state.s, 8), 6.59070225)
state = IAPWS95(rho=870.769, T=900)
self.assertEqual(round(state.P*1e3, 3), 700000.006)
self.assertEqual(round(state.cv, 8), 2.66422350)
self.assertEqual(round(state.w, 5), 2019.33608)
self.assertEqual(round(state.s, 8), 4.17223802)
def test_saturation(self):
"""Table 8 from IAPWS95, pag 14"""
fluid = IAPWS95()
rhol, rhov, Ps = fluid._saturation(275)
liquid = fluid._Helmholtz(rhol, 275)
vapor = fluid._Helmholtz(rhov, 275)
self.assertEqual(round(Ps, 9), 0.698451167)
self.assertEqual(round(rhol, 6), 999.887406)
self.assertEqual(round(rhov, 11), 0.00550664919)
self.assertEqual(round(liquid["h"], 8), 7.75972202)
self.assertEqual(round(vapor["h"], 5), 2504.28995)
self.assertEqual(round(liquid["s"], 10), 0.0283094670)
self.assertEqual(round(vapor["s"], 8), 9.10660121)
rhol, rhov, Ps = fluid._saturation(450)
liquid = fluid._Helmholtz(rhol, 450)
vapor = fluid._Helmholtz(rhov, 450)
self.assertEqual(round(Ps, 6), 932.203564)
self.assertEqual(round(rhol, 6), 890.341250)
self.assertEqual(round(rhov, 8), 4.81200360)
self.assertEqual(round(liquid["h"], 6), 749.161585)
self.assertEqual(round(vapor["h"], 5), 2774.41078)
self.assertEqual(round(liquid["s"], 8), 2.10865845)
self.assertEqual(round(vapor["s"], 8), 6.60921221)
rhol, rhov, Ps = fluid._saturation(625)
liquid = fluid._Helmholtz(rhol, 625)
vapor = fluid._Helmholtz(rhov, 625)
self.assertEqual(round(Ps, 4), 16908.2693)
self.assertEqual(round(rhol, 6), 567.090385)
self.assertEqual(round(rhov, 6), 118.290280)
self.assertEqual(round(liquid["h"], 5), 1686.26976)
self.assertEqual(round(vapor["h"], 5), 2550.71625)
self.assertEqual(round(liquid["s"], 8), 3.80194683)
self.assertEqual(round(vapor["s"], 8), 5.18506121)
def test_LowT(self):
"""Table 3, pag 5"""
fluid = IAPWS95()
fex, fext, fextt = fluid._phiex(50)
self.assertEqual(round(fex, 11), 0.00381124912)
self.assertEqual(round(fext, 11), 0.00172505502)
self.assertEqual(round(fextt, 12), 0.000525861643)
self.assertEqual(round(fluid._prop0(1, 50).cp/fluid.R, 8), 3.91824190)
fex, fext, fextt = fluid._phiex(100)
self.assertEqual("%0.8e" % fex, "3.98019838e-06")
self.assertEqual(round(fext, 13), 0.120506637e-4)
self.assertEqual(round(fextt, 13), 0.277309851e-4)
self.assertEqual(round(fluid._prop0(1, 100).cp/fluid.R, 8), 4.00536708)
fluid = IAPWS95(T=120, P=0.1)
def test_Melting(self):
"""Table 3, pag 7"""
self.assertRaises(NotImplementedError, _Sublimation_Pressure, 49)
self.assertRaises(NotImplementedError, _Sublimation_Pressure, 274)
self.assertEqual(round(_Sublimation_Pressure(230), 11), 8.94735e-6)
self.assertRaises(NotImplementedError, _Melting_Pressure, 250)
self.assertEqual(round(_Melting_Pressure(260, "Ih"), 3), 138.268)
self.assertEqual(round(_Melting_Pressure(254, "III"), 3), 268.685)
self.assertEqual(round(_Melting_Pressure(265, "V"), 3), 479.640)
self.assertEqual(round(_Melting_Pressure(320, "VI"), 2), 1356.76)
self.assertEqual(round(_Melting_Pressure(550, "VII"), 2), 6308.71)
def test_Viscosity_1(self):
"""Table 4, pag 8"""
self.assertEqual(round(_Viscosity(998, 298.15)*1e6, 6), 889.735100)
self.assertEqual(round(_Viscosity(1200, 298.15)*1e6, 6), 1437.649467)
self.assertEqual(round(_Viscosity(1000, 373.15)*1e6, 6), 307.883622)
self.assertEqual(round(_Viscosity(1, 433.15)*1e6, 6), 14.538324)
self.assertEqual(round(_Viscosity(1000, 433.15)*1e6, 6), 217.685358)
self.assertEqual(round(_Viscosity(1, 873.15)*1e6, 6), 32.619287)
self.assertEqual(round(_Viscosity(100, 873.15)*1e6, 6), 35.802262)
self.assertEqual(round(_Viscosity(600, 873.15)*1e6, 6), 77.430195)
self.assertEqual(round(_Viscosity(1, 1173.15)*1e6, 6), 44.217245)
self.assertEqual(round(_Viscosity(100, 1173.15)*1e6, 6), 47.640433)
self.assertEqual(round(_Viscosity(400, 1173.15)*1e6, 6), 64.154608)
# Table 5, pag 9
fluid = IAPWS95(rho=122, T=647.35)
self.assertEqual(round(fluid.mu*1e6, 6), 25.520677)
fluid = IAPWS95(rho=222, T=647.35)
self.assertEqual(round(fluid.mu*1e6, 6), 31.337589)
fluid = IAPWS95(rho=272, T=647.35)
self.assertEqual(round(fluid.mu*1e6, 6), 36.228143)
fluid = IAPWS95(rho=322, T=647.35)
self.assertEqual(round(fluid.mu*1e6, 6), 42.961579)
fluid = IAPWS95(rho=372, T=647.35)
self.assertEqual(round(fluid.mu*1e6, 6), 45.688204)
fluid = IAPWS95(rho=422, T=647.35)
self.assertEqual(round(fluid.mu*1e6, 6), 49.436256)
def test_ThCond(self):
"""Table 4, pag 10"""
self.assertEqual(round(_ThCond(0, 298.15)*1000, 7), 18.4341883)
self.assertEqual(round(_ThCond(998, 298.15)*1000, 6), 607.712868)
self.assertEqual(round(_ThCond(1200, 298.15)*1000, 6), 799.038144)
self.assertEqual(round(_ThCond(0, 873.15)*1000, 7), 79.1034659)
# Table 5, pag 10
fluid = IAPWS95(rho=1, T=647.35)
self.assertEqual(round(fluid.k*1000, 7), 51.9298924)
fluid = IAPWS95(rho=122, T=647.35)
self.assertEqual(round(fluid.k*1000, 6), 130.922885)
fluid = IAPWS95(rho=222, T=647.35)
self.assertEqual(round(fluid.k*1000, 6), 367.787459)
fluid = IAPWS95(rho=272, T=647.35)
self.assertEqual(round(fluid.k*1000, 6), 757.959776)
fluid = IAPWS95(rho=322, T=647.35)
self.assertEqual(round(fluid.k*1000, 5), 1443.75556)
fluid = IAPWS95(rho=372, T=647.35)
self.assertEqual(round(fluid.k*1000, 6), 650.319402)
fluid = IAPWS95(rho=422, T=647.35)
self.assertEqual(round(fluid.k*1000, 6), 448.883487)
fluid = IAPWS95(rho=750, T=647.35)
self.assertEqual(round(fluid.k*1000, 6), 600.961346)
# Industrial formulation, Table 7, 8, 9
fluid = IAPWS97(T=620, P=20)
self.assertEqual(round(fluid.k*1000, 6), 481.485195)
fluid = IAPWS97(T=620, P=50)
self.assertEqual(round(fluid.k*1000, 6), 545.038940)
fluid = IAPWS97(T=650, P=0.3)
self.assertEqual(round(fluid.k*1000, 7), 52.2311024)
fluid = IAPWS97(T=800, P=50)
self.assertEqual(round(fluid.k*1000, 6), 177.709914)
P = _Region3(T=647.35, rho=222)["P"]
fluid = IAPWS97(T=647.35, P=P)
self.assertEqual(round(fluid.k*1000, 6), 366.879411)
P = _Region3(T=647.35, rho=322)["P"]
fluid = IAPWS97(T=647.35, P=P)
self.assertEqual(round(fluid.k*1000, 5), 1241.82415)
def test_Tension(self):
"""Selected values from table 1"""
self.assertRaises(NotImplementedError, _Tension, 230)
self.assertEqual(round(_Tension(273.16)*1000, 2), 75.65)
self.assertEqual(round(_Tension(283.15)*1000, 2), 74.22)
self.assertEqual(round(_Tension(293.15)*1000, 2), 72.74)
self.assertEqual(round(_Tension(303.15)*1000, 2), 71.19)
self.assertEqual(round(_Tension(313.15)*1000, 2), 69.60)
self.assertEqual(round(_Tension(323.15)*1000, 2), 67.94)
self.assertEqual(round(_Tension(333.15)*1000, 2), 66.24)
self.assertEqual(round(_Tension(343.15)*1000, 2), 64.48)
self.assertEqual(round(_Tension(353.15)*1000, 2), 62.67)
self.assertEqual(round(_Tension(363.15)*1000, 2), 60.82)
self.assertEqual(round(_Tension(373.15)*1000, 2), 58.91)
self.assertEqual(round(_Tension(393.15)*1000, 2), 54.97)
self.assertEqual(round(_Tension(413.15)*1000, 2), 50.86)
self.assertEqual(round(_Tension(433.15)*1000, 2), 46.59)
self.assertEqual(round(_Tension(453.15)*1000, 2), 42.19)
self.assertEqual(round(_Tension(473.15)*1000, 2), 37.67)
self.assertEqual(round(_Tension(523.15)*1000, 2), 26.04)
self.assertEqual(round(_Tension(573.15)*1000, 2), 14.36)
self.assertEqual(round(_Tension(623.15)*1000, 2), 3.67)
self.assertEqual(round(_Tension(643.15)*1000, 2), 0.39)
def test_Dielect(self):
"""Table 4, pag 8"""
fluid = IAPWS95(P=0.101325, T=240)
self.assertEqual(round(fluid.epsilon, 5), 104.34982)
fluid = IAPWS95(P=0.101325, T=300)
self.assertEqual(round(fluid.epsilon, 5), 77.74735)
fluid = IAPWS95(P=10, T=300)
self.assertEqual(round(fluid.epsilon, 5), 78.11269)
fluid = IAPWS95(P=1000, T=300)
self.assertEqual(round(fluid.epsilon, 5), 103.69632)
fluid = IAPWS95(P=10, T=650)
self.assertEqual(round(fluid.epsilon, 5), 1.26715)
fluid = IAPWS95(P=100, T=650)
self.assertEqual(round(fluid.epsilon, 5), 17.71733)
fluid = IAPWS95(P=500, T=650)
self.assertEqual(round(fluid.epsilon, 5), 26.62132)
fluid = IAPWS95(P=10, T=870)
self.assertEqual(round(fluid.epsilon, 5), 1.12721)
fluid = IAPWS95(P=100, T=870)
self.assertEqual(round(fluid.epsilon, 5), 4.98281)
fluid = IAPWS95(P=500, T=870)
self.assertEqual(round(fluid.epsilon, 5), 15.09746)
def test_Refractive(self):
"""Selected values from table 3, pag 6"""
fluid = IAPWS95(P=0.1, T=273.15, l=0.2265)
self.assertEqual(round(fluid.n, 6), 1.394527)
fluid = IAPWS95(P=10., T=273.15, l=0.2265)
self.assertEqual(round(fluid.n, 6), 1.396526)
fluid = IAPWS95(P=1., T=373.15, l=0.2265)
self.assertEqual(round(fluid.n, 6), 1.375622)
fluid = IAPWS95(P=100., T=373.15, l=0.2265)
self.assertEqual(round(fluid.n, 6), 1.391983)
fluid = IAPWS95(P=0.1, T=473.15, l=0.589)
self.assertEqual(round(fluid.n, 7), 1.0001456)
fluid = IAPWS95(P=1., T=773.15, l=0.589)
self.assertEqual(round(fluid.n, 7), 1.0008773)
fluid = IAPWS95(P=10., T=273.15, l=1.01398)
self.assertEqual(round(fluid.n, 6), 1.327710)
fluid = IAPWS95(P=100., T=473.15, l=1.01398)
self.assertEqual(round(fluid.n, 6), 1.298369)
def test_kw(self):
"""Table 2, pag 4"""
self.assertRaises(NotImplementedError, _Kw, *(1000, 270))
self.assertEqual(round(_Kw(1000, 300), 6), 13.906672)
self.assertEqual(round(_Kw(70, 600), 6), 20.161651)
self.assertEqual(round(_Kw(700, 600), 6), 11.147093)
self.assertEqual(round(_Kw(200, 800), 6), 14.487671)
self.assertEqual(round(_Kw(1200, 800), 7), 6.4058649)
self.assertEqual(round(_Kw(0, 1270), 6), 35.081557)
def test_liquid(self):
"""Table 8, pag 11"""
liq = _Liquid(260)
self.assertEqual(round(liq["g"], 7), -1.2659892)
self.assertEqual(round(liq["s"], 8), -.20998555)
self.assertEqual(round(liq["cp"], 8), 4.30017472)
self.assertEqual(round(liq["rho"], 6), 997.068360)
self.assertEqual(round(liq["vt"]*1e7, 8), -3.86550941)
self.assertEqual(round(liq["vtt"]*1e8, 8), 3.27442503)
self.assertEqual(round(liq["vp"]*1e7, 8), -5.82096820)
self.assertEqual(round(liq["vpt"]*1e9, 8), 7.80938294)
self.assertEqual(round(liq["w"], 5), 1324.87258)
self.assertEqual(round(liq["mu"]*1e6, 5), 3058.36075)
self.assertEqual(round(liq["k"], 9), 0.515628010)
self.assertEqual(round(liq["epsilon"], 6), 93.455835)
liq = _Liquid(298.15)
self.assertEqual(round(liq["g"], 7), -4.5617537)
self.assertEqual(round(liq["s"], 8), 0.36720145)
self.assertEqual(round(liq["cp"], 8), 4.18144618)
self.assertEqual(round(liq["rho"], 6), 997.047013)
self.assertEqual(round(liq["vt"]*1e7, 8), 2.58054178)
self.assertEqual(round(liq["vtt"]*1e8, 8), 0.97202076)
self.assertEqual(round(liq["vp"]*1e7, 8), -4.53803340)
self.assertEqual(round(liq["vpt"]*1e9, 8), 1.00038567)
self.assertEqual(round(liq["w"], 5), 1496.69922)
self.assertEqual(round(liq["mu"]*1e6, 6), 889.996774)
self.assertEqual(round(liq["k"], 9), 0.606502308)
self.assertEqual(round(liq["epsilon"], 6), 78.375218)
liq = _Liquid(375)
self.assertEqual(round(liq["g"], 7), -71.0588021)
self.assertEqual(round(liq["s"], 8), 1.32806616)
self.assertEqual(round(liq["cp"], 8), 4.21774697)
self.assertEqual(round(liq["rho"], 6), 957.009710)
self.assertEqual(round(liq["vt"]*1e7, 8), 7.94706623)
self.assertEqual(round(liq["vtt"]*1e8, 8), 0.62024104)
self.assertEqual(round(liq["vp"]*1e7, 8), -5.15666528)
self.assertEqual(round(liq["vpt"]*1e9, 8), -2.27073594)
self.assertEqual(round(liq["w"], 5), 1541.46611)
self.assertEqual(round(liq["mu"]*1e6, 6), 276.207245)
self.assertEqual(round(liq["k"], 9), 0.677913788)
self.assertEqual(round(liq["epsilon"], 6), 55.266199)
if major == 3:
self.assertWarns(Warning, _Liquid, *(375, 0.2))
self.assertRaises(NotImplementedError, _Liquid, *(375, 0.4))
def test_superCooled(self):
"""Table 5, pag 9"""
liq = _Supercooled(273.15, 0.101325)
self.assertEqual(round(liq["x"], 8), 0.09665472)
self.assertEqual(round(liq["L"], 8), 0.62120474)
self.assertEqual(round(liq["rho"], 5), 999.84229)
self.assertEqual(round(liq["alfap"]*1e4, 6), -0.683042)
self.assertEqual(round(liq["xkappa"]*1e4, 6), 5.088499)
self.assertEqual(round(liq["cp"], 7), 4.2183002)
self.assertEqual(round(liq["w"], 4), 1402.3886)
liq = _Supercooled(235.15, 0.101325)
self.assertEqual(round(liq["x"], 8), 0.25510286)
self.assertEqual(round(liq["L"], 8), 0.09176368)
self.assertEqual(round(liq["rho"], 5), 968.09999)
self.assertEqual(round(liq["alfap"]*1e4, 5), -29.63382)
self.assertEqual(round(liq["xkappa"]*1e4, 6), 11.580785)
self.assertEqual(round(liq["cp"], 6), 5.997563)
self.assertEqual(round(liq["w"], 4), 1134.5855)
liq = _Supercooled(250, 200)
self.assertEqual(round(liq["x"], 8), 0.03042927)
self.assertEqual(round(liq["L"], 8), 0.72377081)
self.assertEqual(round(liq["rho"], 5), 1090.45677)
self.assertEqual(round(liq["alfap"]*1e4, 6), 3.267768)
self.assertEqual(round(liq["xkappa"]*1e4, 6), 3.361311)
self.assertEqual(round(liq["cp"], 7), 3.7083902)
self.assertEqual(round(liq["w"], 4), 1668.2020)
liq = _Supercooled(200, 400)
self.assertEqual(round(liq["x"], 8), 0.00717008)
self.assertEqual(round(liq["L"], 7), 1.1553965)
self.assertEqual(round(liq["rho"], 5), 1185.02800)
self.assertEqual(round(liq["alfap"]*1e4, 6), 6.716009)
self.assertEqual(round(liq["xkappa"]*1e4, 6), 2.567237)
self.assertEqual(round(liq["cp"], 7), 3.3385250)
self.assertEqual(round(liq["w"], 4), 1899.3294)
liq = _Supercooled(250, 400)
self.assertEqual(round(liq["x"], 8), 0.00535884)
self.assertEqual(round(liq["L"], 7), 1.4345145)
self.assertEqual(round(liq["rho"], 4), 1151.7152)
self.assertEqual(round(liq["alfap"]*1e4, 5), 4.92993)
self.assertEqual(round(liq["xkappa"]*1e4, 6), 2.277029)
self.assertEqual(round(liq["cp"], 7), 3.7572144)
self.assertEqual(round(liq["w"], 4), 2015.8782)
self.assertRaises(NotImplementedError, _Supercooled, *(200, 100))
self.assertRaises(NotImplementedError, _Supercooled, *(180, 300))
def test_auxiliarySaturation(self):
"""Table 1 pag 7"""
fluid = IAPWS95()
self.assertEqual(round(fluid._Vapor_Pressure(273.16), 9), 0.000611657)
self.assertEqual(round(fluid._dPdT_sat(273.16), 12), 44.436693e-6)
self.assertEqual(round(fluid._Liquid_Density(273.16), 3), 999.789)
self.assertEqual(round(fluid._Vapor_Density(273.16), 8), 0.00485426)
self.assertEqual(round(fluid._alfa_sat(273.16), 9), -0.011529101)
self.assertEqual(round(fluid._Liquid_Enthalpy(273.16), 9), 0.000611786)
self.assertEqual(round(fluid._Vapor_Enthalpy(273.16), 1), 2500.5)
self.assertEqual(round(fluid._phi_sat(273.16), 5), -0.00004)
self.assertEqual(round(fluid._Liquid_Entropy(273.16), 1), 0)
self.assertEqual(round(fluid._Vapor_Entropy(273.16), 3), 9.154)
self.assertEqual(round(fluid._Vapor_Pressure(373.1243), 6), 0.101325)
self.assertEqual(round(fluid._dPdT_sat(373.1243), 6), 0.003616)
self.assertEqual(round(fluid._Liquid_Density(373.1243), 3), 958.365)
self.assertEqual(round(fluid._Vapor_Density(373.1243), 6), 0.597586)
self.assertEqual(round(fluid._alfa_sat(373.1243), 2), 417.65)
self.assertEqual(round(fluid._Liquid_Enthalpy(373.1243), 2), 419.05)
self.assertEqual(round(fluid._Vapor_Enthalpy(373.1243), 1), 2675.7)
self.assertEqual(round(fluid._phi_sat(373.1243), 3), 1.303)
self.assertEqual(round(fluid._Liquid_Entropy(373.1243), 3), 1.307)
self.assertEqual(round(fluid._Vapor_Entropy(373.1243), 3), 7.355)
self.assertEqual(round(fluid._Vapor_Pressure(647.096), 3), 22.064)
self.assertEqual(round(fluid._dPdT_sat(647.096), 3), 0.268)
self.assertEqual(round(fluid._Liquid_Density(647.096), 3), 322)
self.assertEqual(round(fluid._Vapor_Density(647.096), 8), 322)
self.assertEqual(round(fluid._alfa_sat(647.096), 0), 1548)
self.assertEqual(round(fluid._Liquid_Enthalpy(647.096), 1), 2086.6)
self.assertEqual(round(fluid._Vapor_Enthalpy(647.096), 1), 2086.6)
self.assertEqual(round(fluid._phi_sat(647.096), 3), 3.578)
self.assertEqual(round(fluid._Liquid_Entropy(647.096), 3), 4.410)
self.assertEqual(round(fluid._Vapor_Entropy(647.096), 3), 4.410)
def test_IAPWS97_1(self):
"""Table 5, pag 9"""
fluid = _Region1(300, 3)
self.assertEqual(round(fluid["v"], 11), 0.00100215168)
self.assertEqual(round(fluid["h"], 6), 115.331273)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 6), 112.324818)
self.assertEqual(round(fluid["s"], 9), 0.392294792)
self.assertEqual(round(fluid["cp"], 8), 4.17301218)
self.assertEqual(round(fluid["w"], 5), 1507.73921)
fluid = _Region1(300, 80)
self.assertEqual(round(fluid["v"], 12), 0.000971180894)
self.assertEqual(round(fluid["h"], 6), 184.142828)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 6), 106.448356)
self.assertEqual(round(fluid["s"], 9), 0.368563852)
self.assertEqual(round(fluid["cp"], 8), 4.01008987)
self.assertEqual(round(fluid["w"], 5), 1634.69054)
fluid = _Region1(500, 3)
self.assertEqual(round(fluid["v"], 10), 0.0012024180)
self.assertEqual(round(fluid["h"], 6), 975.542239)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 6), 971.934985)
self.assertEqual(round(fluid["s"], 9), 2.58041912)
self.assertEqual(round(fluid["cp"], 8), 4.65580682)
self.assertEqual(round(fluid["w"], 5), 1240.71337)
# _Backward1_T_Ph Table 7 pag 11
self.assertEqual(round(_Backward1_T_Ph(3, 500), 6), 391.798509)
self.assertEqual(round(_Backward1_T_Ph(80, 500), 6), 378.108626)
self.assertEqual(round(_Backward1_T_Ph(80, 1500), 6), 611.041229)
# _Backward1_T_Ps Table 9 pag 12
self.assertEqual(round(_Backward1_T_Ps(3, 0.5), 6), 307.842258)
self.assertEqual(round(_Backward1_T_Ps(80, 0.5), 6), 309.979785)
self.assertEqual(round(_Backward1_T_Ps(80, 3), 6), 565.899909)
# _Backward1_P_hs Table 3 pag 6 for supplementary p(h,s)
self.assertEqual(round(_Backward1_P_hs(0.001, 0), 13), 0.0009800980612)
self.assertEqual(round(_Backward1_P_hs(90, 0), 8), 91.92954727)
self.assertEqual(round(_Backward1_P_hs(1500, 3.4), 8), 58.68294423)
def test_IAPWS97_2(self):
"""Table 15, pag 17"""
# Auxiliary equation for the boundary 2-3
self.assertEqual(round(_P23_T(623.15), 7), 16.5291643)
self.assertEqual(round(_t_P(16.5291643), 6), 623.15)
# Auxiliary equation for the subregion2 boundary
self.assertEqual(round(_P_2bc(3516.004323), 6), 100.0)
self.assertEqual(round(_hbc_P(100), 6), 3516.004323)
self.assertEqual(round(_hab_s(7), 6), 3376.437884)
fluid = _Region2(300, 0.0035)
self.assertEqual(round(fluid["v"], 7), 39.4913866)
self.assertEqual(round(fluid["h"], 5), 2549.91145)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2411.69160)
self.assertEqual(round(fluid["s"], 8), 8.52238967)
self.assertEqual(round(fluid["cp"], 8), 1.91300162)
self.assertEqual(round(fluid["w"], 6), 427.920172)
fluid = _Region2(700, 0.0035)
self.assertEqual(round(fluid["v"], 7), 92.3015898)
self.assertEqual(round(fluid["h"], 5), 3335.68375)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 3012.62819)
self.assertEqual(round(fluid["s"], 7), 10.1749996)
self.assertEqual(round(fluid["cp"], 8), 2.08141274)
self.assertEqual(round(fluid["w"], 6), 644.289068)
fluid = _Region2(700, 30)
self.assertEqual(round(fluid["v"], 11), 0.00542946619)
self.assertEqual(round(fluid["h"], 5), 2631.49474)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2468.61076)
self.assertEqual(round(fluid["s"], 8), 5.17540298)
self.assertEqual(round(fluid["cp"], 7), 10.3505092)
self.assertEqual(round(fluid["w"], 6), 480.386523)
# Supplementary equation for the metastable region, Table 18 pag 20
fluid = _Region2_meta(450, 1)
self.assertEqual(round(fluid["v"], 9), 0.192516540)
self.assertEqual(round(fluid["h"], 5), 2768.81115)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2576.29461)
self.assertEqual(round(fluid["s"], 8), 6.56660377)
self.assertEqual(round(fluid["cp"], 8), 2.76349265)
self.assertEqual(round(fluid["w"], 6), 498.408101)
fluid = _Region2_meta(440, 1)
self.assertEqual(round(fluid["v"], 9), 0.186212297)
self.assertEqual(round(fluid["h"], 5), 2740.15123)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2553.93894)
self.assertEqual(round(fluid["s"], 8), 6.50218759)
self.assertEqual(round(fluid["cp"], 8), 2.98166443)
self.assertEqual(round(fluid["w"], 6), 489.363295)
fluid = _Region2_meta(450, 1.5)
self.assertEqual(round(fluid["v"], 9), 0.121685206)
self.assertEqual(round(fluid["h"], 5), 2721.34539)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2538.81758)
self.assertEqual(round(fluid["s"], 8), 6.29170440)
self.assertEqual(round(fluid["cp"], 8), 3.62795578)
self.assertEqual(round(fluid["w"], 6), 481.941819)
# Backward2_T_Ph Table 24 pag 25
self.assertEqual(round(_Backward2_T_Ph(0.001, 3000), 6), 534.433241)
self.assertEqual(round(_Backward2_T_Ph(3, 3000), 6), 575.373370)
self.assertEqual(round(_Backward2_T_Ph(3, 4000), 5), 1010.77577)
self.assertEqual(round(_Backward2_T_Ph(5, 3500), 6), 801.299102)
self.assertEqual(round(_Backward2_T_Ph(5, 4000), 5), 1015.31583)
self.assertEqual(round(_Backward2_T_Ph(25, 3500), 6), 875.279054)
self.assertEqual(round(_Backward2_T_Ph(40, 2700), 6), 743.056411)
self.assertEqual(round(_Backward2_T_Ph(60, 2700), 6), 791.137067)
self.assertEqual(round(_Backward2_T_Ph(60, 3200), 6), 882.756860)
# _Backward2_T_Ps Table 9 pag 12
self.assertEqual(round(_Backward2_T_Ps(0.1, 7.5), 6), 399.517097)
self.assertEqual(round(_Backward2_T_Ps(0.1, 8), 6), 514.127081)
self.assertEqual(round(_Backward2_T_Ps(2.5, 8), 5), 1039.84917)
self.assertEqual(round(_Backward2_T_Ps(8, 6), 6), 600.484040)
self.assertEqual(round(_Backward2_T_Ps(8, 7.5), 5), 1064.95556)
self.assertEqual(round(_Backward2_T_Ps(90, 6), 5), 1038.01126)
self.assertEqual(round(_Backward2_T_Ps(20, 5.75), 6), 697.992849)
self.assertEqual(round(_Backward2_T_Ps(80, 5.25), 6), 854.011484)
self.assertEqual(round(_Backward2_T_Ps(80, 5.75), 6), 949.017998)
# _Backward2_P_hs Table 9 pag 10 for supplementary p(h,s)
self.assertEqual(round(_Backward2_P_hs(2800, 6.5), 9), 1.371012767)
self.assertEqual(round(_Backward2_P_hs(2800, 9.5), 12), 0.001879743844)
self.assertEqual(round(_Backward2_P_hs(4100, 9.5), 10), 0.1024788997)
self.assertEqual(round(_Backward2_P_hs(2800, 6), 9), 4.793911442)
self.assertEqual(round(_Backward2_P_hs(3600, 6), 8), 83.95519209)
self.assertEqual(round(_Backward2_P_hs(3600, 7), 9), 7.527161441)
self.assertEqual(round(_Backward2_P_hs(2800, 5.1), 8), 94.39202060)
self.assertEqual(round(_Backward2_P_hs(2800, 5.8), 9), 8.414574124)
self.assertEqual(round(_Backward2_P_hs(3400, 5.8), 8), 83.76903879)
def test_IAPWS97_3(self):
"""Table 33, pag 49"""
fluid = _Region3(500, 650)
self.assertEqual(round(fluid["P"], 7), 25.5837018)
self.assertEqual(round(fluid["h"], 5), 1863.43019)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 1812.26279)
self.assertEqual(round(fluid["s"], 8), 4.05427273)
self.assertEqual(round(fluid["cp"], 7), 13.8935717)
self.assertEqual(round(fluid["w"], 6), 502.005554)
fluid = _Region3(200, 650)
self.assertEqual(round(fluid["P"], 7), 22.2930643)
self.assertEqual(round(fluid["h"], 5), 2375.12401)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2263.65868)
self.assertEqual(round(fluid["s"], 8), 4.85438792)
self.assertEqual(round(fluid["cp"], 7), 44.6579342)
self.assertEqual(round(fluid["w"], 6), 383.444594)
fluid = _Region3(500, 750)
self.assertEqual(round(fluid["P"], 7), 78.3095639)
self.assertEqual(round(fluid["h"], 5), 2258.68845)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 2102.06932)
self.assertEqual(round(fluid["s"], 8), 4.46971906)
self.assertEqual(round(fluid["cp"], 8), 6.34165359)
self.assertEqual(round(fluid["w"], 6), 760.696041)
# _h_3ab pag 7
self.assertEqual(round(_h_3ab(25), 6), 2095.936454)
def test_IAPWS97_3_Sup03(self):
"""Test for supplementary 03 for region 3"""
# _Backward3_T_Ph Table 5 pag 8
self.assertEqual(round(_Backward3_T_Ph(20, 1700), 7), 629.3083892)
self.assertEqual(round(_Backward3_T_Ph(50, 2000), 7), 690.5718338)
self.assertEqual(round(_Backward3_T_Ph(100, 2100), 7), 733.6163014)
self.assertEqual(round(_Backward3_T_Ph(20, 2500), 7), 641.8418053)
self.assertEqual(round(_Backward3_T_Ph(50, 2400), 7), 735.1848618)
self.assertEqual(round(_Backward3_T_Ph(100, 2700), 7), 842.0460876)
# _Backward3_v_Ph Table 8 pag 10
self.assertEqual(round(_Backward3_v_Ph(20, 1700), 12), 1.749903962e-3)
self.assertEqual(round(_Backward3_v_Ph(50, 2000), 12), 1.908139035e-3)
self.assertEqual(round(_Backward3_v_Ph(100, 2100), 12), 1.676229776e-3)
self.assertEqual(round(_Backward3_v_Ph(20, 2500), 12), 6.670547043e-3)
self.assertEqual(round(_Backward3_v_Ph(50, 2400), 12), 2.801244590e-3)
self.assertEqual(round(_Backward3_v_Ph(100, 2700), 12), 2.404234998e-3)
# _Backward3_T_Ps Table 12 pag 13
self.assertEqual(round(_Backward3_T_Ps(20, 3.8), 7), 628.2959869)
self.assertEqual(round(_Backward3_T_Ps(50, 3.6), 7), 629.7158726)
self.assertEqual(round(_Backward3_T_Ps(100, 4.0), 7), 705.6880237)
self.assertEqual(round(_Backward3_T_Ps(20, 5.0), 7), 640.1176443)
self.assertEqual(round(_Backward3_T_Ps(50, 4.5), 7), 716.3687517)
self.assertEqual(round(_Backward3_T_Ps(100, 5.0), 7), 847.4332825)
# _Backward3_v_Ps Table 15 pag 15
self.assertEqual(round(_Backward3_v_Ps(20, 3.8), 12), 1.733791463e-3)
self.assertEqual(round(_Backward3_v_Ps(50, 3.6), 12), 1.469680170e-3)
self.assertEqual(round(_Backward3_v_Ps(100, 4.0), 12), 1.555893131e-3)
self.assertEqual(round(_Backward3_v_Ps(20, 5.0), 12), 6.262101987e-3)
self.assertEqual(round(_Backward3_v_Ps(50, 4.5), 12), 2.332634294e-3)
self.assertEqual(round(_Backward3_v_Ps(100, 5.0), 12), 2.449610757e-3)
# _PSat_h Table 18 pag 18
self.assertRaises(NotImplementedError, _PSat_h, 2.6)
self.assertEqual(round(_PSat_h(1700), 8), 17.24175718)
self.assertEqual(round(_PSat_h(2000), 8), 21.93442957)
self.assertEqual(round(_PSat_h(2400), 8), 20.18090839)
# _PSat_s Table 20 pag 19
self.assertRaises(NotImplementedError, _PSat_s, 3.6)
self.assertEqual(round(_PSat_s(3.8), 8), 16.87755057)
self.assertEqual(round(_PSat_s(4.2), 8), 21.64451789)
self.assertEqual(round(_PSat_s(5.2), 8), 16.68968482)
def test_IAPWS97_3_Sup04(self):
"""Test for supplementary 04 for region 3"""
# _Backward3_P_hs Table 5 pag 10
self.assertEqual(round(_Backward3_P_hs(1700, 3.8), 8), 25.55703246)
self.assertEqual(round(_Backward3_P_hs(2000, 4.2), 8), 45.40873468)
self.assertEqual(round(_Backward3_P_hs(2100, 4.3), 8), 60.78123340)
self.assertEqual(round(_Backward3_P_hs(2600, 5.1), 8), 34.34999263)
self.assertEqual(round(_Backward3_P_hs(2400, 4.7), 8), 63.63924887)
self.assertEqual(round(_Backward3_P_hs(2700, 5.0), 8), 88.39043281)
# _h1_s _h3a_s Table 11 pag 17
self.assertRaises(NotImplementedError, _h1_s, 4)
self.assertEqual(round(_h1_s(1), 7), 308.5509647)
self.assertEqual(round(_h1_s(2), 7), 700.6304472)
self.assertEqual(round(_h1_s(3), 6), 1198.359754)
self.assertRaises(NotImplementedError, _h3a_s, 4.5)
self.assertEqual(round(_h3a_s(3.8), 6), 1685.025565)
self.assertEqual(round(_h3a_s(4), 6), 1816.891476)
self.assertEqual(round(_h3a_s(4.2), 6), 1949.352563)
# _h2ab_s _h2c3b_s Table 18 pag 21
self.assertRaises(NotImplementedError, _h2ab_s, 5)
self.assertEqual(round(_h2ab_s(7), 6), 2723.729985)
self.assertEqual(round(_h2ab_s(8), 6), 2599.047210)
self.assertEqual(round(_h2ab_s(9), 6), 2511.861477)
self.assertRaises(NotImplementedError, _h2c3b_s, 6)
self.assertEqual(round(_h2c3b_s(5.5), 6), 2687.693850)
self.assertEqual(round(_h2c3b_s(5.0), 6), 2451.623609)
self.assertEqual(round(_h2c3b_s(4.5), 6), 2144.360448)
# _h13_s Table 18 pag 21
self.assertRaises(NotImplementedError, _h13_s, 3.3)
self.assertEqual(round(_h13_s(3.7), 6), 1632.525047)
self.assertEqual(round(_h13_s(3.6), 6), 1593.027214)
self.assertEqual(round(_h13_s(3.5), 6), 1566.104611)
# _t_hs Table 26 pag 26
self.assertRaises(NotImplementedError, _t_hs, *(2600, 5))
self.assertEqual(round(_t_hs(2600, 5.1), 7), 713.5259364)
self.assertEqual(round(_t_hs(2700, 5.15), 7), 768.5345532)
self.assertEqual(round(_t_hs(2800, 5.2), 7), 817.6202120)
# _Backward4_T_hs Table 29 pag 31
self.assertEqual(round(_Backward4_T_hs(1800, 5.3), 7), 346.8475498)
self.assertEqual(round(_Backward4_T_hs(2400, 6.0), 7), 425.1373305)
self.assertEqual(round(_Backward4_T_hs(2500, 5.5), 7), 522.5579013)
def test_IAPWS97_3_Sup05(self):
"""Test for supplementary 05 for region 3 v=f(T,P)"""
# T=f(P) limit Table 3 pag 11
self.assertEqual(round(_tab_P(40), 7), 693.0341408)
self.assertEqual(round(_txx_P(25, "cd"), 7), 649.3659208)
self.assertEqual(round(_tef_P(40), 7), 713.9593992)
self.assertEqual(round(_txx_P(23, "gh"), 7), 649.8873759)
self.assertEqual(round(_txx_P(23, "ij"), 7), 651.5778091)
self.assertEqual(round(_txx_P(23, "jk"), 7), 655.8338344)
self.assertEqual(round(_txx_P(22.8, "mn"), 7), 649.6054133)
self.assertEqual(round(_top_P(22.8), 7), 650.0106943)
self.assertEqual(round(_txx_P(22, "qu"), 7), 645.6355027)
self.assertEqual(round(_txx_P(22, "rx"), 7), 648.2622754)
# _Backward3_v_PT Table 5 pag 13
self.assertEqual(round(_Backward3_v_PT(50, 630), 12), 1.470853100e-3)
self.assertEqual(round(_Backward3_v_PT(80, 670), 12), 1.503831359e-3)
self.assertEqual(round(_Backward3_v_PT(50, 710), 12), 2.204728587e-3)
self.assertEqual(round(_Backward3_v_PT(80, 750), 12), 1.973692940e-3)
self.assertEqual(round(_Backward3_v_PT(20, 630), 12), 1.761696406e-3)
self.assertEqual(round(_Backward3_v_PT(30, 650), 12), 1.819560617e-3)
self.assertEqual(round(_Backward3_v_PT(26, 656), 12), 2.245587720e-3)
self.assertEqual(round(_Backward3_v_PT(30, 670), 12), 2.506897702e-3)
self.assertEqual(round(_Backward3_v_PT(26, 661), 12), 2.970225962e-3)
self.assertEqual(round(_Backward3_v_PT(30, 675), 12), 3.004627086e-3)
self.assertEqual(round(_Backward3_v_PT(26, 671), 12), 5.019029401e-3)
self.assertEqual(round(_Backward3_v_PT(30, 690), 12), 4.656470142e-3)
self.assertEqual(round(_Backward3_v_PT(23.6, 649), 12), 2.163198378e-3)
self.assertEqual(round(_Backward3_v_PT(24, 650), 12), 2.166044161e-3)
self.assertEqual(round(_Backward3_v_PT(23.6, 652), 12), 2.651081407e-3)
self.assertEqual(round(_Backward3_v_PT(24, 654), 12), 2.967802335e-3)
self.assertEqual(round(_Backward3_v_PT(23.6, 653), 12), 3.273916816e-3)
self.assertEqual(round(_Backward3_v_PT(24, 655), 12), 3.550329864e-3)
self.assertEqual(round(_Backward3_v_PT(23.5, 655), 12), 4.545001142e-3)
self.assertEqual(round(_Backward3_v_PT(24, 660), 12), 5.100267704e-3)
self.assertEqual(round(_Backward3_v_PT(23, 660), 12), 6.109525997e-3)
self.assertEqual(round(_Backward3_v_PT(24, 670), 12), 6.427325645e-3)
self.assertEqual(round(_Backward3_v_PT(22.6, 646), 12), 2.117860851e-3)
self.assertEqual(round(_Backward3_v_PT(23, 646), 12), 2.062374674e-3)
self.assertEqual(round(_Backward3_v_PT(22.6, 648.6), 12), 2.533063780e-3)
self.assertEqual(round(_Backward3_v_PT(22.8, 649.3), 12), 2.572971781e-3)
self.assertEqual(round(_Backward3_v_PT(22.6, 649.0), 12), 2.923432711e-3)
self.assertEqual(round(_Backward3_v_PT(22.8, 649.7), 12), 2.913311494e-3)
self.assertEqual(round(_Backward3_v_PT(22.6, 649.1), 12), 3.131208996e-3)
self.assertEqual(round(_Backward3_v_PT(22.8, 649.9), 12), 3.221160278e-3)
self.assertEqual(round(_Backward3_v_PT(22.6, 649.4), 12), 3.715596186e-3)
self.assertEqual(round(_Backward3_v_PT(22.8, 650.2), 12), 3.664754790e-3)
self.assertEqual(round(_Backward3_v_PT(21.1, 640), 12), 1.970999272e-3)
self.assertEqual(round(_Backward3_v_PT(21.8, 643), 12), 2.043919161e-3)
self.assertEqual(round(_Backward3_v_PT(21.1, 644), 12), 5.251009921e-3)
self.assertEqual(round(_Backward3_v_PT(21.8, 648), 12), 5.256844741e-3)
self.assertEqual(round(_Backward3_v_PT(19.1, 635), 12), 1.932829079e-3)
self.assertEqual(round(_Backward3_v_PT(20, 638), 12), 1.985387227e-3)
self.assertEqual(round(_Backward3_v_PT(17, 626), 12), 8.483262001e-3)
self.assertEqual(round(_Backward3_v_PT(20, 640), 12), 6.227528101e-3)
# T=f(P) limit Table 11 pag 19
self.assertEqual(round(_txx_P(22.3, "uv"), 7), 647.7996121)
self.assertEqual(round(_twx_P(22.3), 7), 648.2049480)
# _Backward3_v_PT Table 13 pag 20
self.assertEqual(round(_Backward3_v_PT(21.5, 644.6), 12), 2.268366647e-3)
self.assertEqual(round(_Backward3_v_PT(22, 646.1), 12), 2.296350553e-3)
self.assertEqual(round(_Backward3_v_PT(22.5, 648.6), 12), 2.832373260e-3)
self.assertEqual(round(_Backward3_v_PT(22.3, 647.9), 12), 2.811424405e-3)
self.assertEqual(round(_Backward3_v_PT(22.15, 647.5), 12), 3.694032281e-3)
self.assertEqual(round(_Backward3_v_PT(22.3, 648.1), 12), 3.622226305e-3)
self.assertEqual(round(_Backward3_v_PT(22.11, 648), 12), 4.528072649e-3)
self.assertEqual(round(_Backward3_v_PT(22.3, 649), 12), 4.556905799e-3)
self.assertEqual(round(_Backward3_v_PT(22, 646.84), 12), 2.698354719e-3)
self.assertEqual(round(_Backward3_v_PT(22.064, 647.05), 12), 2.717655648e-3)
self.assertEqual(round(_Backward3_v_PT(22, 646.89), 12), 3.798732962e-3)
self.assertEqual(round(_Backward3_v_PT(22.064, 647.15), 11), 3.701940010e-3)
def test_IAPWS97_4(self):
"""Saturation line"""
# _PSat_T Table 35 pag 34
self.assertRaises(NotImplementedError, _PSat_T, 270)
self.assertEqual(round(_PSat_T(300), 11), 0.00353658941)
self.assertEqual(round(_PSat_T(500), 8), 2.63889776)
self.assertEqual(round(_PSat_T(600), 7), 12.3443146)
# _TSat_P Table 36 pag 36
self.assertRaises(NotImplementedError, _TSat_P, 30)
self.assertEqual(round(_TSat_P(0.1), 6), 372.755919)
self.assertEqual(round(_TSat_P(1), 6), 453.035632)
self.assertEqual(round(_TSat_P(10), 6), 584.149488)
def test_IAPWS97_5(self):
"""Table 42, pag 40"""
fluid = _Region5(1500, 0.5)
self.assertEqual(round(fluid["v"], 8), 1.38455090)
self.assertEqual(round(fluid["h"], 5), 5219.76855)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 4527.49310)
self.assertEqual(round(fluid["s"], 8), 9.65408875)
self.assertEqual(round(fluid["cp"], 8), 2.61609445)
self.assertEqual(round(fluid["w"], 6), 917.068690)
fluid = _Region5(1500, 30)
self.assertEqual(round(fluid["v"], 10), 0.0230761299)
self.assertEqual(round(fluid["h"], 5), 5167.23514)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 4474.95124)
self.assertEqual(round(fluid["s"], 8), 7.72970133)
self.assertEqual(round(fluid["cp"], 8), 2.72724317)
self.assertEqual(round(fluid["w"], 6), 928.548002)
fluid = _Region5(2000, 30)
self.assertEqual(round(fluid["v"], 10), 0.0311385219)
self.assertEqual(round(fluid["h"], 5), 6571.22604)
self.assertEqual(round(fluid["h"]-fluid["P"]*1000*fluid["v"], 5), 5637.07038)
self.assertEqual(round(fluid["s"], 8), 8.53640523)
self.assertEqual(round(fluid["cp"], 8), 2.88569882)
self.assertEqual(round(fluid["w"], 5), 1067.36948)
def test_IAPWS97_custom(self):
"""Cycle input parameter from selected point for IAPWS97"""
# Region 1
P = 50 # MPa
T = 470 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
P = 20 # MPa
T = 370 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
# Region 2
P = 25 # MPa
T = 700 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
P = 10 # MPa
T = 700 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
P = 20 # MPa
T = 800 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
P = 0.01 # MPa
T = 1000 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
P = 2 # MPa
T = 1000 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
# Region 3
P = 50 # MPa
T = 700 # K
f_pt = IAPWS97(P=P, T=T)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
P = 20 # MPa
s = 4 # kJ/kgK
f_ps = IAPWS97(P=P, s=s)
f_ph = IAPWS97(h=f_pt.h, P=f_pt.P)
f_pt = IAPWS97(P=f_ph.P, T=f_ph.T)
f_hs = IAPWS97(h=f_ps.h, s=f_ps.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.s-s, 6), 0)
P = 19 # MPa
f_px = IAPWS97(P=P, x=0)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 3), 0)
self.assertEqual(round(f_tx.x, 6), 0)
P = 19 # MPa
f_px = IAPWS97(P=P, x=1)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 3), 0)
self.assertEqual(round(f_tx.x, 6), 1)
P = 21 # MPa
f_px = IAPWS97(P=P, x=1)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 2), 0)
self.assertEqual(round(f_tx.x, 3), 1)
P = 21.5 # MPa
f_px = IAPWS97(P=P, x=0)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 2), 0)
self.assertEqual(round(f_tx.x, 3), 0)
P = 21.5 # MPa
f_px = IAPWS97(P=P, x=1)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 2), 0)
self.assertEqual(round(f_tx.x, 3), 1)
P = 22.02 # MPa
f_px = IAPWS97(P=P, x=0)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 2), 0)
self.assertEqual(round(f_tx.x, 3), 0)
P = 22.02 # MPa
f_px = IAPWS97(P=P, x=1)
f_tx = IAPWS97(T=f_px.T, x=f_px.x)
self.assertEqual(round(f_tx.P-P, 2), 0)
self.assertEqual(round(f_tx.x, 3), 1)
P = 24. # MPa
T = 630 # K
f_pt = IAPWS97(P=P, T=T)
f_hs = IAPWS97(h=f_pt.h, s=f_pt.s)
self.assertEqual(round(f_hs.P-P, 6), 0)
self.assertEqual(round(f_hs.T-T, 6), 0)
# Boundary 1-4
T = 340 # K
f_tx = IAPWS97(T=T, x=0)
f_ph = IAPWS97(h=f_tx.h, P=f_tx.P)
f_ps = IAPWS97(P=f_ph.P, s=f_ph.s)
f_px = IAPWS97(P=f_ps.P, x=f_ps.x)
f_hs = IAPWS97(h=f_px.h, s=f_px.s)
self.assertEqual(round(f_hs.T-T, 6), 0)