-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXSteam.m
3842 lines (3612 loc) · 159 KB
/
XSteam.m
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
%h_prho behöver T_prho för samtliga regioner!!!!
%***********************************************************************************************************
%* 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 *
%***********************************************************************************************************
%
% XSteam provides accurate steam and water properties from 0 - 1000 bar and from 0 - 2000 deg C according to
% the standard IAPWS IF-97. For accuracy of the functions in different regions see IF-97 (www.iapws.org)
%
% *** Using XSteam *****************************************************************************************
%XSteam take 2 or 3 arguments. The first argument must always be the steam table function you want to use.
%The other arguments are the inputs to that function.
%Example: XSteam('h_pt',1,20) Returns the enthalpy of water at 1 bar and 20 degC
%Example: XSteam('TSat_p',1) Returns the saturation temperature of water at 1 bar.
%For a list of valid Steam Table functions se bellow or the XSteam macros for MS Excel.
%
%*** Nomenclature ******************************************************************************************
% First the wanted property then a _ then the wanted input properties.
% Example. T_ph is temperature as a function of pressure and enthalpy.
% For a list of valid functions se bellow or XSteam for MS Excel.
% T Temperature (deg C)
% p Pressure (bar)
% h Enthalpy (kJ/kg)
% v Specific volume (m3/kg)
% rho Density
% s Specific entropy
% u Specific internal energy
% Cp Specific isobaric heat capacity
% Cv Specific isochoric heat capacity
% w Speed of sound
% my Viscosity
% tc Thermal Conductivity
% st Surface Tension
% x Vapour fraction
% vx Vapour Volume Fraction
%
%*** Valid Steam table functions. ****************************************************************************
%
%Temperature
%Tsat_p Saturation temperature
%T_ph Temperture as a function of pressure and enthalpy
%T_ps Temperture as a function of pressure and entropy
%T_hs Temperture as a function of enthalpy and entropy
%
%Pressure
%psat_T Saturation pressure
%p_hs Pressure as a function of h and s.
%p_hrho Pressure as a function of h and rho. Very unaccurate for solid water region since it's almost incompressible!
%
%Enthalpy
%hV_p Saturated vapour enthalpy
%hL_p Saturated liquid enthalpy
%hV_T Saturated vapour enthalpy
%hL_T Saturated liquid enthalpy
%h_pT Entalpy as a function of pressure and temperature.
%h_ps Entalpy as a function of pressure and entropy.
%h_px Entalpy as a function of pressure and vapour fraction
%h_prho Entalpy as a function of pressure and density. Observe for low temperatures (liquid) this equation has 2 solutions.
%h_Tx Entalpy as a function of temperature and vapour fraction
%
%Specific volume
%vV_p Saturated vapour volume
%vL_p Saturated liquid volume
%vV_T Saturated vapour volume
%vL_T Saturated liquid volume
%v_pT Specific volume as a function of pressure and temperature.
%v_ph Specific volume as a function of pressure and enthalpy
%v_ps Specific volume as a function of pressure and entropy.
%
%Density
%rhoV_p Saturated vapour density
%rhoL_p Saturated liquid density
%rhoV_T Saturated vapour density
%rhoL_T Saturated liquid density
%rho_pT Density as a function of pressure and temperature.
%rho_ph Density as a function of pressure and enthalpy
%rho_ps Density as a function of pressure and entropy.
%
%Specific entropy
%sV_p Saturated vapour entropy
%sL_p Saturated liquid entropy
%sV_T Saturated vapour entropy
%sL_T Saturated liquid entropy
%s_pT Specific entropy as a function of pressure and temperature (Returns saturated vapour entalpy if mixture.)
%s_ph Specific entropy as a function of pressure and enthalpy
%
%Specific internal energy
%uV_p Saturated vapour internal energy
%uL_p Saturated liquid internal energy
%uV_T Saturated vapour internal energy
%uL_T Saturated liquid internal energy
%u_pT Specific internal energy as a function of pressure and temperature.
%u_ph Specific internal energy as a function of pressure and enthalpy
%u_ps Specific internal energy as a function of pressure and entropy.
%
%Specific isobaric heat capacity
%CpV_p Saturated vapour heat capacity
%CpL_p Saturated liquid heat capacity
%CpV_T Saturated vapour heat capacity
%CpL_T Saturated liquid heat capacity
%Cp_pT Specific isobaric heat capacity as a function of pressure and temperature.
%Cp_ph Specific isobaric heat capacity as a function of pressure and enthalpy
%Cp_ps Specific isobaric heat capacity as a function of pressure and entropy.
%
%Specific isochoric heat capacity
%CvV_p Saturated vapour isochoric heat capacity
%CvL_p Saturated liquid isochoric heat capacity
%CvV_T Saturated vapour isochoric heat capacity
%CvL_T Saturated liquid isochoric heat capacity
%Cv_pT Specific isochoric heat capacity as a function of pressure and temperature.
%Cv_ph Specific isochoric heat capacity as a function of pressure and enthalpy
%Cv_ps Specific isochoric heat capacity as a function of pressure and entropy.
%
%Speed of sound
%wV_p Saturated vapour speed of sound
%wL_p Saturated liquid speed of sound
%wV_T Saturated vapour speed of sound
%wL_T Saturated liquid speed of sound
%w_pT Speed of sound as a function of pressure and temperature.
%w_ph Speed of sound as a function of pressure and enthalpy
%w_ps Speed of sound as a function of pressure and entropy.
%
%Viscosity
%Viscosity is not part of IAPWS Steam IF97. Equations from
%"Revised Release on the IAPWS Formulation 1985 for the Viscosity of Ordinary Water Substance", 2003 are used.
%Viscosity in the mixed region (4) is interpolated according to the density. This is not true since it will be two fases.
%my_pT Viscosity as a function of pressure and temperature.
%my_ph Viscosity as a function of pressure and enthalpy
%my_ps Viscosity as a function of pressure and entropy.
%
%Thermal Conductivity
%Revised release on the IAPS Formulation 1985 for the Thermal Conductivity of ordinary water substance (IAPWS 1998)
%tcL_p Saturated vapour thermal conductivity
%tcV_p Saturated liquid thermal conductivity
%tcL_T Saturated vapour thermal conductivity
%tcV_T Saturated liquid thermal conductivity
%tc_pT Thermal conductivity as a function of pressure and temperature.
%tc_ph Thermal conductivity as a function of pressure and enthalpy
%tc_hs Thermal conductivity as a function of enthalpy and entropy
%
%Surface tension
%st_T Surface tension for two phase water/steam as a function of T
%st_p Surface tension for two phase water/steam as a function of T
%Vapour fraction
%x_ph Vapour fraction as a function of pressure and enthalpy
%x_ps Vapour fraction as a function of pressure and entropy.
%
%Vapour volume fraction
%vx_ph Vapour volume fraction as a function of pressure and enthalpy
%vx_ps Vapour volume fraction as a function of pressure and entropy.
function Out=XSteam(fun,In1,In2)
%*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
%
%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
%
%7 Verification
%7.1 Verifiy region 1
%7.2 Verifiy region 2
%7.3 Verifiy region 3
%7.4 Verifiy region 4
%7.5 Verifiy region 5
%***********************************************************************************************************
%*1 Calling functions *
%***********************************************************************************************************
%***********************************************************************************************************
%*1.1
fun=lower(fun);
switch fun
%***********************************************************************************************************
%*1.2 Temperature
case 'tsat_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
Out = fromSIunit_T(T4_p(p));
else
Out = NaN;
end
case 'tsat_s'
s = toSIunit_s(In1);
if s > -0.0001545495919 && s < 9.155759395
ps = p4_s(s);
Out = fromSIunit_T(T4_p(ps));
else
Out = NaN;
end
case 't_ph'
p = toSIunit_p(In1);
h = toSIunit_h(In2);
Region = region_ph(p, h);
switch Region
case 1
Out = fromSIunit_T(T1_ph(p, h));
case 2
Out = fromSIunit_T(T2_ph(p, h));
case 3
Out = fromSIunit_T(T3_ph(p, h));
case 4
Out = fromSIunit_T(T4_p(p));
case 5
Out = fromSIunit_T(T5_ph(p, h));
otherwise
Out = NaN;
end
case 't_ps'
p = toSIunit_p(In1);
s = toSIunit_s(In2);
Region = region_ps(p, s);
switch Region
case 1
Out = fromSIunit_T(T1_ps(p, s));
case 2
Out = fromSIunit_T(T2_ps(p, s));
case 3
Out = fromSIunit_T(T3_ps(p, s));
case 4
Out = fromSIunit_T(T4_p(p));
case 5
Out = fromSIunit_T(T5_ps(p, s));
otherwise
Out = NaN;
end
case 't_hs'
h = toSIunit_h(In1);
s = toSIunit_s(In2);
Region = region_hs(h, s);
switch Region
case 1
p1 = p1_hs(h, s);
Out = fromSIunit_T(T1_ph(p1, h));
case 2
p2 = p2_hs(h, s);
Out = fromSIunit_T(T2_ph(p2, h));
case 3
p3 = p3_hs(h, s);
Out = fromSIunit_T(T3_ph(p3, h));
case 4
Out = fromSIunit_T(T4_hs(h, s));
case 5
error('functions of hs is not avlaible in region 5');
otherwise
Out = NaN;
end
%***********************************************************************************************************
%*1.3 Pressure (p)
case 'psat_t'
T = toSIunit_T(In1);
if T < 647.096 && T > 273.15
Out = fromSIunit_p(p4_T(T));
else
Out = NaN;
end
case 'psat_s'
s = toSIunit_s(In1);
if s > -0.0001545495919 && s < 9.155759395
Out = fromSIunit_p(p4_s(s));
else
Out = NaN;
end
case 'p_hs'
h = toSIunit_h(In1);
s = toSIunit_s(In2);
Region = region_hs(h, s);
switch Region
case 1
Out = fromSIunit_p(p1_hs(h, s));
case 2
Out = fromSIunit_p(p2_hs(h, s));
case 3
Out = fromSIunit_p(p3_hs(h, s));
case 4
tSat = T4_hs(h, s);
Out = fromSIunit_p(p4_T(tSat));
case 5
error('functions of hs is not avlaible in region 5');
otherwise
Out = NaN;
end
case 'p_hrho'
h=In1;
rho=In2;
%Not valid for water or sumpercritical since water rho does not change very much with p.
%Uses iteration to find p.
High_Bound = fromSIunit_p(100);
Low_Bound = fromSIunit_p(0.000611657);
ps = fromSIunit_p(10);
rhos = 1 / XSteam('v_ph',ps, h);
while abs(rho - rhos) > 0.0000001
rhos = 1 / XSteam('v_ph',ps, h);
if rhos >= rho
High_Bound = ps;
else
Low_Bound = ps;
end
ps = (Low_Bound + High_Bound) / 2;
end
Out = ps;
%***********************************************************************************************************
%*1.4 Enthalpy (h)
case 'hv_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
Out = fromSIunit_h(h4V_p(p));
else
Out = NaN;
end
case 'hl_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
Out = fromSIunit_h(h4L_p(p));
else
Out = NaN;
end
case 'hv_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
p = p4_T(T);
Out = fromSIunit_h(h4V_p(p));
else
Out = NaN;
end
case 'hl_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
p = p4_T(T);
Out = fromSIunit_h(h4L_p(p));
else
Out = NaN;
end
case 'h_pt'
p = toSIunit_p(In1);
T = toSIunit_T(In2);
Region = region_pT(p, T);
switch Region
case 1
Out = fromSIunit_h(h1_pT(p, T));
case 2
Out = fromSIunit_h(h2_pT(p, T));
case 3
Out = fromSIunit_h(h3_pT(p, T));
case 4
Out = NaN;
case 5
Out = fromSIunit_h(h5_pT(p, T));
otherwise
Out = NaN;
end
case 'h_ps'
p = toSIunit_p(In1);
s = toSIunit_s(In2);
Region = region_ps(p, s);
switch Region
case 1
Out = fromSIunit_h(h1_pT(p, T1_ps(p, s)));
case 2
Out = fromSIunit_h(h2_pT(p, T2_ps(p, s)));
case 3
Out = fromSIunit_h(h3_rhoT(1 / v3_ps(p, s), T3_ps(p, s)));
case 4
xs = x4_ps(p, s);
Out = fromSIunit_h(xs * h4V_p(p) + (1 - xs) * h4L_p(p));
case 5
Out = fromSIunit_h(h5_pT(p, T5_ps(p, s)));
otherwise
Out = NaN;
end
case 'h_px'
p = toSIunit_p(In1);
x = toSIunit_x(In2);
if x > 1 || x < 0 || p >= 22.064
Out = NaN;
return
end
hL = h4L_p(p);
hV = h4V_p(p);
Out = hL + x * (hV - hL);
case 'h_prho'
p = toSIunit_p(In1);
rho = 1 / toSIunit_v(1 / In2);
Region = Region_prho(p, rho);
switch Region
case 1
Out = fromSIunit_h(h1_pT(p, T1_prho(p, rho)));
case 2
Out = fromSIunit_h(h2_pT(p, T2_prho(p, rho)));
case 3
Out = fromSIunit_h(h3_rhoT(rho, T3_prho(p, rho)));
case 4
if p < 16.529
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
hV = h4V_p(p);
hL = h4L_p(p);
x = (1 / rho - vL) / (vV - vL);
Out = fromSIunit_h((1 - x) * hL + x * hV);
case 5
Out = fromSIunit_h(h5_pT(p, T5_prho(p, rho)));
otherwise
Out = NaN;
end
case 'h_tx'
T = toSIunit_T(In1);
x = toSIunit_x(In2);
if x > 1 || x < 0 || T >= 647.096
Out = NaN;
return
end
p = p4_T(T);
hL = h4L_p(p);
hV = h4V_p(p);
Out = hL + x * (hV - hL);
%***********************************************************************************************************
%*1.5 Specific Volume (v)
case {'vv_p','rhov_p'}
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_v(v2_pT(p, T4_p(p)));
else
Out = fromSIunit_v(v3_ph(p, h4V_p(p)));
end
else
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
case {'vl_p','rhol_p'}
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_v(v1_pT(p, T4_p(p)));
else
Out = fromSIunit_v(v3_ph(p, h4L_p(p)));
end
else
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
case {'vv_t','rhov_t'}
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_v(v2_pT(p4_T(T), T));
else
Out = fromSIunit_v(v3_ph(p4_T(T), h4V_p(p4_T(T))));
end
else
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
case {'vl_t','rhol_t'}
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_v(v1_pT(p4_T(T), T));
else
Out = fromSIunit_v(v3_ph(p4_T(T), h4L_p(p4_T(T))));
end
else
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
case {'v_pt','rho_pt'}
p = toSIunit_p(In1);
T = toSIunit_T(In2);
Region = region_pT(p, T);
switch Region
case 1
Out = fromSIunit_v(v1_pT(p, T));
case 2
Out = fromSIunit_v(v2_pT(p, T));
case 3
Out = fromSIunit_v(v3_ph(p, h3_pT(p, T)));
case 4
Out = NaN;
case 5
Out = fromSIunit_v(v5_pT(p, T));
otherwise
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
case {'v_ph','rho_ph'}
p = toSIunit_p(In1);
h = toSIunit_h(In2);
Region = region_ph(p, h);
switch Region
case 1
Out = fromSIunit_v(v1_pT(p, T1_ph(p, h)));
case 2
Out = fromSIunit_v(v2_pT(p, T2_ph(p, h)));
case 3
Out = fromSIunit_v(v3_ph(p, h));
case 4
xs = x4_ph(p, h);
if p < 16.529
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
Out = fromSIunit_v((xs * v4v + (1 - xs) * v4L));
case 5
Ts = T5_ph(p, h);
Out = fromSIunit_v(v5_pT(p, Ts));
otherwise
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
case {'v_ps','rho_ps'}
p = toSIunit_p(In1);
s = toSIunit_s(In2);
Region = region_ps(p, s);
switch Region
case 1
Out = fromSIunit_v(v1_pT(p, T1_ps(p, s)));
case 2
Out = fromSIunit_v(v2_pT(p, T2_ps(p, s)));
case 3
Out = fromSIunit_v(v3_ps(p, s));
case 4
xs = x4_ps(p, s);
if p < 16.529
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
Out = fromSIunit_v((xs * v4v + (1 - xs) * v4L));
case 5
Ts = T5_ps(p, s);
Out = fromSIunit_v(v5_pT(p, Ts));
otherwise
Out = NaN;
end
if fun(1)=='r'
Out=1/Out;
end
%***********************************************************************************************************
%*1.6 Density (rho)
% Density is calculated as 1/v. Se section 1.5 Volume
%***********************************************************************************************************
%*1.7 Specific entropy (s)
case 'sv_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_s(s2_pT(p, T4_p(p)));
else
Out = fromSIunit_s(s3_rhoT(1 / (v3_ph(p, h4V_p(p))), T4_p(p)));
end
else
Out = NaN;
end
case 'sl_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_s(s1_pT(p, T4_p(p)));
else
Out = fromSIunit_s(s3_rhoT(1 / (v3_ph(p, h4L_p(p))), T4_p(p)));
end
else
Out = NaN;
end
case 'sv_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_s(s2_pT(p4_T(T), T));
else
Out = fromSIunit_s(s3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T));
end
else
Out = NaN;
end
case 'sl_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_s(s1_pT(p4_T(T), T));
else
Out = fromSIunit_s(s3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T));
end
else
Out = NaN;
end
case 's_pt'
p = toSIunit_p(In1);
T = toSIunit_T(In2);
Region = region_pT(p, T);
switch Region
case 1
Out = fromSIunit_s(s1_pT(p, T));
case 2
Out = fromSIunit_s(s2_pT(p, T));
case 3
hs = h3_pT(p, T);
rhos = 1 / v3_ph(p, hs);
Out = fromSIunit_s(s3_rhoT(rhos, T));
case 4
Out = NaN;
case 5
Out = fromSIunit_s(s5_pT(p, T));
otherwise
Out = NaN;
end
case 's_ph'
p = toSIunit_p(In1);
h = toSIunit_h(In2);
Region = region_ph(p, h);
switch Region
case 1
T = T1_ph(p, h);
Out = fromSIunit_s(s1_pT(p, T));
case 2
T = T2_ph(p, h);
Out = fromSIunit_s(s2_pT(p, T));
case 3
rhos = 1 / v3_ph(p, h);
Ts = T3_ph(p, h);
Out = fromSIunit_s(s3_rhoT(rhos, Ts));
case 4
Ts = T4_p(p);
xs = x4_ph(p, h);
if p < 16.529
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
Out = fromSIunit_s((xs * s4v + (1 - xs) * s4L));
case 5
T = T5_ph(p, h);
Out = fromSIunit_s(s5_pT(p, T));
otherwise
Out = NaN;
end
%***********************************************************************************************************
%*1.8 Specific internal energy (u)
case 'uv_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_u(u2_pT(p, T4_p(p)));
else
Out = fromSIunit_u(u3_rhoT(1 / (v3_ph(p, h4V_p(p))), T4_p(p)));
end
else
Out = NaN;
end
case 'ul_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_u(u1_pT(p, T4_p(p)));
else
Out = fromSIunit_u(u3_rhoT(1 / (v3_ph(p, h4L_p(p))), T4_p(p)));
end
else
Out = NaN;
end
case 'uv_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_u(u2_pT(p4_T(T), T));
else
Out = fromSIunit_u(u3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T));
end
else
Out = NaN;
end
case 'ul_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_u(u1_pT(p4_T(T), T));
else
Out = fromSIunit_u(u3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T));
end
else
Out = NaN;
end
case 'u_pt'
p = toSIunit_p(In1);
T = toSIunit_T(In2);
Region = region_pT(p, T);
switch Region
case 1
Out = fromSIunit_u(u1_pT(p, T));
case 2
Out = fromSIunit_u(u2_pT(p, T));
case 3
hs = h3_pT(p, T);
rhos = 1 / v3_ph(p, hs);
Out = fromSIunit_u(u3_rhoT(rhos, T));
case 4
Out = NaN;
case 5
Out = fromSIunit_u(u5_pT(p, T));
otherwise
Out = NaN;
end
case 'u_ph'
p = toSIunit_p(In1);
h = toSIunit_h(In2);
Region = region_ph(p, h);
switch Region
case 1
Ts = T1_ph(p, h);
Out = fromSIunit_u(u1_pT(p, Ts));
case 2
Ts = T2_ph(p, h);
Out = fromSIunit_u(u2_pT(p, Ts));
case 3
rhos = 1 / v3_ph(p, h);
Ts = T3_ph(p, h);
Out = fromSIunit_u(u3_rhoT(rhos, Ts));
case 4
Ts = T4_p(p);
xs = x4_ph(p, h);
if p < 16.529
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
Out = fromSIunit_u((xs * u4v + (1 - xs) * u4L));
case 5
Ts = T5_ph(p, h);
Out = fromSIunit_u(u5_pT(p, Ts));
otherwise
Out = NaN;
end
case 'u_ps'
p = toSIunit_p(In1);
s = toSIunit_s(In2);
Region = region_ps(p, s);
switch Region
case 1
Ts = T1_ps(p, s);
Out = fromSIunit_u(u1_pT(p, Ts));
case 2
Ts = T2_ps(p, s);
Out = fromSIunit_u(u2_pT(p, Ts));
case 3
rhos = 1 / v3_ps(p, s);
Ts = T3_ps(p, s);
Out = fromSIunit_u(u3_rhoT(rhos, Ts));
case 4
if p < 16.529
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
xs = x4_ps(p, s);
Out = fromSIunit_u((xs * uVp + (1 - xs) * uLp));
case 5
Ts = T5_ps(p, s);
Out = fromSIunit_u(u5_pT(p, Ts));
otherwise
Out = NaN;
end
%***********************************************************************************************************
%*1.9 Specific isobaric heat capacity (Cp)
case 'cpv_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_Cp(Cp2_pT(p, T4_p(p)));
else
Out = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(p, h4V_p(p))), T4_p(p)));
end
else
Out = NaN;
end
case 'cpl_p'
p = toSIunit_p(In1);
if p > 0.000611657 && p < 22.06395
if p < 16.529
Out = fromSIunit_Cp(Cp1_pT(p, T4_p(p)));
else
Out = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(p, h4L_p(p))), T4_p(p)));
end
else
Out = NaN;
end
case 'cpv_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_Cp(Cp2_pT(p4_T(T), T));
else
Out = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(p4_T(T), h4V_p(p4_T(T)))), T));
end
else
Out = NaN;
end
case 'cpl_t'
T = toSIunit_T(In1);
if T > 273.15 && T < 647.096
if T <= 623.15
Out = fromSIunit_Cp(Cp1_pT(p4_T(T), T));
else
Out = fromSIunit_Cp(Cp3_rhoT(1 / (v3_ph(p4_T(T), h4L_p(p4_T(T)))), T));
end
else
Out = NaN;
end
case 'cp_pt'
p = toSIunit_p(In1);
T = toSIunit_T(In2);
Region = region_pT(p, T);
switch Region
case 1
Out = fromSIunit_Cp(Cp1_pT(p, T));
case 2
Out = fromSIunit_Cp(Cp2_pT(p, T));
case 3
hs = h3_pT(p, T);
rhos = 1 / v3_ph(p, hs);
Out = fromSIunit_Cp(Cp3_rhoT(rhos, T));
case 4
Out = NaN;
case 5
Out = fromSIunit_Cp(Cp5_pT(p, T));
otherwise
Out = NaN;
end
case 'cp_ph'
p = toSIunit_p(In1);
h = toSIunit_h(In2);
Region = region_ph(p, h);
switch Region
case 1
Ts = T1_ph(p, h);
Out = fromSIunit_Cp(Cp1_pT(p, Ts));
case 2
Ts = T2_ph(p, h);
Out = fromSIunit_Cp(Cp2_pT(p, Ts));
case 3
rhos = 1 / v3_ph(p, h);
Ts = T3_ph(p, h);
Out = fromSIunit_Cp(Cp3_rhoT(rhos, Ts));
case 4
Out = NaN;
case 5
Ts = T5_ph(p, h);
Out = fromSIunit_Cp(Cp5_pT(p, Ts));
otherwise
Out = NaN;
end
case 'cp_ps'
p = toSIunit_p(In1);
s = toSIunit_s(In2);
Region = region_ps(p, s);
switch Region
case 1
Ts = T1_ps(p, s);
Out = fromSIunit_Cp(Cp1_pT(p, Ts));
case 2
Ts = T2_ps(p, s);
Out = fromSIunit_Cp(Cp2_pT(p, Ts));
case 3
rhos = 1 / v3_ps(p, s);
Ts = T3_ps(p, s);
Out = fromSIunit_Cp(Cp3_rhoT(rhos, Ts));
case 4
Out = NaN;
case 5
Ts = T5_ps(p, s);
Out = fromSIunit_Cp(Cp5_pT(p, Ts));
otherwise
Out = NaN;
end
%***********************************************************************************************************
%*1.10 Specific isochoric heat capacity (Cv)