forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.mo
1384 lines (1269 loc) · 54.7 KB
/
package.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.IdealGases;
package Common "Common packages and data for the ideal gas models"
extends Modelica.Icons.Package;
record DataRecord
"Coefficient data record for properties of ideal gases based on NASA source"
extends Modelica.Icons.Record;
String name "Name of ideal gas";
SI.MolarMass MM "Molar mass";
SI.SpecificEnthalpy Hf "Enthalpy of formation at 298.15K";
SI.SpecificEnthalpy H0 "H0(298.15K) - H0(0K)";
SI.Temperature Tlimit "Temperature limit between low and high data sets";
Real alow[7] "Low temperature coefficients a";
Real blow[2] "Low temperature constants b";
Real ahigh[7] "High temperature coefficients a";
Real bhigh[2] "High temperature constants b";
SI.SpecificHeatCapacity R_s "Gas constant";
annotation (Documentation(info="<html>
<p>
This data record contains the coefficients for the
ideal gas equations according to:
</p>
<blockquote>
<p>McBride B.J., Zehe M.J., and Gordon S. (2002): <strong>NASA Glenn Coefficients
for Calculating Thermodynamic Properties of Individual Species</strong>. NASA
report TP-2002-211556</p>
</blockquote>
<p>
The equations have the following structure:
</p>
<div><img src=\"modelica://Modelica/Resources/Images/Media/IdealGases/Common/singleEquations.png\"></div>
<p>
The polynomials for h(T) and s0(T) are derived via integration from the one for cp(T) and contain the integration constants b1, b2 that define the reference specific enthalpy and entropy. For entropy differences the reference pressure p0 is arbitrary, but not for absolute entropies. It is chosen as 1 standard atmosphere (101325 Pa).
</p>
<p>
For most gases, the region of validity is from 200 K to 6000 K.
The equations are split into two regions that are separated
by Tlimit (usually 1000 K). In both regions the gas is described
by the data above. The two branches are continuous and in most
gases also differentiable at Tlimit.
</p>
</html>"));
end DataRecord;
partial package SingleGasNasa
"Medium model of an ideal gas based on NASA source"
extends Interfaces.PartialPureSubstance(
ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.pT,
redeclare record FluidConstants =
Modelica.Media.Interfaces.Types.IdealGas.FluidConstants,
mediumName=data.name,
substanceNames={data.name},
singleState=false,
Temperature(min=200, max=6000, start=500, nominal=500),
SpecificEnthalpy(start=if Functions.referenceChoice==ReferenceEnthalpy.ZeroAt0K then data.H0 else
if Functions.referenceChoice==ReferenceEnthalpy.UserDefined then Functions.h_offset else 0, nominal=1.0e5),
Density(start=10, nominal=10),
AbsolutePressure(start=10e5, nominal=10e5));
redeclare record extends ThermodynamicState
"Thermodynamic state variables for ideal gases"
AbsolutePressure p "Absolute pressure of medium";
Temperature T "Temperature of medium";
end ThermodynamicState;
import Modelica.Math;
import Modelica.Media.Interfaces.Choices.ReferenceEnthalpy;
constant IdealGases.Common.DataRecord data
"Data record of ideal gas substance";
constant FluidConstants[nS] fluidConstants "Constant data for the fluid";
redeclare model extends BaseProperties(
T(stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default),
p(stateSelect=if preferredMediumStates then StateSelect.prefer else StateSelect.default))
"Base properties of ideal gas medium"
equation
assert(T >= 200 and T <= 6000, "
Temperature T (= " + String(T) + " K) is not in the allowed range
200 K <= T <= 6000 K required from medium model \"" + mediumName + "\".
");
MM = data.MM;
R_s = data.R_s;
h = Modelica.Media.IdealGases.Common.Functions.h_T(
data, T,
Modelica.Media.IdealGases.Common.Functions.excludeEnthalpyOfFormation,
Modelica.Media.IdealGases.Common.Functions.referenceChoice,
Modelica.Media.IdealGases.Common.Functions.h_offset);
u = h - R_s*T;
// Has to be written in the form d=f(p,T) in order that static
// state selection for p and T is possible
d = p/(R_s*T);
// connect state with BaseProperties
state.T = T;
state.p = p;
end BaseProperties;
redeclare function setState_pTX
"Return thermodynamic state as function of p, T and composition X"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input Temperature T "Temperature";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := ThermodynamicState(p=p,T=T);
annotation(Inline=true,smoothOrder=2);
end setState_pTX;
redeclare function setState_phX
"Return thermodynamic state as function of p, h and composition X"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEnthalpy h "Specific enthalpy";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := ThermodynamicState(p=p,T=T_h(h));
annotation(Inline=true,smoothOrder=2);
end setState_phX;
redeclare function setState_psX
"Return thermodynamic state as function of p, s and composition X"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEntropy s "Specific entropy";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := ThermodynamicState(p=p,T=T_ps(p,s));
annotation(Inline=true,smoothOrder=2);
end setState_psX;
redeclare function setState_dTX
"Return thermodynamic state as function of d, T and composition X"
extends Modelica.Icons.Function;
input Density d "Density";
input Temperature T "Temperature";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := ThermodynamicState(p=d*data.R_s*T,T=T);
annotation(Inline=true,smoothOrder=2);
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=Media.Common.smoothStep(x, state_a.p, state_b.p, x_small),
T=Media.Common.smoothStep(x, state_a.T, state_b.T, x_small));
annotation(Inline=true,smoothOrder=2);
end setSmoothState;
redeclare function extends pressure "Return pressure of ideal gas"
algorithm
p := state.p;
annotation(Inline=true,smoothOrder=2);
end pressure;
redeclare function extends temperature "Return temperature of ideal gas"
algorithm
T := state.T;
annotation(Inline=true,smoothOrder=2);
end temperature;
redeclare function extends density "Return density of ideal gas"
algorithm
d := state.p/(data.R_s*state.T);
annotation(Inline=true,smoothOrder=2);
end density;
redeclare function extends specificEnthalpy "Return specific enthalpy"
extends Modelica.Icons.Function;
algorithm
h := Modelica.Media.IdealGases.Common.Functions.h_T(
data,state.T);
annotation(Inline=true,smoothOrder=2);
end specificEnthalpy;
redeclare function extends specificInternalEnergy
"Return specific internal energy"
extends Modelica.Icons.Function;
algorithm
u := Modelica.Media.IdealGases.Common.Functions.h_T(
data,state.T) - data.R_s*state.T;
annotation(Inline=true,smoothOrder=2);
end specificInternalEnergy;
redeclare function extends specificEntropy "Return specific entropy"
extends Modelica.Icons.Function;
algorithm
s := Modelica.Media.IdealGases.Common.Functions.s0_T(
data, state.T) - data.R_s*Modelica.Math.log(state.p/reference_p);
annotation(Inline=true,smoothOrder=2);
end specificEntropy;
redeclare function extends specificGibbsEnergy "Return specific Gibbs energy"
extends Modelica.Icons.Function;
algorithm
g := Modelica.Media.IdealGases.Common.Functions.h_T(
data,state.T) - state.T*specificEntropy(state);
annotation(Inline=true,smoothOrder=2);
end specificGibbsEnergy;
redeclare function extends specificHelmholtzEnergy
"Return specific Helmholtz energy"
extends Modelica.Icons.Function;
algorithm
f := Modelica.Media.IdealGases.Common.Functions.h_T(
data,state.T) - data.R_s*state.T - state.T*specificEntropy(state);
annotation(Inline=true,smoothOrder=2);
end specificHelmholtzEnergy;
redeclare function extends specificHeatCapacityCp
"Return specific heat capacity at constant pressure"
algorithm
cp := Modelica.Media.IdealGases.Common.Functions.cp_T(
data, state.T);
annotation(Inline=true,smoothOrder=2);
end specificHeatCapacityCp;
redeclare function extends specificHeatCapacityCv
"Compute specific heat capacity at constant volume from temperature and gas data"
algorithm
cv := Modelica.Media.IdealGases.Common.Functions.cp_T(
data, state.T) - data.R_s;
annotation(Inline=true,smoothOrder=2);
end specificHeatCapacityCv;
redeclare function extends isentropicExponent "Return isentropic exponent"
algorithm
gamma := specificHeatCapacityCp(state)/specificHeatCapacityCv(state);
annotation(Inline=true,smoothOrder=2);
end isentropicExponent;
redeclare function extends velocityOfSound "Return velocity of sound"
extends Modelica.Icons.Function;
algorithm
a := sqrt(max(0,data.R_s*state.T*Modelica.Media.IdealGases.Common.Functions.cp_T(
data, state.T)/specificHeatCapacityCv(state)));
annotation(Inline=true,smoothOrder=2);
end velocityOfSound;
function isentropicEnthalpyApproximation
"Approximate method of calculating h_is from upstream properties and downstream pressure"
extends Modelica.Icons.Function;
input SI.Pressure p2 "Downstream pressure";
input ThermodynamicState state "Properties at upstream location";
input Boolean exclEnthForm=Functions.excludeEnthalpyOfFormation
"If true, enthalpy of formation Hf is not included in specific enthalpy h";
input ReferenceEnthalpy refChoice=Functions.referenceChoice
"Choice of reference enthalpy";
input SpecificEnthalpy h_off=Functions.h_offset
"User defined offset for reference enthalpy, if referenceChoice = UserDefined";
output SI.SpecificEnthalpy h_is "Isentropic enthalpy";
protected
IsentropicExponent gamma = isentropicExponent(state) "Isentropic exponent";
algorithm
h_is := Modelica.Media.IdealGases.Common.Functions.h_T(
data,state.T,exclEnthForm,refChoice,h_off) +
gamma/(gamma - 1.0)*state.p/density(state)*((p2/state.p)^((gamma - 1)/gamma) - 1.0);
annotation(Inline=true,smoothOrder=2);
end isentropicEnthalpyApproximation;
redeclare function extends isentropicEnthalpy "Return isentropic enthalpy"
input Boolean exclEnthForm=Functions.excludeEnthalpyOfFormation
"If true, enthalpy of formation Hf is not included in specific enthalpy h";
input ReferenceEnthalpy refChoice=Functions.referenceChoice
"Choice of reference enthalpy";
input SpecificEnthalpy h_off=Functions.h_offset
"User defined offset for reference enthalpy, if referenceChoice = UserDefined";
algorithm
h_is := isentropicEnthalpyApproximation(p_downstream,refState,exclEnthForm,refChoice,h_off);
annotation(Inline=true,smoothOrder=2);
end isentropicEnthalpy;
redeclare function extends isobaricExpansionCoefficient
"Returns overall the isobaric expansion coefficient beta"
algorithm
beta := 1/state.T;
annotation(Inline=true,smoothOrder=2);
end isobaricExpansionCoefficient;
redeclare function extends isothermalCompressibility
"Returns overall the isothermal compressibility factor"
algorithm
kappa := 1.0/state.p;
annotation(Inline=true,smoothOrder=2);
end isothermalCompressibility;
redeclare function extends density_derp_T
"Returns the partial derivative of density with respect to pressure at constant temperature"
algorithm
ddpT := 1/(state.T*data.R_s);
annotation(Inline=true,smoothOrder=2);
end density_derp_T;
redeclare function extends density_derT_p
"Returns the partial derivative of density with respect to temperature at constant pressure"
algorithm
ddTp := -state.p/(state.T*state.T*data.R_s);
annotation(Inline=true,smoothOrder=2);
end density_derT_p;
redeclare function extends density_derX
"Returns the partial derivative of density with respect to mass fractions at constant pressure and temperature"
algorithm
dddX := fill(0,nX);
annotation(Inline=true,smoothOrder=2);
end density_derX;
redeclare replaceable function extends dynamicViscosity "Dynamic viscosity"
algorithm
assert(fluidConstants[1].hasCriticalData,
"Failed to compute dynamicViscosity: For the species \"" + mediumName + "\" no critical data is available.");
assert(fluidConstants[1].hasDipoleMoment,
"Failed to compute dynamicViscosity: For the species \"" + mediumName + "\" no critical data is available.");
eta := Modelica.Media.IdealGases.Common.Functions.dynamicViscosityLowPressure(
state.T,
fluidConstants[1].criticalTemperature,
fluidConstants[1].molarMass,
fluidConstants[1].criticalMolarVolume,
fluidConstants[1].acentricFactor,
fluidConstants[1].dipoleMoment);
annotation (smoothOrder=2);
end dynamicViscosity;
redeclare replaceable function extends thermalConductivity
"Thermal conductivity of gas"
// input IdealGases.Common.DataRecord data "Ideal gas data";
input Integer method=Functions.methodForThermalConductivity
"1: Eucken Method, 2: Modified Eucken Method";
algorithm
assert(fluidConstants[1].hasCriticalData,
"Failed to compute thermalConductivity: For the species \"" + mediumName + "\" no critical data is available.");
lambda := Modelica.Media.IdealGases.Common.Functions.thermalConductivityEstimate(
specificHeatCapacityCp(state),
dynamicViscosity(state), method=method,data=data);
annotation (smoothOrder=2);
end thermalConductivity;
redeclare function extends molarMass "Return the molar mass of the medium"
algorithm
MM := data.MM;
annotation(Inline=true,smoothOrder=2);
end molarMass;
function T_h "Compute temperature from specific enthalpy"
extends Modelica.Icons.Function;
input SpecificEnthalpy h "Specific enthalpy";
output Temperature T "Temperature";
protected
function f_nonlinear "Solve h(data,T) for T with given h (use only indirectly via temperature_phX)"
extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
input DataRecord data "Ideal gas data";
input SpecificEnthalpy h "Specific enthalpy";
algorithm
y := Functions.h_T(data=data, T=u) - h;
end f_nonlinear;
algorithm
T := Modelica.Math.Nonlinear.solveOneNonlinearEquation(
function f_nonlinear(data=data, h=h), 200, 6000);
end T_h;
function T_ps "Compute temperature from pressure and specific entropy"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEntropy s "Specific entropy";
output Temperature T "Temperature";
protected
function f_nonlinear "Solve s(data,T) for T with given s (use only indirectly via temperature_psX)"
extends Modelica.Math.Nonlinear.Interfaces.partialScalarFunction;
input DataRecord data "Ideal gas data";
input AbsolutePressure p "Pressure";
input SpecificEntropy s "Specific entropy";
algorithm
y := Functions.s0_T(data=data, T=u) - data.R_s*Modelica.Math.log(p/reference_p) - s;
end f_nonlinear;
algorithm
T := Modelica.Math.Nonlinear.solveOneNonlinearEquation(
function f_nonlinear(data=data, p=p, s=s), 200, 6000);
end T_ps;
// the functions below are not strictly necessary, there are just here for compatibility reasons
function dynamicViscosityLowPressure
"Dynamic viscosity of low pressure gases"
extends Modelica.Icons.Function;
input SI.Temperature T "Gas temperature";
input SI.Temperature Tc "Critical temperature of gas";
input SI.MolarMass M "Molar mass of gas";
input SI.MolarVolume Vc "Critical molar volume of gas";
input Real w "Acentric factor of gas";
input Modelica.Media.Interfaces.Types.DipoleMoment mu
"Dipole moment of gas molecule";
input Real k = 0.0 "Special correction for highly polar substances";
output Modelica.Media.Interfaces.Types.DynamicViscosity eta
"Dynamic viscosity of gas";
protected
parameter Real Const1_SI=40.785*10^(-9.5)
"Constant in formula for eta converted to SI units";
parameter Real Const2_SI=131.3/1000.0
"Constant in formula for mur converted to SI units";
Real mur=Const2_SI*mu/sqrt(Vc*Tc)
"Dimensionless dipole moment of gas molecule";
Real Fc=1 - 0.2756*w + 0.059035*mur^4 + k
"Factor to account for molecular shape and polarities of gas";
Real Tstar "Dimensionless temperature defined by equation below";
Real Ov "Viscosity collision integral for the gas";
algorithm
eta := Functions.dynamicViscosityLowPressure(T,Tc,M,Vc,w,mu,k);
annotation (smoothOrder=2,
Documentation(info="<html>
<p>
The used formula are based on the method of Chung et al (1984, 1988) referred to in ref [1] chapter 9.
The formula 9-4.10 is the one being used. The formula is given in non-SI units, the following conversion constants were used to
transform the formula to SI units:
</p>
<ul>
<li> <strong>Const1_SI:</strong> The factor 10^(-9.5) =10^(-2.5)*1e-7 where the
factor 10^(-2.5) originates from the conversion of g/mol->kg/mol + cm^3/mol->m^3/mol
and the factor 1e-7 is due to conversion from microPoise->Pa.s.</li>
<li> <strong>Const2_SI:</strong> The factor 1/3.335641e-27 = 1e-3/3.335641e-30
where the factor 3.335641e-30 comes from debye->C.m and
1e-3 is due to conversion from cm^3/mol->m^3/mol</li>
</ul>
<h4>References</h4>
<p>
[1] Bruce E. Poling, John E. Prausnitz, John P. O'Connell, \"The Properties of Gases and Liquids\" 5th Ed. Mc Graw Hill.
</p>
<h4>Author</h4>
<p>T. Skoglund, Lund, Sweden, 2004-08-31</p>
</html>"));
end dynamicViscosityLowPressure;
function thermalConductivityEstimate
"Thermal conductivity of polyatomic gases(Eucken and Modified Eucken correlation)"
extends Modelica.Icons.Function;
input Modelica.Media.Interfaces.Types.SpecificHeatCapacity Cp
"Constant pressure heat capacity";
input Modelica.Media.Interfaces.Types.DynamicViscosity eta
"Dynamic viscosity";
input Integer method(min=1,max=2)=1
"1: Eucken Method, 2: Modified Eucken Method";
input IdealGases.Common.DataRecord data "Ideal gas data";
output Modelica.Media.Interfaces.Types.ThermalConductivity lambda
"Thermal conductivity [W/(m.k)]";
algorithm
lambda := Functions.thermalConductivityEstimate(Cp,eta,method,data);
annotation (smoothOrder=2,
Documentation(info="<html>
<p>
This function provides two similar methods for estimating the
thermal conductivity of polyatomic gases.
The Eucken method (input method == 1) gives good results for low temperatures,
but it tends to give an underestimated value of the thermal conductivity
(lambda) at higher temperatures.<br>
The Modified Eucken method (input method == 2) gives good results for
high-temperatures, but it tends to give an overestimated value of the
thermal conductivity (lambda) at low temperatures.
</p>
</html>"));
end thermalConductivityEstimate;
annotation (
Documentation(info="<html>
<p>
This model calculates medium properties
for an ideal gas of a single substance, or for an ideal
gas consisting of several substances where the
mass fractions are fixed. Independent variables
are temperature <strong>T</strong> and pressure <strong>p</strong>.
Only density is a function of T and p. All other quantities
are solely a function of T. The properties
are valid in the range:
</p>
<blockquote><pre>
200 K ≤ T ≤ 6000 K
</pre></blockquote>
<p>
The following quantities are always computed:
</p>
<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">
<tr><td><strong>Variable</strong></td>
<td><strong>Unit</strong></td>
<td><strong>Description</strong></td></tr>
<tr><td>h</td>
<td>J/kg</td>
<td>specific enthalpy h = h(T)</td></tr>
<tr><td>u</td>
<td>J/kg</td>
<td>specific internal energy u = u(T)</td></tr>
<tr><td>d</td>
<td>kg/m^3</td>
<td>density d = d(p,T)</td></tr>
</table>
<p>
For the other variables, see the functions in
Modelica.Media.IdealGases.Common.SingleGasNasa.
Note, dynamic viscosity and thermal conductivity are only provided
for gases that use a data record from Modelica.Media.IdealGases.FluidData.
Currently these are the following gases:
</p>
<blockquote><pre>
Ar
C2H2_vinylidene
C2H4
C2H5OH
C2H6
C3H6_propylene
C3H7OH
C3H8
C4H8_1_butene
C4H9OH
C4H10_n_butane
C5H10_1_pentene
C5H12_n_pentane
C6H6
C6H12_1_hexene
C6H14_n_heptane
C7H14_1_heptene
C8H10_ethylbenz
CH3OH
CH4
CL2
CO
CO2
F2
H2
H2O
He
N2
N2O
NH3
NO
O2
SO2
SO3
</pre></blockquote>
<p>
<strong>Sources for model and literature:</strong><br>
Original Data: Computer program for calculation of complex chemical
equilibrium compositions and applications. Part 1: Analysis
Document ID: 19950013764 N (95N20180) File Series: NASA Technical Reports
Report Number: NASA-RP-1311 E-8017 NAS 1.61:1311
Authors: Gordon, Sanford (NASA Lewis Research Center)
Mcbride, Bonnie J. (NASA Lewis Research Center)
Published: Oct 01, 1994.
</p>
<p><strong>Known limits of validity:</strong><br>
The data is valid for
temperatures between 200K and 6000K. A few of the data sets for
monatomic gases have a discontinuous 1st derivative at 1000K, but
this never caused problems so far.
</p>
<p>
This model has been copied from the ThermoFluid library
and adapted to the Modelica.Media package.
</p>
</html>"));
end SingleGasNasa;
partial package MixtureGasNasa
"Medium model of a mixture of ideal gases based on NASA source"
import Modelica.Math;
import Modelica.Media.Interfaces.Choices.ReferenceEnthalpy;
extends Modelica.Media.Interfaces.PartialMixtureMedium(
ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.pTX,
substanceNames=data[:].name,
reducedX = false,
singleState=false,
reference_X=fill(1/nX,nX),
SpecificEnthalpy(start=if referenceChoice==ReferenceEnthalpy.ZeroAt0K then 3e5 else
if referenceChoice==ReferenceEnthalpy.UserDefined then h_offset else 0, nominal=1.0e5),
Density(start=10, nominal=10),
AbsolutePressure(start=10e5, nominal=10e5),
Temperature(min=200, max=6000, start=500, nominal=500));
redeclare record extends ThermodynamicState "Thermodynamic state variables"
end ThermodynamicState;
// redeclare record extends FluidConstants "Fluid constants"
// end FluidConstants;
constant Modelica.Media.IdealGases.Common.DataRecord[:] data
"Data records of ideal gas substances";
// ={Common.SingleGasesData.N2,Common.SingleGasesData.O2}
constant Boolean excludeEnthalpyOfFormation=true
"If true, enthalpy of formation Hf is not included in specific enthalpy h";
constant ReferenceEnthalpy referenceChoice=ReferenceEnthalpy.ZeroAt0K
"Choice of reference enthalpy";
constant SpecificEnthalpy h_offset=0.0
"User defined offset for reference enthalpy, if referenceChoice = UserDefined";
// constant FluidConstants[nX] fluidConstants
// "Additional data needed for transport properties";
constant MolarMass[nX] MMX=data[:].MM "Molar masses of components";
constant Integer methodForThermalConductivity(min=1,max=2)=1;
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)
"Base properties (p, d, T, h, u, R_s, MM, X, and Xi of NASA mixture gas"
equation
assert(T >= 200 and T <= 6000, "
Temperature T (=" + String(T) + " K = 200 K) is not in the allowed range
200 K <= T <= 6000 K
required from medium model \"" + mediumName + "\".");
MM = molarMass(state);
h = h_TX(T, X);
R_s = data.R_s*X;
u = h - R_s*T;
d = p/(R_s*T);
// connect state with BaseProperties
state.T = T;
state.p = p;
state.X = if fixedX then reference_X else X;
end BaseProperties;
redeclare function setState_pTX
"Return thermodynamic state as function of p, T and composition X"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input Temperature T "Temperature";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := if size(X,1) == 0 then ThermodynamicState(p=p,T=T,X=reference_X) else 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)}));
annotation(Inline=true,smoothOrder=2);
end setState_pTX;
redeclare function setState_phX
"Return thermodynamic state as function of p, h and composition X"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEnthalpy h "Specific enthalpy";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := if size(X,1) == 0 then ThermodynamicState(p=p,T=T_hX(h,reference_X),X=reference_X) else if size(X,1) == nX then ThermodynamicState(p=p,T=T_hX(h,X),X=X) else
ThermodynamicState(p=p,T=T_hX(h,X), X=cat(1,X,{1-sum(X)}));
annotation(Inline=true,smoothOrder=2);
end setState_phX;
redeclare function setState_psX
"Return thermodynamic state as function of p, s and composition X"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEntropy s "Specific entropy";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := if size(X,1) == 0 then ThermodynamicState(p=p,T=T_psX(p,s,reference_X),X=reference_X) else if size(X,1) == nX then ThermodynamicState(p=p,T=T_psX(p,s,X),X=X) else
ThermodynamicState(p=p,T=T_psX(p,s,X), X=cat(1,X,{1-sum(X)}));
annotation(Inline=true,smoothOrder=2);
end setState_psX;
redeclare function setState_dTX
"Return thermodynamic state as function of d, T and composition X"
extends Modelica.Icons.Function;
input Density d "Density";
input Temperature T "Temperature";
input MassFraction X[:]=reference_X "Mass fractions";
output ThermodynamicState state;
algorithm
state := if size(X,1) == 0 then ThermodynamicState(p=d*(data.R_s*reference_X)*T,T=T,X=reference_X) else if size(X,1) == nX then ThermodynamicState(p=d*(data.R_s*X)*T,T=T,X=X) else
ThermodynamicState(p=d*(data.R_s*cat(1,X,{1-sum(X)}))*T,T=T, X=cat(1,X,{1-sum(X)}));
annotation(Inline=true,smoothOrder=2);
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=Media.Common.smoothStep(x, state_a.p, state_b.p, x_small),
T=Media.Common.smoothStep(x, state_a.T, state_b.T, x_small),
X=Media.Common.smoothStep(x, state_a.X, state_b.X, x_small));
annotation(Inline=true,smoothOrder=2);
end setSmoothState;
redeclare function extends pressure "Return pressure of ideal gas"
algorithm
p := state.p;
annotation(Inline=true,smoothOrder=2);
end pressure;
redeclare function extends temperature "Return temperature of ideal gas"
algorithm
T := state.T;
annotation(Inline=true,smoothOrder=2);
end temperature;
redeclare function extends density "Return density of ideal gas"
algorithm
d := state.p/((state.X*data.R_s)*state.T);
annotation(Inline = true, smoothOrder = 3);
end density;
redeclare function extends specificEnthalpy "Return specific enthalpy"
extends Modelica.Icons.Function;
algorithm
h := h_TX(state.T,state.X);
annotation(Inline=true,smoothOrder=2);
end specificEnthalpy;
redeclare function extends specificInternalEnergy
"Return specific internal energy"
extends Modelica.Icons.Function;
algorithm
u := h_TX(state.T,state.X) - gasConstant(state)*state.T;
annotation(Inline=true,smoothOrder=2);
end specificInternalEnergy;
redeclare function extends specificEntropy "Return specific entropy"
extends Modelica.Icons.Function;
algorithm
s := specificEntropyOfpTX(state.p, state.T, state.X);
annotation(Inline=true,smoothOrder=2);
end specificEntropy;
redeclare function extends specificGibbsEnergy "Return specific Gibbs energy"
extends Modelica.Icons.Function;
algorithm
g := h_TX(state.T,state.X) - state.T*specificEntropy(state);
annotation(Inline=true,smoothOrder=2);
end specificGibbsEnergy;
redeclare function extends specificHelmholtzEnergy
"Return specific Helmholtz energy"
extends Modelica.Icons.Function;
algorithm
f := h_TX(state.T,state.X) - gasConstant(state)*state.T - state.T*specificEntropy(state);
annotation(Inline=true,smoothOrder=2);
end specificHelmholtzEnergy;
function h_TX "Return specific enthalpy"
import Modelica.Media.Interfaces.Choices;
extends Modelica.Icons.Function;
input SI.Temperature T "Temperature";
input MassFraction X[nX]=reference_X
"Independent Mass fractions of gas mixture";
input Boolean exclEnthForm=excludeEnthalpyOfFormation
"If true, enthalpy of formation Hf is not included in specific enthalpy h";
input Modelica.Media.Interfaces.Choices.ReferenceEnthalpy
refChoice=referenceChoice
"Choice of reference enthalpy";
input SI.SpecificEnthalpy h_off=h_offset
"User defined offset for reference enthalpy, if referenceChoice = UserDefined";
output SI.SpecificEnthalpy h "Specific enthalpy at temperature T";
algorithm
h :=(if fixedX then reference_X else X)*
{Modelica.Media.IdealGases.Common.Functions.h_T(
data[i], T, exclEnthForm, refChoice, h_off) for i in 1:nX};
annotation(Inline=false,smoothOrder=2);
end h_TX;
function h_TX_der "Return specific enthalpy derivative"
import Modelica.Media.Interfaces.Choices;
extends Modelica.Icons.Function;
input SI.Temperature T "Temperature";
input MassFraction X[nX] "Independent Mass fractions of gas mixture";
input Boolean exclEnthForm=excludeEnthalpyOfFormation
"If true, enthalpy of formation Hf is not included in specific enthalpy h";
input Modelica.Media.Interfaces.Choices.ReferenceEnthalpy
refChoice=referenceChoice
"Choice of reference enthalpy";
input SI.SpecificEnthalpy h_off=h_offset
"User defined offset for reference enthalpy, if referenceChoice = UserDefined";
input Real dT "Temperature derivative";
input Real dX[nX] "Independent mass fraction derivative";
output Real h_der "Specific enthalpy at temperature T";
algorithm
h_der := if fixedX then
dT*sum((Modelica.Media.IdealGases.Common.Functions.cp_T(
data[i], T)*reference_X[i]) for i in 1:nX) else
dT*sum((Modelica.Media.IdealGases.Common.Functions.cp_T(
data[i], T)*X[i]) for i in 1:nX)+
sum((Modelica.Media.IdealGases.Common.Functions.h_T(
data[i], T)*dX[i]) for i in 1:nX);
annotation (Inline = false, smoothOrder=1);
end h_TX_der;
redeclare function extends gasConstant "Return gasConstant"
algorithm
R_s := data.R_s*state.X;
annotation(Inline = true, smoothOrder = 3);
end gasConstant;
redeclare function extends specificHeatCapacityCp
"Return specific heat capacity at constant pressure"
algorithm
cp := {Modelica.Media.IdealGases.Common.Functions.cp_T(
data[i], state.T) for i in 1:nX}*state.X;
annotation(Inline=true,smoothOrder=1);
end specificHeatCapacityCp;
redeclare function extends specificHeatCapacityCv
"Return specific heat capacity at constant volume from temperature and gas data"
algorithm
cv := {Modelica.Media.IdealGases.Common.Functions.cp_T(
data[i], state.T) for i in 1:nX}*state.X -data.R_s*state.X;
annotation(Inline=true, smoothOrder = 1);
end specificHeatCapacityCv;
function MixEntropy "Return mixing entropy of ideal gases / R"
extends Modelica.Icons.Function;
input SI.MoleFraction x[:] "Mole fraction of mixture";
output Real smix "Mixing entropy contribution, divided by gas constant";
algorithm
smix := sum(if x[i] > Modelica.Constants.eps then -x[i]*Modelica.Math.log(x[i]) else
x[i] for i in 1:size(x,1));
annotation(Inline=true,smoothOrder=2);
end MixEntropy;
function s_TX
"Return temperature dependent part of the entropy, expects full entropy vector"
extends Modelica.Icons.Function;
input Temperature T "Temperature";
input MassFraction[nX] X "Mass fraction";
output SpecificEntropy s "Specific entropy";
algorithm
s := sum(Modelica.Media.IdealGases.Common.Functions.s0_T(
data[i], T)*X[i] for i in 1:size(X,1));
annotation(Inline=true,smoothOrder=2);
end s_TX;
redeclare function extends isentropicExponent "Return isentropic exponent"
algorithm
gamma := specificHeatCapacityCp(state)/specificHeatCapacityCv(state);
annotation(Inline=true,smoothOrder=2);
end isentropicExponent;
redeclare function extends velocityOfSound "Return velocity of sound"
extends Modelica.Icons.Function;
input ThermodynamicState state "Properties at upstream location";
algorithm
a := sqrt(max(0,gasConstant(state)*state.T*specificHeatCapacityCp(state)/specificHeatCapacityCv(state)));
annotation(Inline=true,smoothOrder=2);
end velocityOfSound;
function isentropicEnthalpyApproximation
"Approximate method of calculating h_is from upstream properties and downstream pressure"
extends Modelica.Icons.Function;
input AbsolutePressure p2 "Downstream pressure";
input ThermodynamicState state "Thermodynamic state at upstream location";
output SpecificEnthalpy h_is "Isentropic enthalpy";
protected
SpecificEnthalpy h "Specific enthalpy at upstream location";
SpecificEnthalpy h_component[nX] "Specific enthalpy at upstream location";
IsentropicExponent gamma = isentropicExponent(state) "Isentropic exponent";
protected
MassFraction[nX] X "Complete X-vector";
algorithm
X := if reducedX then cat(1,state.X,{1-sum(state.X)}) else state.X;
h_component :={Modelica.Media.IdealGases.Common.Functions.h_T(
data[i], state.T, excludeEnthalpyOfFormation,
referenceChoice, h_offset) for i in 1:nX};
h :=h_component*X;
h_is := h + gamma/(gamma - 1.0)*(state.T*gasConstant(state))*
((p2/state.p)^((gamma - 1)/gamma) - 1.0);
annotation(smoothOrder=2);
end isentropicEnthalpyApproximation;
redeclare function extends isentropicEnthalpy "Return isentropic enthalpy"
input Boolean exact = false
"Flag whether exact or approximate version should be used";
algorithm
h_is := if exact then specificEnthalpy_psX(p_downstream,specificEntropy(refState),refState.X) else
isentropicEnthalpyApproximation(p_downstream,refState);
annotation(Inline=true,smoothOrder=2);
end isentropicEnthalpy;
function gasMixtureViscosity
"Return viscosities of gas mixtures at low pressures (Wilke method)"
extends Modelica.Icons.Function;
input MoleFraction[:] yi "Mole fractions";
input MolarMass[size(yi,1)] M "Mole masses";
input DynamicViscosity[size(yi,1)] eta "Pure component viscosities";
output DynamicViscosity etam "Viscosity of the mixture";
protected
Real fi[size(yi,1),size(yi,1)];
algorithm
for i in 1:size(eta,1) loop
assert(fluidConstants[i].hasDipoleMoment,"Dipole moment for " + fluidConstants[i].chemicalFormula +
" not known. Can not compute viscosity.");
assert(fluidConstants[i].hasCriticalData, "Critical data for "+ fluidConstants[i].chemicalFormula +
" not known. Can not compute viscosity.");
for j in 1:size(eta,1) loop
if i==1 then
fi[i,j] := (1 + (eta[i]/eta[j])^(1/2)*(M[j]/M[i])^(1/4))^2/(8*(1 + M[i]/M[j]))^(1/2);
elseif j<i then
fi[i,j] := eta[i]/eta[j]*M[j]/M[i]*fi[j,i];
else
fi[i,j] := (1 + (eta[i]/eta[j])^(1/2)*(M[j]/M[i])^(1/4))^2/(8*(1 + M[i]/M[j]))^(1/2);
end if;
end for;
end for;
etam := sum(yi[i]*eta[i]/sum(yi[j]*fi[i,j] for j in 1:size(eta,1)) for i in 1:size(eta,1));
annotation (smoothOrder=2,
Documentation(info="<html>
<p>
Simplification of the kinetic theory (Chapman and Enskog theory)
approach neglecting the second-order effects.<br>
<br>
This equation has been extensively tested (Amdur and Mason, 1958;
Bromley and Wilke, 1951; Cheung, 1958; Dahler, 1959; Gandhi and Saxena,
1964; Ranz and Brodowsky, 1962; Saxena and Gambhir, 1963a; Strunk, et
al., 1964; Vanderslice, et al. 1962; Wright and Gray, 1962). In most
cases, only nonpolar mixtures were compared, and very good results
obtained. For some systems containing hydrogen as one component, less
satisfactory agreement was noted. Wilke's method predicted mixture
viscosities that were larger than experimental for the H2-N2 system,
but for H2-NH3, it underestimated the viscosities.<br>
Gururaja, et al. (1967) found that this method also overpredicted in
the H2-O2 case but was quite accurate for the H2-CO2 system.<br>
Wilke's approximation has proved reliable even for polar-polar gas
mixtures of aliphatic alcohols (Reid and Belenyessy, 1960). The
principal reservation appears to lie in those cases where Mi>>Mj
and etai>>etaj.<br>
</p>
</html>"));
end gasMixtureViscosity;
redeclare replaceable function extends dynamicViscosity
"Return mixture dynamic viscosity"
protected
DynamicViscosity[nX] etaX "Component dynamic viscosities";
algorithm
for i in 1:nX loop
etaX[i] := Modelica.Media.IdealGases.Common.Functions.dynamicViscosityLowPressure(
state.T,
fluidConstants[i].criticalTemperature,
fluidConstants[i].molarMass,
fluidConstants[i].criticalMolarVolume,
fluidConstants[i].acentricFactor,
fluidConstants[i].dipoleMoment);
end for;
eta := gasMixtureViscosity(massToMoleFractions(state.X,
fluidConstants[:].molarMass),
fluidConstants[:].molarMass,
etaX);
annotation (smoothOrder=2);
end dynamicViscosity;
function mixtureViscosityChung
"Return the viscosity of gas mixtures without access to component viscosities (Chung, et. al. rules)"
extends Modelica.Icons.Function;
input Temperature T "Temperature";
input Temperature[nX] Tc "Critical temperatures";
input MolarVolume[nX] Vcrit "Critical volumes (m3/mol)";
input Real[nX] w "Acentric factors";
input Real[nX] mu "Dipole moments (debyes)";
input MolarMass[nX] MolecularWeights "Molecular weights (kg/mol)";
input MoleFraction[nX] y "Molar Fractions";
input Real[nX] kappa = zeros(nX) "Association Factors";
output DynamicViscosity etaMixture "Mixture viscosity (Pa.s)";
protected
constant Real[size(y,1)] Vc = Vcrit*1000000 "Critical volumes (cm3/mol)";
constant Real[size(y,1)] M = MolecularWeights*1000
"Molecular weights (g/mol)";
Integer n = size(y,1) "Number of mixed elements";
Real sigmam3 "Mixture sigma3 in Angstrom";
Real sigma[size(y,1),size(y,1)];
Real edivkm;
Real edivk[size(y,1),size(y,1)];
Real Mm;
Real Mij[size(y,1),size(y,1)];
Real wm "Acentric factor";
Real wij[size(y,1),size(y,1)];
Real kappam
"Correlation for highly polar substances such as alcohols and acids";
Real kappaij[size(y,1),size(y,1)];
Real mum;
Real Vcm;
Real Tcm;
Real murm "Dimensionless dipole moment of the mixture";
Real Fcm "Factor to correct for shape and polarity";
Real omegav;
Real Tmstar;