forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pipes.mo
3381 lines (3044 loc) · 159 KB
/
Pipes.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 Pipes "Devices for conveying fluid"
extends Modelica.Icons.VariantsPackage;
model StaticPipe "Basic pipe flow model without storage of mass or energy"
// extending PartialStraightPipe
extends Modelica.Fluid.Pipes.BaseClasses.PartialStraightPipe;
// Initialization
parameter Medium.AbsolutePressure p_a_start=system.p_start
"Start value of pressure at port a"
annotation(Dialog(tab = "Initialization"));
parameter Medium.AbsolutePressure p_b_start=p_a_start
"Start value of pressure at port b"
annotation(Dialog(tab = "Initialization"));
parameter Medium.MassFlowRate m_flow_start = system.m_flow_start
"Start value for mass flow rate"
annotation(Evaluate=true, Dialog(tab = "Initialization"));
FlowModel flowModel(
redeclare package Medium = Medium,
final n=2,
states={Medium.setState_phX(port_a.p, inStream(port_a.h_outflow), inStream(port_a.Xi_outflow)),
Medium.setState_phX(port_b.p, inStream(port_b.h_outflow), inStream(port_b.Xi_outflow))},
vs={port_a.m_flow/Medium.density(flowModel.states[1])/flowModel.crossAreas[1],
-port_b.m_flow/Medium.density(flowModel.states[2])/flowModel.crossAreas[2]}/nParallel,
final momentumDynamics=Types.Dynamics.SteadyState,
final allowFlowReversal=allowFlowReversal,
final p_a_start=p_a_start,
final p_b_start=p_b_start,
final m_flow_start=m_flow_start,
final nParallel=nParallel,
final pathLengths={length},
final crossAreas={crossArea, crossArea},
final dimensions={4*crossArea/perimeter, 4*crossArea/perimeter},
final roughnesses={roughness, roughness},
final dheights={height_ab},
final g=system.g) "Flow model"
annotation (Placement(transformation(extent={{-38,-18},{38,18}})));
equation
// Mass balance
port_a.m_flow = flowModel.m_flows[1];
0 = port_a.m_flow + port_b.m_flow;
port_a.Xi_outflow = inStream(port_b.Xi_outflow);
port_b.Xi_outflow = inStream(port_a.Xi_outflow);
port_a.C_outflow = inStream(port_b.C_outflow);
port_b.C_outflow = inStream(port_a.C_outflow);
// Energy balance, considering change of potential energy
// Wb_flow = v*A*dpdx + v*F_fric
// = m_flow/d/A * (A*dpdx + A*pressureLoss.dp_fg - F_grav)
// = m_flow/d/A * (-A*g*height_ab*d)
// = -m_flow*g*height_ab
port_b.h_outflow = inStream(port_a.h_outflow) - system.g*height_ab;
port_a.h_outflow = inStream(port_b.h_outflow) + system.g*height_ab;
annotation (defaultComponentName="pipe",
Documentation(info="<html>
<p>Model of a straight pipe with constant cross section and with steady-state mass, momentum and energy balances, i.e., the model does not store mass or energy.
There exist two thermodynamic states, one at each fluid port. The momentum balance is formulated for the two states, taking into account
momentum flows, friction and gravity. The same result can be obtained by using <a href=\"modelica://Modelica.Fluid.Pipes.DynamicPipe\">DynamicPipe</a> with
steady-state dynamic settings. The intended use is to provide simple connections of vessels or other devices with storage, as it is done in:
</p>
<ul>
<li><a href=\"modelica://Modelica.Fluid.Examples.Tanks.EmptyTanks\">Examples.Tanks.EmptyTanks</a></li>
<li><a href=\"modelica://Modelica.Fluid.Examples.InverseParameterization\">Examples.InverseParameterization</a></li>
</ul>
<h4>Numerical Issues</h4>
<p>
With the stream connectors the thermodynamic states on the ports are generally defined by models with storage or by sources placed upstream and downstream of the static pipe.
Other non storage components in the flow path may yield to state transformation. Note that this generally leads to nonlinear equation systems if multiple static pipes,
or other flow models without storage, are directly connected.
</p>
</html>"));
end StaticPipe;
model DynamicPipe "Dynamic pipe model with storage of mass and energy"
import Modelica.Fluid.Types.ModelStructure;
// extending PartialStraightPipe
extends Modelica.Fluid.Pipes.BaseClasses.PartialStraightPipe(
final port_a_exposesState = (modelStructure == ModelStructure.av_b) or (modelStructure == ModelStructure.av_vb),
final port_b_exposesState = (modelStructure == ModelStructure.a_vb) or (modelStructure == ModelStructure.av_vb));
// extending PartialTwoPortFlow
extends BaseClasses.PartialTwoPortFlow(
final lengths=fill(length/n, n),
final crossAreas=fill(crossArea, n),
final dimensions=fill(4*crossArea/perimeter, n),
final roughnesses=fill(roughness, n),
final dheights=height_ab*dxs);
// Wall heat transfer
parameter Boolean use_HeatTransfer = false
"= true to use the HeatTransfer model"
annotation (Dialog(tab="Assumptions", group="Heat transfer"));
replaceable model HeatTransfer =
Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.IdealFlowHeatTransfer
constrainedby
Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.PartialFlowHeatTransfer
"Wall heat transfer"
annotation (Dialog(tab="Assumptions", group="Heat transfer",enable=use_HeatTransfer),choicesAllMatching=true);
Interfaces.HeatPorts_a[nNodes] heatPorts if use_HeatTransfer
annotation (Placement(transformation(extent={{-10,45},{10,65}}), iconTransformation(extent={{-30,36},
{32,52}})));
HeatTransfer heatTransfer(
redeclare package Medium = Medium,
final n=n,
final nParallel=nParallel,
final surfaceAreas=perimeter*lengths,
final lengths=lengths,
final dimensions=dimensions,
final roughnesses=roughnesses,
final states=mediums.state,
final vs = vs,
final use_k = use_HeatTransfer) "Heat transfer model"
annotation (Placement(transformation(extent={{-45,20},{-23,42}})));
final parameter Real[n] dxs = lengths/sum(lengths) "Normalized lengths";
equation
Qb_flows = heatTransfer.Q_flows;
// Wb_flow = v*A*dpdx + v*F_fric
// = v*A*dpdx + v*A*flowModel.dp_fg - v*A*dp_grav
if n == 1 or useLumpedPressure then
Wb_flows = dxs * ((vs*dxs)*(crossAreas*dxs)*((port_b.p - port_a.p) + sum(flowModel.dps_fg) - system.g*(dheights*mediums.d)))*nParallel;
else
if modelStructure == ModelStructure.av_vb then
Wb_flows[1] = vs[1]*crossAreas[1]*((mediums[2].p - mediums[1].p)/(if n==2 then 2 else 1.5) + flowModel.dps_fg[1]/(if n==2 then 2 else 1.5) - system.g*dheights[1]*mediums[1].d)*nParallel;
Wb_flows[2:n-1] = {vs[i]*crossAreas[i]*((mediums[i].p - mediums[i-1].p)/(if i==2 then 3 else 2) + (mediums[i+1].p - mediums[i].p)/(if i==n-1 then 3 else 2) + flowModel.dps_fg[i-1]/(if i==2 then 3 else 2) + flowModel.dps_fg[i]/(if i==n-1 then 3 else 2) - system.g*dheights[i]*mediums[i].d) for i in 2:n-1}*nParallel;
Wb_flows[n] = vs[n]*crossAreas[n]*((mediums[n].p - mediums[n-1].p)/(if n==2 then 2 else 1.5) + flowModel.dps_fg[n-1]/(if n==2 then 2 else 1.5) - system.g*dheights[n]*mediums[n].d)*nParallel;
elseif modelStructure == ModelStructure.av_b then
Wb_flows[1:n-1] = {vs[i]*crossAreas[i]*((mediums[i+1].p - mediums[i].p) + flowModel.dps_fg[i] - system.g*dheights[i]*mediums[i].d) for i in 1:n-1}*nParallel;
Wb_flows[n] = vs[n]*crossAreas[n]*((port_b.p - mediums[n].p) + flowModel.dps_fg[n] - system.g*dheights[n]*mediums[n].d)*nParallel;
elseif modelStructure == ModelStructure.a_vb then
Wb_flows[1] = vs[1]*crossAreas[1]*((mediums[1].p - port_a.p) + flowModel.dps_fg[1] - system.g*dheights[1]*mediums[1].d)*nParallel;
Wb_flows[2:n] = {vs[i]*crossAreas[i]*((mediums[i].p - mediums[i-1].p) + flowModel.dps_fg[i] - system.g*dheights[i]*mediums[i].d) for i in 2:n}*nParallel;
elseif modelStructure == ModelStructure.a_v_b then
Wb_flows[1] = vs[1]*crossAreas[1]*(((mediums[1].p + mediums[2].p)/2 - port_a.p) + flowModel.dps_fg[1] + flowModel.dps_fg[2]/2 - system.g*dheights[1]*mediums[1].d)*nParallel;
Wb_flows[2:n-1] = {vs[i]*crossAreas[i]*((mediums[i+1].p - mediums[i-1].p)/2 + (flowModel.dps_fg[i] + flowModel.dps_fg[i+1])/2 - system.g*dheights[i]*mediums[i].d) for i in 2:n-1}*nParallel;
Wb_flows[n] = vs[n]*crossAreas[n]*((port_b.p - (mediums[n-1].p + mediums[n].p)/2) + flowModel.dps_fg[n]/2 + flowModel.dps_fg[n+1] - system.g*dheights[n]*mediums[n].d)*nParallel;
else
assert(false, "Unknown model structure");
end if;
end if;
connect(heatPorts, heatTransfer.heatPorts)
annotation (Line(points={{0,55},{0,54},{-34,54},{-34,38.7}}, color={191,0,0}));
annotation (defaultComponentName="pipe",
Documentation(info="<html>
<p>Model of a straight pipe with distributed mass, energy and momentum balances. It provides the complete balance equations for one-dimensional fluid flow as formulated in <a href=\"modelica://Modelica.Fluid.UsersGuide.ComponentDefinition.BalanceEquations\">UsersGuide.ComponentDefinition.BalanceEquations</a>.</p>
<p>This generic model offers a large number of combinations of possible parameter settings. In order to reduce model complexity, consider defining and/or using a tailored model for the application at hand, such as
<a href=\"modelica://Modelica.Fluid.Examples.HeatExchanger.HeatExchangerSimulation\">HeatExchanger</a>.</p>
<p>DynamicPipe treats the partial differential equations with the finite volume method and a staggered grid scheme for momentum balances. The pipe is split into nNodes equally spaced segments along the flow path. The default value is nNodes=2. This results in two lumped mass and energy balances and one lumped momentum balance across the dynamic pipe.</p>
<p>Note that this generally leads to high-index DAEs for pressure states if dynamic pipes are directly connected to each other, or generally to models with storage exposing a thermodynamic state through the port. This may not be valid if the dynamic pipe is connected to a model with non-differentiable pressure, like a Sources.Boundary_pT with prescribed jumping pressure. The <code><strong>modelStructure</strong></code> can be configured as appropriate in such situations, in order to place a momentum balance between a pressure state of the pipe and a non-differentiable boundary condition.</p>
<p>The default <code><strong>modelStructure</strong></code> is <code>av_vb</code> (see Advanced tab). The simplest possible alternative symmetric configuration, avoiding potential high-index DAEs at the cost of the potential introduction of nonlinear equation systems, is obtained with the setting <code>nNodes=1, modelStructure=a_v_b</code>. Depending on the configured model structure, the first and the last pipe segment, or the flow path length of the first and the last momentum balance, are of half size. See the documentation of the base class <a href=\"modelica://Modelica.Fluid.Pipes.BaseClasses.PartialTwoPortFlow\">Pipes.BaseClasses.PartialTwoPortFlow</a>, also covering asymmetric configurations.</p>
<p>The <code><strong>HeatTransfer</strong></code> component specifies the source term <code>Qb_flows</code> of the energy balance. The default component uses a constant coefficient for the heat transfer between the bulk flow and the segment boundaries exposed through the <code>heatPorts</code>. The <code>HeatTransfer</code> model is replaceable and can be exchanged with any model extended from <a href=\"modelica://Modelica.Fluid.Pipes.BaseClasses.HeatTransfer.PartialFlowHeatTransfer\">BaseClasses.HeatTransfer.PartialFlowHeatTransfer</a>.</p>
<p>The intended use is for complex networks of pipes and other flow devices, like valves. See, e.g.,</p>
<ul>
<li><a href=\"modelica://Modelica.Fluid.Examples.BranchingDynamicPipes\">Examples.BranchingDynamicPipes</a>, or</li>
<li><a href=\"modelica://Modelica.Fluid.Examples.IncompressibleFluidNetwork\">Examples.IncompressibleFluidNetwork</a>.</li>
</ul>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,100}}), graphics={
Rectangle(
extent={{-100,44},{100,-44}},
fillPattern=FillPattern.HorizontalCylinder,
fillColor={0,127,255}),
Ellipse(
extent={{-72,10},{-52,-10}},
fillPattern=FillPattern.Solid),
Ellipse(
extent={{50,10},{70,-10}},
fillPattern=FillPattern.Solid),
Text(
extent={{-48,15},{46,-20}},
textString="%nNodes")}),
Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={
Rectangle(
extent={{-100,60},{100,50}},
fillColor={255,255,255},
fillPattern=FillPattern.Backward),
Rectangle(
extent={{-100,-50},{100,-60}},
fillColor={255,255,255},
fillPattern=FillPattern.Backward),
Line(
points={{100,45},{100,50}},
arrow={Arrow.None,Arrow.Filled},
pattern=LinePattern.Dot),
Line(
points={{0,45},{0,50}},
arrow={Arrow.None,Arrow.Filled},
pattern=LinePattern.Dot),
Line(
points={{100,-45},{100,-50}},
arrow={Arrow.None,Arrow.Filled},
pattern=LinePattern.Dot),
Line(
points={{0,-45},{0,-50}},
arrow={Arrow.None,Arrow.Filled},
pattern=LinePattern.Dot),
Line(
points={{-50,60},{-50,50}},
pattern=LinePattern.Dot),
Line(
points={{50,60},{50,50}},
pattern=LinePattern.Dot),
Line(
points={{0,-50},{0,-60}},
pattern=LinePattern.Dot)}));
end DynamicPipe;
package BaseClasses
"Base classes used in the Pipes package (only of interest to build new component models)"
extends Modelica.Icons.BasesPackage;
partial model PartialStraightPipe "Base class for straight pipe models"
extends Modelica.Fluid.Interfaces.PartialTwoPort;
// Geometry
// Note: define nParallel as Real to support inverse calculations
parameter Real nParallel(min=1)=1 "Number of identical parallel pipes"
annotation(Dialog(group="Geometry"));
parameter SI.Length length "Length"
annotation(Dialog(tab="General", group="Geometry"));
parameter Boolean isCircular=true
"= true, if cross sectional area is circular"
annotation (Evaluate=true, Dialog(tab="General", group="Geometry"));
parameter SI.Diameter diameter "Diameter of circular pipe"
annotation(Dialog(group="Geometry", enable=isCircular));
parameter SI.Area crossArea=Modelica.Constants.pi*diameter*diameter/4
"Inner cross section area"
annotation(Dialog(tab="General", group="Geometry", enable=not isCircular));
parameter SI.Length perimeter(min=0)=Modelica.Constants.pi*diameter
"Inner perimeter"
annotation(Dialog(tab="General", group="Geometry", enable=not isCircular));
parameter Modelica.Fluid.Types.Roughness roughness=2.5e-5
"Average height of surface asperities (default: smooth steel pipe)"
annotation(Dialog(group="Geometry"));
final parameter SI.Volume V=crossArea*length*nParallel "Volume size";
// Static head
parameter SI.Length height_ab=0 "Height(port_b) - Height(port_a)"
annotation(Dialog(group="Static head"));
// Pressure loss
replaceable model FlowModel =
Modelica.Fluid.Pipes.BaseClasses.FlowModels.DetailedPipeFlow
constrainedby
Modelica.Fluid.Pipes.BaseClasses.FlowModels.PartialStaggeredFlowModel
"Wall friction, gravity, momentum flow"
annotation(Dialog(group="Pressure loss"), choicesAllMatching=true);
equation
assert(length >= height_ab, "Parameter length must be greater or equal height_ab.");
annotation (defaultComponentName="pipe",Icon(coordinateSystem(
preserveAspectRatio=false,
extent={{-100,-100},{100,100}}), graphics={Rectangle(
extent={{-100,40},{100,-40}},
fillPattern=FillPattern.Solid,
fillColor={95,95,95},
pattern=LinePattern.None), Rectangle(
extent={{-100,44},{100,-44}},
fillPattern=FillPattern.HorizontalCylinder,
fillColor={0,127,255})}), Documentation(info="<html>
<p>
Base class for one dimensional flow models. It specializes a PartialTwoPort with a parameter interface and icon graphics.
</p>
</html>"));
end PartialStraightPipe;
partial model PartialTwoPortFlow "Base class for distributed flow models"
import Modelica.Fluid.Types.ModelStructure;
// extending PartialTwoPort
extends Modelica.Fluid.Interfaces.PartialTwoPort(
final port_a_exposesState = (modelStructure == ModelStructure.av_b) or (modelStructure == ModelStructure.av_vb),
final port_b_exposesState = (modelStructure == ModelStructure.a_vb) or (modelStructure == ModelStructure.av_vb));
// distributed volume model
extends Modelica.Fluid.Interfaces.PartialDistributedVolume(
final n = nNodes,
final fluidVolumes = {crossAreas[i]*lengths[i] for i in 1:n}*nParallel);
// Geometry parameters
parameter Real nParallel(min=1)=1
"Number of identical parallel flow devices"
annotation(Dialog(group="Geometry"));
parameter SI.Length[n] lengths "Lengths of flow segments"
annotation(Dialog(group="Geometry"));
parameter SI.Area[n] crossAreas "Cross flow areas of flow segments"
annotation(Dialog(group="Geometry"));
parameter SI.Length[n] dimensions "Hydraulic diameters of flow segments"
annotation(Dialog(group="Geometry"));
parameter Modelica.Fluid.Types.Roughness[n] roughnesses
"Average heights of surface asperities"
annotation(Dialog(group="Geometry"));
// Static head
parameter SI.Length[n] dheights=zeros(n)
"Differences in heights of flow segments"
annotation(Dialog(group="Static head"), Evaluate=true);
// Assumptions
parameter Types.Dynamics momentumDynamics=system.momentumDynamics
"Formulation of momentum balances"
annotation(Evaluate=true, Dialog(tab = "Assumptions", group="Dynamics"));
// Initialization
parameter Medium.MassFlowRate m_flow_start = system.m_flow_start
"Start value for mass flow rate"
annotation(Evaluate=true, Dialog(tab = "Initialization"));
// Discretization
parameter Integer nNodes(min=1)=2 "Number of discrete flow volumes"
annotation(Dialog(tab="Advanced"),Evaluate=true);
parameter Types.ModelStructure modelStructure=Types.ModelStructure.av_vb
"Determines whether flow or volume models are present at the ports"
annotation(Dialog(tab="Advanced"), Evaluate=true);
parameter Boolean useLumpedPressure=false
"= true to lump pressure states together"
annotation(Dialog(tab="Advanced"),Evaluate=true);
final parameter Integer nFM=if useLumpedPressure then nFMLumped else nFMDistributed
"Number of flow models in flowModel";
final parameter Integer nFMDistributed=if modelStructure==Types.ModelStructure.a_v_b then n+1 else if (modelStructure==Types.ModelStructure.a_vb or modelStructure==Types.ModelStructure.av_b) then n else n-1 "Number of distributed flow models";
final parameter Integer nFMLumped=if modelStructure==Types.ModelStructure.a_v_b then 2 else 1 "Number of lumped flow models";
final parameter Integer iLumped=integer(n/2)+1
"Index of control volume with representative state if useLumpedPressure"
annotation(Evaluate=true);
// Advanced model options
parameter Boolean useInnerPortProperties=false
"= true to take port properties for flow models from internal control volumes"
annotation(Dialog(tab="Advanced"),Evaluate=true);
Medium.ThermodynamicState state_a
"State defined by volume outside port_a";
Medium.ThermodynamicState state_b
"State defined by volume outside port_b";
Medium.ThermodynamicState[nFM+1] statesFM
"State vector for flowModel model";
// Pressure loss model
replaceable model FlowModel =
Modelica.Fluid.Pipes.BaseClasses.FlowModels.DetailedPipeFlow
constrainedby
Modelica.Fluid.Pipes.BaseClasses.FlowModels.PartialStaggeredFlowModel
"Wall friction, gravity, momentum flow"
annotation(Dialog(group="Pressure loss"), choicesAllMatching=true);
FlowModel flowModel(
redeclare package Medium = Medium,
final n=nFM+1,
final states=statesFM,
final vs=vsFM,
final momentumDynamics=momentumDynamics,
final allowFlowReversal=allowFlowReversal,
final p_a_start=p_a_start,
final p_b_start=p_b_start,
final m_flow_start=m_flow_start,
final nParallel=nParallel,
final pathLengths=pathLengths,
final crossAreas=crossAreasFM,
final dimensions=dimensionsFM,
final roughnesses=roughnessesFM,
final dheights=dheightsFM,
final g=system.g) "Flow model"
annotation (Placement(transformation(extent={{-77,-37},{75,-19}})));
// Flow quantities
Medium.MassFlowRate[n+1] m_flows(
each min=if allowFlowReversal then -Modelica.Constants.inf else 0,
each start=m_flow_start)
"Mass flow rates of fluid across segment boundaries";
Medium.MassFlowRate[n+1, Medium.nXi] mXi_flows
"Independent mass flow rates across segment boundaries";
Medium.MassFlowRate[n+1, Medium.nC] mC_flows
"Trace substance mass flow rates across segment boundaries";
Medium.EnthalpyFlowRate[n+1] H_flows
"Enthalpy flow rates of fluid across segment boundaries";
SI.Velocity[n] vs = {0.5*(m_flows[i] + m_flows[i+1])/mediums[i].d/crossAreas[i] for i in 1:n}/nParallel
"Mean velocities in flow segments";
// Model structure dependent flow geometry
protected
SI.Length[nFM] pathLengths "Lengths along flow path";
SI.Length[nFM] dheightsFM "Differences in heights between flow segments";
SI.Area[nFM+1] crossAreasFM "Cross flow areas of flow segments";
SI.Velocity[nFM+1] vsFM "Mean velocities in flow segments";
SI.Length[nFM+1] dimensionsFM "Hydraulic diameters of flow segments";
Modelica.Fluid.Types.Roughness[nFM+1] roughnessesFM "Average heights of surface asperities";
equation
assert(nNodes > 1 or modelStructure <> ModelStructure.av_vb,
"nNodes needs to be at least 2 for modelStructure av_vb, as flow model disappears otherwise!");
// staggered grid discretization of geometry for flowModel, depending on modelStructure
if useLumpedPressure then
if modelStructure <> ModelStructure.a_v_b then
pathLengths[1] = sum(lengths);
dheightsFM[1] = sum(dheights);
if n == 1 then
crossAreasFM[1:2] = {crossAreas[1], crossAreas[1]};
dimensionsFM[1:2] = {dimensions[1], dimensions[1]};
roughnessesFM[1:2] = {roughnesses[1], roughnesses[1]};
else // n > 1
crossAreasFM[1:2] = {sum(crossAreas[1:iLumped-1])/(iLumped-1), sum(crossAreas[iLumped:n])/(n-iLumped+1)};
dimensionsFM[1:2] = {sum(dimensions[1:iLumped-1])/(iLumped-1), sum(dimensions[iLumped:n])/(n-iLumped+1)};
roughnessesFM[1:2] = {sum(roughnesses[1:iLumped-1])/(iLumped-1), sum(roughnesses[iLumped:n])/(n-iLumped+1)};
end if;
else
if n == 1 then
pathLengths[1:2] = {lengths[1]/2, lengths[1]/2};
dheightsFM[1:2] = {dheights[1]/2, dheights[1]/2};
crossAreasFM[1:3] = {crossAreas[1], crossAreas[1], crossAreas[1]};
dimensionsFM[1:3] = {dimensions[1], dimensions[1], dimensions[1]};
roughnessesFM[1:3] = {roughnesses[1], roughnesses[1], roughnesses[1]};
else // n > 1
pathLengths[1:2] = {sum(lengths[1:iLumped-1]), sum(lengths[iLumped:n])};
dheightsFM[1:2] = {sum(dheights[1:iLumped-1]), sum(dheights[iLumped:n])};
crossAreasFM[1:3] = {sum(crossAreas[1:iLumped-1])/(iLumped-1), sum(crossAreas)/n, sum(crossAreas[iLumped:n])/(n-iLumped+1)};
dimensionsFM[1:3] = {sum(dimensions[1:iLumped-1])/(iLumped-1), sum(dimensions)/n, sum(dimensions[iLumped:n])/(n-iLumped+1)};
roughnessesFM[1:3] = {sum(roughnesses[1:iLumped-1])/(iLumped-1), sum(roughnesses)/n, sum(roughnesses[iLumped:n])/(n-iLumped+1)};
end if;
end if;
else
if modelStructure == ModelStructure.av_vb then
//nFM = n-1
if n == 2 then
pathLengths[1] = lengths[1] + lengths[2];
dheightsFM[1] = dheights[1] + dheights[2];
else
pathLengths[1:n-1] = cat(1, {lengths[1] + 0.5*lengths[2]}, 0.5*(lengths[2:n-2] + lengths[3:n-1]), {0.5*lengths[n-1] + lengths[n]});
dheightsFM[1:n-1] = cat(1, {dheights[1] + 0.5*dheights[2]}, 0.5*(dheights[2:n-2] + dheights[3:n-1]), {0.5*dheights[n-1] + dheights[n]});
end if;
crossAreasFM[1:n] = crossAreas;
dimensionsFM[1:n] = dimensions;
roughnessesFM[1:n] = roughnesses;
elseif modelStructure == ModelStructure.av_b then
//nFM = n
pathLengths[1:n] = lengths;
dheightsFM[1:n] = dheights;
crossAreasFM[1:n+1] = cat(1, crossAreas[1:n], {crossAreas[n]});
dimensionsFM[1:n+1] = cat(1, dimensions[1:n], {dimensions[n]});
roughnessesFM[1:n+1] = cat(1, roughnesses[1:n], {roughnesses[n]});
elseif modelStructure == ModelStructure.a_vb then
//nFM = n
pathLengths[1:n] = lengths;
dheightsFM[1:n] = dheights;
crossAreasFM[1:n+1] = cat(1, {crossAreas[1]}, crossAreas[1:n]);
dimensionsFM[1:n+1] = cat(1, {dimensions[1]}, dimensions[1:n]);
roughnessesFM[1:n+1] = cat(1, {roughnesses[1]}, roughnesses[1:n]);
elseif modelStructure == ModelStructure.a_v_b then
//nFM = n+1;
pathLengths[1:n+1] = cat(1, {0.5*lengths[1]}, 0.5*(lengths[1:n-1] + lengths[2:n]), {0.5*lengths[n]});
dheightsFM[1:n+1] = cat(1, {0.5*dheights[1]}, 0.5*(dheights[1:n-1] + dheights[2:n]), {0.5*dheights[n]});
crossAreasFM[1:n+2] = cat(1, {crossAreas[1]}, crossAreas[1:n], {crossAreas[n]});
dimensionsFM[1:n+2] = cat(1, {dimensions[1]}, dimensions[1:n], {dimensions[n]});
roughnessesFM[1:n+2] = cat(1, {roughnesses[1]}, roughnesses[1:n], {roughnesses[n]});
else
assert(false, "Unknown model structure");
end if;
end if;
// Source/sink terms for mass and energy balances
for i in 1:n loop
mb_flows[i] = m_flows[i] - m_flows[i + 1];
mbXi_flows[i, :] = mXi_flows[i, :] - mXi_flows[i + 1, :];
mbC_flows[i, :] = mC_flows[i, :] - mC_flows[i + 1, :];
Hb_flows[i] = H_flows[i] - H_flows[i + 1];
end for;
// Distributed flow quantities, upwind discretization
for i in 2:n loop
H_flows[i] = semiLinear(m_flows[i], mediums[i - 1].h, mediums[i].h);
mXi_flows[i, :] = semiLinear(m_flows[i], mediums[i - 1].Xi, mediums[i].Xi);
mC_flows[i, :] = semiLinear(m_flows[i], Cs[i - 1, :], Cs[i, :]);
end for;
H_flows[1] = semiLinear(port_a.m_flow, inStream(port_a.h_outflow), mediums[1].h);
H_flows[n + 1] = -semiLinear(port_b.m_flow, inStream(port_b.h_outflow), mediums[n].h);
mXi_flows[1, :] = semiLinear(port_a.m_flow, inStream(port_a.Xi_outflow), mediums[1].Xi);
mXi_flows[n + 1, :] = -semiLinear(port_b.m_flow, inStream(port_b.Xi_outflow), mediums[n].Xi);
mC_flows[1, :] = semiLinear(port_a.m_flow, inStream(port_a.C_outflow), Cs[1, :]);
mC_flows[n + 1, :] = -semiLinear(port_b.m_flow, inStream(port_b.C_outflow), Cs[n, :]);
// Boundary conditions
port_a.m_flow = m_flows[1];
port_b.m_flow = -m_flows[n + 1];
port_a.h_outflow = mediums[1].h;
port_b.h_outflow = mediums[n].h;
port_a.Xi_outflow = mediums[1].Xi;
port_b.Xi_outflow = mediums[n].Xi;
port_a.C_outflow = Cs[1, :];
port_b.C_outflow = Cs[n, :];
// The two equations below are not correct if C is stored in volumes.
// C should be treated the same way as Xi.
//port_a.C_outflow = inStream(port_b.C_outflow);
//port_b.C_outflow = inStream(port_a.C_outflow);
if useInnerPortProperties and n > 0 then
state_a = Medium.setState_phX(port_a.p, mediums[1].h, mediums[1].Xi);
state_b = Medium.setState_phX(port_b.p, mediums[n].h, mediums[n].Xi);
else
state_a = Medium.setState_phX(port_a.p, inStream(port_a.h_outflow), inStream(port_a.Xi_outflow));
state_b = Medium.setState_phX(port_b.p, inStream(port_b.h_outflow), inStream(port_b.Xi_outflow));
end if;
// staggered grid discretization for flowModel, depending on modelStructure
if useLumpedPressure then
if modelStructure <> ModelStructure.av_vb then
// all pressures are equal
fill(mediums[1].p, n-1) = mediums[2:n].p;
elseif n > 2 then
// need two pressures
fill(mediums[1].p, iLumped-2) = mediums[2:iLumped-1].p;
fill(mediums[n].p, n-iLumped) = mediums[iLumped:n-1].p;
end if;
if modelStructure == ModelStructure.av_vb then
port_a.p = mediums[1].p;
statesFM[1] = mediums[1].state;
m_flows[iLumped] = flowModel.m_flows[1];
statesFM[2] = mediums[n].state;
port_b.p = mediums[n].p;
vsFM[1] = vs[1:iLumped-1]*lengths[1:iLumped-1]/sum(lengths[1:iLumped-1]);
vsFM[2] = vs[iLumped:n]*lengths[iLumped:n]/sum(lengths[iLumped:n]);
elseif modelStructure == ModelStructure.av_b then
port_a.p = mediums[1].p;
statesFM[1] = mediums[iLumped].state;
statesFM[2] = state_b;
m_flows[n+1] = flowModel.m_flows[1];
vsFM[1] = vs*lengths/sum(lengths);
vsFM[2] = m_flows[n+1]/Medium.density(state_b)/crossAreas[n]/nParallel;
elseif modelStructure == ModelStructure.a_vb then
m_flows[1] = flowModel.m_flows[1];
statesFM[1] = state_a;
statesFM[2] = mediums[iLumped].state;
port_b.p = mediums[n].p;
vsFM[1] = m_flows[1]/Medium.density(state_a)/crossAreas[1]/nParallel;
vsFM[2] = vs*lengths/sum(lengths);
elseif modelStructure == ModelStructure.a_v_b then
m_flows[1] = flowModel.m_flows[1];
statesFM[1] = state_a;
statesFM[2] = mediums[iLumped].state;
statesFM[3] = state_b;
m_flows[n+1] = flowModel.m_flows[2];
vsFM[1] = m_flows[1]/Medium.density(state_a)/crossAreas[1]/nParallel;
vsFM[2] = vs*lengths/sum(lengths);
vsFM[3] = m_flows[n+1]/Medium.density(state_b)/crossAreas[n]/nParallel;
else
assert(false, "Unknown model structure");
end if;
else
if modelStructure == ModelStructure.av_vb then
//nFM = n-1
statesFM[1:n] = mediums[1:n].state;
m_flows[2:n] = flowModel.m_flows[1:n-1];
vsFM[1:n] = vs;
port_a.p = mediums[1].p;
port_b.p = mediums[n].p;
elseif modelStructure == ModelStructure.av_b then
//nFM = n
statesFM[1:n] = mediums[1:n].state;
statesFM[n+1] = state_b;
m_flows[2:n+1] = flowModel.m_flows[1:n];
vsFM[1:n] = vs;
vsFM[n+1] = m_flows[n+1]/Medium.density(state_b)/crossAreas[n]/nParallel;
port_a.p = mediums[1].p;
elseif modelStructure == ModelStructure.a_vb then
//nFM = n
statesFM[1] = state_a;
statesFM[2:n+1] = mediums[1:n].state;
m_flows[1:n] = flowModel.m_flows[1:n];
vsFM[1] = m_flows[1]/Medium.density(state_a)/crossAreas[1]/nParallel;
vsFM[2:n+1] = vs;
port_b.p = mediums[n].p;
elseif modelStructure == ModelStructure.a_v_b then
//nFM = n+1
statesFM[1] = state_a;
statesFM[2:n+1] = mediums[1:n].state;
statesFM[n+2] = state_b;
m_flows[1:n+1] = flowModel.m_flows[1:n+1];
vsFM[1] = m_flows[1]/Medium.density(state_a)/crossAreas[1]/nParallel;
vsFM[2:n+1] = vs;
vsFM[n+2] = m_flows[n+1]/Medium.density(state_b)/crossAreas[n]/nParallel;
else
assert(false, "Unknown model structure");
end if;
end if;
annotation (defaultComponentName="pipe",
Documentation(info="<html>
<p>Base class for distributed flow models. The total volume is split into nNodes segments along the flow path.
The default value is nNodes=2.
</p>
<h4>Mass and Energy balances</h4>
<p>
The mass and energy balances are inherited from <a href=\"modelica://Modelica.Fluid.Interfaces.PartialDistributedVolume\">Interfaces.PartialDistributedVolume</a>.
One total mass and one energy balance is formed across each segment according to the finite volume approach.
Substance mass balances are added if the medium contains more than one component.
</p>
<p>
An extending model needs to define the geometry and the difference in heights between the flow segments (static head).
Moreover it needs to define two vectors of source terms for the distributed energy balance:
</p>
<ul>
<li><code><strong>Qb_flows[nNodes]</strong></code>, the heat flow source terms, e.g., conductive heat flows across segment boundaries, and</li>
<li><code><strong>Wb_flows[nNodes]</strong></code>, the work source terms.</li>
</ul>
<h4>Momentum balance</h4>
<p>
The momentum balance is determined by the <strong><code>FlowModel</code></strong> component, which can be replaced with any model extended from
<a href=\"modelica://Modelica.Fluid.Pipes.BaseClasses.FlowModels.PartialStaggeredFlowModel\">BaseClasses.FlowModels.PartialStaggeredFlowModel</a>.
The default setting is <a href=\"modelica://Modelica.Fluid.Pipes.BaseClasses.FlowModels.DetailedPipeFlow\">DetailedPipeFlow</a>.
</p>
<p>
This considers
</p>
<ul>
<li>pressure drop due to friction and other dissipative losses, and</li>
<li>gravity effects for non-horizontal devices.</li>
<li>variation of flow velocity along the flow path,
which occur due to changes in the cross sectional area or the fluid density, provided that <code>flowModel.use_Ib_flows</code> is true.</li>
</ul>
<h4>Model Structure</h4>
<p>
The momentum balances are formulated across the segment boundaries along the flow path according to the staggered grid approach.
The configurable <strong><code>modelStructure</code></strong> determines the formulation of the boundary conditions at <code>port_a</code> and <code>port_b</code>.
The options include (default: av_vb):
</p>
<ul>
<li><code>av_vb</code>: Symmetric setting with nNodes-1 momentum balances between nNodes flow segments.
The ports <code>port_a</code> and <code>port_b</code> expose the first and the last thermodynamic state, respectively.
Connecting two or more flow devices therefore may result in high-index DAEs for the pressures of connected flow segments.</li>
<li><code>a_v_b</code>: Alternative symmetric setting with nNodes+1 momentum balances across nNodes flow segments.
Half momentum balances are placed between <code>port_a</code> and the first flow segment as well as between the last flow segment and <code>port_b</code>.
Connecting two or more flow devices therefore results in algebraic pressures at the ports.
The specification of good start values for the port pressures is essential for the solution of large nonlinear equation systems.</li>
<li><code>av_b</code>: Asymmetric setting with nNodes momentum balances, one between nth volume and <code>port_b</code>, potential pressure state at <code>port_a</code></li>
<li><code>a_vb</code>: Asymmetric setting with nNodes momentum balance, one between first volume and <code>port_a</code>, potential pressure state at <code>port_b</code></li>
</ul>
<p>
When connecting two components, e.g., two pipes, the momentum balance across the connection point reduces to
</p>
<blockquote><pre>pipe1.port_b.p = pipe2.port_a.p</pre></blockquote>
<p>
This is only true if the flow velocity remains the same on each side of the connection.
Consider using a fitting for any significant change in diameter or fluid density, if the resulting effects,
such as change in kinetic energy, cannot be neglected.
This also allows for taking into account friction losses with respect to the actual geometry of the connection point.
</p>
</html>",
revisions="<html>
<ul>
<li><em>5 Dec 2008</em>
by Michael Wetter:<br>
Modified mass balance for trace substances. With the new formulation, the trace substances masses <code>mC</code> are stored
in the same way as the species <code>mXi</code>.</li>
<li><em>Dec 2008</em>
by Rüdiger Franke:<br>
Derived model from original DistributedPipe models
<ul>
<li>moved mass and energy balances to PartialDistributedVolume</li>
<li>introduced replaceable pressure loss models</li>
<li>combined all model structures and lumped pressure into one model</li>
<li>new ModelStructure av_vb, replacing former avb</li>
</ul></li>
<li><em>04 Mar 2006</em>
by Katrin Prölß:<br>
Model added to the Fluid library</li>
</ul>
</html>"),
Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100,
100}}), graphics={Ellipse(
extent={{-72,10},{-52,-10}},
fillPattern=FillPattern.Solid), Ellipse(
extent={{50,10},{70,-10}},
fillPattern=FillPattern.Solid)}),
Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{
100,100}}), graphics={
Polygon(
points={{-100,-50},{-100,50},{100,60},{100,-60},{-100,-50}},
fillColor={215,215,215},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Polygon(
points={{-34,-53},{-34,53},{34,57},{34,-57},{-34,-53}},
fillColor={255,255,255},
fillPattern=FillPattern.Solid,
pattern=LinePattern.None),
Line(
points={{-100,-50},{-100,50}},
arrow={Arrow.Filled,Arrow.Filled},
pattern=LinePattern.Dot),
Text(
extent={{-99,36},{-69,30}},
textColor={0,0,255},
textString="crossAreas[1]"),
Line(
points={{-100,70},{-34,70}},
arrow={Arrow.Filled,Arrow.Filled},
pattern=LinePattern.Dot),
Text(
extent={{0,36},{40,30}},
textColor={0,0,255},
textString="crossAreas[2:n-1]"),
Line(
points={{100,-60},{100,60}},
arrow={Arrow.Filled,Arrow.Filled},
pattern=LinePattern.Dot),
Text(
extent={{100.5,36},{130.5,30}},
textColor={0,0,255},
textString="crossAreas[n]"),
Line(
points={{-34,52},{-34,-53}},
pattern=LinePattern.Dash),
Line(
points={{34,57},{34,-57}},
pattern=LinePattern.Dash),
Line(
points={{34,70},{100,70}},
arrow={Arrow.Filled,Arrow.Filled},
pattern=LinePattern.Dot),
Line(
points={{-34,70},{34,70}},
arrow={Arrow.Filled,Arrow.Filled},
pattern=LinePattern.Dot),
Text(
extent={{-30,77},{30,71}},
textColor={0,0,255},
textString="lengths[2:n-1]"),
Line(
points={{-100,-70},{0,-70}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{-80,-63},{-20,-69}},
textColor={0,0,255},
textString="flowModel.dps_fg[1]"),
Line(
points={{0,-70},{100,-70}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{20.5,-63},{80,-69}},
textColor={0,0,255},
textString="flowModel.dps_fg[2:n-1]"),
Line(
points={{-95,0},{-5,0}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{-62,7},{-32,1}},
textColor={0,0,255},
textString="m_flows[2]"),
Line(
points={{5,0},{95,0}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{34,7},{64,1}},
textColor={0,0,255},
textString="m_flows[3:n]"),
Line(
points={{-150,0},{-105,0}},
arrow={Arrow.None,Arrow.Filled}),
Line(
points={{105,0},{150,0}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{-140,7},{-110,1}},
textColor={0,0,255},
textString="m_flows[1]"),
Text(
extent={{111,7},{141,1}},
textColor={0,0,255},
textString="m_flows[n+1]"),
Text(
extent={{35,-92},{100,-98}},
textColor={0,0,255},
textString="(ModelStructure av_vb, n=3)"),
Line(
points={{-100,-50},{-100,-86}},
pattern=LinePattern.Dot),
Line(
points={{0,-55},{0,-86}},
pattern=LinePattern.Dot),
Line(
points={{100,-60},{100,-86}},
pattern=LinePattern.Dot),
Ellipse(
extent={{-5,5},{5,-5}},
pattern=LinePattern.None,
fillPattern=FillPattern.Solid),
Text(
extent={{3,-4},{33,-10}},
textColor={0,0,255},
textString="states[2:n-1]"),
Ellipse(
extent={{95,5},{105,-5}},
pattern=LinePattern.None,
fillPattern=FillPattern.Solid),
Text(
extent={{104,-4},{124,-10}},
textColor={0,0,255},
textString="states[n]"),
Ellipse(
extent={{-105,5},{-95,-5}},
pattern=LinePattern.None,
fillPattern=FillPattern.Solid),
Text(
extent={{-96,-4},{-76,-10}},
textColor={0,0,255},
textString="states[1]"),
Text(
extent={{-99.5,30},{-69.5,24}},
textColor={0,0,255},
textString="dimensions[1]"),
Text(
extent={{-0.5,30},{40,24}},
textColor={0,0,255},
textString="dimensions[2:n-1]"),
Text(
extent={{100.5,30},{130.5,24}},
textColor={0,0,255},
textString="dimensions[n]"),
Line(
points={{-34,73},{-34,52}},
pattern=LinePattern.Dot),
Line(
points={{34,73},{34,57}},
pattern=LinePattern.Dot),
Line(
points={{-100,50},{100,60}},
thickness=0.5),
Line(
points={{-100,-50},{100,-60}},
thickness=0.5),
Line(
points={{-100,73},{-100,50}},
pattern=LinePattern.Dot),
Line(
points={{100,73},{100,60}},
pattern=LinePattern.Dot),
Line(
points={{0,-55},{0,55}},
arrow={Arrow.Filled,Arrow.Filled},
pattern=LinePattern.Dot),
Line(
points={{-34,11},{34,11}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{5,18},{25,12}},
textColor={0,0,255},
textString="vs[2:n-1]"),
Text(
extent={{-72,18},{-62,12}},
textColor={0,0,255},
textString="vs[1]"),
Line(
points={{-100,11},{-34,11}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{63,18},{73,12}},
textColor={0,0,255},
textString="vs[n]"),
Line(
points={{34,11},{100,11}},
arrow={Arrow.None,Arrow.Filled}),
Text(
extent={{-80,-75},{-20,-81}},
textColor={0,0,255},
textString="flowModel.pathLengths[1]"),
Line(
points={{-100,-82},{0,-82}},
arrow={Arrow.Filled,Arrow.Filled}),
Line(
points={{0,-82},{100,-82}},
arrow={Arrow.Filled,Arrow.Filled}),
Text(
extent={{15,-75},{85,-81}},
textColor={0,0,255},
textString="flowModel.pathLengths[2:n-1]"),
Text(
extent={{-100,77},{-37,71}},
textColor={0,0,255},
textString="lengths[1]"),
Text(
extent={{34,77},{100,71}},
textColor={0,0,255},
textString="lengths[n]")}));
end PartialTwoPortFlow;
package FlowModels
"Flow models for pipes, including wall friction, static head and momentum flow"
extends Modelica.Icons.Package;
partial model PartialStaggeredFlowModel
"Base class for momentum balances in flow models"
//
// Internal interface
// (not exposed to GUI; needs to be hard coded when using this model
//
replaceable package Medium =
Modelica.Media.Interfaces.PartialMedium "Medium in the component"
annotation(Dialog(tab="Internal interface",enable=false));
parameter Integer n=2 "Number of discrete flow volumes"
annotation(Dialog(tab="Internal interface",enable=false));
// Inputs
input Medium.ThermodynamicState[n] states
"Thermodynamic states along design flow";
input SI.Velocity[n] vs
"Mean velocities of fluid flow";
// Geometry parameters and inputs
parameter Real nParallel
"Number of identical parallel flow devices"
annotation(Dialog(tab="Internal interface",enable=false,group="Geometry"));
input SI.Area[n] crossAreas
"Cross flow areas at segment boundaries";
input SI.Length[n] dimensions
"Characteristic dimensions for fluid flow (diameters for pipe flow)";
input Modelica.Fluid.Types.Roughness[n] roughnesses
"Average height of surface asperities";
// Static head
input SI.Length[n-1] dheights
"Height(states[2:n]) - Height(states[1:n-1])";
parameter SI.Acceleration g=system.g
"Constant gravity acceleration"
annotation(Dialog(tab="Internal interface",enable=false,group="Static head"));
// Assumptions
parameter Boolean allowFlowReversal=system.allowFlowReversal
"= true, if flow reversal is enabled, otherwise restrict flow to design direction (states[1] -> states[n+1])"
annotation(Dialog(tab="Internal interface",enable=false,group="Assumptions"), Evaluate=true);
parameter Modelica.Fluid.Types.Dynamics momentumDynamics=system.momentumDynamics
"Formulation of momentum balance"
annotation(Dialog(tab="Internal interface",enable=false,group = "Assumptions"), Evaluate=true);
// Initialization
parameter Medium.MassFlowRate m_flow_start=system.m_flow_start
"Start value of mass flow rates"
annotation(Dialog(tab="Internal interface",enable=false,group = "Initialization"));
parameter Medium.AbsolutePressure p_a_start
"Start value for p[1] at design inflow"
annotation(Dialog(tab="Internal interface",enable=false,group = "Initialization"));
parameter Medium.AbsolutePressure p_b_start
"Start value for p[n+1] at design outflow"
annotation(Dialog(tab="Internal interface",enable=false,group = "Initialization"));
//
// Implementation of momentum balance
//
extends Modelica.Fluid.Interfaces.PartialDistributedFlow(
final m = n-1);
// Advanced parameters
parameter Boolean useUpstreamScheme = true
"= false to average upstream and downstream properties across flow segments"
annotation(Dialog(group="Advanced"), Evaluate=true);
parameter Boolean use_Ib_flows = momentumDynamics <> Types.Dynamics.SteadyState
"= true to consider differences in flow of momentum through boundaries"
annotation(Dialog(group="Advanced"), Evaluate=true);
// Variables
Medium.Density[n] rhos = if use_rho_nominal then fill(rho_nominal, n) else Medium.density(states);
Medium.Density[n-1] rhos_act "Actual density per segment";
Medium.DynamicViscosity[n] mus = if use_mu_nominal then fill(mu_nominal, n) else Medium.dynamicViscosity(states);
Medium.DynamicViscosity[n-1] mus_act "Actual viscosity per segment";
// Variables
SI.Pressure[n-1] dps_fg(each start = (p_a_start - p_b_start)/(n-1))
"Pressure drop between states";
// Reynolds Number
parameter SI.ReynoldsNumber Re_turbulent = 4000
"Start of turbulent regime, depending on type of flow device";
parameter Boolean show_Res = false
"= true, if Reynolds numbers are included for plotting"
annotation (Evaluate=true, Dialog(group="Diagnostics"));
SI.ReynoldsNumber[n] Res=Modelica.Fluid.Pipes.BaseClasses.CharacteristicNumbers.ReynoldsNumber(
vs,
rhos,
mus,
dimensions) if show_Res "Reynolds numbers";
Medium.MassFlowRate[n-1] m_flows_turbulent=
{nParallel*(crossAreas[i] + crossAreas[i+1])/(dimensions[i] + dimensions[i+1])*mus_act[i]*Re_turbulent for i in 1:n-1} if
show_Res "Start of turbulent flow";
protected