Skip to content

Commit 0b2415a

Browse files
authored
feat: Add automatic elevation propagation (#89)
* Add a new elevation z to contact The elevation gets automatically propagated via the connections Introduces a `fixElevation` parameter for source and sink models (e.g., `Reservoir`, `VolumeFlowSource`). This parameter allows users to either: - Enforce a fixed absolute elevation (`z_0`) at the outlet (when `fixElevation` is true, default). - Allow the outlet elevation to be determined by the connected topology (when `fixElevation` is false), enabling more flexible model configurations where elevation propagates into these components.
1 parent e73f920 commit 0b2415a

33 files changed

Lines changed: 179 additions & 88 deletions

OpenHPL/Data.mo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
within OpenHPL;
22
record Data "Provides a data set of most common used settings"
33
extends Modelica.Icons.Record;
4+
parameter Boolean showElevation=true "Display elevation of connectors"
5+
annotation(Dialog(group = "Icon"),
6+
choices(checkBox = true));
47
parameter SI.Acceleration g = Modelica.Constants.g_n "Gravity constant"
58
annotation (Dialog(enable=false, group = "Constants"));
69
parameter Real gamma_air = 1.4 "Ratio of heat capacities at constant pressure (C_p) to constant volume (C_v) for air at STP"

OpenHPL/ElectroMech/BaseClasses/BaseValve.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ equation
3434
Vdot = mdot/data.rho;
3535
dp*(C_v_*max(epsilon, u^alpha))^2 = Vdot*abs(Vdot) "Valve equation for pressure drop";
3636
dp = i.p - o.p "Link the pressure drop to the ports";
37+
o.elevation.z = i.elevation.z "Elevation propagation: no height change across valve";
3738
annotation (preferredView="info", Documentation(info="<html>
3839
<p>
3940
This is a partial, simple model of hydraulic valve. &nbsp;</p><p>This model is based on the energy balance of a valve.

OpenHPL/ElectroMech/Turbines/Francis.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ model Francis "Model of the Francis turbine"
7979
Real W_t2_n "Euler second term, nominal", W_t1_n "Euler first term, nominal", Wdot_t_n "Total power, nominal", cot_a1_n "Cotant nominal alpha", Vdot_n_ = Vdot_n / 0.99 "Flow rate for fully open guide vane", d_n(start = 0.67) "Nominal servo term", theta_n "Servo angle for fully open guide vane";
8080
SI.Angle alpha1_n "Nominal inlet guide vane angle";
8181
// connectors
82+
extends OpenHPL.Interfaces.TwoContacts;
8283
extends OpenHPL.Interfaces.TurbineContacts(enable_P_out=true);
8384
Modelica.Blocks.Interfaces.RealInput w_in "Input angular velocity from the generator" annotation (
8485
Placement(transformation(origin={-120,-80}, extent={{-20,-20},
@@ -210,6 +211,7 @@ equation
210211
p_tr2 = o.p;
211212
i.mdot+o.mdot=0;
212213
mdot=i.mdot;
214+
o.elevation.z = i.elevation.z "Elevation propagation: no height change across turbine";
213215

214216
connect(p_out, P_out) annotation (Line(points={{40,90},{40,110}}, color={0,0,127}));
215217
annotation (preferredView="info",

OpenHPL/ElectroMech/Turbines/Pelton.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ model Pelton "Model of the Pelton turbine"
2121
SI.AngularVelocity w=w_in "Angular velocity";
2222
Real cos_b = Modelica.Math.cos(Modelica.Units.Conversions.from_deg(beta));
2323
// connectors
24+
extends OpenHPL.Interfaces.TwoContacts;
2425
extends OpenHPL.Interfaces.TurbineContacts(enable_P_out=true);
2526
Modelica.Blocks.Interfaces.RealInput w_in "Input angular velocity from the generator" annotation (
2627
Placement(transformation(origin={-120,-80}, extent={{-20,-20},
@@ -54,6 +55,7 @@ equation
5455
// Flow rate connectors
5556
i.mdot+o.mdot=0;
5657
mdot=i.mdot;
58+
o.elevation.z = i.elevation.z "Elevation propagation: no height change across turbine";
5759

5860
connect(p_out, P_out) annotation (Line(points={{40,90},{40,110}}, color={0,0,127}));
5961
annotation (preferredView="info",

OpenHPL/Examples/BranchingPipes.mo

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
within OpenHPL.Examples;
22
model BranchingPipes "Model of branching pipes"
33
extends Modelica.Icons.Example;
4-
Waterway.Reservoir reservoir annotation (
4+
Waterway.Reservoir reservoir(fixElevation = true, z_0 = 3) annotation (
55
Placement(transformation(extent = {{-80, -10}, {-60, 10}})));
66
Waterway.Pipe mainPipe(D_i = 6, H = 1, L = 100) annotation (
77
Placement(transformation(extent = {{-52, -10}, {-32, 10}})));
88
Waterway.Reservoir reservoir1 annotation (
99
Placement(transformation(extent = {{-10, -10}, {10, 10}}, rotation = 180, origin = {70, 0})));
1010
Waterway.Pipe branch1(D_i = 3, H = 1, L = 100, Vdot_0 = data.Vdot_0/2) annotation (
1111
Placement(transformation(extent = {{-10, 10}, {10, 30}})));
12-
Waterway.Pipe branch2(D_i = 3, H = 1, L = 100, Vdot_0 = data.Vdot_0/2) annotation (
12+
Waterway.Pipe branch2(D_i = 3, H = 1, L = 100, Vdot_0 = data.Vdot_0/2) annotation(
1313
Placement(transformation(extent = {{-10, -30}, {10, -10}})));
1414
Waterway.Pipe mainPipeOut(D_i = 5, H = 1, L = 100) annotation (
1515
Placement(transformation(extent = {{30, -10}, {50, 10}})));
1616
inner Data data(SteadyState = true, Vdot_0 = 75) annotation (
1717
Placement(transformation(extent = {{-100, 80}, {-80, 100}})));
1818
equation
19-
connect(reservoir.o, mainPipe.i) annotation (
19+
connect(reservoir.o, mainPipe.i) annotation(
2020
Line(points = {{-60, 0}, {-52, 0}}, color = {28, 108, 200}));
21-
connect(branch1.i, mainPipe.o) annotation (
21+
connect(branch1.i, mainPipe.o) annotation(
2222
Line(points = {{-10, 20}, {-20, 20}, {-20, 0}, {-32, 0}}, color = {28, 108, 200}));
23-
connect(mainPipe.o, branch2.i) annotation (
23+
connect(mainPipe.o, branch2.i) annotation(
2424
Line(points = {{-32, 0}, {-20, 0}, {-20, -20}, {-10, -20}}, color = {28, 108, 200}));
25-
connect(branch2.o, mainPipeOut.i) annotation (
25+
connect(branch2.o, mainPipeOut.i) annotation(
2626
Line(points = {{10, -20}, {20, -20}, {20, 0}, {30, 0}}, color = {28, 108, 200}));
27-
connect(branch1.o, mainPipeOut.i) annotation (
27+
connect(branch1.o, mainPipeOut.i) annotation(
2828
Line(points = {{10, 20}, {20, 20}, {20, 0}, {30, 0}}, color = {28, 108, 200}));
29-
connect(mainPipeOut.o, reservoir1.o) annotation (
29+
connect(mainPipeOut.o, reservoir1.o) annotation(
3030
Line(points = {{50, 0}, {60, 0}}, color = {0, 128, 255}));
3131
annotation (
3232
experiment(StopTime = 2000, StartTime = 0, Tolerance = 0.0001, Interval = 0.4));
33-
end BranchingPipes;
33+
end BranchingPipes;

OpenHPL/Examples/DetailedTurbine.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ within OpenHPL.Examples;
22
model DetailedTurbine "Hydropower system using KP scheme based penstock"
33
extends SimpleTurbine(
44
redeclare Waterway.PenstockKP penstock);
5-
annotation (experiment(StopTime=1000));
6-
end DetailedTurbine;
5+
annotation (experiment(StopTime = 1000, StartTime = 0, Tolerance = 1e-06, Interval = 2));
6+
end DetailedTurbine;

OpenHPL/Examples/Gate.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
within OpenHPL.Examples;
22
model Gate "Usage of the tainter gate"
33
extends Modelica.Icons.Example;
4-
inner Data data(SteadyState = true, Vdot_0 = 75) annotation (
4+
inner Data data(SteadyState = true, Vdot_0 = 75, showElevation = false) annotation (
55
Placement(transformation(extent = {{-100, 80}, {-80, 100}})));
66
Modelica.Blocks.Sources.Ramp gateOpening(
77
height=0,
@@ -12,7 +12,7 @@ model Gate "Usage of the tainter gate"
1212
constantLevel=false,
1313
useLevel=true,
1414
L=10,
15-
W=10) annotation (Placement(transformation(extent={{-40,40},{-20,60}})));
15+
W=10, fixElevation = true) annotation (Placement(transformation(extent={{-40,40},{-20,60}})));
1616
Waterway.Reservoir downstream(
1717
h_0=4,
1818
constantLevel=false,
@@ -32,7 +32,7 @@ model Gate "Usage of the tainter gate"
3232
constantLevel=false,
3333
useLevel=true,
3434
L=10,
35-
W=10) annotation (Placement(transformation(extent={{-40,-10},{-20,10}})));
35+
W=10, fixElevation = true) annotation (Placement(transformation(extent={{-40,-10},{-20,10}})));
3636
Waterway.Reservoir downstream1(
3737
h_0=4,
3838
constantLevel=false,
@@ -51,7 +51,7 @@ model Gate "Usage of the tainter gate"
5151
constantLevel=false,
5252
useLevel=true,
5353
L=10,
54-
W=10) annotation (Placement(transformation(extent={{-40,-60},{-20,-40}})));
54+
W=10, fixElevation = true) annotation (Placement(transformation(extent={{-40,-60},{-20,-40}})));
5555
Waterway.Reservoir downstream2(
5656
h_0=4,
5757
constantLevel=false,
@@ -91,4 +91,4 @@ equation
9191
connect(upstream2.level, up_level.y) annotation (Line(points={{-42,-44},{-52,-44},{-52,0},{-59,0}}, color={0,0,127}));
9292
annotation (
9393
experiment(StopTime=2000, Interval=0.4));
94-
end Gate;
94+
end Gate;

OpenHPL/Examples/Pipes.mo

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@ model Pipes "Example of contracting, contstant and expanding pipe diameters"
55
inner OpenHPL.Data data annotation (
66
Placement(transformation(origin={-90,90}, extent={{-10,-10},{10,10}})));
77
parameter SI.Diameter Dn=0.3568 "Nominal Diameter";
8-
Waterway.Reservoir Upstream(h_0 = 100.0, constantLevel=true)
8+
Waterway.Reservoir Upstream(h_0 = 100.0, constantLevel=true, fixElevation = true, z_0 = 10)
99
annotation (
1010
Placement(transformation(origin={-50,0}, extent={{-10,-10},{10,10}})));
11-
Waterway.Reservoir Downstream(h_0 = 0.0, constantLevel=true)
11+
Waterway.Reservoir Downstream(h_0 = 0.0, constantLevel=true, fixElevation = false)
1212
annotation (
1313
Placement(transformation(origin={50,0}, extent={{10,-10},{-10,10}}, rotation = -0)));
1414
OpenHPL.Waterway.Pipe pipeExpanding(
1515
D_i=0.8*Dn,
1616
D_o=1.2*Dn,
17-
H=0,
17+
H= 10,
1818
L=1000) annotation (Placement(transformation(origin={0,20}, extent={{-10,-10},{10,10}})));
1919
OpenHPL.Waterway.Pipe pipeConstant(
2020
D_i=Dn,
2121
D_o=Dn,
22-
H=0,
22+
H= 10,
2323
L=1000) annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
2424
OpenHPL.Waterway.Pipe pipeContracting(
2525
D_i=1.2*Dn,
2626
D_o=0.8*Dn,
27-
H=0,
27+
H= 10,
2828
L=1000) annotation (Placement(transformation(origin={0,-20}, extent={{-10,-10},{10,10}})));
2929

3030
equation
@@ -36,4 +36,4 @@ equation
3636
connect(pipeContracting.o, Downstream.o) annotation (Line(points={{10,-20},{30,-20},{30,0},{40,0}}, color={0,128,255}));
3737
annotation (
3838
experiment(StartTime = 0, StopTime = 100, Tolerance = 1e-06, Interval = 0.02));
39-
end Pipes;
39+
end Pipes;

OpenHPL/Examples/SimpleGen.mo

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
within OpenHPL.Examples;
22
model SimpleGen "Model of a hydropower system with a simple turbine turbine and generator"
33
extends SimpleTurbine(
4-
turbine(
5-
enable_nomSpeed=false,
6-
enable_P_out=true));
4+
turbine(enable_nomSpeed = false, enable_P_out = true), reservoir(fixElevation = true, z_0 = 100));
75
ElectroMech.Generators.SimpleGen simpleGen annotation (Placement(transformation(extent={{20,50},{40,70}})));
86
Modelica.Blocks.Math.Gain loadLevel(k=1) annotation (Placement(transformation(extent={{72,70},{52,90}})));
97
equation
@@ -12,5 +10,5 @@ equation
1210
connect(simpleGen.flange, turbine.flange) annotation (Line(
1311
points={{30,60},{30,10}},
1412
color={0,0,0}));
15-
annotation (experiment(StopTime=1000));
16-
end SimpleGen;
13+
annotation (experiment(StopTime = 1000, StartTime = 0, Tolerance = 1e-06, Interval = 2));
14+
end SimpleGen;

OpenHPL/Examples/SimpleGenFrancis.mo

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
within OpenHPL.Examples;
22
model SimpleGenFrancis "Model of a hydropower system with Francis turbine model"
33
extends Modelica.Icons.Example;
4-
Waterway.Reservoir reservoir(h_0=48) annotation (Placement(transformation(
4+
Waterway.Reservoir reservoir(h_0 = 48, fixElevation = true) annotation (Placement(transformation(
55
origin={-90,50},
66
extent={{-10,-10},{10,10}})));
77
Modelica.Blocks.Sources.Ramp control(
@@ -57,7 +57,7 @@ model SimpleGenFrancis "Model of a hydropower system with Francis turbine model"
5757
annotation (Placement(transformation(
5858
origin={30,0},
5959
extent={{-10,-10},{10,10}})));
60-
inner OpenHPL.Data data(Vdot_0=4.54) annotation (Placement(transformation(
60+
inner OpenHPL.Data data(SteadyState = false) annotation (Placement(transformation(
6161
origin={-90,90},
6262
extent={{-10,-10},{10,10}})));
6363
Waterway.Fitting fitting(
@@ -86,5 +86,5 @@ equation
8686
Line(points={{80,6.66134e-16},{80,0},{70,0}}, color = {28, 108, 200}));
8787
connect(penstock.o, fitting.i) annotation (
8888
Line(points={{-20,0},{-12,0}}, color = {28, 108, 200}));
89-
annotation (experiment(StopTime=1000));
90-
end SimpleGenFrancis;
89+
annotation (experiment(StopTime = 1000, StartTime = 0, Tolerance = 1e-06, Interval = 2));
90+
end SimpleGenFrancis;

0 commit comments

Comments
 (0)