forked from modelica/ModelicaStandardLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicPipeEnergyConservationCheck2.mo
154 lines (154 loc) · 6.98 KB
/
DynamicPipeEnergyConservationCheck2.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
within ModelicaTest.Fluid.TestComponents.Pipes;
model DynamicPipeEnergyConservationCheck2
"Test DynamicPipe for total energy conservation using each discretization scheme"
extends Modelica.Icons.Example;
Real total_AV_B_a, total_AV_B_b;
Real total_A_VB_a, total_A_VB_b;
Real total_AV_VB_a, total_AV_VB_b;
Real total_A_V_B_a, total_A_V_B_b;
Modelica.Fluid.Pipes.DynamicPipe pipeAV_B(
length=100,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
use_T_start=false,
h_start=3000e3,
m_flow_start=1,
diameter=0.3,
redeclare model FlowModel =
Modelica.Fluid.Pipes.BaseClasses.FlowModels.NominalLaminarFlow (
useUpstreamScheme=false,
use_Ib_flows=true,
dp_nominal=100000,
m_flow_nominal=1),
nNodes=30,
p_a_start=200000,
p_b_start=100000,
modelStructure=Modelica.Fluid.Types.ModelStructure.av_b,
useInnerPortProperties=true)
annotation (Placement(transformation(extent={{-10,40},{10,60}})));
inner Modelica.Fluid.System system
annotation (Placement(transformation(extent={{-100,80},{-80,100}})));
Modelica.Fluid.Sources.MassFlowSource_h boundary(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
m_flow=1) annotation (Placement(transformation(extent={{-40,40},{-20,60}})));
Modelica.Fluid.Sources.FixedBoundary boundary1(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
p=100000) annotation (Placement(transformation(extent={{40,40},{20,60}})));
Modelica.Fluid.Pipes.DynamicPipe pipeA_VB(
length=100,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
use_T_start=false,
h_start=3000e3,
m_flow_start=1,
diameter=0.3,
redeclare model FlowModel =
Modelica.Fluid.Pipes.BaseClasses.FlowModels.NominalLaminarFlow (
useUpstreamScheme=false,
use_Ib_flows=true,
dp_nominal=100000,
m_flow_nominal=1),
nNodes=30,
p_a_start=200000,
p_b_start=100000,
modelStructure=Modelica.Fluid.Types.ModelStructure.a_vb,
useInnerPortProperties=true)
annotation (Placement(transformation(extent={{-10,0},{10,20}})));
Modelica.Fluid.Sources.MassFlowSource_h boundary6(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
m_flow=1) annotation (Placement(transformation(extent={{-40,0},{-20,20}})));
Modelica.Fluid.Sources.FixedBoundary boundary7(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
p=100000) annotation (Placement(transformation(extent={{40,0},{20,20}})));
Modelica.Fluid.Pipes.DynamicPipe pipeAV_VB(
length=100,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
use_T_start=false,
h_start=3000e3,
m_flow_start=1,
diameter=0.3,
redeclare model FlowModel =
Modelica.Fluid.Pipes.BaseClasses.FlowModels.NominalLaminarFlow (
useUpstreamScheme=false,
use_Ib_flows=true,
dp_nominal=100000,
m_flow_nominal=1),
nNodes=30,
p_a_start=200000,
p_b_start=100000,
modelStructure=Modelica.Fluid.Types.ModelStructure.av_vb,
useInnerPortProperties=true)
annotation (Placement(transformation(extent={{-10,-40},{10,-20}})));
Modelica.Fluid.Sources.MassFlowSource_h boundary12(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
m_flow=1) annotation (Placement(transformation(extent={{-40,-40},{-20,-20}})));
Modelica.Fluid.Sources.FixedBoundary boundary13(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
p=100000) annotation (Placement(transformation(extent={{40,-40},{20,-20}})));
Modelica.Fluid.Pipes.DynamicPipe pipeA_V_B(
length=100,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
use_T_start=false,
h_start=3000e3,
m_flow_start=1,
diameter=0.3,
redeclare model FlowModel =
Modelica.Fluid.Pipes.BaseClasses.FlowModels.NominalLaminarFlow (
useUpstreamScheme=false,
use_Ib_flows=true,
dp_nominal=100000,
m_flow_nominal=1),
nNodes=30,
p_a_start=200000,
p_b_start=100000,
modelStructure=Modelica.Fluid.Types.ModelStructure.a_v_b,
useInnerPortProperties=true)
annotation (Placement(transformation(extent={{-10,-80},{10,-60}})));
Modelica.Fluid.Sources.MassFlowSource_h boundary18(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
m_flow=1) annotation (Placement(transformation(extent={{-40,-80},{-20,-60}})));
Modelica.Fluid.Sources.FixedBoundary boundary19(
nPorts=1,
redeclare package Medium = Modelica.Media.Air.DryAirNasa,
p=100000) annotation (Placement(transformation(extent={{40,-80},{20,-60}})));
equation
total_AV_B_a = pipeAV_B.H_flows[1] + pipeAV_B.m_flows[1]*pipeAV_B.flowModel.vs[1]^2/2;
total_AV_B_b = pipeAV_B.H_flows[end] + pipeAV_B.m_flows[end]*pipeAV_B.flowModel.vs[end]^2/2;
total_A_VB_a = pipeA_VB.H_flows[1] + pipeA_VB.m_flows[1]*pipeA_VB.flowModel.vs[1]^2/2;
total_A_VB_b = pipeA_VB.H_flows[end] + pipeA_VB.m_flows[end]*pipeA_VB.flowModel.vs[end]^2/2;
total_AV_VB_a = pipeAV_VB.H_flows[1] + pipeAV_VB.m_flows[1]*pipeAV_VB.flowModel.vs[1]^2/2;
total_AV_VB_b = pipeAV_VB.H_flows[end] + pipeAV_VB.m_flows[end]*pipeAV_VB.flowModel.vs[end]^2/2;
total_A_V_B_a = pipeA_V_B.H_flows[1] + pipeA_V_B.m_flows[1]*pipeA_V_B.flowModel.vs[1]^2/2;
total_A_V_B_b = pipeA_V_B.H_flows[end] + pipeA_V_B.m_flows[end]*pipeA_V_B.flowModel.vs[end]^2/2;
assert(time < 500 or Modelica.Math.isEqual(total_AV_B_a, total_AV_B_b, 1), "Energy not conserved!");
assert(time < 500 or Modelica.Math.isEqual(total_A_VB_a, total_A_VB_b, 1), "Energy not conserved!");
assert(time < 500 or Modelica.Math.isEqual(total_AV_VB_a, total_AV_VB_b, 1), "Energy not conserved!");
assert(time < 500 or Modelica.Math.isEqual(total_A_V_B_a, total_A_V_B_b, 1), "Energy not conserved!");
connect(boundary.ports[1], pipeAV_B.port_a)
annotation (Line(points={{-20,50},{-10,50}}, color={0,127,255}));
connect(pipeAV_B.port_b, boundary1.ports[1])
annotation (Line(points={{10,50},{20,50}}, color={0,127,255}));
connect(boundary6.ports[1], pipeA_VB.port_a)
annotation (Line(points={{-20,10},{-10,10}}, color={0,127,255}));
connect(pipeA_VB.port_b, boundary7.ports[1])
annotation (Line(points={{10,10},{20,10}}, color={0,127,255}));
connect(boundary12.ports[1], pipeAV_VB.port_a)
annotation (Line(points={{-20,-30},{-10,-30}}, color={0,127,255}));
connect(pipeAV_VB.port_b, boundary13.ports[1])
annotation (Line(points={{10,-30},{20,-30}}, color={0,127,255}));
connect(boundary18.ports[1], pipeA_V_B.port_a)
annotation (Line(points={{-20,-70},{-10,-70}}, color={0,127,255}));
connect(pipeA_V_B.port_b, boundary19.ports[1])
annotation (Line(points={{10,-70},{20,-70}}, color={0,127,255}));
annotation (experiment(StopTime=500),
Documentation(info="<html>
Test of energy conservation in dynamic pipes.
</html>"),
Diagram(coordinateSystem(extent={{-100,-100},{100,100}})),
Icon(coordinateSystem(extent={{-100,-100},{100,100}})));
end DynamicPipeEnergyConservationCheck2;