forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fittings.mo
2760 lines (2541 loc) · 125 KB
/
Fittings.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.Fluid;
package Fittings
"Adaptors for connections of fluid components and the regulation of fluid flow"
package Bends "Flow models for bends"
extends Modelica.Icons.VariantsPackage;
model CurvedBend "Curved bend flow model"
extends Modelica.Fluid.Dissipation.Utilities.Icons.PressureLoss.Bend_i;
extends Modelica.Fluid.Interfaces.PartialPressureLoss;
parameter Modelica.Fluid.Fittings.BaseClasses.Bends.CurvedBend.Geometry geometry
"Geometry of curved bend"
annotation (Placement(transformation(extent={{-20,0},{0,20}})));
protected
parameter Medium.AbsolutePressure dp_small(min=0)=
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_curvedOverall_DP(
geometry,
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_curvedOverall_IN_var(
rho=Medium.density(state_dp_small),
eta=Medium.dynamicViscosity(state_dp_small)),
m_flow_small)
"Default small pressure drop for regularization of laminar and zero flow (calculated from m_flow_small)";
equation
if allowFlowReversal then
m_flow = Modelica.Fluid.Fittings.BaseClasses.Bends.CurvedBend.massFlowRate(
dp, geometry, d_a, d_b, eta_a, eta_b, dp_small, m_flow_small);
else
m_flow = Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_curvedOverall_MFLOW(
geometry,
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_curvedOverall_IN_var(rho=d_a, eta=eta_a), dp);
end if;
annotation (Documentation(info="<html>
<p>
This component models a <strong>curved bend</strong> in the overall flow regime for incompressible and single-phase fluid flow through circular cross sectional area considering surface roughness. It is expected that also compressible fluid flow can be handled up to about Ma = 0.3. It is assumed that neither mass nor energy is stored in this component.
In the model basically a function is called to compute the mass flow rate as a function
of pressure loss for a curved bend. Also the inverse of this function is defined, and a tool
might use this inverse function instead, in order to avoid the solution of a nonlinear equation.
</p>
<p>
The details of the model are described in the
<a href=\"modelica://Modelica.Fluid.Dissipation.Utilities.SharedDocumentation.PressureLoss.Bend.dp_curvedOverall\">documentation of the underlying function</a>.
</p>
</html>"));
end CurvedBend;
model EdgedBend "Edged bend flow model"
extends Modelica.Fluid.Dissipation.Utilities.Icons.PressureLoss.Bend_i;
extends Modelica.Fluid.Interfaces.PartialPressureLoss;
parameter Modelica.Fluid.Fittings.BaseClasses.Bends.EdgedBend.Geometry geometry
"Geometry of curved bend"
annotation (Placement(transformation(extent={{-20,0},{0,20}})));
protected
parameter Medium.AbsolutePressure dp_small(min=0)=
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_edgedOverall_DP(
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_edgedOverall_IN_con(
d_hyd=geometry.d_hyd,
delta=geometry.delta,
K=geometry.K),
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_edgedOverall_IN_var(
rho=Medium.density(state_dp_small),
eta=Medium.dynamicViscosity(state_dp_small)),
m_flow_small)
"Default small pressure drop for regularization of laminar and zero flow (calculated from m_flow_small)";
equation
if allowFlowReversal then
m_flow = Modelica.Fluid.Fittings.BaseClasses.Bends.EdgedBend.massFlowRate(
dp, geometry, d_a, d_b, eta_a, eta_b, dp_small, m_flow_small);
else
m_flow = Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_edgedOverall_MFLOW(
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_edgedOverall_IN_con(
d_hyd=geometry.d_hyd,
delta=geometry.delta,
K=geometry.K),
Modelica.Fluid.Dissipation.PressureLoss.Bend.dp_edgedOverall_IN_var(rho=d_a, eta=eta_a), dp);
end if;
annotation (Documentation(info="<html>
<p>
This component models an <strong>edged bend</strong> in the overall flow regime for incompressible and single-phase fluid flow through circular cross sectional area considering surface roughness. It is expected that also compressible fluid flow can be handled up to about Ma = 0.3. It is assumed that neither mass nor energy is stored in this component.
In the model basically a function is called to compute the mass flow rate as a function
of pressure loss for an edged bend. Also the inverse of this function is defined, and a tool
might use this inverse function instead, in order to avoid the solution of a nonlinear equation.
</p>
<p>
The details of the model are described in the
<a href=\"modelica://Modelica.Fluid.Dissipation.Utilities.SharedDocumentation.PressureLoss.Bend.dp_edgedOverall\">documentation of the underlying function</a>.
</p>
</html>"));
end EdgedBend;
end Bends;
package Orifices "Flow models for orifices"
extends Modelica.Icons.VariantsPackage;
model ThickEdgedOrifice "Thicked edged orifice flow model"
extends Modelica.Fluid.Dissipation.Utilities.Icons.PressureLoss.Orifice_i;
extends Modelica.Fluid.Interfaces.PartialPressureLoss;
parameter
Modelica.Fluid.Fittings.BaseClasses.Orifices.ThickEdgedOrifice.Geometry geometry
"Geometry of thick edged orifice"
annotation (Placement(transformation(extent={{-20,0},{0,20}})),
choices(
choice=Modelica.Fluid.Fittings.BaseClasses.Orifices.ThickEdgedOrifice.Choices.circular(),
choice=Modelica.Fluid.Fittings.BaseClasses.Orifices.ThickEdgedOrifice.Choices.rectangular(),
choice=Modelica.Fluid.Fittings.BaseClasses.Orifices.ThickEdgedOrifice.Choices.general()));
protected
parameter Medium.AbsolutePressure dp_small(min=0)=
Modelica.Fluid.Dissipation.PressureLoss.Orifice.dp_thickEdgedOverall_DP(
Modelica.Fluid.Dissipation.PressureLoss.Orifice.dp_thickEdgedOverall_IN_con(
A_0=geometry.venaCrossArea,
A_1=geometry.crossArea,
C_0=geometry.venaPerimeter,
C_1=geometry.perimeter,
L=geometry.venaLength,
dp_smooth=1e-10),
Modelica.Fluid.Dissipation.PressureLoss.Orifice.dp_thickEdgedOverall_IN_var(
rho=Medium.density(state_dp_small),
eta=Medium.dynamicViscosity(state_dp_small)),
m_flow_small)
"Default small pressure drop for regularization of laminar and zero flow (calculated from m_flow_small)";
equation
if allowFlowReversal then
m_flow = Modelica.Fluid.Fittings.BaseClasses.Orifices.ThickEdgedOrifice.massFlowRate(
dp, geometry, d_a, d_b, eta_a, eta_b, dp_small, m_flow_small);
else
m_flow = Modelica.Fluid.Dissipation.PressureLoss.Orifice.dp_thickEdgedOverall_MFLOW(
Modelica.Fluid.Dissipation.PressureLoss.Orifice.dp_thickEdgedOverall_IN_con(
A_0=geometry.venaCrossArea,
A_1=geometry.crossArea,
C_0=geometry.venaPerimeter,
C_1=geometry.perimeter,
L=geometry.venaLength,
dp_smooth=dp_small),
Modelica.Fluid.Dissipation.PressureLoss.Orifice.dp_thickEdgedOverall_IN_var(rho=d_a, eta=eta_a), dp);
end if;
annotation (Documentation(info="<html>
<p>
This component models a <strong>thick edged orifice</strong> with sharp corners in the overall flow regime for incompressible and single-phase fluid flow through an arbitrary shaped cross sectional area (square, circular, etc.) considering influence of surface roughness. It is expected that also compressible fluid flow can be handled up to about Ma = 0.3. It is assumed that neither mass nor energy is stored in this component.
In the model basically a function is called to compute the mass flow rate as a function
of pressure loss for a thick edged orifice. Also the inverse of this function is defined, and a tool
might use this inverse function instead, in order to avoid the solution of a nonlinear equation.
</p>
<p>
The details of the model are described in the
<a href=\"modelica://Modelica.Fluid.Dissipation.Utilities.SharedDocumentation.PressureLoss.Orifice.dp_thickEdgedOverall\">documentation of the underlying function</a>.
</p>
</html>"));
end ThickEdgedOrifice;
end Orifices;
package GenericResistances "Flow models for generic resistances"
extends Modelica.Icons.VariantsPackage;
model VolumeFlowRate
"Flow model for generic resistance parameterized with the volume flow rate"
extends Modelica.Fluid.Dissipation.Utilities.Icons.PressureLoss.General_i;
extends Modelica.Fluid.Interfaces.PartialTwoPortTransport;
parameter Real a(unit="(Pa.s2)/m6") "Coefficient for quadratic term"
annotation(Dialog(group="dp = a*V_flow^2 + b*V_flow"));
parameter Real b(unit="(Pa.s)/m3") "Coefficient for linear term"
annotation(Dialog(group="dp = a*V_flow^2 + b*V_flow"));
protected
parameter Medium.ThermodynamicState state_dp_small=Medium.setState_pTX(
Medium.reference_p,
Medium.reference_T,
Medium.reference_X)
"Medium state to compute dp_small";
parameter Medium.AbsolutePressure dp_small(min=0)=
Modelica.Fluid.Dissipation.PressureLoss.General.dp_volumeFlowRate_DP(
Modelica.Fluid.Dissipation.PressureLoss.General.dp_volumeFlowRate_IN_con(
a=a,
b=b,
dp_min=1e-10),
Modelica.Fluid.Dissipation.PressureLoss.General.dp_volumeFlowRate_IN_var(
rho=Medium.density(state_dp_small)),
m_flow_small)
"Default small pressure drop for regularization of laminar and zero flow (calculated from m_flow_small)";
Medium.Density d_a
"Density at port_a when fluid is flowing from port_a to port_b";
Medium.Density d_b
"If allowFlowReversal=true then density at port_b when fluid is flowing from port_b to port_a else d_a";
equation
// Isenthalpic state transformation (no storage and no loss of energy)
port_a.h_outflow = inStream(port_b.h_outflow);
port_b.h_outflow = inStream(port_a.h_outflow);
// Medium properties
d_a = Medium.density(state_a);
if allowFlowReversal then
d_b = Medium.density(state_b);
else
d_b = d_a;
end if;
if allowFlowReversal then
m_flow = Modelica.Fluid.Fittings.BaseClasses.GenericResistances.VolumeFlowRate.massFlowRate(
dp, a, b, d_a, d_b, dp_small, m_flow_small);
else
m_flow = Modelica.Fluid.Dissipation.PressureLoss.General.dp_volumeFlowRate_MFLOW(
Modelica.Fluid.Dissipation.PressureLoss.General.dp_volumeFlowRate_IN_con(
a=a,
b=b,
dp_min=dp_small),
Modelica.Fluid.Dissipation.PressureLoss.General.dp_volumeFlowRate_IN_var(rho=d_a), dp);
end if;
annotation (Documentation(info="<html>
<p>
This component models a generic resistance parameterized
with the volume flow rate:
</p>
<blockquote><pre>
dp = a*V_flow^2 + b*V_flow
m_flow = rho*V_flow
</pre></blockquote>
<p>
with
</p>
<table>
<tr><td><strong> a </strong></td><td> as quadratic coefficient [Pa*s^2/m^6],</td></tr>
<tr><td><strong> b </strong></td><td> as linear coefficient [Pa*s/m3],</td></tr>
<tr><td><strong> dp </strong></td><td> as pressure loss [Pa],</td></tr>
<tr><td><strong> m_flow </strong></td><td> as mass flow rate [kg/s],</td></tr>
<tr><td><strong> rho </strong></td><td> as density of fluid [kg/m3],</td></tr>
<tr><td><strong> V_flow </strong></td><td> as volume flow rate [m3/s].</td></tr>
</table>
<p>
The geometry parameters of energy devices necessary for the pressure loss calculations are often not exactly known. Therefore the modelling of the detailed pressure loss calculation has to be simplified. This components use a linear and a quadratic dependence of the pressure loss on the volume flow rate. It is assumed that neither mass nor energy is stored in this component.
In the model basically a function is called to compute the mass flow rate as a function
of pressure loss. Also the inverse of this function is defined, and a tool
might use this inverse function instead, in order to avoid the solution of a nonlinear equation.
</p>
<p>
The details of the model are described in the
<a href=\"modelica://Modelica.Fluid.Dissipation.Utilities.SharedDocumentation.PressureLoss.General.dp_volumeFlowRate\">documentation of the underlying function</a>.
</p>
</html>"));
end VolumeFlowRate;
annotation (Documentation(info="<html>
<p>
The geometry parameters of energy devices necessary for the pressure loss
calculations are often not exactly known. Therefore the modelling of the detailed
pressure loss calculation has to be simplified.
In this package components are present that provide different forms of
such approximations.
</p>
</html>"));
end GenericResistances;
extends Modelica.Icons.VariantsPackage;
model SimpleGenericOrifice
"Simple generic orifice defined by pressure loss coefficient and diameter (only for flow from port_a to port_b)"
extends Modelica.Fluid.Interfaces.PartialTwoPortTransport(
dp_start = dp_nominal,
m_flow_small = if system.use_eps_Re then system.eps_m_flow*m_flow_nominal else system.m_flow_small,
m_flow(stateSelect = if momentumDynamics == Types.Dynamics.SteadyState then StateSelect.default
else StateSelect.prefer));
extends Modelica.Fluid.Interfaces.PartialLumpedFlow(
final pathLength = 0,
final momentumDynamics = Types.Dynamics.SteadyState);
parameter SI.Diameter diameter "Diameter of orifice";
parameter Real zeta "Loss factor for flow of port_a -> port_b"
annotation(Dialog(enable=use_zeta));
parameter Boolean use_zeta = true
"= false to obtain zeta from dp_nominal and m_flow_nominal";
// Operational conditions
parameter SI.MassFlowRate m_flow_nominal = if system.use_eps_Re then system.m_flow_nominal else 1e2*system.m_flow_small
"Mass flow rate for dp_nominal"
annotation(Dialog(group="Nominal operating point"));
parameter SI.Pressure dp_nominal = if not system.use_eps_Re then 1e3 else
BaseClasses.lossConstant_D_zeta(diameter, zeta)/Medium.density_pTX(Medium.p_default, Medium.T_default, Medium.X_default)*m_flow_nominal^2
"Nominal pressure drop"
annotation(Dialog(group="Nominal operating point"));
parameter Boolean use_Re = system.use_eps_Re
"= true, if turbulent region is defined by Re, otherwise by m_flow_small"
annotation(Dialog(tab="Advanced"), Evaluate=true);
parameter Boolean from_dp = true
"= true, use m_flow = f(dp) else dp = f(m_flow)"
annotation (Evaluate=true, Dialog(tab="Advanced"));
protected
parameter Medium.AbsolutePressure dp_small(min=0) = if system.use_eps_Re then dp_nominal/m_flow_nominal*m_flow_small else system.dp_small
"Regularization of zero flow if |dp| < dp_small"
annotation(Dialog(tab="Advanced", enable=not use_Re and from_dp));
// Variables
public
Real zeta_nominal;
Medium.Density d = 0.5*(Medium.density(state_a) + Medium.density(state_b));
SI.Pressure dp_fg(start=dp_start)
"Pressure loss due to friction and gravity";
SI.Area A_mean = Modelica.Constants.pi/4*diameter^2
"Mean cross flow area";
constant SI.ReynoldsNumber Re_turbulent = 10000 "cf. sharpEdgedOrifice";
SI.MassFlowRate m_flow_turbulent=if not use_Re then m_flow_small else
max(m_flow_small,
(Modelica.Constants.pi/8)*diameter*(Medium.dynamicViscosity(state_a) + Medium.dynamicViscosity(state_b))*Re_turbulent);
SI.AbsolutePressure dp_turbulent=if not use_Re then dp_small else
max(dp_small, BaseClasses.lossConstant_D_zeta(diameter, zeta_nominal)/d*m_flow_turbulent^2);
equation
if use_zeta then
zeta_nominal = zeta;
else
zeta_nominal = 2*A_mean^2*d*dp_nominal/m_flow_nominal^2;
end if;
Ib_flow = 0;
F_p = A_mean*(Medium.pressure(state_b) - Medium.pressure(state_a));
F_fg = A_mean*dp_fg;
/*
dp = 0.5*zeta*d*v*|v|
= 0.5*zeta*d*1/(d*A)^2 * m_flow * |m_flow|
= 0.5*zeta/A^2 *1/d * m_flow * |m_flow|
= k/d * m_flow * |m_flow|
k = 0.5*zeta/A^2
= 0.5*zeta/(pi*(D/2)^2)^2
= 8*zeta/(pi*D^2)^2
*/
if from_dp then
m_flow = homotopy(Utilities.regRoot2(
dp_fg,
dp_turbulent,
Medium.density(state_a)/BaseClasses.lossConstant_D_zeta(diameter, zeta_nominal),
Medium.density(state_b)/BaseClasses.lossConstant_D_zeta(diameter, zeta_nominal)),
m_flow_nominal*dp_fg/dp_nominal);
else
dp_fg = homotopy(Utilities.regSquare2(
m_flow,
m_flow_turbulent,
BaseClasses.lossConstant_D_zeta(diameter, zeta_nominal)/Medium.density(state_a),
BaseClasses.lossConstant_D_zeta(diameter, zeta_nominal)/Medium.density(state_b)),
dp_nominal*m_flow/m_flow_nominal);
end if;
// Isenthalpic state transformation (no storage and no loss of energy)
port_a.h_outflow = inStream(port_b.h_outflow);
port_b.h_outflow = inStream(port_a.h_outflow);
annotation (defaultComponentName="orifice",
Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}}), graphics={
Line(
points={{-60,-50},{-60,50},{60,-50},{60,50}},
thickness=0.5),
Line(points={{-60,0},{-100,0}}, color={0,127,255}),
Line(points={{60,0},{100,0}}, color={0,127,255}),
Text(
extent={{-173,104},{175,62}},
textString="zeta=%zeta")}),
Documentation(info="<html>
<p>
This pressure drop component defines a
simple, generic orifice, where the loss factor ζ is provided
for one flow direction (e.g., from loss table of a book):
</p>
<blockquote><pre>
Δp = 0.5*ζ*ρ*v*|v|
= 8*ζ/(π^2*D^4*ρ) * m_flow*|m_flow|
</pre></blockquote>
<p>
where
</p>
<ul>
<li> Δp is the pressure drop: Δp = port_a.p - port_b.p</li>
<li> D is the diameter of the orifice at the position where
ζ is defined (either at port_a or port_b). If the orifice has not a
circular cross section, D = 4*A/P, where A is the cross section
area and P is the wetted perimeter.</li>
<li> ζ is the loss factor with respect to D
that depends on the geometry of
the orifice. In the turbulent flow regime, it is assumed that
ζ is constant.<br>
For small mass flow rates, the flow is laminar and is approximated
by a polynomial that has a finite derivative for m_flow=0.</li>
<li> v is the mean velocity.</li>
<li> ρ is the upstream density.</li>
</ul>
<p>
Since the pressure loss factor zeta is provided only for a mass flow
from port_a to port_b, the pressure loss is not correct when the
flow is reversing. If reversing flow only occurs in a short time interval,
this is most likely uncritical. If significant reversing flow
can appear, this component should not be used.
</p>
</html>"));
end SimpleGenericOrifice;
model SharpEdgedOrifice
"Pressure drop due to sharp edged orifice (for both flow directions)"
import Modelica.Units.NonSI;
extends BaseClasses.QuadraticTurbulent.BaseModel(final data=
BaseClasses.QuadraticTurbulent.LossFactorData.sharpEdgedOrifice(
diameter,
leastDiameter,
length,
alpha));
parameter SI.Length length "Length of orifice";
parameter SI.Diameter diameter
"Inner diameter of pipe (= same at port_a and port_b)";
parameter SI.Diameter leastDiameter "Smallest diameter of orifice";
parameter NonSI.Angle_deg alpha "Angle of orifice";
annotation (defaultComponentName="orifice",
Documentation(info="<html>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,
100}}), graphics={
Rectangle(
extent={{-100,44},{100,-44}},
fillPattern=FillPattern.HorizontalCylinder,
fillColor={0,127,255}),
Polygon(
points={{-25,44},{-25,7},{35,37},{35,44},{-25,44}},
fillPattern=FillPattern.Backward,
fillColor={175,175,175}),
Polygon(
points={{-25,-7},{-25,-44},{35,-44},{35,-36},{-25,-7}},
fillColor={175,175,175},
fillPattern=FillPattern.Backward)}),
Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{
100,100}}), graphics={
Rectangle(
extent={{-100,60},{100,-60}},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Polygon(
points={{-30,60},{-30,12},{30,50},{30,60},{-30,60}},
fillColor={255,255,255},
fillPattern=FillPattern.Backward),
Polygon(
points={{-30,-10},{-30,-60},{30,-60},{30,-50},{-30,-10}},
fillColor={255,255,255},
fillPattern=FillPattern.Backward),
Line(
points={{-82,-60},{-82,60}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{-78,16},{-44,-8}},
textColor={0,0,255},
textString="diameter"),
Line(
points={{-30,-10},{-30,12}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{-24,14},{8,-10}},
textColor={0,0,255},
textString="leastDiameter"),
Text(
extent={{-20,84},{18,70}},
textColor={0,0,255},
textString="length"),
Line(
points={{30,68},{-30,68}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Line(
points={{16,40},{32,18},{36,-2},{34,-20},{20,-42}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{38,8},{92,-6}},
textColor={0,0,255},
textString="alpha")}));
end SharpEdgedOrifice;
model AbruptAdaptor
"Pressure drop in pipe due to suddenly expanding or reducing area (for both flow directions)"
extends BaseClasses.QuadraticTurbulent.BaseModelNonconstantCrossSectionArea(final data=
BaseClasses.QuadraticTurbulent.LossFactorData.suddenExpansion(
diameter_a, diameter_b));
parameter SI.Diameter diameter_a "Inner diameter of pipe at port_a";
parameter SI.Diameter diameter_b "Inner diameter of pipe at port_b";
annotation (
Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{
100,100}}), graphics={
Line(points={{0,40},{-100,40},{-100,-40},{0,-40},{0,-100},{100,-100},
{100,100},{0,100},{0,40}}),
Rectangle(
extent={{-100,40},{0,-40}},
lineColor={255,255,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,100},{100,-100}},
lineColor={255,255,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Line(points={{0,40},{-100,40},{-100,-40},{0,-40},{0,-100},{100,-100},
{100,100},{0,100},{0,40}}),
Line(
points={{-60,-40},{-60,40}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{-50,16},{-26,-10}},
textColor={0,0,255},
textString="diameter_a"),
Line(
points={{34,-100},{34,100}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{54,16},{78,-10}},
textColor={0,0,255},
textString="diameter_b")}),
Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,
100}}), graphics={Rectangle(
extent=DynamicSelect({{-100,22},{0,-22}}, {{-100,max(0.1, min(1,
diameter_a/max(diameter_a, diameter_b)))*60},{0,-max(0.1, min(1,
diameter_a/max(diameter_a, diameter_b)))*60}}),
fillPattern=FillPattern.HorizontalCylinder,
fillColor={0,127,255}), Rectangle(
extent=DynamicSelect({{0,60},{100,-60}}, {{0,max(0.1, min(1,
diameter_b/max(diameter_a, diameter_b)))*60},{100,-max(0.1, min(
1, diameter_b/max(diameter_a, diameter_b)))*60}}),
fillPattern=FillPattern.HorizontalCylinder,
fillColor={0,127,255})}),
Documentation(info="<html>
</html>"));
end AbruptAdaptor;
model MultiPort
"Multiply a port; useful if multiple connections shall be made to a port exposing a state"
function positiveMax
extends Modelica.Icons.Function;
input Real x;
output Real y;
algorithm
y :=max(x, 1e-10);
end positiveMax;
import Modelica.Constants;
replaceable package Medium=Modelica.Media.Interfaces.PartialMedium annotation(choicesAllMatching);
// Ports
parameter Integer nPorts_b=0
"Number of outlet ports (mass is distributed evenly between the outlet ports"
annotation(Dialog(connectorSizing=true));
Modelica.Fluid.Interfaces.FluidPort_a port_a(
redeclare package Medium=Medium)
annotation (Placement(transformation(extent={{-50,-10},{-30,10}})));
Modelica.Fluid.Interfaces.FluidPorts_b ports_b[nPorts_b](
redeclare each package Medium=Medium)
annotation (Placement(transformation(extent={{30,40},{50,-40}})));
Medium.MassFraction ports_b_Xi_inStream[nPorts_b,Medium.nXi]
"inStream mass fractions at ports_b";
Medium.ExtraProperty ports_b_C_inStream[nPorts_b,Medium.nC]
"inStream extra properties at ports_b";
equation
// Only one connection allowed to a port to avoid unwanted ideal mixing
for i in 1:nPorts_b loop
assert(cardinality(ports_b[i]) <= 1,"
each ports_b[i] of boundary shall at most be connected to one component.
If two or more connections are present, ideal mixing takes
place with these connections, which is usually not the intention
of the modeller. Increase nPorts_b to add an additional port.
");
end for;
// mass and momentum balance
0 = port_a.m_flow + sum(ports_b.m_flow);
ports_b.p = fill(port_a.p, nPorts_b);
// mixing at port_a
port_a.h_outflow = sum({positiveMax(ports_b[j].m_flow)*inStream(ports_b[j].h_outflow) for j in 1:nPorts_b})
/ sum({positiveMax(ports_b[j].m_flow) for j in 1:nPorts_b});
for j in 1:nPorts_b loop
// expose stream values from port_a to ports_b
ports_b[j].h_outflow = inStream(port_a.h_outflow);
ports_b[j].Xi_outflow = inStream(port_a.Xi_outflow);
ports_b[j].C_outflow = inStream(port_a.C_outflow);
ports_b_Xi_inStream[j,:] = inStream(ports_b[j].Xi_outflow);
ports_b_C_inStream[j,:] = inStream(ports_b[j].C_outflow);
end for;
for i in 1:Medium.nXi loop
port_a.Xi_outflow[i] = (positiveMax(ports_b.m_flow)*ports_b_Xi_inStream[:,i])
/ sum(positiveMax(ports_b.m_flow));
end for;
for i in 1:Medium.nC loop
port_a.C_outflow[i] = (positiveMax(ports_b.m_flow)*ports_b_C_inStream[:,i])
/ sum(positiveMax(ports_b.m_flow));
end for;
annotation (Icon(coordinateSystem(preserveAspectRatio=true, extent={{-40,
-100},{40,100}}), graphics={
Line(
points={{-40,0},{40,0}},
color={0,128,255},
thickness=1),
Line(
points={{-40,0},{40,26}},
color={0,128,255},
thickness=1),
Line(
points={{-40,0},{40,-26}},
color={0,128,255},
thickness=1),
Text(
extent={{-150,100},{150,60}},
textColor={0,0,255},
textString="%name")}),
Documentation(info="<html>
<p>
This model is useful if multiple connections shall be made to a port of a volume model exposing a state,
like a pipe with ModelStructure av_vb.
The mixing is shifted into the volume connected to port_a and the result is propagated back to each ports_b.
</p>
<p>
If multiple connections were directly made to the volume,
then ideal mixing would take place in the connection set, outside the volume. This is normally not intended.
</p>
</html>"));
end MultiPort;
model TeeJunctionIdeal
"Splitting/joining component with static balances for an infinitesimal control volume"
extends Modelica.Fluid.Fittings.BaseClasses.PartialTeeJunction;
equation
connect(port_1, port_2) annotation (Line(
points={{-100,0},{100,0}}, color={0,127,255}));
connect(port_1, port_3) annotation (Line(
points={{-100,0},{0,0},{0,100}}, color={0,127,255}));
annotation(Documentation(info="<html>
This model is the simplest implementation for a splitting/joining component for
three flows. Its use is not required. It just formulates the balance
equations in the same way that the connect semantics would formulate them anyways.
The main advantage of using this component is, that the user does not get
confused when looking at the specific enthalpy at each port which might be confusing
when not using a splitting/joining component. The reason for the confusion is that one examines the mixing
enthalpy of the infinitesimal control volume introduced with the connect statement when
looking at the specific enthalpy in the connector which
might not be equal to the specific enthalpy at the port in the \"real world\".</html>"));
end TeeJunctionIdeal;
model TeeJunctionVolume
"Splitting/joining component with static balances for a dynamic control volume"
extends Modelica.Fluid.Fittings.BaseClasses.PartialTeeJunction;
extends Modelica.Fluid.Interfaces.PartialLumpedVolume(
final fluidVolume = V);
parameter SI.Volume V "Mixing volume inside junction";
equation
// Only one connection allowed to a port to avoid unwanted ideal mixing
assert(cardinality(port_1) <= 1,"
port_1 of volume can at most be connected to one component.
If two or more connections are present, ideal mixing takes
place with these connections which is usually not the intention
of the modeller.
");
assert(cardinality(port_2) <= 1,"
port_2 of volume can at most be connected to one component.
If two or more connections are present, ideal mixing takes
place with these connections which is usually not the intention
of the modeller.
");
assert(cardinality(port_3) <= 1,"
port_3 of volume can at most be connected to one component.
If two or more connections are present, ideal mixing takes
place with these connections which is usually not the intention
of the modeller.
");
// Boundary conditions
port_1.h_outflow = medium.h;
port_2.h_outflow = medium.h;
port_3.h_outflow = medium.h;
port_1.Xi_outflow = medium.Xi;
port_2.Xi_outflow = medium.Xi;
port_3.Xi_outflow = medium.Xi;
port_1.C_outflow = C;
port_2.C_outflow = C;
port_3.C_outflow = C;
// Mass balances
mb_flow = port_1.m_flow + port_2.m_flow + port_3.m_flow "Mass balance";
mbXi_flow = port_1.m_flow*actualStream(port_1.Xi_outflow)
+ port_2.m_flow*actualStream(port_2.Xi_outflow)
+ port_3.m_flow*actualStream(port_3.Xi_outflow)
"Component mass balances";
mbC_flow = port_1.m_flow*actualStream(port_1.C_outflow)
+ port_2.m_flow*actualStream(port_2.C_outflow)
+ port_3.m_flow*actualStream(port_3.C_outflow)
"Trace substance mass balances";
// Momentum balance (suitable for compressible media)
port_1.p = medium.p;
port_2.p = medium.p;
port_3.p = medium.p;
// Energy balance
Hb_flow = port_1.m_flow*actualStream(port_1.h_outflow)
+ port_2.m_flow*actualStream(port_2.h_outflow)
+ port_3.m_flow*actualStream(port_3.h_outflow);
Qb_flow = 0;
Wb_flow = 0;
annotation (Documentation(info="<html>
This model introduces a mixing volume into a junction.
This might be useful to examine the non-ideal mixing taking place in a real junction.</html>"),
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={Ellipse(
extent={{-9,10},{11,-10}},
fillPattern=FillPattern.Solid)}));
end TeeJunctionVolume;
package BaseClasses
"Base classes used in the Fittings package (only of interest to build new component models)"
extends Modelica.Icons.BasesPackage;
function lossConstant_D_zeta "Return the loss constant 8*zeta/(pi^2*D^4)"
extends Modelica.Icons.Function;
input SI.Diameter D "Diameter at port_a or port_b";
input Real zeta
"Constant pressure loss factor with respect to D (i.e., either port_a or port_b)";
output Real k "Loss constant (= 8*zeta/(pi^2*D^4))";
algorithm
k :=8*zeta/(Modelica.Constants.pi*Modelica.Constants.pi*D*D*D*D);
annotation (Documentation(info="<html>
</html>"));
end lossConstant_D_zeta;
package QuadraticTurbulent
"Pressure loss components that are mainly defined by a quadratic turbulent regime with constant loss factor data"
extends Modelica.Icons.Package;
record LossFactorData
"Data structure defining constant loss factor data for dp = zeta*rho*v*|v|/2 and functions providing the data for some loss types"
extends Modelica.Icons.Record;
SI.Diameter diameter_a "Diameter at port_a" annotation(Dialog);
SI.Diameter diameter_b "Diameter at port_b" annotation(Dialog);
Real zeta1 "Loss factor for flow port_a -> port_b" annotation(Dialog);
Real zeta2 "Loss factor for flow port_b -> port_a" annotation(Dialog);
SI.ReynoldsNumber Re_turbulent
"Loss factors suited for Re >= Re_turbulent" annotation(Dialog);
SI.Diameter D_Re "Diameter used to compute Re" annotation(Dialog);
Boolean zeta1_at_a = true
"dp = zeta1*(if zeta1_at_a then rho_a*v_a^2/2 else rho_b*v_b^2/2)"
annotation(Dialog);
Boolean zeta2_at_a = false
"dp = -zeta2*(if zeta2_at_a then rho_a*v_a^2/2 else rho_b*v_b^2/2)"
annotation(Dialog);
Boolean zetaLaminarKnown = false
"= true, if zeta = c0/Re in laminar region" annotation(Dialog);
Real c0 = 1
"zeta = c0/Re; dp = zeta*rho_Re*v_Re^2/2, Re=v_Re*D_Re*rho_Re/mu_Re)"
annotation(Dialog(enable=zetaLaminarKnown));
encapsulated function wallFriction
"Return pressure loss data due to friction in a straight pipe with walls of nonuniform roughness (not useful for smooth pipes, since zeta is no function of Re)"
import Modelica.Units.SI;
import Modelica.Fluid.Fittings.BaseClasses.QuadraticTurbulent.LossFactorData;
import Modelica.Fluid.Types.Roughness;
import lg = Modelica.Math.log10;
input SI.Length length "Length of pipe" annotation(Dialog);
input SI.Diameter diameter "Inner diameter of pipe" annotation(Dialog);
input Roughness roughness(min=1e-10)
"Absolute roughness of pipe (> 0 required, details see info layer)" annotation(Dialog);
output LossFactorData data
"Pressure loss factors for both flow directions";
protected
Real Delta(min=0) = roughness/diameter "Relative roughness";
algorithm
data.diameter_a := diameter;
data.diameter_b := diameter;
data.zeta1 := (length/diameter)/(2*lg(3.7 /Delta))^2;
data.zeta2 := data.zeta1;
data.Re_turbulent := 4000
">= 560/Delta flow does not depend on Re, but interpolation is bad";
data.D_Re := diameter;
data.zeta1_at_a := true;
data.zeta2_at_a := false;
data.zetaLaminarKnown := true;
data.c0 := 64*(length/diameter);
annotation (Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}}), graphics={Rectangle(
extent={{-100,50},{100,-50}},
fillColor={255,255,255},
fillPattern=FillPattern.Solid)}),
Diagram(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}}), graphics={
Rectangle(
extent={{-100,64},{100,-64}},
fillColor={255,255,255},
fillPattern=FillPattern.Backward),
Rectangle(
extent={{-100,50},{100,-49}},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Line(
points={{-60,-49},{-60,50}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{-50,16},{6,-10}},
textColor={0,0,255},
textString="diameter"),
Line(
points={{-100,74},{100,74}},
color={0,0,255},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{-34,92},{34,74}},
textColor={0,0,255},
textString="length")}),
Documentation(info="<html>
<p>
Friction in straight pipe with walls of nonuniform roughness
(commercial pipes) in the region that does not depend on the Reynolds-number
</p>
<p>
The loss factors are given for mass flow rates from
port_a to port_b as:
</p>
<blockquote><pre>
turbulent flow (Idelchik 1994, diagram 2-5, p. 117)
zeta = (L/D)/(2*lg(3.7 / Δ))^2, for Re >= 560/Δ
for Re ≥ 560/Δ the loss factor does not depend on the
Reynolds number. For Re ≥ 4000, the flow is turbulent,
but depends both on Δ and slightly on Re.
laminar flow (Idelchik 1994, diagram 2-1, p. 110):
zeta = 64*(L/D)/Re
</pre></blockquote>
<p>
where
</p>
<ul>
<li> D is the inner pipe diameter</li>
<li> L is the length of the pipe</li>
<li> Δ = δ/D is the relative roughness where δ is
the absolute \"roughness\", i.e., the averaged height of asperities in the pipe.
(δ may change over time due to growth of surface asperities during
service, see [Idelchik 1994, p. 85, Tables 2-1, 2-2]).</li>
</ul>
<p>
Since the LossFactorData record can only describe loss factors that depend
on geometry (but, e.g., not on the Reynolds number), only the region
with Re ≥ 560/Δ is described by this data. Still, the turbulent
region with the above zeta is defined to start at Re=4000, since otherwise
the approximation for Re < 560/Δ is too bad.
</p>
<p>
The absolute roughness δ has usually to
be estimated. In <em>[Idelchik 1994, pp. 105-109,
Table 2-5; Miller 1990, p. 190, Table 8-1]</em> many examples are given.
As a short summary:
</p>
<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">
<tr><td><strong>Smooth pipes</strong></td>
<td>Drawn brass, copper, aluminium, glass, etc.</td>
<td>δ = 0.0025 mm</td>
</tr>
<tr><td rowspan=\"3\"><strong>Steel pipes</strong></td>
<td>New smooth pipes</td>
<td>δ = 0.025 mm</td>
</tr>
<tr><td>Mortar lined, average finish</td>
<td>δ = 0.1 mm</td>
</tr>
<tr><td>Heavy rust</td>
<td>δ = 1 mm</td>
</tr>
<tr><td rowspan=\"3\"><strong>Concrete pipes</strong></td>
<td>Steel forms, first class workmanship</td>
<td>δ = 0.025 mm</td>
</tr>
<tr><td>Steel forms, average workmanship</td>
<td>δ = 0.1 mm</td>
</tr>
<tr><td>Block linings</td>
<td>δ = 1 mm</td>
</tr>
</table>
</html>"));
end wallFriction;
encapsulated function suddenExpansion
"Return pressure loss data for sudden expansion or contraction in a pipe (for both flow directions)"
import Modelica.Units.SI;
import
Modelica.Fluid.Fittings.BaseClasses.QuadraticTurbulent.LossFactorData;
input SI.Diameter diameter_a "Inner diameter of pipe at port_a" annotation(Dialog);
input SI.Diameter diameter_b "Inner diameter of pipe at port_b" annotation(Dialog);
output LossFactorData data
"Pressure loss factors for both flow directions";
protected
Real A_rel;
algorithm
data.diameter_a := diameter_a;
data.diameter_b := diameter_b;
data.Re_turbulent := 100;
data.zetaLaminarKnown := true;
data.c0 := 30;
if diameter_a <= diameter_b then
A_rel :=(diameter_a/diameter_b)^2;
data.zeta1 :=(1 - A_rel)^2;
data.zeta2 :=0.5*(1 - A_rel)^0.75;
data.zeta1_at_a :=true;
data.zeta2_at_a :=true;
data.D_Re := diameter_a;
else
A_rel :=(diameter_b/diameter_a)^2;
data.zeta1 :=0.5*(1 - A_rel)^0.75;
data.zeta2 :=(1 - A_rel)^2;
data.zeta1_at_a :=false;
data.zeta2_at_a :=false;
data.D_Re := diameter_b;
end if;
annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,
-100},{100,100}}), graphics={
Rectangle(
extent={{-100,40},{0,-40}},
lineColor={255,255,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,100},{100,-100}},
lineColor={255,255,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Line(points={{0,40},{-100,40},{-100,-40},{0,-40},{0,-100},{100,
-100},{100,100},{0,100},{0,40}})}),
Diagram(coordinateSystem(
preserveAspectRatio=false, extent={{-100,-100},{100,100}}),
graphics={
Line(points={{0,40},{-100,40},{-100,-40},{0,-40},{0,-100},{100,
-100},{100,100},{0,100},{0,40}}),
Rectangle(
extent={{-100,40},{0,-40}},
lineColor={255,255,255},
fillColor={255,255,255},
fillPattern=FillPattern.Solid),
Rectangle(
extent={{0,100},{100,-100}},
lineColor={255,255,255},
fillColor={255,255,255},