-
Notifications
You must be signed in to change notification settings - Fork 164
/
R134a.mo
9427 lines (9101 loc) · 627 KB
/
R134a.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;
package R134a "R134a: Medium model for R134a"
extends Modelica.Icons.VariantsPackage;
package Common
extends Modelica.Icons.Package;
record PhaseBoundaryProperties
"Thermodynamic base properties on the phase boundary"
extends Modelica.Icons.Record;
SI.Density d "Density";
SI.SpecificEnthalpy h "Enthalpy";
SI.SpecificEnergy u "Inner energy";
SI.SpecificEntropy s "Entropy";
SI.SpecificHeatCapacity cp
"Heat capacity at constant pressure";
SI.SpecificHeatCapacity cv
"Heat capacity at constant volume";
SI.IsothermalCompressibility kappa "Isentropic exponent";
SI.Velocity a "Velocity of sound";
Modelica.Media.Interfaces.Types.IsobaricExpansionCoefficient beta
"Isobaric expansion coefficient";
SI.IsentropicExponent gamma "Isentropic exponent";
SI.DerPressureByTemperature pt
"Derivative of pressure w.r.t. temperature";
SI.DerPressureByDensity pd
"Derivative of pressure w.r.t. density";
end PhaseBoundaryProperties;
record InverseDerivatives_rhoT
"Derivatives required for inversion of density and temperature functions w.r.t. pressure and enthalpy states"
extends Modelica.Icons.Record;
Integer phase "Number of phases";
SI.Pressure p "Pressure";
SI.Temperature T "Kelvin-temperature";
SI.Density rho "Density";
SI.SpecificEnthalpy h "Specific enthalpy";
SI.SpecificHeatCapacity cv
"Specific heat capacity at constant volume";
Real pt "Derivative of pressure w.r.t. temperature";
Real pd "Derivative of pressure w.r.t. density";
Real dpT "dp/dT derivative of saturation curve";
end InverseDerivatives_rhoT;
record EOSIdealCoeff
"Record for coefficients of ideal term of Helmholtz equation of state"
extends Modelica.Icons.Record;
parameter Integer nc=5 "No. of coefficients in a";
parameter Real[nc] a
"Coefficients of ideal term of Helmholtz equation of state";
end EOSIdealCoeff;
record EOSResidualCoeff
"Record for coefficients of residual term of Helmholtz equation of state"
extends Modelica.Icons.Record;
parameter Integer nc=20 "No. of coefficients in c, d, t, n";
parameter Integer ns1 "No. of zero coefficients in c";
parameter Real[nc] c
"Coefficients of residual term of Helmholtz equation of state";
parameter Real[nc] d
"Coefficients of residual term of Helmholtz equation of state";
parameter Real[nc] t
"Coefficients of residual term of Helmholtz equation of state";
parameter Real[nc] n
"Coefficients of residual term of Helmholtz equation of state";
end EOSResidualCoeff;
function CubicSplineDerEval "Derivative of cubic spline"
extends Modelica.Icons.Function;
input Real x "Input";
input Real[4] coefs "Spline coefficients";
output Real yder "Spline derivative";
algorithm
yder := coefs[3] + x*(2.0*coefs[2] + x*3.0*coefs[1]);
end CubicSplineDerEval;
function CubicSplineEval "Cubic spline"
extends Modelica.Icons.Function;
input Real x "Input";
input Real[4] coefs "Spline coefficients";
output Real y "Output";
algorithm
y := coefs[4] + x*(coefs[3] + x*(coefs[2] + x*coefs[1]));
end CubicSplineEval;
function cv2Phase
"Compute isochoric specific heat capacity inside the two-phase region"
extends Modelica.Icons.Function;
input PhaseBoundaryProperties liq "Properties on the boiling curve";
input PhaseBoundaryProperties vap "Properties on the condensation curve";
input SI.MassFraction x "Vapour mass fraction";
input SI.Temperature T "Temperature";
input SI.Pressure p "Pressure";
output SI.SpecificHeatCapacity cv "Isochoric specific heat capacity";
output Real dpT "Derivative of pressure w.r.t. temperature";
protected
Real dxv "Derivative of vapour mass fraction w.r.t. specific volume";
Real dvTl "Derivative of liquid specific volume w.r.t. temperature";
Real dvTv "Derivative of vapour specific volume w.r.t. temperature";
Real duTl "Derivative of liquid specific inner energy w.r.t. temperature";
Real duTv "Derivative of vapour specific inner energy w.r.t. temperature";
Real dxt "Derivative of vapour mass fraction w.r.t. temperature";
algorithm
dxv := if (liq.d <> vap.d) then liq.d*vap.d/(liq.d - vap.d) else 0.0;
dpT := (vap.s - liq.s)*dxv;
// wrong at critical point
dvTl := (liq.pt - dpT)/liq.pd/liq.d/liq.d;
dvTv := (vap.pt - dpT)/vap.pd/vap.d/vap.d;
dxt := -dxv*(dvTl + x*(dvTv - dvTl));
duTl := liq.cv + (T*liq.pt - p)*dvTl;
duTv := vap.cv + (T*vap.pt - p)*dvTv;
cv := duTl + x*(duTv - duTl) + dxt*(vap.u - liq.u);
end cv2Phase;
function FindInterval "Half-interval search algorithm"
extends Modelica.Icons.Function;
input Real x "Input";
input Real[:] breaks "Grid points defining the intervals";
output Integer i "Found interval number";
output Integer error=0 "1=did not find interval";
protected
Integer n=scalar(size(breaks)) - 1 "Max value";
Integer ix=1 "Min value";
Integer m=n "New interval";
algorithm
i := 1;
if ((x < breaks[1]) or (x >= breaks[n])) then
error := 1;
end if;
if ((x < breaks[1]) or (x >= breaks[2])) then
while m <> ix loop
if (x < breaks[m]) then
n := m;
else
ix := m;
end if;
m := integer(div(ix + n, 2));
end while;
i := ix;
end if;
end FindInterval;
function helmholtzToBoundaryProps
"Calculate phase boundary property record from dimensionless Helmholtz function"
extends Modelica.Icons.Function;
input Modelica.Media.Common.HelmholtzDerivs f
"Dimensionless derivatives of Helmholtz function";
output PhaseBoundaryProperties sat "Phase boundary property record";
protected
SI.Pressure p "Pressure";
algorithm
p := f.R_s*f.d*f.T*f.delta*f.fdelta;
sat.d := f.d;
sat.h := f.R_s*f.T*(f.tau*f.ftau + f.delta*f.fdelta);
sat.s := f.R_s*(f.tau*f.ftau - f.f);
sat.u := f.R_s*f.T*f.tau*f.ftau;
sat.cp := f.R_s*(-f.tau*f.tau*f.ftautau + (f.delta*f.fdelta - f.delta*f.tau
*f.fdeltatau)^2/(2*f.delta*f.fdelta + f.delta*f.delta*f.fdeltadelta));
sat.cv := f.R_s*(-f.tau*f.tau*f.ftautau);
sat.pt := f.R_s*f.d*(f.delta*(f.fdelta - f.tau*f.fdeltatau));
sat.pd := f.R_s*f.T*(f.delta*(2.0*f.fdelta + f.delta*f.fdeltadelta));
sat.a := abs(f.R_s*f.T*(2*f.delta*f.fdelta + f.delta*f.delta*f.fdeltadelta
- ((f.delta*f.fdelta - f.delta*f.tau*f.fdeltatau)*(f.delta*f.fdelta -
f.delta*f.tau*f.fdeltatau))/(f.tau*f.tau*f.ftautau)))^0.5;
sat.kappa := 1/(f.d*f.R_s*f.T*f.delta*(2.0*f.fdelta + f.delta*f.fdeltadelta));
sat.beta := f.R_s*f.d*f.delta*(f.fdelta - f.tau*f.fdeltatau)*sat.kappa;
sat.gamma := sat.a^2/f.R_s/f.T;
end helmholtzToBoundaryProps;
end Common;
package R134a_ph "Medium model for R134a and p,h as states"
extends Modelica.Media.Interfaces.PartialTwoPhaseMedium(
ThermoStates=Modelica.Media.Interfaces.Choices.IndependentVariables.ph,
mediumName="R134a_ph",
substanceNames={"tetrafluoroethane"},
singleState=false,
SpecificEnthalpy(start=h_default, nominal=5.0e5),
Density(start=4, nominal=500),
AbsolutePressure(start=p_default, nominal=10e5),
Temperature(start=T_default, nominal=350),
smoothModel=false,
onePhase=false,
fluidConstants=r134aConstants,
h_default=420e3);
constant Boolean ph_explicit=true;
constant Boolean dT_explicit=false;
constant Modelica.Media.Interfaces.Types.FluidLimits[1] r134aLimits(
each TMIN=169.85,
each TMAX=455,
each DMIN=0,
each DMAX=1591.7,
each PMIN=389.563789,
each PMAX=7e7,
each HMIN=0,
each HMAX=0,
each SMIN=0,
each SMAX=0);
constant Modelica.Media.Interfaces.Types.TwoPhase.FluidConstants[1]
r134aConstants(
each chemicalFormula="CF3CH2F",
each structureFormula="1,1,1,2-tetrafluoroethane",
each iupacName="tetrafluoroethane",
each casRegistryNumber="811-97-2",
each molarMass=R134aData.data.MM,
each criticalMolarVolume=R134aData.data.MM/R134aData.data.DCRIT,
each criticalTemperature=R134aData.data.TCRIT,
each criticalPressure=R134aData.data.PCRIT,
each triplePointTemperature=R134aData.data.TTRIPLE,
each triplePointPressure=R134aData.data.PTRIPLE,
each meltingPoint=172.15,
each normalBoilingPoint=247.076,
each acentricFactor=0.32684,
each dipoleMoment=1.99,
each hasCriticalData=true);
redeclare record extends SaturationProperties
end SaturationProperties;
redeclare record extends ThermodynamicState "Thermodynamic state"
SpecificEnthalpy h "Specific enthalpy";
Density d "Density";
Temperature T "Temperature";
AbsolutePressure p "Pressure";
end ThermodynamicState;
redeclare replaceable model extends BaseProperties(
h(stateSelect=StateSelect.prefer),
d(stateSelect=StateSelect.default),
T(stateSelect=StateSelect.default),
p(stateSelect=StateSelect.prefer),
sat(Tsat(start=273.0), psat(start=3.0e5))) "Base properties of R134a"
Integer phase(
min=0,
max=2,
start=1,
fixed=false) "2 for two-phase, 1 for one-phase, 0 if not known";
MassFraction quality "Quality of vapour";
equation
MM = R134aData.data.MM;
phase = 0;
T = temperature_ph(p, h);
d = density_ph(p, h);
sat.Tsat = saturationTemperature(p=p);
sat.psat = p;
quality = vapourQuality(state);
u = h - p/d;
R_s = R134aData.data.R_s;
h = state.h;
p = state.p;
T = state.T;
d = state.d;
phase = state.phase;
end BaseProperties;
redeclare function extends setState_phX
"Set state for pressure and specific enthalpy (X not used since single substance)"
algorithm
state := ThermodynamicState(phase=getPhase_ph(p, h), p=p, h=h, d=density_ph(p, h), T=temperature_ph(p, h));
annotation (Documentation(info="<html>
<p>This function should be used by default in order to calculate the thermodynamic state record used as input by many functions.</p>
<p>
Example:
</p>
<blockquote><pre>
parameter Medium.AbsolutePressure p = 3e5;
parameter Medium.SpecificEnthalpy h = 4.2e5;
Medium.Density rho;
<strong>equation</strong>
rho = Medium.density(setState_phX(p, h, fill(0, Medium.nX)));
</pre></blockquote>
</html>", revisions="<html>
<p>2020-01-20 Stefan Wischhusen: Converted into single line assignment for state record.</p>
</html>"));
end setState_phX;
redeclare function extends setState_dTX
"Set state for density and temperature (X not used since single substance)"
protected
Modelica.Media.Common.HelmholtzDerivs f "Helmholtz derivatives";
SI.SpecificHeatCapacity R_s "Specific gas constant";
SaturationProperties sat "Saturation temperature and pressure";
SI.Density dl "Liquid density";
SI.Density dv "Vapor density";
algorithm
R_s := R134aData.data.R_s;
sat := setSat_T(T);
dl := bubbleDensity(sat);
dv := dewDensity(sat);
if d < dl and d > dv and T < R134aData.data.FTCRIT then
f := Modelica.Media.Common.HelmholtzDerivs(
d=d, T=T, R_s=R_s, delta=0, tau=0, f=0, fdelta=0,
fdeltadelta=0, ftau=0, ftautau=0, fdeltatau=0);
state.p := saturationPressure_sat(sat);
state.h := (dl*dv/d*(dewEnthalpy(sat) - bubbleEnthalpy(sat))
- dv*dewEnthalpy(sat) + dl*bubbleEnthalpy(sat))/(dl - dv);
state.phase := 2;
else
f := f_R134a(d=d, T=T);
state.p := d*R_s*T*f.delta*f.fdelta;
state.h := R_s*T*(f.tau*f.ftau + f.delta*f.fdelta);
state.phase := 1;
end if;
state.T := T;
state.d := d;
annotation (Documentation(revisions="<html>
<p>2019-12-20 Francesco Casella and Stefan Wischhusen: Two-phase calculation corrected.</p>
<p>2012-08-01 Stefan Wischhusen: Corrected passing-error of inputs.</p>
</html>", info="<html>
<p>Although the medium package is explicit for pressure and specific enthalpy, this function may be used in order to calculate the thermodynamic state record used as input by many functions. It will calculate the missing states:</p>
<ul>
<li>pressure</li>
<li>specific enthalpy</li>
</ul>
<p>
Example:
</p>
<blockquote><pre>
parameter Medium.Density d = 4;
parameter Medium.Temperature T = 298;
Medium.SpecificEntropy s;
<strong>equation</strong>
s = Medium.specificEntropy(setState_dTX(d, T, fill(0, Medium.nX)));
</pre></blockquote>
</html>"));
end setState_dTX;
redeclare function extends setState_psX
"Set state for pressure and specific entropy (X not used since single substance)"
protected
SI.Pressure delp=1e-2 "Iteration accuracy for pressure";
SI.SpecificEntropy dels=1e-1
"Iteration accuracy for entropy";
Integer error "If newton iteration fails (too many calls)";
Modelica.Media.Common.HelmholtzDerivs f "Helmholtz derivatives";
SaturationProperties sat "Saturation temperature and pressure";
algorithm
state.p := p;
state.phase := getPhase_ps(p, s);
if state.phase == 1 then
(state.d, state.T, error) := dtofpsOnePhase(
p=p,
s=s,
delp=delp,
dels=dels);
f := f_R134a(d=state.d, T=state.T);
state.h := R134aData.R_s*state.T*(f.tau*f.ftau + f.delta*f.fdelta);
else
state.h := hofpsTwoPhase(p, s);
(state.d, state.T) := dt_ph(p, state.h);
end if;
annotation (Documentation(info="<html>
<p>This function may be used in order to calculate the thermodynamic state record used as input by many functions. It will calculate the missing states:</p>
<ul>
<li>density</li>
<li>pressure</li>
<li>specific enthalpy</li>
</ul>
<p>
Example:
</p>
<blockquote><pre>
parameter Medium.AbsolutePressure p = 3e5;
parameter Medium.SpecificEntropy s = 1.7e3;
Medium.SpecificEnthalpy h;
<strong>equation</strong>
h = Medium.specificEnthalpy(setState_psX(p, s, fill(0, Medium.nX)));
</pre></blockquote>
</html>", revisions="<html>
<p>2020-02-05 Stefan Wischhusen: Added missing property calculation for d and T.</p>
</html>"));
end setState_psX;
redeclare function extends setState_pTX
"Set state for pressure and temperature (X not used since single substance)"
protected
SI.Pressure delp=1.0e-2
"Relative error in p in iteration";
algorithm
Modelica.Media.R134a.R134a_ph.phaseBoundaryAssert(p, T);
state := ThermodynamicState(
d=dofpT(p, T, delp),
T=T,
h=hofpT(p, T, delp),
p=p,
phase=1);
annotation (Inline=true, Documentation(info="<html>
<p>This function should be used by default in order to calculate the thermodynamic state record used as input by many functions.</p>
<p>
Example:
</p>
<blockquote><pre>
parameter Medium.AbsolutePressure p = 3e5;
parameter Medium.Temperature T = 290;
Medium.Density rho;
<strong>equation</strong>
rho = Medium.density(setState_pTX(p, T, fill(0, Medium.nX)));
</pre></blockquote>
<p>
Please note, that in contrast to setState_phX, setState_dTX and setState_psX this function can not calculate properties in the two-phase region since pressure and temperature are dependent variables. A guard function will be called if the temperature difference to the phase boundary is lower than 1K or the pressure difference to the critical pressure is lower than 1000 Pa.
</p>
</html>"));
end setState_pTX;
redeclare function extends setBubbleState
"Return the thermodynamic state on the bubble line"
algorithm
if sat.psat < Modelica.Media.R134a.R134aData.data.FPCRIT then
state.p := sat.psat;
state.T := saturationTemperature(sat.psat);
state.d := bubbleDensity(sat);
state.h := bubbleEnthalpy(sat);
else
assert(sat.psat < Modelica.Media.R134a.R134aData.data.FPCRIT,
"Function setBubbleState is only valid in two-phase regime");
end if;
annotation (Documentation(info="<html>
<p>This function shall be used in order to calculate the thermodynamic state record for the liquid phase boundary. It requires the saturation record as input which can be determined by both functions setSat_p and setSat_T:
</p>
<p>
Example:
</p>
<blockquote><pre>
Medium.AbsolutePressure p=3e5;
// Viscosity on the liquid phase boundary
SI.DynamicViscosity eta_liq;
equation
eta_liq = Medium.DynamicViscosity(Medium.setBubbleState(Medium.setSat_p(p)));
</pre></blockquote>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end setBubbleState;
redeclare function extends setDewState
"Return the thermodynamic state on the dew line"
algorithm
if sat.psat < Modelica.Media.R134a.R134aData.data.FPCRIT then
state.p := sat.psat;
state.T := saturationTemperature(sat.psat);
state.d := dewDensity(sat);
state.h := dewEnthalpy(sat);
else
assert(sat.psat < Modelica.Media.R134a.R134aData.data.FPCRIT,
"Function setDewState is only valid in two-phase regime");
end if;
annotation (Documentation(info="<html>
<p>This function shall be used in order to calculate the thermodynamic state record for the vapor phase boundary. It requires the saturation record as input which can be determined by both functions setSat_p and setSat_T:
</p>
<p>
Example:
</p>
<blockquote><pre>
Medium.AbsolutePressure p=3e5;
// Viscosity on the vapor phase boundary
SI.DynamicViscosity eta_vap;
equation
eta_vap = Medium.DynamicViscosity(Medium.setBubbleState(Medium.setSat_p(p)));
</pre></blockquote>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end setDewState;
redeclare function density_ph
"Density as function of pressure and specific enthalpy"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEnthalpy h "Specific enthalpy";
input Integer phase=0 "2 for two-phase, 1 for one-phase, 0 if not known";
output Density d "Density";
algorithm
d := rho_props_ph(
p,
h,
derivsOf_ph(
p,
h,
getPhase_ph(p, h)));
annotation (Inline=true, Documentation(info="<html>
<p>This function calculates the density of R134a from the state variables p (absolute pressure) and h (specific enthalpy). The density is modelled by the fundamental equation of state of Tillner-Roth and Baehr (1994).</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)d-Diagram-R134a.png\"/></p>
</html>"));
end density_ph;
redeclare function extends density
"Density as function of pressure and specific enthalpy | use setState_phX function for input"
algorithm
d := state.d;
annotation (Inline=true, Documentation(info="<html>
<p>
This function calculates the density of R134a from the state record
(e.g., use setState_phX function for input). The density is modelled
by the fundamental equation of state of Tillner-Roth and Baehr (1994).
</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)d-Diagram-R134a.png\"/></p>
</html>"));
end density;
redeclare function temperature_ph
"Temperature as function of pressure and specific enthalpy"
extends Modelica.Icons.Function;
input AbsolutePressure p "Pressure";
input SpecificEnthalpy h "Specific enthalpy";
input Integer phase=0 "2 for two-phase, 1 for one-phase, 0 if not known";
output Temperature T "Temperature";
algorithm
T := T_props_ph(
p,
h,
derivsOf_ph(
p,
h,
getPhase_ph(p, h)));
annotation (Inline=true, Documentation(info="<html>
<p>This function calculates the Kelvin temperature of R134a from the state variables p (absolute pressure) and h (specific enthalpy). The temperature is modelled by the fundamental equation of state of Tillner-Roth and Baehr (1994).</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)h-Diagram-R134a.png\"/></p>
</html>"));
end temperature_ph;
redeclare function extends temperature
"Temperature as function of pressure and specific enthalpy | use setState_phX function for input"
algorithm
T := state.T;
annotation (Inline=true, Documentation(info="<html>
<p>This function calculates the Kelvin temperature of R134a from the state record (e.g., use setState_phX function for input). The temperature is modelled by the fundamental equation of state of Tillner-Roth and Baehr (1994).</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)h-Diagram-R134a.png\"/></p>
</html>"));
end temperature;
redeclare function extends pressure "Pressure w.r.t. thermodynamic state"
algorithm
p := state.p;
annotation (Inline=true, Documentation(info="<html>
<p>This function is included for the sake of completeness.</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)h-Diagram-R134a.png\"/></p>
</html>"));
end pressure;
redeclare function extends specificInternalEnergy
"Specific internal energy w.r.t. thermodynamic state"
algorithm
u := specificEnthalpy(state) - pressure(state)/density(state);
annotation (Inline=true, Documentation(info="<html>
<p>This function calculates the specific internal energy of R134a from the state record (e.g., use setState_phX function for input). The specific internal energy is modelled by the fundamental equation of state of Tillner-Roth and Baehr (1994).</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)u-Diagram-R134a.png\"/></p>
</html>"));
end specificInternalEnergy;
redeclare function extends specificEnthalpy
"Specific enthalpy w.r.t. thermodynamic state | use setState_phX function for input"
algorithm
h := state.h;
annotation (Inline=true, Documentation(info="<html>
<p>This function is included for the sake of completeness.</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)h-Diagram-R134a.png\"/></p>
</html>"));
end specificEnthalpy;
redeclare function extends specificEntropy
"Specific entropy w.r.t. thermodynamic state | use setState_phX function for input if necessary"
protected
Modelica.Media.Common.HelmholtzDerivs f "Helmholtz derivatives";
Common.PhaseBoundaryProperties liq "Properties on liquid phase boundary";
SaturationProperties sat "Saturation temperature and pressure";
Common.PhaseBoundaryProperties vap "Properties on vapor phase boundary";
SI.MassFraction x "Vapor quality";
algorithm
if getPhase_ph(state.p, state.h) == 2 then
sat.psat := state.p;
sat.Tsat := saturationTemperature(state.p);
liq := R134a_liqofdT(T=state.T);
vap := R134a_vapofdT(T=state.T);
x := if liq.h <> vap.h then (state.h - liq.h)/(vap.h - liq.h) else if
state.h >= vap.h then 1 else 0;
s := liq.s + x*(vap.s - liq.s);
else
f := f_R134a(state.d, state.T);
s := R134aData.R_s*(f.tau*f.ftau - f.f);
end if;
annotation (Documentation(info="<html>
<p>This function calculates the specific entropy of R134a from the state record (e.g., use setState_phX function for input). The specific entropy is modelled by the fundamental equation of state of Tillner-Roth and Baehr (1994).</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)s-Diagram-R134a.png\"/></p>
</html>"));
end specificEntropy;
redeclare function extends saturationTemperature
"Saturation temperature in two-phase region"
protected
constant Real T_coef[:, :]=R134aData.Tcoef
"Coefficients of cubic spline for Tsat(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := p/R134aData.data.FPCRIT;
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
T := Common.CubicSplineEval(localx, T_coef[int, :]);
// annotation(smoothOrder=5);
annotation (derivative=saturationTemperature_der_p, Documentation(info="<html>
<p>This function calculates the saturation temperature of R134a from the state variable p (absolute pressure). It is modelled by cubic splines which are fitted with non-equidistant grid points derived from
the fundamental equation of state of Tillner-Roth and Baehr (1994) and the Maxwell criteria.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
<p><img src=\"modelica://Modelica/Resources/Images/Media/R134a/log(p)Tsat-Diagram-R134a.png\"/></p>
</html>"));
end saturationTemperature;
redeclare function extends saturationTemperature_derp
"Derivative of saturation temperature in two-phase region"
protected
constant Real T_coef[:, :]=R134aData.Tcoef
"Coefficients of cubic spline for Tsat(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := p/R134aData.data.FPCRIT;
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
dTp := Common.CubicSplineDerEval(localx, T_coef[int, :])/R134aData.data.FPCRIT;
annotation (Documentation(info="<html>
<p>This function calculates the derivative of saturation temperature of R134a with regard to the state variable p (absolute pressure). The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.saturationTemperature\"> saturatuionTemperature</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end saturationTemperature_derp;
function saturationTemperature_der_p
"Time derivative of saturation temperature in two-phase region"
extends Modelica.Icons.Function;
input SI.AbsolutePressure p "Pressure";
input Real der_p "Time derivative of pressure";
output Real der_Tsat "Time derivative of saturation temperature";
protected
constant Real T_coef[:, :]=R134aData.Tcoef
"Coefficients of cubic spline for Tsat(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := p/R134aData.data.FPCRIT;
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
der_Tsat := Common.CubicSplineDerEval(localx, T_coef[int, :])/R134aData.data.FPCRIT
*der_p;
annotation (Documentation(info="<html>
<p>This function calculates the time derivative of saturation temperature of R134a with regard to the time derivative of p. The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.saturationTemperature\"> saturatuionTemperature</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end saturationTemperature_der_p;
redeclare function extends bubbleDensity
"Density of liquid phase w.r.t. saturation pressure | use setSat_p function for input"
protected
constant Real dl_coef[:, :]=R134aData.dlcoef
"Coefficients of cubic spline for d_liq(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
dl := R134aData.data.FDCRIT*Common.CubicSplineEval(localx, dl_coef[int, 1
:4]);
// annotation(smoothOrder=5);
annotation (derivative=dBubbleDensity_dPressure_der_sat, Documentation(
info="<html>
<p>This function calculates the liquid phase density of R134a from the state variable p (absolute pressure). It is modelled by cubic splines which are fitted with non-equidistant grid points derived from
the fundamental equation of state of Tillner-Roth and Baehr (1994) and the Maxwell criteria.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end bubbleDensity;
redeclare function extends dBubbleDensity_dPressure
"Derivative of liquid density in two-phase region w.r.t. pressure"
protected
constant Real dl_coef[:, :]=R134aData.dlcoef
"Coefficients of cubic spline for d_liq(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
ddldp := R134aData.data.FDCRIT*Common.CubicSplineDerEval(localx, dl_coef[
int, 1:4])/R134aData.data.FPCRIT;
annotation (Documentation(info="<html>
<p>This function calculates the derivative of liquid density of R134a in the two-phase region with regard to the state variable p (absolute pressure). The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.bubbleDensity\"> bubbleDensity</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end dBubbleDensity_dPressure;
function dBubbleDensity_dPressure_der_sat
"Time derivative of liquid density in two-phase region w.r.t. pressure"
extends Modelica.Icons.Function;
input SaturationProperties sat
"Saturation properties | pressure is used for interpolation";
input SaturationProperties der_sat "Derivative of saturation properties";
output Real der_ddldp
"Time derivative of liquid density in two-phase region w.r.t. pressure";
protected
constant Real dl_coef[:, :]=R134aData.dlcoef
"Coefficients of cubic spline for d_liq(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
der_ddldp := R134aData.data.FDCRIT*Common.CubicSplineDerEval(localx,
dl_coef[int, 1:4])/R134aData.data.FPCRIT*der_sat.psat;
annotation (Documentation(info="<html>
<p>This function calculates the time derivative of liquid density of R134a with regard to the time derivative of p. The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.bubbleDensity\"> bubbleDensity</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end dBubbleDensity_dPressure_der_sat;
redeclare function extends dewDensity
"Density of vapor phase w.r.t. saturation pressure | use setSat_p function for input"
protected
constant Real dv_coef[:, :]=R134aData.dvcoef
"Coefficients of cubic spline for d_vap(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
dv := R134aData.data.FDCRIT*Common.CubicSplineEval(localx, dv_coef[int, 1
:4]);
// annotation(smoothOrder=5);
annotation (derivative=dDewDensity_dPressure_der_sat, Documentation(info="<html>
<p>This function calculates the vapor phase density of R134a from the state variable p (absolute pressure). It is modelled by cubic splines which are fitted with non-equidistant grid points derived from
the fundamental equation of state of Tillner-Roth and Baehr (1994) and the Maxwell criteria.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end dewDensity;
redeclare function extends dDewDensity_dPressure
"Derivative of vapor density in two-phase region w.r.t. pressure"
protected
constant Real dv_coef[:, :]=R134aData.dvcoef
"Coefficients of cubic spline for d_vap(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
ddvdp := R134aData.data.FDCRIT*Common.CubicSplineDerEval(localx, dv_coef[
int, 1:4])/R134aData.data.FPCRIT;
annotation (Documentation(info="<html>
<p>This function calculates the derivative of vapor density of R134a in two-phase region with regard to the state variable p (absolute pressure). The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.dewDensity\"> dewDensity</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end dDewDensity_dPressure;
function dDewDensity_dPressure_der_sat
"Time derivative of vapor density in two-phase region w.r.t. pressure"
extends Modelica.Icons.Function;
input SaturationProperties sat
"Saturation properties | pressure is used for interpolation";
input SaturationProperties der_sat "Derivative of saturation properties";
output Real der_ddvdp
"Time derivative of vapor density in two-phase region w.r.t. pressure";
protected
constant Real dv_coef[:, :]=R134aData.dvcoef
"Coefficients of cubic spline for d_vap(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
der_ddvdp := R134aData.data.FDCRIT*Common.CubicSplineDerEval(localx,
dv_coef[int, 1:4])/R134aData.data.FPCRIT*der_sat.psat;
annotation (Documentation(info="<html>
<p>This function calculates the time derivative of vapor density of R134a with regard to the time derivative of p. The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.dewDensity\"> dewDensity</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end dDewDensity_dPressure_der_sat;
redeclare function extends bubbleEnthalpy
"Specific enthalpy of liquid phase w.r.t. saturation pressure | use setSat_p function for input"
protected
constant Real hl_coef[:, :]=R134aData.hlcoef
"Coefficients of cubic spline for h_liq(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
hl := R134aData.data.HCRIT*Common.CubicSplineEval(localx, hl_coef[int, 1:
4]);
// annotation(smoothOrder=5);
annotation (derivative=dBubbleEnthalpy_dPressure_der_sat, Documentation(
info="<html>
<p>This function calculates the liquid phase enthalpy of R134a from the state variable p (absolute pressure). It is modelled by cubic splines which are fitted with non-equidistant grid points derived from
the fundamental equation of state of Tillner-Roth and Baehr (1994) and the Maxwell criteria.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end bubbleEnthalpy;
redeclare function extends dBubbleEnthalpy_dPressure
"Derivative of liquid specific enthalpy in two-phase region w.r.t. pressure"
protected
constant Real hl_coef[:, :]=R134aData.hlcoef
"Coefficients of cubic spline for h_liq(p)";
constant Real p_breaks[:]=R134aData.pbreaks
"Grid points of reduced pressure";
Integer int "Interval number";
Integer error "Interval for spline interpolation not found";
Real pred "Reduced pressure";
Real localx "Abscissa of local spline";
algorithm
pred := min(sat.psat/R134aData.data.FPCRIT, 1.0);
(int,error) := Common.FindInterval(pred, p_breaks);
localx := pred - p_breaks[int];
dhldp := R134aData.data.HCRIT*Common.CubicSplineDerEval(localx, hl_coef[
int, 1:4])/R134aData.data.FPCRIT;
annotation (Documentation(info="<html>
<p>This function calculates the derivative of liquid enthalpy of R134a with regard to the state variable p (absolute pressure). The non-derivative function is <a href=\"modelica://Modelica.Media.R134a.R134a_ph.bubbleEnthalpy\"> bubbleEnthalpy</a>.
</p>
<h4> Restrictions</h4>
<p>It is only valid in the two-phase region (i.e., p<sub>triple</sub> ≤ p ≤ p<sub>crit</sub> ).
</p>
</html>"));
end dBubbleEnthalpy_dPressure;
function dBubbleEnthalpy_dPressure_der_sat
"Time derivative of liquid specific enthalpy in two-phase region w.r.t. pressure"
extends Modelica.Icons.Function;
input SaturationProperties sat
"Saturation properties | pressure is used for interpolation";
input SaturationProperties der_sat "Derivative of saturation properties";
output Real der_dhldp
"Time derivative of liquid specific enthalpy in two-phase region w.r.t. pressure";