Skip to content

Commit a6da1d2

Browse files
committed
add proper initialization to Generic models and corresponding examples
1 parent d83c7be commit a6da1d2

File tree

6 files changed

+324
-214
lines changed

6 files changed

+324
-214
lines changed

PowerSystems/Examples/Network/NetworkControlled.mo

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
within PowerSystems.Examples.Network;
2-
model NetworkControlled
3-
"see Oeding, Oswald: Elektrische Kraftwerke und Netze, section 14.2.6: Leistungsfluss in Ringnetzen"
2+
model NetworkControlled "Dynamic power flow calculation with two generators"
43
extends Modelica.Icons.Example;
54

65
PowerSystems.Generic.Impedance impedance1(R=2, L=0)
@@ -49,37 +48,38 @@ model NetworkControlled
4948
origin={50,30},
5049
extent={{-10,-10},{10,10}},
5150
rotation=270)));
52-
PowerSystems.Generic.EMF eMF annotation (Placement(transformation(
53-
extent={{-30,70},{-10,90}}, rotation=0)));
54-
Modelica.Mechanics.Rotational.Components.Inertia inertia(
55-
J=1e3, w(start=2*pi*50))
56-
annotation (Placement(transformation(extent={{-60,70},{-40,90}},
57-
rotation=0)));
58-
PowerSystems.Generic.EMF eMF1
59-
annotation (Placement(transformation(extent={
60-
{70,70},{90,90}}, rotation=0)));
51+
PowerSystems.Generic.Generator generator1 annotation (Placement(
52+
transformation(extent={{-30,70},{-10,90}}, rotation=0)));
6153
Modelica.Mechanics.Rotational.Components.Inertia inertia1(
62-
J=1e3, w(start=2*pi*50))
54+
J=1e3,
55+
w(start=system.w_nom/generator1.pp),
56+
a(start=0)) annotation (Placement(transformation(extent={{-60,
57+
70},{-40,90}}, rotation=0)));
58+
PowerSystems.Generic.Generator generator2(pp=8) annotation (Placement(
59+
transformation(extent={{70,70},{90,90}}, rotation=0)));
60+
Modelica.Mechanics.Rotational.Components.Inertia inertia2(
61+
J=1e3,
62+
w(start=system.w_nom/generator2.pp),
63+
a(start=0))
6364
annotation (Placement(transformation(extent={{40,70},{60,90}}, rotation=
6465
0)));
65-
Modelica.Mechanics.Rotational.Sources.Torque torque(useSupport=false)
66-
annotation (Placement(transformation(extent={{-90,70},{-70,90}},
67-
rotation=0)));
66+
Modelica.Mechanics.Rotational.Sources.Torque turbine1(useSupport=false)
67+
annotation (Placement(transformation(extent={{-90,70},{-70,90}}, rotation=0)));
6868
Modelica.Mechanics.Rotational.Sensors.SpeedSensor angularVelocity
6969
annotation (Placement(transformation(extent={{-50,110},{-70,130}},
7070
rotation=0)));
71-
Modelica.Mechanics.Rotational.Sources.Torque torque1(useSupport=false)
72-
annotation (Placement(transformation(extent={{10,70},{30,90}}, rotation=
73-
0)));
71+
Modelica.Mechanics.Rotational.Sources.Torque turbine2(useSupport=false)
72+
annotation (Placement(transformation(extent={{10,70},{30,90}}, rotation=0)));
7473
Modelica.Blocks.Sources.Trapezoid disturbance(
7574
width=30,
76-
amplitude=2e4,
77-
offset=2e4,
7875
rising=0,
7976
falling=0,
80-
period=60) annotation (Placement(transformation(extent={{30,110},{10,
77+
period=60,
78+
amplitude=2e3,
79+
offset=2e3)
80+
annotation (Placement(transformation(extent={{30,110},{10,
8181
130}}, rotation=0)));
82-
Modelica.Blocks.Sources.Constant const(k=50)
82+
Modelica.Blocks.Sources.Constant const(k=system.f_nom)
8383
annotation (Placement(transformation(extent={{-160,70},{-140,90}},
8484
rotation=0)));
8585
Modelica.Blocks.Continuous.LimPID frequencyPowerControl(
@@ -92,6 +92,20 @@ model NetworkControlled
9292
rotation=0)));
9393
Modelica.Blocks.Math.Gain frequency(k=1/(2*pi))
9494
annotation (Placement(transformation(extent={{-80,110},{-100,130}})));
95+
inner System system( fType_par=false)
96+
annotation (Placement(transformation(extent={{-170,110},{-150,130}})));
97+
Interfaces.Sender sender1(H=0.5*inertia1.J*inertia1.w^2/1e6, w=generator1.w)
98+
annotation (Placement(transformation(extent={{-26,100},{-14,112}})));
99+
Interfaces.Sender sender2(H=0.5*inertia2.J*inertia2.w^2/1e6, w=generator2.w)
100+
annotation (Placement(transformation(extent={{74,100},{86,112}})));
101+
initial equation
102+
if system.steadyIni then
103+
inertia1.a = 0;
104+
else
105+
inertia1.w = system.omega/generator1.pp;
106+
end if;
107+
inertia1.phi = system.theta/generator1.pp;
108+
95109
equation
96110
connect(impedance1.terminal_n, impedance2.terminal_p)
97111
annotation (Line(points={{-50,-20},{-50,-40}}, color={0,120,120}));
@@ -113,27 +127,24 @@ equation
113127
annotation (Line(points={{-50,20},{-50,0}}, color={0,120,120}));
114128
connect(transformer2.terminal_n, impedance5.terminal_p)
115129
annotation (Line(points={{50,20},{50,0}}, color={0,120,120}));
116-
connect(inertia.flange_b, eMF.flange) annotation (Line(points={{-40,80},{
117-
-30,80}}, color={0,0,0}));
118-
connect(eMF.terminal, transformer1.terminal_p) annotation (Line(points={{
119-
-10,80},{-10,60},{-50,60},{-50,40}}, color={0,120,120}));
120-
connect(inertia1.flange_b, eMF1.flange) annotation (Line(points={{60,80},
121-
{70,80}}, color={0,0,0}));
122-
connect(eMF1.terminal, transformer2.terminal_p) annotation (Line(points={
123-
{90,80},{90,60},{50,60},{50,40}}, color={0,120,120}));
124-
connect(torque.flange, inertia.flange_a)
130+
connect(inertia1.flange_b, generator1.flange)
131+
annotation (Line(points={{-40,80},{-30,80}}, color={0,0,0}));
132+
connect(generator1.terminal, transformer1.terminal_p) annotation (Line(points=
133+
{{-10,80},{-10,60},{-50,60},{-50,40}}, color={0,120,120}));
134+
connect(inertia2.flange_b, generator2.flange)
135+
annotation (Line(points={{60,80},{70,80}}, color={0,0,0}));
136+
connect(generator2.terminal, transformer2.terminal_p) annotation (Line(points=
137+
{{90,80},{90,60},{50,60},{50,40}}, color={0,120,120}));
138+
connect(turbine1.flange, inertia1.flange_a)
125139
annotation (Line(points={{-70,80},{-60,80}}, color={0,0,0}));
126-
connect(torque1.flange, inertia1.flange_a)
140+
connect(turbine2.flange, inertia2.flange_a)
127141
annotation (Line(points={{30,80},{40,80}}, color={0,0,0}));
128-
connect(disturbance.y, torque1.tau)
129-
annotation (Line(points={{9,120},{0,120},
130-
{0,80},{8,80}}, color={0,0,127}));
131-
connect(angularVelocity.flange, inertia.flange_b)
132-
annotation (Line(points={{-50,120},
133-
{-40,120},{-40,80}}, color={0,0,0}));
134-
connect(frequencyPowerControl.y, torque.tau)
135-
annotation (Line(points={{-99,80},{-92,80}},
136-
color={0,0,127}));
142+
connect(disturbance.y, turbine2.tau)
143+
annotation (Line(points={{9,120},{0,120},{0,80},{8,80}}, color={0,0,127}));
144+
connect(angularVelocity.flange, inertia1.flange_b)
145+
annotation (Line(points={{-50,120},{-40,120},{-40,80}}, color={0,0,0}));
146+
connect(frequencyPowerControl.y, turbine1.tau)
147+
annotation (Line(points={{-99,80},{-92,80}}, color={0,0,127}));
137148
connect(const.y, frequencyPowerControl.u_s) annotation (Line(
138149
points={{-139,80},{-122,80}},
139150
color={0,0,127},
@@ -146,8 +157,23 @@ equation
146157
points={{-101,120},{-110,120},{-110,92}},
147158
color={0,0,127},
148159
smooth=Smooth.None));
149-
annotation (Diagram(coordinateSystem(
150-
preserveAspectRatio=true,
160+
connect(system.receiveFreq, sender1.sendFreq) annotation (Line(
161+
points={{-168,128},{-168,138},{-20,138},{-20,104.08}},
162+
color={120,0,120},
163+
smooth=Smooth.None));
164+
connect(system.receiveFreq, sender2.sendFreq) annotation (Line(
165+
points={{-168,128},{-168,138},{80,138},{80,104.08}},
166+
color={120,0,120},
167+
smooth=Smooth.None));
168+
annotation (Documentation(info="<html>
169+
<p>The fixed voltage sources of NetworkOpened have been replaced with generators.
170+
Generator1 provides for primary frequency control, while generator2 introduces fluctuations.</p>
171+
<p>Note the computation of the average sytem frequency in the global system model, basing on senders for
172+
each generator. This is needed for initialization (see initial equations in
173+
the text view). The initialization of the simulation corresponds to a black start in the real world.</p>
174+
<p>The remainder of the PowerFlow library hides this mechanism in the composed generator or plant models.</p>
175+
</html>"), Diagram(coordinateSystem(
176+
preserveAspectRatio=false,
151177
extent={{-180,-100},{100,140}},
152178
initialScale=0.1), graphics),
153179
experiment(StopTime=120));

PowerSystems/Examples/Network/package.mo

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package Network "Network flow calculations"
44

55

66
model NetworkLoop
7-
"See Oeding, Oswald: Elektrische Kraftwerke und Netze, section 14.2.6: Leistungsfluss in Ringnetzen"
7+
"Simple textbook example for a steady-state power flow calculation"
88
extends Modelica.Icons.Example;
99

1010
PowerSystems.Generic.FixedVoltageSource
@@ -59,6 +59,8 @@ package Network "Network flow calculations"
5959
origin={50,30},
6060
extent={{-10,-10},{10,10}},
6161
rotation=270)));
62+
inner System system
63+
annotation (Placement(transformation(extent={{-100,80},{-80,100}})));
6264
equation
6365
connect(impedance1.terminal_n, impedance2.terminal_p)
6466
annotation (Line(points={{-50,-20},{-50,-40}}, color={0,120,120}));
@@ -91,15 +93,18 @@ package Network "Network flow calculations"
9193
points={{50,-60},{50,-80},{10,-80}},
9294
color={0,120,120},
9395
smooth=Smooth.None));
94-
annotation (preferredView="diagram", Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
96+
annotation (Documentation(info="<html>
97+
<p>This textbook example demonstrates a basic power flow calculation.</p>
98+
<p>See Oeding, Oswald: Elektrische Kraftwerke und Netze, section 14.2.6: Leistungsfluss in Ringnetzen.</p>
99+
</html>"), Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
95100
-100},{100,100}}),
96101
graphics),
97102
experiment(StopTime=1));
98103
end NetworkLoop;
99104

