Skip to content

Commit 34ba0e3

Browse files
committed
Fix the examples by proper initialisation and protection
Introduces a small flow rate epsilon to avoid division by zero when calculating blade angles at zero flow. Adds a conditional check for total turbine power to prevent division by zero when computing efficiency.
1 parent b5d3303 commit 34ba0e3

10 files changed

Lines changed: 178 additions & 224 deletions

File tree

OpenHPL/ElectroMech/Generators/SynchGen.mo

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ model SynchGen "Simple model of the generator connected to the grid"
3535
Dialog(group = "Mechanical part"));
3636
parameter Real k_b = 1000 "Friction factor in the generator bearing box, W*s3/rad3" annotation (
3737
Dialog(group = "Mechanical part"));
38+
parameter SI.AngularVelocity w_min = Wm_op * 1e-3 "Minimum angular velocity to prevent division by zero" annotation (
39+
Dialog(group = "Mechanical part"));
3840
parameter Boolean UseFrequencyOutput = true "If checked - get a connector for frequency output" annotation (
3941
choices(checkBox = true),
4042
Dialog(group = "Network")), SelfInitialization = false "If checked - specify initial values" annotation (
@@ -89,7 +91,7 @@ equation
8991
Vt = sqrt((EEd - Ra * Id - xxq * Iq) ^ 2 + (EEq - Ra * Iq + xxd * Id) ^ 2);
9092
It = sqrt(Id ^ 2 + Iq ^ 2);
9193
Pe = 3 * (EEd * Id + EEq * Iq);
92-
Qe = sqrt(9 * Vt ^ 2 * It ^ 2 - Pe ^ 2);
94+
Qe = sqrt(noEvent(max(9 * Vt ^ 2 * It ^ 2 - Pe ^ 2, 0)));
9395
// dynamic equations
9496
TTqo * der(EEd) = (-EEd) + (xxq - xq) * Iq;
9597
TTdo * der(EEq) = (-EEq) + (xd - xxd) * Id + Ef;
@@ -105,7 +107,7 @@ equation
105107
der(Vstabilizer) = ((-Vstabilizer) + KF * der(Ef)) / TFE;
106108
// Mechanical equation
107109
W_fa = 0.5 * k_b * w ^ 2;
108-
der(w) = (Wdot_ts - Pe) / (J * w);
110+
der(w) = (Wdot_ts - Pe) / (J * noEvent(max(w, w_min)));
109111
// - W_fa;
110112
//
111113
annotation (preferredView="info",

OpenHPL/ElectroMech/Turbines/Francis.mo

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ model Francis "Model of the Francis turbine"
8585
Placement(transformation(origin={-120,-80}, extent={{-20,-20},
8686
{20,20}})));
8787
protected
88+
parameter SI.VolumeFlowRate Vdot_eps = Vdot_n * 1e-4 "Small flow rate to regularize equations at zero flow";
8889
Modelica.Blocks.Interfaces.RealOutput p_out = Wdot_s "Internal connector for output power" annotation (Placement(transformation(
8990
extent={{-10,-10},{10,10}},
9091
rotation=90,
@@ -197,16 +198,16 @@ equation
197198
alpha1 = phi - psi;
198199
// Blade angles relation
199200
cot_a1 = 1 / Modelica.Math.tan(alpha1);
200-
cot_a2 = cot_b2 + w * R_2 / (Vdot / A_2);
201+
cot_a2 = cot_b2 + w * R_2 / (noEvent(max(Vdot, Vdot_eps)) / A_2);
201202
cot_b1 =1/Modelica.Math.tan(Modelica.Units.Conversions.from_deg(beta1));
202203
cot_b2 =1/Modelica.Math.tan(Modelica.Units.Conversions.from_deg(beta2));
203-
cot_g1 = cot_a1 - w * R_1 / (Vdot / A_1);
204+
cot_g1 = cot_a1 - w * R_1 / (noEvent(max(Vdot, Vdot_eps)) / A_1);
204205
// pressure drop through the turbine
205-
dp_r * Vdot + 0.5 * mdot * Vdot ^ 2 * (1 / A_0 ^ 2 - 1 / A_2 ^ 2) = Wdot_t;
206+
dp_r * noEvent(max(Vdot, Vdot_eps)) + 0.5 * mdot * Vdot ^ 2 * (1 / A_0 ^ 2 - 1 / A_2 ^ 2) = Wdot_t;
206207
Wdot_t = Wdot_s + Wdot_ft;
207208
dp_r = p_r1 - p_tr2;
208209
// turbine efficiency
209-
coef = Wdot_s / Wdot_t;
210+
coef = if noEvent(abs(Wdot_t) > 1e-6) then Wdot_s / Wdot_t else 0;
210211
// connectors
211212
p_tr2 = o.p;
212213
i.mdot+o.mdot=0;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
within OpenHPL.Examples.WithOpenIPSL;
2-
model DetailedGenFrancis
3-
extends SimpleGenFrancis(redeclare Waterway.PenstockKP penstock(
2+
model DetailedGen
3+
extends SimpleGen( redeclare Waterway.PenstockKP penstock(
44
vertical=true,
55
H=428.5,
66
D_i=3), data(SteadyState=false));
77
annotation (experiment(StopTime=2000));
8-
end DetailedGenFrancis;
8+
end DetailedGen;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
within OpenHPL.Examples.WithOpenIPSL;
2+
model SimpleGen "Synergy with OpenIPSL library(generator)"
3+
extends Modelica.Icons.Example;
4+
extends OpenIPSL.Tests.BaseClasses.MachineTestBase(pwLine2(displayPF=true), pwLine1(displayPF=true));
5+
OpenHPL.Waterway.Reservoir reservoir(h_0=48,
6+
fixElevation=true,
7+
z_0=500) annotation (Placement(transformation(
8+
origin={-80,-80},
9+
extent={{-10,-10},{10,10}})));
10+
OpenHPL.Waterway.Pipe intake(H=23, D_i=3)
11+
annotation (Placement(transformation(extent={{-66,-90},{-46,-70}})));
12+
OpenHPL.Waterway.Pipe discharge(L=600, H=0.5) annotation (Placement(transformation(extent={{48,-90},{68,-70}})));
13+
OpenHPL.Waterway.Reservoir tail(h_0=5) annotation (Placement(transformation(
14+
origin={84,-80},
15+
extent={{-10,10},{10,-10}},
16+
rotation=180)));
17+
replaceable
18+
Waterway.Pipe penstock(
19+
vertical=true,
20+
L=600,
21+
H=428.5,
22+
D_i=3) constrainedby Interfaces.TwoContacts
23+
annotation (Placement(transformation(
24+
origin={0,-80},
25+
extent={{-10,-10},{10,10}})));
26+
OpenHPL.Waterway.SurgeTank surgeTank(h_0=70.939) annotation (Placement(transformation(
27+
origin={-30,-80},
28+
extent={{-10,-10},{10,10}})));
29+
ElectroMech.Turbines.Turbine turbine(
30+
H_n=460,
31+
Vdot_n=24.3,
32+
Pmax(displayUnit="MW") = 125000000,
33+
enable_P_out=true)
34+
annotation (Placement(transformation(
35+
origin={32,-80},
36+
extent={{-10,-10},{10,10}})));
37+
inner OpenHPL.Data data(SteadyState=true, Vdot_0=4.49)
38+
annotation (Placement(transformation(
39+
origin={-90,70},
40+
extent={{-10,-10},{10,10}})));
41+
OpenIPSL.Electrical.Machines.PSAT.Order2 generator(
42+
D=0,
43+
M=10,
44+
P_0=16035269.869201,
45+
Q_0=11859436.505981,
46+
Sn=120000000,
47+
Vn=400000,
48+
ra=0.001,
49+
w(fixed=true),
50+
x1d=0.302) annotation (Placement(transformation(extent={{-40,-10},{-20,10}})));
51+
OpenHPL.Controllers.Governor governor(Pn=103, Y_gv_ref = 0.1)
52+
annotation (Placement(transformation(origin={0,-40}, extent = {{-10, -10}, {10, 10}})));
53+
//(a = 7.862E-25, c = 1.108E-08, d = -5.344E-02, b = -1.010E-16)
54+
Modelica.Blocks.Math.Gain fpu_to_fSI(k=SysData.fn) annotation (Placement(transformation(
55+
origin={-60,-52},
56+
extent={{6,6},{-6,-6}},
57+
rotation=180)));
58+
Modelica.Blocks.Sources.Ramp power(duration = 1, height = +1e6, offset = 12e6,
59+
startTime=200) annotation (
60+
Placement(transformation(origin={-36,-36}, extent={{-8,-8},{8,8}})));
61+
equation
62+
connect(fpu_to_fSI.y, governor.f) annotation (
63+
Line(points={{-53.4,-52},{-22,-52},{-22,-44},{-12,-44}},
64+
color = {0, 0, 127}));
65+
connect(governor.Y_gv, turbine.u_t) annotation (
66+
Line(points={{11,-40},{24,-40},{24,-68}}, color = {0, 0, 127}));
67+
connect(governor.P_ref, power.y) annotation (
68+
Line(points={{-12,-36},{-27.2,-36}}, color = {0, 0, 127}));
69+
connect(generator.vf, generator.vf0) annotation (Line(points={{-42,5},{-46,5},{-46,14},{-38,14},{-38,11}}, color={0,0,127}));
70+
connect(generator.p, bus1.p) annotation (Line(points={{-20,0},{0,0}}, color={0,0,255}));
71+
connect(discharge.o, tail.o) annotation (Line(points={{68,-80},{74,-80}}, color={28,108,200}));
72+
connect(turbine.o, discharge.i) annotation (Line(points={{42,-80},{48,-80}}, color={28,108,200}));
73+
connect(turbine.i, penstock.o) annotation (Line(points={{22,-80},{10,-80}}, color={28,108,200}));
74+
connect(penstock.i, surgeTank.o) annotation (Line(points={{-10,-80},{-20,-80}},color={28,108,200}));
75+
connect(surgeTank.i, intake.o) annotation (Line(points={{-40,-80},{-46,-80}}, color={28,108,200}));
76+
connect(intake.i, reservoir.o) annotation (Line(points={{-66,-80},{-70,-80}}, color={28,108,200}));
77+
connect(turbine.P_out, generator.pm) annotation (Line(points={{36,-69},{36,-22},{-52,-22},{-52,-5},{-42,-5}}, color={0,0,127}));
78+
connect(generator.w, fpu_to_fSI.u) annotation (Line(points={{-19,9},{-14,9},{-14,20},{-72,20},{-72,-52},{-67.2,-52}}, color={0,0,127}));
79+
annotation (experiment(StopTime = 2000));
80+
end SimpleGen;

OpenHPL/Examples/WithOpenIPSL/SimpleGenFrancis.mo

Lines changed: 0 additions & 105 deletions
This file was deleted.

OpenHPL/Examples/WithOpenIPSL/SimpleGenFrancisTG.mo

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)