forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReferenceMoistAir.mo
4158 lines (3773 loc) · 154 KB
/
ReferenceMoistAir.mo
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
within Modelica.Media.Air;
package ReferenceMoistAir
"ReferenceMoistAir: Detailed moist air model (143.15 ... 2000 K)"
extends Modelica.Media.Interfaces.PartialRealCondensingGases(
mediumName="Moist air",
substanceNames={"Water","Air"},
final fixedX=false,
final reducedX=true,
final singleState=false,
reference_X={0.01,0.99},
fluidConstants={Utilities.Water95_Utilities.waterConstants,Modelica.Media.Air.ReferenceAir.airConstants},
ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.pTX);
constant Integer Water=1
"Index of water (in substanceNames, massFractions X, etc.)";
constant Integer Air=2
"Index of air (in substanceNames, massFractions X, etc.)";
constant Boolean useEnhancementFactor=false
"Use the enhancement factor in the calculations";
constant Boolean useDissociation=true
"Take dissociation into account for high temperatures";
constant Real k_mair=steam.MM/dryair.MM "Ratio of molar weights";
constant Common.FundamentalConstants dryair=ReferenceAir.Air_Utilities.Basic.Constants;
constant Common.FundamentalConstants steam=Utilities.Water95_Utilities.Constants;
constant SI.MolarMass[2] MMX={steam.MM,dryair.MM}
"Molar masses of components";
import Modelica.Media.Interfaces;
import Modelica.Math;
import Modelica.Constants;
import Modelica.Media.IdealGases.Common.SingleGasNasa;
redeclare record extends ThermodynamicState
"ThermodynamicState record for moist air"
end ThermodynamicState;
redeclare replaceable model extends BaseProperties(
T(stateSelect=if preferredMediumStates then StateSelect.prefer else
StateSelect.default),
p(stateSelect=if preferredMediumStates then StateSelect.prefer else
StateSelect.default),
Xi(each stateSelect=if preferredMediumStates then StateSelect.prefer else
StateSelect.default),
final standardOrderComponents=true) "Moist air base properties record"
Real x_water "Mass of total water/mass of dry air";
Real phi "Relative humidity";
protected
MassFraction X_liquid "Mass fraction of liquid or solid water";
MassFraction X_steam "Mass fraction of steam water";
MassFraction X_air "Mass fraction of air";
MassFraction X_sat
"Steam water mass fraction of saturation boundary in kg_water/kg_moistair";
Real x_sat
"Steam water mass content of saturation boundary in kg_water/kg_dryair";
AbsolutePressure p_steam_sat "Partial saturation pressure of steam";
equation
assert(T >= 143.15 and T <= 2000,
"Temperature T is not in the allowed range 143.15 K <= (T =" + String(T)
+ " K) <= 2000 K required from medium model \"" + mediumName + "\".");
MM = 1/(Xi[Water]/MMX[Water] + (1.0 - Xi[Water])/MMX[Air]);
p_steam_sat = Modelica.Media.Air.ReferenceMoistAir.Utilities.pds_pT(p, T);
X_sat = Modelica.Media.Air.ReferenceMoistAir.Xsaturation(state);
X_liquid = max(Xi[Water] - X_sat, 0.0);
X_steam = Xi[Water] - X_liquid;
X_air = 1 - Xi[Water];
h = specificEnthalpy_pTX(
p,
T,
Xi);
R_s = dryair.R_s*(X_air/(1 - X_liquid)) + steam.R_s*X_steam/(1 - X_liquid);
u = Modelica.Media.Air.ReferenceMoistAir.Utilities.u_pTX(
p,
T,
Xi);
d = Modelica.Media.Air.ReferenceMoistAir.Utilities.rho_pTX(
p,
T,
Xi);
state.p = p;
state.T = T;
state.X = X;
// these x are per unit mass of DRY air!
x_sat = Modelica.Media.Air.ReferenceMoistAir.xsaturation(state);
x_water = Modelica.Media.Air.ReferenceMoistAir.waterContent_X(state.X);
phi = Modelica.Media.Air.ReferenceMoistAir.Utilities.phi_pTX(
p,
T,
Xi);
annotation (Documentation(revisions="<html>
2017-04-13 Stefan Wischhusen: Resolved a problem for high saturation pressures and temperatures.
</html>"));
end BaseProperties;
redeclare function extends setState_pTX
"Return thermodynamic state as function of pressure p, temperature T and composition X"
algorithm
state := if size(X, 1) == nX then ThermodynamicState(
p=p,
T=T,
X=X) else ThermodynamicState(
p=p,
T=T,
X=cat(
1,
X,
{1 - sum(X)}));
end setState_pTX;
redeclare function extends setState_phX
"Return thermodynamic state as function of pressure p, specific enthalpy h and composition X"
algorithm
state := if size(X, 1) == nX then ThermodynamicState(
p=p,
T=Modelica.Media.Air.ReferenceMoistAir.Utilities.Inverses.T_phX(
p,
h,
X),
X=X) else ThermodynamicState(
p=p,
T=Modelica.Media.Air.ReferenceMoistAir.Utilities.Inverses.T_phX(
p,
h,
X),
X=cat(
1,
X,
{1 - sum(X)}));
end setState_phX;
redeclare function extends setState_psX
"Return thermodynamic state as function of pressure p, specific enthalpy h and composition X"
algorithm
state := if size(X, 1) == nX then ThermodynamicState(
p=p,
T=Modelica.Media.Air.ReferenceMoistAir.Utilities.Inverses.T_psX(
p,
s,
X),
X=X) else ThermodynamicState(
p=p,
T=Modelica.Media.Air.ReferenceMoistAir.Utilities.Inverses.T_psX(
p,
s,
X),
X=cat(
1,
X,
{1 - sum(X)}));
end setState_psX;
redeclare function extends setState_dTX
"Return thermodynamic state as function of density d, temperature T and composition X"
algorithm
state := if size(X, 1) == nX then ThermodynamicState(
p=Modelica.Media.Air.ReferenceMoistAir.Utilities.Inverses.p_dTX(
d,
T,
X),
T=T,
X=X) else ThermodynamicState(
p=Modelica.Media.Air.ReferenceMoistAir.Utilities.Inverses.p_dTX(
d,
T,
X),
T=T,
X=cat(
1,
X,
{1 - sum(X)}));
end setState_dTX;
redeclare function extends setSmoothState
"Return thermodynamic state so that it smoothly approximates: if x > 0 then state_a else state_b"
algorithm
state := ThermodynamicState(
p=Modelica.Media.Common.smoothStep(
x,
state_a.p,
state_b.p,
x_small),
T=Modelica.Media.Common.smoothStep(
x,
state_a.T,
state_b.T,
x_small),
X=Modelica.Media.Common.smoothStep(
x,
state_a.X,
state_b.X,
x_small));
end setSmoothState;
function Xsaturation
"Return absolute humidity per unit mass of moist air at saturation as a function of the thermodynamic state record"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output MassFraction X_sat "Steam mass fraction of sat. boundary";
protected
MassFraction[:] X;
algorithm
X := massFractionSaturation(state);
X_sat := X[1];
end Xsaturation;
function xsaturation
"Return absolute humidity per unit mass of dry air at saturation as a function of the thermodynamic state record"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output MassFraction x_sat "Absolute humidity per unit mass of dry air";
algorithm
x_sat := Modelica.Media.Air.ReferenceMoistAir.Utilities.xws_pT(state.p,
state.T);
assert(x_sat > -1,
"Calculation of absolute humidity is meaningless\nfor input pressure p = "
+ String(state.p) + " Pa and temperature T = " + String(state.T) + " K.");
end xsaturation;
redeclare function extends massFraction_pTphi
"Return mass fractions as a function of pressure, temperature and relative humidity"
protected
Real pds;
algorithm
assert(phi < 1.0 and phi > 0, "Illegal input phi = " + String(phi) +
". Relative humidity is only defined in the range\n 0 <= phi <= 1.0.");
pds := Modelica.Media.Air.ReferenceMoistAir.Utilities.pds_pT(p, T);
assert(pds > -1,
"Calculation of mass fraction of steam is meaningless\nfor input pressure p = "
+ String(p) + " Pa and temperature T = " + String(T) + " K.");
X := {phi*k_mair/(p/pds - phi),1 - phi*k_mair/(p/pds - phi)};
end massFraction_pTphi;
function massFractionWaterVapor "Return mass fraction of water vapor"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output MassFraction X "Mass fraction of water vapor";
protected
Real xw;
Real xws;
algorithm
xw := state.X[1]/max(100*Modelica.Constants.eps, (1 - state.X[1]));
xws := Utilities.xws_pT(state.p, state.T);
X := if (xw <= xws) then xw/(1 + xw) else xws/(1 + xw);
annotation (Documentation(revisions="<html>
2017-04-13 Stefan Wischhusen: Guard introduced against division by zero.
</html>"));
end massFractionWaterVapor;
function massFractionWaterNonVapor
"Return mass fraction of liquid and solid water"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output MassFraction X "Mass fraction of water varpor";
protected
Real xw;
Real xws;
algorithm
xw := state.X[1]/max(100*Modelica.Constants.eps, (1 - state.X[1]));
xws := Utilities.xws_pT(state.p, state.T);
X := if (xw <= xws) then 0 else (xw - xws)/(1 + xw);
annotation (Documentation(revisions="<html>
2017-04-13 Stefan Wischhusen: Guard introduced against division by zero.
</html>"));
end massFractionWaterNonVapor;
redeclare function extends massFractionSaturation
"Return saturation mass fractions"
protected
AbsolutePressure pds;
algorithm
pds := Utilities.pds_pT(state.p, state.T);
Xsat := {k_mair/(state.p/pds - 1 + k_mair),(state.p/pds - 1)/(state.p/pds
- 1 + k_mair)};
assert(Xsat[1] > -1,
"Calculation of saturation mass fraction is meaningless\nfor input pressure p = "
+ String(state.p) + " Pa and temperature T = " + String(state.T) + " K.");
end massFractionSaturation;
function massFractionSaturation_ppsat
"Return mass fvraction at saturation boundary given pressure and saturation pressure"
extends Modelica.Icons.Function;
input AbsolutePressure p "Ambient pressure";
input AbsolutePressure psat "Saturation pressure";
output MassFraction[:] X "Mass fraction";
algorithm
X := {k_mair/(p/psat - 1 + k_mair),(p/psat - 1)/(p/psat - 1 + k_mair)};
end massFractionSaturation_ppsat;
function massFraction_waterContent
"Return mass fractions as a function of pressure, temperature and absolute humidity in kg(water)/kg(dry air)"
extends Modelica.Icons.Function;
input Real xw "Water content in kg(water)/kg(dry air)";
output MassFraction[:] X "Mass fractions";
algorithm
X := {xw/(1 + xw),1/(1 + xw)};
end massFraction_waterContent;
function waterContent_X
"Return water content in kg(water)/kg(dry air) given mass fractions"
extends Modelica.Icons.Function;
input MassFraction[:] X "Mass fractions";
output Real xw "Water content in kg(water)/kg(dry air)";
algorithm
xw := X[1]/max(100*Modelica.Constants.eps, (1 - X[1]));
annotation (Documentation(revisions="<html>
2017-04-13 Stefan Wischhusen: Guard introduced against division by zero.
</html>"));
end waterContent_X;
redeclare function extends relativeHumidity "Return relative humidity"
algorithm
phi := Utilities.phi_pTX(
state.p,
state.T,
state.X);
assert(phi > -1,
"Calculation of relative humidity is meaningless\nfor input pressure p = "
+ String(state.p) + " Pa and temperature T = " + String(state.T) + " K.");
end relativeHumidity;
redeclare function extends gasConstant
"Return ideal gas constant as a function from thermodynamic state, only valid for phi<1"
algorithm
R_s := dryair.R_s*(1 - state.X[Water]) + steam.R_s*state.X[Water];
end gasConstant;
function saturationPressureLiquid
"Return saturation pressure of water as a function of temperature T"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output AbsolutePressure psat "Saturation pressure";
algorithm
psat :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.Water95_Utilities.psat(
state.T);
end saturationPressureLiquid;
function sublimationPressureIce
"Return sublimation pressure of water as a function of temperature T between 223.16 and 273.16 K"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output AbsolutePressure psat "Sublimation pressure";
algorithm
psat :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.Ice09_Utilities.Basic.psub(
state.T);
end sublimationPressureIce;
redeclare function extends saturationPressure
"Return saturation pressure of condensing fluid"
algorithm
psat := Utilities.pds_pT(state.p, state.T);
assert(psat > -1,
"Calculation of saturation pressure is meaningless\nfor input temperature T = "
+ String(state.T) + " K.");
end saturationPressure;
redeclare function extends saturationTemperature
"Return saturation temperature of condensing fluid"
protected
partial function Tsat_res
extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
input SI.Pressure p "Pressure";
algorithm
y := Modelica.Media.Air.ReferenceMoistAir.Utilities.pds_pT(p=p, T=u) - p;
end Tsat_res;
algorithm
Tsat := Modelica.Math.Nonlinear.solveOneNonlinearEquation(
function Tsat_res(p=state.p),
50.0,
673.15,
1e-9);
end saturationTemperature;
redeclare function extends enthalpyOfVaporization
"Return enthalpy of vaporization of water"
protected
AbsolutePressure p_liq;
algorithm
p_liq := saturationPressureLiquid(state);
r0 := Modelica.Media.Water.IF97_Utilities.hv_p(p_liq) -
Modelica.Media.Water.IF97_Utilities.hl_p(p_liq);
end enthalpyOfVaporization;
redeclare function extends enthalpyOfLiquid "Return enthalpy of liquid water"
protected
Real xw;
Real xws;
algorithm
xw := state.X[1]/(1 - state.X[1]);
xws := Utilities.xws_pT(state.p, state.T);
if ((xws > xw) and (state.T > 273.15)) then
h := Modelica.Media.Water.IF97_Utilities.h_pT(
state.p,
state.T,
region=1);
else
h := 0;
end if;
end enthalpyOfLiquid;
redeclare function extends enthalpyOfGas
"Return specific enthalpy of gas (air and steam)"
protected
Real xw;
Real xws;
Real pd;
Real pl;
algorithm
pd := Utilities.pd_pTX(
state.p,
state.T,
state.X);
pl := state.p - pd;
xw := state.X[1]/(1 - state.X[1]);
xws := Utilities.xws_pT(state.p, state.T);
if ((xw <= xws) or (xws == -1)) then
h := Modelica.Media.Air.ReferenceAir.Air_Utilities.h_pT(pl, state.T) + xw
*Utilities.IF97_new.h_pT(pd, state.T);
else
if (state.T < 273.16) then
h := Modelica.Media.Air.ReferenceAir.Air_Utilities.h_pT(pl, state.T) +
xws*Utilities.IF97_new.h_pT(pd, state.T);
else
h := Modelica.Media.Air.ReferenceAir.Air_Utilities.h_pT(pl, state.T) +
xws*Utilities.IF97_new.h_pT(pd, state.T);
end if;
end if;
annotation (Inline=false, LateInline=true);
end enthalpyOfGas;
redeclare function extends enthalpyOfCondensingGas
"Return specific enthalpy of steam"
protected
Real xw;
Real pd;
algorithm
pd := Utilities.pd_pTX(
state.p,
state.T,
state.X);
xw := state.X[1]/(1 - state.X[1]);
h := xw*Utilities.IF97_new.h_pT(pd, state.T);
annotation (Inline=false, LateInline=true);
end enthalpyOfCondensingGas;
redeclare function extends enthalpyOfNonCondensingGas
"Return specific enthalpy of dry air"
algorithm
h := Modelica.Media.Air.ReferenceAir.Air_Utilities.h_pT(state.p, state.T);
end enthalpyOfNonCondensingGas;
function enthalpyOfDryAir = enthalpyOfNonCondensingGas
"Return specific enthalpy of dry air";
function enthalpyOfWater
"Return specific enthalpy of water (solid + liquid + steam)"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output SI.SpecificEnthalpy h "Specific enthalpy of water";
algorithm
h := specificEnthalpy(state) - enthalpyOfNonCondensingGas(state);
end enthalpyOfWater;
function enthalpyOfWaterVapor = enthalpyOfCondensingGas
"Return specific enthalpy of steam";
function enthalpyOfWaterNonVapor "Return enthalpy of liquid and solid water"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output SI.SpecificEnthalpy h "Specific enthalpy of water";
algorithm
h := enthalpyOfWater(state) - enthalpyOfWaterVapor(state);
end enthalpyOfWaterNonVapor;
redeclare function extends pressure
"Returns pressure of ideal gas as a function of the thermodynamic state record"
algorithm
p := state.p;
end pressure;
redeclare function extends temperature
"Return temperature of ideal gas as a function of the thermodynamic state record"
algorithm
T := state.T;
end temperature;
redeclare function extends density
"Returns density as a function of the thermodynamic state record"
algorithm
d := Utilities.rho_pTX(
state.p,
state.T,
state.X);
end density;
redeclare function extends specificEnthalpy
"Return specific enthalpy of moist air as a function of the thermodynamic state record"
algorithm
h := Modelica.Media.Air.ReferenceMoistAir.Utilities.h_pTX(
state.p,
state.T,
state.X);
end specificEnthalpy;
redeclare function extends specificInternalEnergy
"Return specific internal energy of moist air as a function of the thermodynamic state record"
algorithm
u := Utilities.u_pTX(
state.p,
state.T,
state.X);
end specificInternalEnergy;
redeclare function extends specificEntropy
"Return specific entropy from thermodynamic state record, only valid for phi<1"
algorithm
s := Utilities.s_pTX(
state.p,
state.T,
state.X);
end specificEntropy;
redeclare function extends specificGibbsEnergy
"Return specific Gibbs energy as a function of the thermodynamic state record, only valid for phi<1"
algorithm
g := Utilities.h_pTX(
state.p,
state.T,
state.X) - state.T*Utilities.s_pTX(
state.p,
state.T,
state.X);
end specificGibbsEnergy;
redeclare function extends specificHelmholtzEnergy
"Return specific Helmholtz energy as a function of the thermodynamic state record, only valid for phi<1"
algorithm
f := Utilities.u_pTX(
state.p,
state.T,
state.X) - state.T*Utilities.s_pTX(
state.p,
state.T,
state.X);
end specificHelmholtzEnergy;
redeclare function extends specificHeatCapacityCp
"Return specific heat capacity at constant pressure as a function of the thermodynamic state record"
algorithm
cp := Utilities.cp_pTX(
state.p,
state.T,
state.X);
end specificHeatCapacityCp;
redeclare function extends specificHeatCapacityCv
"Return specific heat capacity at constant volume as a function of the thermodynamic state record"
algorithm
cv := Utilities.cv_pTX(
state.p,
state.T,
state.X);
end specificHeatCapacityCv;
redeclare function extends isentropicExponent "Return isentropic exponent"
algorithm
gamma := specificHeatCapacityCp(state)/specificHeatCapacityCv(state);
end isentropicExponent;
redeclare function extends isentropicEnthalpy "Return isentropic enthalpy"
protected
MassFraction[nX] X "Complete X-vector";
algorithm
/*X := if reducedX then cat(
1,
refState.X,
{1 - sum(refState.X)}) else refState.X;*/
X := refState.X;
h_is := specificEnthalpy(setState_psX(
p_downstream,
specificEntropy(refState),
X));
annotation (Documentation(revisions="<html>
2013-07-18 Stefan Wischhusen: Changed internal calculation of X.
</html>"));
end isentropicEnthalpy;
redeclare function extends velocityOfSound "Return velocity of sound"
algorithm
a := sqrt(max(0, gasConstant(state)*state.T*specificHeatCapacityCp(state)/
specificHeatCapacityCv(state)));
end velocityOfSound;
redeclare function extends molarMass "Return the molar mass of the medium"
algorithm
MM := 1/(state.X[1]/steam.MM + state.X[2]/dryair.MM);
end molarMass;
redeclare function extends dynamicViscosity
"Return dynamic viscosity as a function of the thermodynamic state record, valid from 73.15 K to 373.15 K"
algorithm
eta := Utilities.Transport.eta_pTX(
state.p,
state.T,
state.X);
end dynamicViscosity;
redeclare function extends thermalConductivity
"Return thermal conductivity as a function of the thermodynamic state record, valid from 73.15 K to 373.15 K"
algorithm
lambda := Utilities.Transport.lambda_pTX(
state.p,
state.T,
state.X);
end thermalConductivity;
package Utilities "Utility package for moist air"
extends Modelica.Icons.UtilitiesPackage;
final constant MoleFraction[4] MMX={18.015257E-003,28.01348E-003,
31.9988E-003,39.948E-003};
final constant Real[3] Xi_Air={0.7557,0.2316,0.0127};
package Inverses "Compute inverse function"
extends Modelica.Icons.BasesPackage;
function T_phX
"Return temperature as a function of pressure, specific enthalpy and mass fractions"
extends Modelica.Icons.Function;
input SI.AbsolutePressure p "Pressure";
input SI.SpecificEnthalpy h "Specific enthalpy";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
output SI.Temperature T "Temperature";
protected
MassFraction[nX] Xfull=if size(X, 1) == nX then X else cat(
1,
X,
{1 - sum(X)});
function T_phX_res
extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
input SI.AbsolutePressure p "Pressure";
input SI.SpecificEnthalpy h "Specific enthalpy";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
algorithm
y := Modelica.Media.Air.ReferenceMoistAir.Utilities.h_pTX(
p=p,
T=u,
X=X) - h;
end T_phX_res;
algorithm
T := Modelica.Math.Nonlinear.solveOneNonlinearEquation(
function T_phX_res(
p=p,
h=h,
X=Xfull),
173.15,
2000.0,
1e-9);
annotation (inverse(h=
Modelica.Media.Air.ReferenceMoistAir.Utilities.h_pTX(
p=p,
T=T,
X=X)));
end T_phX;
function T_psX
"Return temperature as function of pressure, specific entropy and mass fractions"
extends Modelica.Icons.Function;
input SI.AbsolutePressure p "Pressure";
input SI.SpecificEntropy s "Specific entropy";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
output SI.Temperature T "Temperature";
protected
MassFraction[nX] Xfull=if size(X, 1) == nX then X else cat(
1,
X,
{1 - sum(X)});
function T_psX_res
extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
input SI.AbsolutePressure p "Pressure";
input SI.SpecificEntropy s "Specific entropy";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
algorithm
y := Modelica.Media.Air.ReferenceMoistAir.Utilities.s_pTX(
p=p,
T=u,
X=X) - s;
end T_psX_res;
algorithm
T := Modelica.Math.Nonlinear.solveOneNonlinearEquation(
function T_psX_res(
p=p,
s=s,
X=Xfull),
173.15,
2000.0,
1e-9);
annotation (inverse(s=
Modelica.Media.Air.ReferenceMoistAir.Utilities.s_pTX(
p=p,
T=T,
X=X)));
end T_psX;
function p_dTX
"Return pressure as function of density, temperature and mass fractions"
extends Modelica.Icons.Function;
input SI.Density d "Density";
input SI.Temperature T "Temperature";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
output SI.AbsolutePressure p "Pressure";
protected
MassFraction[nX] Xfull=if size(X, 1) == nX then X else cat(
1,
X,
{1 - sum(X)});
function p_dTX_res
extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
input SI.Density d "Density";
input SI.Temperature T "Temperature";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
algorithm
y := Modelica.Media.Air.ReferenceMoistAir.Utilities.rho_pTX(
p=u,
T=T,
X=X) - d;
end p_dTX_res;
algorithm
p := Modelica.Math.Nonlinear.solveOneNonlinearEquation(
function p_dTX_res(
d=d,
T=T,
X=Xfull),
611.2,
1e7,
1e-9);
annotation (inverse(d=
Modelica.Media.Air.ReferenceMoistAir.Utilities.rho_pTX(
p=p,
T=T,
X=X)), Documentation(revisions="<html>
2013-07-18 Stefan Wischhusen: Corrected inverse interval of pressure to complete range of medium model.
</html>"));
end p_dTX;
end Inverses;
package Transport "Package for transport properties of moist air"
extends Modelica.Icons.BasesPackage;
record coef
"Coefficients for polynomials used to calculate transport properties"
extends Modelica.Icons.Record;
Real sigma=2.52;
Real epsilon=775;
Real M=18.0152;
Real R=0.46144;
Real[5] w={0.69339511,-0.002597963,1.2864772,0.1576848,0.02543632};
Real[5] a={0.4159259E+001,-0.1725577E-002,0.5702012E-005,-0.4596049E-008,
0.1424309E-011};
end coef;
function eta_pTX "Dynamic viscosity"
extends Modelica.Icons.Function;
input SI.AbsolutePressure p "Pressure";
input SI.Temperature T "Temperature";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
output SI.DynamicViscosity eta "Dynamic viscosity";
protected
Real ya;
Real yd;
Real yf;
Real va;
Real vd;
Real vf;
Real xw;
Real xws;
Real pd;
Real pl;
Real da;
Real dd;
Real df;
Real Omega;
Real Tred;
Real etad;
Modelica.Media.Air.ReferenceMoistAir.Utilities.Transport.coef coef;
algorithm
xw := X[1]/(1 - X[1]);
xws := Modelica.Media.Air.ReferenceMoistAir.Utilities.xws_pT(p, T);
pd := Modelica.Media.Air.ReferenceMoistAir.Utilities.pd_pTX(
p,
T,
X);
pl := p - pd;
da := Modelica.Media.Air.ReferenceAir.Air_Utilities.rho_pT(pl, T);
if ((xw <= xws) or (xws == -1)) then
if (T < 273.16) then
dd := pd/(Modelica.Media.Air.ReferenceMoistAir.steam.R_s*T);
ya := da/(da + dd);
yd := 1 - ya;
Tred := T/coef.epsilon;
Omega := coef.w[1] + coef.w[2]*Tred + coef.w[3]*Modelica.Math.exp(
coef.w[4]*Tred)/(coef.w[5] + Tred);
etad := 2.6695E-006*sqrt(T*coef.M)/(coef.sigma^2*Omega);
eta := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.eta_dT(da,
T) + yd*etad;
else
dd :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.rho_pT(pd,
T);
ya := da/(da + dd);
yd := 1 - ya;
eta := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.eta_dT(da,
T) + yd*
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.visc_dT(
dd, T);
end if;
else
if (T < 273.16) then
dd := pd/(Modelica.Media.Air.ReferenceMoistAir.steam.R_s*T);
ya := da/(da + dd);
yd := 1 - ya;
Tred := T/coef.epsilon;
Omega := coef.w[1] + coef.w[2]*Tred + coef.w[3]*Modelica.Math.exp(
coef.w[4]*Tred)/(coef.w[5] + Tred);
etad := 2.6695E-006*sqrt(T*coef.M)/(coef.sigma^2*Omega);
eta := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.eta_dT(da,
T) + yd*etad;
else
dd :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.rho_pT(pd,
T);
df := Modelica.Media.Water.IF97_Utilities.rho_pT(p, T);
yf := (xw - xws)/df/((1 + xws)/(da + dd) + (xw - xws)/df);
ya := (1 - yf)/(1 + dd/da);
yd := 1 - (ya + yf);
eta := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.eta_dT(da,
T) + yd*
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.visc_dT(
dd, T) + yf*
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.visc_dT(
df, T);
end if;
end if;
end eta_pTX;
function lambda_pTX "Thermal conductivity"
extends Modelica.Icons.Function;
input SI.AbsolutePressure p "Pressure";
input SI.Temperature T "Temperature";
input SI.MassFraction X[:]=Modelica.Media.Air.ReferenceMoistAir.reference_X
"Mass fractions";
output SI.ThermalConductivity lambda
"Thermal conductivity";
protected
Real ya;
Real yd;
Real yf;
Real va;
Real vd;
Real vf;
Real xw;
Real xws;
Real pd;
Real pl;
Real da;
Real dd;
Real df;
Real Omega;
Real Tred;
Real cp;
Real Eu;
Real lambdad;
Modelica.Media.Air.ReferenceMoistAir.Utilities.Transport.coef coef;
algorithm
xw := X[1]/(1 - X[1]);
xws := Modelica.Media.Air.ReferenceMoistAir.Utilities.xws_pT(p, T);
pd := Modelica.Media.Air.ReferenceMoistAir.Utilities.pd_pTX(
p,
T,
X);
pl := p - pd;
da := Modelica.Media.Air.ReferenceAir.Air_Utilities.rho_pT(pl, T);
if ((xw <= xws) or (xws == -1)) then
if (T < 273.16) then
dd := pd/(Modelica.Media.Air.ReferenceMoistAir.steam.R_s*T);
ya := da/(da + dd);
yd := 1 - ya;
Tred := T/coef.epsilon;
Omega := coef.w[1] + coef.w[2]*Tred + coef.w[3]*Modelica.Math.exp(
coef.w[4]*Tred)/(coef.w[5] + Tred);
cp := coef.a[1] + coef.a[2]*T + coef.a[3]*T^2 + coef.a[4]*T^3 +
coef.a[5]*T^4;
Eu := 0.35424*cp + 0.1144;
Eu := 0;
lambdad := 0.083232*sqrt(T/coef.M)/(coef.sigma^2*Omega)*Eu;
lambda := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.lambda_dT(
da, T) + yd*lambdad;
else
dd :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.rho_pT(pd,
T);
ya := da/(da + dd);
yd := 1 - ya;
lambda := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.lambda_dT(
da, T) + yd*
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.cond_dT(
dd, T);
end if;
else
if (T < 273.16) then
dd := pd/(Modelica.Media.Air.ReferenceMoistAir.steam.R_s*T);
df :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.Ice09_Utilities.rho_pT(
p, T);
yf := (xw - xws)/df/((1 + xws)/(da + dd) + (xw - xws)/df);
ya := (1 - yf)/(1 + dd/da);
yd := 1 - (ya + yf);
Tred := T/coef.epsilon;
Omega := coef.w[1] + coef.w[2]*Tred + coef.w[3]*Modelica.Math.exp(
coef.w[4]*Tred)/(coef.w[5] + Tred);
cp := coef.a[1] + coef.a[2]*T + coef.a[3]*T^2 + coef.a[4]*T^3 +
coef.a[5]*T^4;
Eu := 0.35424*cp + 0.1144;
lambdad := 0.083232*sqrt(T/coef.M)/(coef.sigma^2*Omega)*Eu;
lambda := ya*
Modelica.Media.Air.ReferenceAir.Air_Utilities.Transport.lambda_dT(
da, T) + yd*lambdad + yf*2.21;
else
dd :=
Modelica.Media.Air.ReferenceMoistAir.Utilities.IF97_new.rho_pT(pd,
T);
df := Modelica.Media.Water.IF97_Utilities.rho_pT(p, T);
yf := (xw - xws)/df/((1 + xws)/(da + dd) + (xw - xws)/df);