100105

101106
model NetworkOpened
102-
"See Oeding, Oswald: Elektrische Kraftwerke und Netze, section 14.2.6: Leistungsfluss in Ringnetzen"
107+
"Steady-state power flow calculation with two voltage sources"
103108
extends Modelica.Icons.Example;
104109

105110
PowerSystems.Generic.FixedVoltageSource
@@ -160,6 +165,8 @@ package Network "Network flow calculations"
160165
origin={50,30},
161166
extent={{-10,-10},{10,10}},
162167
rotation=270)));
168+
inner System system
169+
annotation (Placement(transformation(extent={{-100,80},{-80,100}})));
163170
equation
164171
connect(impedance1.terminal_n, impedance2.terminal_p)
165172
annotation (Line(points={{-50,-20},{-50,-40}}, color={0,120,120}));
@@ -185,10 +192,16 @@ package Network "Network flow calculations"
185192
annotation (Line(points={{50,60},{50,40}}, color={0,120,120}));
186193
connect(transformer2.terminal_n, impedance5.terminal_p)
187194
annotation (Line(points={{50,20},{50,0}}, color={0,120,120}));
188-
annotation (preferredView="diagram", Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
195+
annotation (Documentation(info="<html>
196+
<p>The loop of the NetworkLoop example has been opened and a second voltage source was added.</p>
197+
</html>"), Diagram(coordinateSystem(preserveAspectRatio=false, extent={{-100,
189198
-100},{100,100}}),
190199
graphics),
191200
experiment(StopTime=1));
192201
end NetworkOpened;
193202

203+
204+
annotation(Documentation(info="<html><p>The Network examples demonstrate the evolution of
205+
a simple powerflow calculation from a textbook to a dynamic simulation model with power/frequency control.
206+
</p></html>"));
194207
end Network;

0 commit comments

Comments
 (0)