-
Notifications
You must be signed in to change notification settings - Fork 1
/
zXSteam.bas
3450 lines (3376 loc) · 153 KB
/
zXSteam.bas
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
Attribute VB_Name = "zXSteam"
Option Explicit
'***********************************************************************************************************
'* Water and steam properties according to IAPWS IF-97 *
'* By Magnus Holmgren, www.x-eng.com *
'* The steam tables are free and provided as is. *
'* We take no responsibilities for any errors in the code or damage thereby. *
'* You are free to use, modify and distribute the code as long as authorship is properly acknowledged. *
'* Please notify me at [email protected] if the code is used in commercial applications *
'***********************************************************************************************************'
'
' The code is also avalibale for matlab at www.x-eng.com
'
'*Contents.
'*1 Calling functions
'*1.1
'*1.2 Temperature (T)
'*1.3 Pressure (p)
'*1.4 Enthalpy (h)
'*1.5 Specific Volume (v)
'*1.6 Density (rho)
'*1.7 Specific entropy (s)
'*1.8 Specific internal energy (u)
'*1.9 Specific isobaric heat capacity (Cp)
'*1.10 Specific isochoric heat capacity (Cv)
'*1.11 Speed of sound
'*1.12 Viscosity
'*1.13 Prandtl
'*1.14 Kappa
'*1.15 Surface tension
'*1.16 Heat conductivity
'*1.17 Vapour fraction
'*1.18 Vapour Volume Fraction
'
'*2 IAPWS IF 97 Calling functions
'*2.1 Functions for region 1
'*2.2 Functions for region 2
'*2.3 Functions for region 3
'*2.4 Functions for region 4
'*2.5 Functions for region 5
'
'*3 Region Selection
'*3.1 Regions as a function of pT
'*3.2 Regions as a function of ph
'*3.3 Regions as a function of ps
'*3.4 Regions as a function of hs
'*3.5 Regions as a function of p and rho
'
'4 Region Borders
'4.1 Boundary between region 1 and 3.
'4.2 Region 3. pSat_h and pSat_s
'4.3 Region boundary 1to3 and 3to2 as a functions of s
'
'5 Transport properties
'5.1 Viscosity (IAPWS formulation 1985)
'5.2 Thermal Conductivity (IAPWS formulation 1985)
'5.3 Surface Tension
'
'6 Units
'***********************************************************************************************************
'*1 Calling functions *
'***********************************************************************************************************
'***********************************************************************************************************
'*1.1
'***********************************************************************************************************
'*1.2 Temperature
Function Tsat_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P >= 0.000611657 And P <= 22.06395 + 0.001 Then '0.001 Added to enable the tripple point.
Tsat_p = fromSIunit_T(T4_p(P))
Else
Tsat_p = CVErr(xlErrValue)
End If
End Function
Function Tsat_s(ByVal s As Double) As Double
s = toSIunit_s(s)
If s > -0.0001545495919 And s < 9.155759395 Then
Tsat_s = fromSIunit_T(T4_p(p4_s(s)))
Else
Tsat_s = CVErr(xlErrValue)
End If
End Function
Function T_ph(ByVal P As Double, ByVal h As Double) As Double
P = toSIunit_p(P)
h = toSIunit_h(h)
Select Case region_ph(P, h)
Case 1
T_ph = fromSIunit_T(T1_ph(P, h))
Case 2
T_ph = fromSIunit_T(T2_ph(P, h))
Case 3
T_ph = fromSIunit_T(T3_ph(P, h))
Case 4
T_ph = fromSIunit_T(T4_p(P))
Case 5
T_ph = fromSIunit_T(T5_ph(P, h))
Case Else
T_ph = CVErr(xlErrValue)
End Select
End Function
Function T_ps(ByVal P As Double, ByVal s As Double) As Double
P = toSIunit_p(P)
s = toSIunit_s(s)
Select Case region_ps(P, s)
Case 1
T_ps = fromSIunit_T(T1_ps(P, s))
Case 2
T_ps = fromSIunit_T(T2_ps(P, s))
Case 3
T_ps = fromSIunit_T(T3_ps(P, s))
Case 4
T_ps = fromSIunit_T(T4_p(P))
Case 5
T_ps = fromSIunit_T(T5_ps(P, s))
Case Else
T_ps = CVErr(xlErrValue)
End Select
End Function
Function T_hs(ByVal h As Double, ByVal s As Double) As Double
h = toSIunit_h(h)
s = toSIunit_s(s)
Select Case Region_hs(h, s)
Case 1
T_hs = fromSIunit_T(T1_ph(p1_hs(h, s), h))
Case 2
T_hs = fromSIunit_T(T2_ph(p2_hs(h, s), h))
Case 3
T_hs = fromSIunit_T(T3_ph(p3_hs(h, s), h))
Case 4
T_hs = fromSIunit_T(T4_hs(h, s))
Case 5
T_hs = CVErr(xlErrValue) 'Functions of hs is not implemented in region 5
Case Else
T_hs = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.3 Pressure (p)
Function psat_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T <= 647.096 And T > 273.15 Then
psat_T = fromSIunit_p(p4_T(T))
Else
psat_T = CVErr(xlErrValue)
End If
End Function
Function psat_s(ByVal s As Double) As Double
s = toSIunit_s(s)
If s > -0.0001545495919 And s < 9.155759395 Then
psat_s = fromSIunit_p(p4_s(s))
Else
psat_s = CVErr(xlErrValue)
End If
End Function
Function p_hs(ByVal h As Double, ByVal s As Double) As Double
h = toSIunit_h(h)
s = toSIunit_s(s)
Select Case Region_hs(h, s)
Case 1
p_hs = fromSIunit_p(p1_hs(h, s))
Case 2
p_hs = fromSIunit_p(p2_hs(h, s))
Case 3
p_hs = fromSIunit_p(p3_hs(h, s))
Case 4
p_hs = fromSIunit_p(p4_T(T4_hs(h, s)))
Case 5
p_hs = CVErr(xlErrValue) 'Functions of hs is not implemented in region 5
Case Else
p_hs = CVErr(xlErrValue)
End Select
End Function
Function p_hrho(ByVal h As Double, ByVal rho As Double) As Double
'*Not valid for water or sumpercritical since water rho does not change very much with p.
'*Uses iteration to find p.
Dim High_Bound As Double
Dim Low_Bound As Double
Dim P As Double
Dim rhos As Double
High_Bound = fromSIunit_p(100)
Low_Bound = fromSIunit_p(0.000611657)
P = fromSIunit_p(10)
rhos = 1 / v_ph(P, h)
Do While Abs(rho - rhos) > 0.0000001
rhos = 1 / v_ph(P, h)
If rhos >= rho Then
High_Bound = P
Else
Low_Bound = P
End If
P = (Low_Bound + High_Bound) / 2
Loop
p_hrho = P
End Function
'***********************************************************************************************************
'*1.4 Enthalpy (h)
Function hV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
hV_p = fromSIunit_h(h4V_p(P))
Else
hV_p = CVErr(xlErrValue)
End If
End Function
Function hL_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
hL_p = fromSIunit_h(h4L_p(P))
Else
hL_p = CVErr(xlErrValue)
End If
End Function
Function hV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
hV_T = fromSIunit_h(h4V_p(p4_T(T)))
Else
hV_T = CVErr(xlErrValue)
End If
End Function
Function hL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
hL_T = fromSIunit_h(h4L_p(p4_T(T)))
Else
hL_T = CVErr(xlErrValue)
End If
End Function
Function h_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
h_pT = fromSIunit_h(h1_pT(P, T))
Case 2
h_pT = fromSIunit_h(h2_pT(P, T))
Case 3
h_pT = fromSIunit_h(h3_pT(P, T))
Case 4
h_pT = CVErr(xlErrValue)
Case 5
h_pT = fromSIunit_h(h5_pT(P, T))
Case Else
h_pT = CVErr(xlErrValue)
End Select
End Function
Function h_ps(ByVal P As Double, ByVal s As Double) As Double
Dim xs As Double
P = toSIunit_p(P)
s = toSIunit_s(s)
Select Case region_ps(P, s)
Case 1
h_ps = fromSIunit_h(h1_pT(P, T1_ps(P, s)))
Case 2
h_ps = fromSIunit_h(h2_pT(P, T2_ps(P, s)))
Case 3
h_ps = fromSIunit_h(h3_rhoT(1 / v3_ps(P, s), T3_ps(P, s)))
Case 4
xs = x4_ps(P, s)
h_ps = fromSIunit_h(xs * h4V_p(P) + (1 - xs) * h4L_p(P))
Case 5
h_ps = fromSIunit_h(h5_pT(P, T5_ps(P, s)))
Case Else
h_ps = CVErr(xlErrValue)
End Select
End Function
Function h_px(ByVal P As Double, ByVal x As Double) As Double
Dim hL As Double
Dim hV As Double
P = toSIunit_p(P)
x = toSIunit_x(x)
If x > 1 Or x < 0 Or P >= 22.064 Then
h_px = CVErr(xlErrValue)
Exit Function
End If
hL = h4L_p(P)
hV = h4V_p(P)
h_px = fromSIunit_h(hL + x * (hV - hL))
End Function
Function h_Tx(ByVal T As Double, ByVal x As Double) As Double
Dim hL As Double
Dim hV As Double
Dim P As Double
T = toSIunit_T(T)
x = toSIunit_x(x)
If x > 1 Or x < 0 Or T >= 647.096 Then
h_Tx = CVErr(xlErrValue)
Exit Function
End If
P = p4_T(T)
hL = h4L_p(P)
hV = h4V_p(P)
h_Tx = fromSIunit_h(hL + x * (hV - hL))
End Function
Function h_prho(ByVal P As Double, ByVal rho As Double) As Double
Dim hL, hV, vL, vV, x As Double
P = toSIunit_p(P)
rho = 1 / toSIunit_v(1 / rho)
Select Case Region_prho(P, rho)
Case 1
h_prho = fromSIunit_h(h1_pT(P, T1_prho(P, rho)))
Case 2
h_prho = fromSIunit_h(h2_pT(P, T2_prho(P, rho)))
Case 3
h_prho = fromSIunit_h(h3_rhoT(rho, T3_prho(P, rho)))
Case 4
If P < 16.529 Then
vV = v2_pT(P, T4_p(P))
vL = v1_pT(P, T4_p(P))
Else
vV = v3_ph(P, h4V_p(P))
vL = v3_ph(P, h4L_p(P))
End If
hV = h4V_p(P)
hL = h4L_p(P)
x = (1 / rho - vL) / (vV - vL)
h_prho = fromSIunit_h((1 - x) * hL + x * hV)
Case 5
h_prho = fromSIunit_h(h5_pT(P, T5_prho(P, rho)))
Case Else
h_prho = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.5 Specific Volume (v)
Function vV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
vV_p = fromSIunit_v(v2_pT(P, T4_p(P)))
Else
vV_p = fromSIunit_v(v3_ph(P, h4V_p(P)))
End If
Else
vV_p = CVErr(xlErrValue)
End If
End Function
Function vL_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
vL_p = fromSIunit_v(v1_pT(P, T4_p(P)))
Else
vL_p = fromSIunit_v(v3_ph(P, h4L_p(P)))
End If
Else
vL_p = CVErr(xlErrValue)
End If
End Function
Function vV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
vV_T = fromSIunit_v(v2_pT(p4_T(T), T))
Else
vV_T = fromSIunit_v(v3_ph(p4_T(T), h4V_p(p4_T(T))))
End If
Else
vV_T = CVErr(xlErrValue)
End If
End Function
Function vL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
vL_T = fromSIunit_v(v1_pT(p4_T(T), T))
Else
vL_T = fromSIunit_v(v3_ph(p4_T(T), h4L_p(p4_T(T))))
End If
Else
vL_T = CVErr(xlErrValue)
End If
End Function
Function v_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
v_pT = fromSIunit_v(v1_pT(P, T))
Case 2
v_pT = fromSIunit_v(v2_pT(P, T))
Case 3
v_pT = fromSIunit_v(v3_ph(P, h3_pT(P, T)))
Case 4
v_pT = CVErr(xlErrValue)
Case 5
v_pT = fromSIunit_v(v5_pT(P, T))
Case Else
v_pT = CVErr(xlErrValue)
End Select
End Function
Function v_ph(ByVal P As Double, ByVal h As Double) As Double
Dim xs As Double
Dim v4V As Double
Dim v4L As Double
P = toSIunit_p(P)
h = toSIunit_h(h)
Select Case region_ph(P, h)
Case 1
v_ph = fromSIunit_v(v1_pT(P, T1_ph(P, h)))
Case 2
v_ph = fromSIunit_v(v2_pT(P, T2_ph(P, h)))
Case 3
v_ph = fromSIunit_v(v3_ph(P, h))
Case 4
xs = x4_ph(P, h)
If P < 16.529 Then
v4V = v2_pT(P, T4_p(P))
v4L = v1_pT(P, T4_p(P))
Else
v4V = v3_ph(P, h4V_p(P))
v4L = v3_ph(P, h4L_p(P))
End If
v_ph = fromSIunit_v((xs * v4V + (1 - xs) * v4L))
Case 5
v_ph = fromSIunit_v(v5_pT(P, T5_ph(P, h)))
Case Else
v_ph = CVErr(xlErrValue)
End Select
End Function
Function v_ps(ByVal P As Double, ByVal s As Double) As Double
Dim xs As Double
Dim v4V As Double
Dim v4L As Double
P = toSIunit_p(P)
s = toSIunit_s(s)
Select Case region_ps(P, s)
Case 1
v_ps = fromSIunit_v(v1_pT(P, T1_ps(P, s)))
Case 2
v_ps = fromSIunit_v(v2_pT(P, T2_ps(P, s)))
Case 3
v_ps = fromSIunit_v(v3_ps(P, s))
Case 4
xs = x4_ps(P, s)
If P < 16.529 Then
v4V = v2_pT(P, T4_p(P))
v4L = v1_pT(P, T4_p(P))
Else
v4V = v3_ph(P, h4V_p(P))
v4L = v3_ph(P, h4L_p(P))
End If
v_ps = fromSIunit_v((xs * v4V + (1 - xs) * v4L))
Case 5
v_ps = fromSIunit_v(v5_pT(P, T5_ps(P, s)))
Case Else
v_ps = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.6 Density (rho)
' Density is calculated as 1/v
Function rhoV_p(ByVal P As Double) As Double
rhoV_p = 1 / vV_p(P)
End Function
Function rhoL_p(ByVal P As Double) As Double
rhoL_p = 1 / vL_p(P)
End Function
Function rhoL_T(ByVal T As Double) As Double
rhoL_T = 1 / vL_T(T)
End Function
Function rhoV_T(ByVal T As Double) As Double
rhoV_T = 1 / vV_T(T)
End Function
Function rho_pT(ByVal P As Double, ByVal T As Double) As Double
rho_pT = 1 / v_pT(P, T)
End Function
Function rho_ph(ByVal P As Double, ByVal h As Double) As Double
rho_ph = 1 / v_ph(P, h)
End Function
Function rho_ps(ByVal P As Double, ByVal s As Double) As Double
rho_ps = 1 / v_ps(P, s)
End Function
'***********************************************************************************************************
'*1.7 Specific entropy (s)
Function sV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
sV_p = fromSIunit_s(s2_pT(P, T4_p(P)))
Else
sV_p = fromSIunit_s(s3_rhoT(1 / (v3_ph(P, h4V_p(P))), T4_p(P)))
End If
Else
sV_p = CVErr(xlErrValue)
End If
End Function
Function sL_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
sL_p = fromSIunit_s(s1_pT(P, T4_p(P)))
Else
sL_p = fromSIunit_s(s3_rhoT(1 / (v3_ph(P, h4L_p(P))), T4_p(P)))
End If
Else
sL_p = CVErr(xlErrValue)
End If
End Function
Function sV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
sV_T = fromSIunit_s(s2_pT(p4_T(T), T))
Else
sV_T = fromSIunit_s(s3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T))
End If
Else
sV_T = CVErr(xlErrValue)
End If
End Function
Function sL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
sL_T = fromSIunit_s(s1_pT(p4_T(T), T))
Else
sL_T = fromSIunit_s(s3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T))
End If
Else
sL_T = CVErr(xlErrValue)
End If
End Function
Function s_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
s_pT = fromSIunit_s(s1_pT(P, T))
Case 2
s_pT = fromSIunit_s(s2_pT(P, T))
Case 3
s_pT = fromSIunit_s(s3_rhoT(1 / v3_ph(P, h3_pT(P, T)), T))
Case 4
s_pT = CVErr(xlErrValue)
Case 5
s_pT = fromSIunit_s(s5_pT(P, T))
Case Else
s_pT = CVErr(xlErrValue)
End Select
End Function
Function s_ph(ByVal P As Double, ByVal h As Double) As Double
Dim Ts As Double
Dim xs As Double
Dim s4V As Double
Dim s4L As Double
Dim v4V As Double
Dim v4L As Double
P = toSIunit_p(P)
h = toSIunit_h(h)
Select Case region_ph(P, h)
Case 1
s_ph = fromSIunit_s(s1_pT(P, T1_ph(P, h)))
Case 2
s_ph = fromSIunit_s(s2_pT(P, T2_ph(P, h)))
Case 3
s_ph = fromSIunit_s(s3_rhoT(1 / v3_ph(P, h), T3_ph(P, h)))
Case 4
Ts = T4_p(P)
xs = x4_ph(P, h)
If P < 16.529 Then
s4V = s2_pT(P, Ts)
s4L = s1_pT(P, Ts)
Else
v4V = v3_ph(P, h4V_p(P))
s4V = s3_rhoT(1 / v4V, Ts)
v4L = v3_ph(P, h4L_p(P))
s4L = s3_rhoT(1 / v4L, Ts)
End If
s_ph = fromSIunit_s((xs * s4V + (1 - xs) * s4L))
Case 5
s_ph = fromSIunit_s(s5_pT(P, T5_ph(P, h)))
Case Else
s_ph = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.8 Specific internal energy (u)
Function uV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
uV_p = fromSIunit_u(u2_pT(P, T4_p(P)))
Else
uV_p = fromSIunit_u(u3_rhoT(1 / (v3_ph(P, h4V_p(P))), T4_p(P)))
End If
Else
uV_p = CVErr(xlErrValue)
End If
End Function
Function uL_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
uL_p = fromSIunit_u(u1_pT(P, T4_p(P)))
Else
uL_p = fromSIunit_u(u3_rhoT(1 / (v3_ph(P, h4L_p(P))), T4_p(P)))
End If
Else
uL_p = CVErr(xlErrValue)
End If
End Function
Function uV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
uV_T = fromSIunit_u(u2_pT(p4_T(T), T))
Else
uV_T = fromSIunit_u(u3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T))
End If
Else
uV_T = CVErr(xlErrValue)
End If
End Function
Function uL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
uL_T = fromSIunit_u(u1_pT(p4_T(T), T))
Else
uL_T = fromSIunit_u(u3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T))
End If
Else
uL_T = CVErr(xlErrValue)
End If
End Function
Function u_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
u_pT = fromSIunit_u(u1_pT(P, T))
Case 2
u_pT = fromSIunit_u(u2_pT(P, T))
Case 3
u_pT = fromSIunit_u(u3_rhoT(1 / v3_ph(P, h3_pT(P, T)), T))
Case 4
u_pT = CVErr(xlErrValue)
Case 5
u_pT = fromSIunit_u(u5_pT(P, T))
Case Else
u_pT = CVErr(xlErrValue)
End Select
End Function
Function u_ph(ByVal P As Double, ByVal h As Double) As Double
Dim Ts As Double
Dim xs As Double
Dim u4v As Double
Dim u4L As Double
Dim v4V As Double
Dim v4L As Double
P = toSIunit_p(P)
h = toSIunit_h(h)
Select Case region_ph(P, h)
Case 1
u_ph = fromSIunit_u(u1_pT(P, T1_ph(P, h)))
Case 2
u_ph = fromSIunit_u(u2_pT(P, T2_ph(P, h)))
Case 3
u_ph = fromSIunit_u(u3_rhoT(1 / v3_ph(P, h), T3_ph(P, h)))
Case 4
Ts = T4_p(P)
xs = x4_ph(P, h)
If P < 16.529 Then
u4v = u2_pT(P, Ts)
u4L = u1_pT(P, Ts)
Else
v4V = v3_ph(P, h4V_p(P))
u4v = u3_rhoT(1 / v4V, Ts)
v4L = v3_ph(P, h4L_p(P))
u4L = u3_rhoT(1 / v4L, Ts)
End If
u_ph = fromSIunit_u((xs * u4v + (1 - xs) * u4L))
Case 5
Ts = T5_ph(P, h)
u_ph = fromSIunit_u(u5_pT(P, Ts))
Case Else
u_ph = CVErr(xlErrValue)
End Select
End Function
Function u_ps(ByVal P As Double, ByVal s As Double) As Double
Dim x As Double
Dim u4v, uLp, uVp, u4L As Double
P = toSIunit_p(P)
s = toSIunit_s(s)
Select Case region_ps(P, s)
Case 1
u_ps = fromSIunit_u(u1_pT(P, T1_ps(P, s)))
Case 2
u_ps = fromSIunit_u(u2_pT(P, T2_ps(P, s)))
Case 3
u_ps = fromSIunit_u(u3_rhoT(1 / v3_ps(P, s), T3_ps(P, s)))
Case 4
If P < 16.529 Then
uLp = u1_pT(P, T4_p(P))
uVp = u2_pT(P, T4_p(P))
Else
uLp = u3_rhoT(1 / (v3_ph(P, h4L_p(P))), T4_p(P))
uVp = u3_rhoT(1 / (v3_ph(P, h4V_p(P))), T4_p(P))
End If
x = x4_ps(P, s)
u_ps = fromSIunit_u((x * uVp + (1 - x) * uLp))
Case 5
u_ps = fromSIunit_u(u5_pT(P, T5_ps(P, s)))
Case Else
u_ps = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.9 Specific isobaric heat capacity (Cp)
Function CpV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
CpV_p = fromSIunit_Cp(Cp2_pT(P, T4_p(P)))
Else
CpV_p = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(P, h4V_p(P))), T4_p(P)))
End If
Else
CpV_p = CVErr(xlErrValue)
End If
End Function
Function CpL_p(ByVal P As Double) As Double
Dim T, h, v As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
CpL_p = fromSIunit_Cp(Cp1_pT(P, T4_p(P)))
Else
T = T4_p(P)
h = h4L_p(P)
v = v3_ph(P, h4L_p(P))
CpL_p = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(P, h4L_p(P))), T4_p(P)))
End If
Else
CpL_p = CVErr(xlErrValue)
End If
End Function
Function CpV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
CpV_T = fromSIunit_Cp(Cp2_pT(p4_T(T), T))
Else
CpV_T = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T))
End If
Else
CpV_T = CVErr(xlErrValue)
End If
End Function
Function CpL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
CpL_T = fromSIunit_Cp(Cp1_pT(p4_T(T), T))
Else
CpL_T = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T))
End If
Else
CpL_T = CVErr(xlErrValue)
End If
End Function
Function Cp_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
Cp_pT = fromSIunit_Cp(Cp1_pT(P, T))
Case 2
Cp_pT = fromSIunit_Cp(Cp2_pT(P, T))
Case 3
Cp_pT = fromSIunit_Cp(Cp3_rhoT(1 / v3_ph(P, h3_pT(P, T)), T))
Case 4
Cp_pT = CVErr(xlErrValue)
Case 5
Cp_pT = fromSIunit_Cp(Cp5_pT(P, T))
Case Else
Cp_pT = CVErr(xlErrValue)
End Select
End Function
Function Cp_ph(ByVal P As Double, ByVal h As Double) As Double
P = toSIunit_p(P)
h = toSIunit_h(h)
Select Case region_ph(P, h)
Case 1
Cp_ph = fromSIunit_Cp(Cp1_pT(P, T1_ph(P, h)))
Case 2
Cp_ph = fromSIunit_Cp(Cp2_pT(P, T2_ph(P, h)))
Case 3
Cp_ph = fromSIunit_Cp(Cp3_rhoT(1 / v3_ph(P, h), T3_ph(P, h)))
Case 4
Cp_ph = CVErr(xlErrValue) '#Not def. for mixture"
Case 5
Cp_ph = fromSIunit_Cp(Cp5_pT(P, T5_ph(P, h)))
Case Else
Cp_ph = CVErr(xlErrValue)
End Select
End Function
Function Cp_ps(ByVal P As Double, ByVal s As Double) As Double
P = toSIunit_p(P)
s = toSIunit_s(s)
Select Case region_ps(P, s)
Case 1
Cp_ps = fromSIunit_Cp(Cp1_pT(P, T1_ps(P, s)))
Case 2
Cp_ps = fromSIunit_Cp(Cp2_pT(P, T2_ps(P, s)))
Case 3
Cp_ps = fromSIunit_Cp(Cp3_rhoT(1 / v3_ps(P, s), T3_ps(P, s)))
Case 4
Cp_ps = CVErr(xlErrValue) '#Not def. for mixture"
Case 5
Cp_ps = fromSIunit_Cp(Cp5_pT(P, T5_ps(P, s)))
Case Else
Cp_ps = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.10 Specific isochoric heat capacity (Cv)
Function CvV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
CvV_p = fromSIunit_Cv(Cv2_pT(P, T4_p(P)))
Else
CvV_p = fromSIunit_Cv(Cv3_rhoT(1 / (v3_ph(P, h4V_p(P))), T4_p(P)))
End If
Else
CvV_p = CVErr(xlErrValue)
End If
End Function
Function CvL_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
CvL_p = fromSIunit_Cv(Cv1_pT(P, T4_p(P)))
Else
CvL_p = fromSIunit_Cv(Cv3_rhoT(1 / (v3_ph(P, h4L_p(P))), T4_p(P)))
End If
Else
CvL_p = CVErr(xlErrValue)
End If
End Function
Function CvV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
CvV_T = fromSIunit_Cv(Cv2_pT(p4_T(T), T))
Else
CvV_T = fromSIunit_Cv(Cv3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T))
End If
Else
CvV_T = CVErr(xlErrValue)
End If
End Function
Function CvL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
CvL_T = fromSIunit_Cv(Cv1_pT(p4_T(T), T))
Else
CvL_T = fromSIunit_Cv(Cv3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T))
End If
Else
CvL_T = CVErr(xlErrValue)
End If
End Function
Function Cv_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
Cv_pT = fromSIunit_Cv(Cv1_pT(P, T))
Case 2
Cv_pT = fromSIunit_Cv(Cv2_pT(P, T))
Case 3
Cv_pT = fromSIunit_Cv(Cv3_rhoT(1 / v3_ph(P, h3_pT(P, T)), T))
Case 4
Cv_pT = CVErr(xlErrValue)
Case 5
Cv_pT = fromSIunit_Cv(Cv5_pT(P, T))
Case Else
Cv_pT = CVErr(xlErrValue)
End Select
End Function
Function Cv_ph(ByVal P, ByVal h) As Double
P = toSIunit_p(P)
h = toSIunit_h(h)
Select Case region_ph(P, h)
Case 1
Cv_ph = fromSIunit_Cv(Cv1_pT(P, T1_ph(P, h)))
Case 2
Cv_ph = fromSIunit_Cv(Cv2_pT(P, T2_ph(P, h)))
Case 3
Cv_ph = fromSIunit_Cv(Cv3_rhoT(1 / v3_ph(P, h), T3_ph(P, h)))
Case 4
Cv_ph = CVErr(xlErrValue) '#Not def. for mixture"
Case 5
Cv_ph = fromSIunit_Cv(Cv5_pT(P, T5_ph(P, h)))
Case Else
Cv_ph = CVErr(xlErrValue)
End Select
End Function
Function Cv_ps(ByVal P As Double, ByVal s As Double) As Double
P = toSIunit_p(P)
s = toSIunit_s(s)
Select Case region_ps(P, s)
Case 1
Cv_ps = fromSIunit_Cv(Cv1_pT(P, T1_ps(P, s)))
Case 2
Cv_ps = fromSIunit_Cv(Cv2_pT(P, T2_ps(P, s)))
Case 3
Cv_ps = fromSIunit_Cv(Cv3_rhoT(1 / v3_ps(P, s), T3_ps(P, s)))
Case 4
Cv_ps = CVErr(xlErrValue) '#Not def. for mixture
Case 5
Cv_ps = fromSIunit_Cv(Cv5_pT(P, T5_ps(P, s)))
Case Else
Cv_ps = CVErr(xlErrValue)
End Select
End Function
'***********************************************************************************************************
'*1.11 Speed of sound
Function wV_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
wV_p = fromSIunit_w(w2_pT(P, T4_p(P)))
Else
wV_p = fromSIunit_w(w3_rhoT(1 / (v3_ph(P, h4V_p(P))), T4_p(P)))
End If
Else
wV_p = CVErr(xlErrValue)
End If
End Function
Function wL_p(ByVal P As Double) As Double
P = toSIunit_p(P)
If P > 0.000611657 And P < 22.06395 Then
If P < 16.529 Then
wL_p = fromSIunit_w(w1_pT(P, T4_p(P)))
Else
wL_p = fromSIunit_w(w3_rhoT(1 / (v3_ph(P, h4L_p(P))), T4_p(P)))
End If
Else
wL_p = CVErr(xlErrValue)
End If
End Function
Function wV_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
wV_T = fromSIunit_w(w2_pT(p4_T(T), T))
Else
wV_T = fromSIunit_w(w3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T))
End If
Else
wV_T = CVErr(xlErrValue)
End If
End Function
Function wL_T(ByVal T As Double) As Double
T = toSIunit_T(T)
If T > 273.15 And T < 647.096 Then
If T <= 623.15 Then
wL_T = fromSIunit_w(w1_pT(p4_T(T), T))
Else
wL_T = fromSIunit_w(w3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T))
End If
Else
wL_T = CVErr(xlErrValue)
End If
End Function
Function w_pT(ByVal P As Double, ByVal T As Double) As Double
P = toSIunit_p(P)
T = toSIunit_T(T)
Select Case region_pT(P, T)
Case 1
w_pT = fromSIunit_w(w1_pT(P, T))
Case 2
w_pT = fromSIunit_w(w2_pT(P, T))
Case 3
w_pT = fromSIunit_w(w3_rhoT(1 / v3_ph(P, h3_pT(P, T)), T))
Case 4