Skip to content

Commit 66c6ad4

Browse files
committed
Improves elevation handling and propagation
Relocates elevation equations (`o.z = i.z` or `o.z = i.z - H`) from the `equation` section to the `initial equation` section for most components. This ensures elevation values are determined once at initialization and then propagated through the connected topology, simplifying model structure and potentially improving simulation performance. 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 1ef4615 commit 66c6ad4

17 files changed

Lines changed: 40 additions & 19 deletions

File tree

OpenHPL/ElectroMech/BaseClasses/BaseValve.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ protected
2828
annotation (Placement(transformation(origin = {0, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 270), iconTransformation(extent = {{-20, -20}, {20, 20}}, rotation = 270, origin = {0, 80})));
2929
constant Real epsilon = 5.0e-5 "Constant to ensure robust expression for dp vs flow. Trial and error to find suitable value.";
3030

31+
initial equation
32+
o.z = i.z "Elevation propagation: no height change across valve";
3133
equation
3234
i.mdot + o.mdot = 0;
3335
mdot = i.mdot;
3436
Vdot = mdot/data.rho;
3537
dp*(C_v_*max(epsilon, u^alpha))^2 = Vdot*abs(Vdot) "Valve equation for pressure drop";
3638
dp = i.p - o.p "Link the pressure drop to the ports";
37-
o.z = i.z "Elevation propagation: no height change across valve";
3839
annotation (preferredView="info", Documentation(info="<html>
3940
<p>
4041
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ protected
8888
extent={{-10,-10},{10,10}},
8989
rotation=90,
9090
origin={40,90})));
91+
initial equation
92+
o.z = i.z "Elevation propagation: no height change across turbine";
9193
equation
9294
// design algorithm for runner
9395
if GivenData then
@@ -210,7 +212,6 @@ equation
210212
p_tr2 = o.p;
211213
i.mdot+o.mdot=0;
212214
mdot=i.mdot;
213-
o.z = i.z "Elevation propagation: no height change across turbine";
214215

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

OpenHPL/ElectroMech/Turbines/Pelton.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ protected
3030
extent={{-10,-10},{10,10}},
3131
rotation=90,
3232
origin={40,90})));
33+
initial equation
34+
o.z = i.z "Elevation propagation: no height change across turbine";
3335
equation
3436
// Condition for inlet water compressibility
3537
if not CompElas then
@@ -54,7 +56,6 @@ equation
5456
// Flow rate connectors
5557
i.mdot+o.mdot=0;
5658
mdot=i.mdot;
57-
o.z = i.z "Elevation propagation: no height change across turbine";
5859

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

OpenHPL/Interfaces/TwoContacts.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ partial model TwoContacts "Model of two connectors"
77
annotation (
88
Placement(transformation(extent={{90,-10},{110,10}})));
99
equation
10-
i.gz = 0 "Elevation auxiliary variable (no elevation source/sink at this connection point)";
10+
o.gz = i.gz "Elevation auxiliary variable: propagate gz from inlet to outlet";
1111
annotation (
1212
Documentation(info = "<html>
1313
<p>TwoContact is a partial model, which consists of two Contacts <em>i</em>and <em>o</em>.

OpenHPL/Waterway/BendPipe.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ model BendPipe "Bend in pipes"
1616
SI.Pressure dp "Pressure drop of fitting";
1717
SI.MassFlowRate mdot "Mass flow rate";
1818
extends OpenHPL.Interfaces.TwoContacts;
19+
initial equation
20+
o.z = i.z "Elevation propagation: no height change across bend";
1921
equation
2022
v = mdot / data.rho / A;
2123
dp = K_L * 0.5 * data.rho * v^2;
2224
// Connections
2325
o.p = i.p - dp "Pressure of the output connector";
2426
i.mdot + o.mdot = 0 "Mass balance";
2527
mdot = i.mdot "Flow direction";
26-
o.z = i.z "Elevation propagation: no height change across bend";
2728
annotation (preferredView="info",
2829
Documentation(info="<html>
2930
<p>Usually minor head losses in pipes are considered to be due to fittings, diffusers, nozzles, bend in pipes, etc. We are more interested in head loss due to bend pipes for this model.</p>

OpenHPL/Waterway/DraftTube.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ initial equation
9191
Vdot = Vdot_0;
9292
//n.T = p.T;
9393
end if;
94+
o.z = i.z - H "Elevation propagation: outlet is H below inlet";
9495
equation
9596
der(M) = Mdot + F "Momentum balance";
9697
if DraftTubeType == OpenHPL.Types.DraftTube.ConicalDiffuser then
@@ -153,7 +154,6 @@ equation
153154
p_o = o.p;
154155
i.mdot+o.mdot=0;
155156
mdot = i.mdot;
156-
o.z = i.z - H "Elevation propagation: outlet is H below inlet";
157157
annotation (preferredView="info", Documentation(info="<html>
158158
<p>Two of the draft tubes are modeled using <em>Momentum balance</em>.
159159
They are:</p>

OpenHPL/Waterway/Fitting.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ model Fitting "Different pipes fitting"
2121
Real phi "Dimensionless factor based on the type of fitting ";
2222
/* Connector */
2323
extends OpenHPL.Interfaces.TwoContacts;
24+
initial equation
25+
o.z = i.z "Elevation propagation: no height change across fitting";
2426
equation
2527
v = mdot / data.rho / A;
2628
if v>=0 then
@@ -53,7 +55,6 @@ equation
5355
o.p = i.p - dp "Pressure of the output connector";
5456
i.mdot+o.mdot = 0 "Mass balance";
5557
mdot = i.mdot "Flow direction";
56-
o.z = i.z "Elevation propagation: no height change across fitting";
5758
annotation (preferredView="info",
5859
Documentation(info="<html>
5960
<p>Various possibilities of the fittings for the pipes with different diameters

OpenHPL/Waterway/Gate.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ model Gate "Model of a sluice or tainter gate based on [Bollrich2019]"
2525
extent={{-20,-20},{20,20}},
2626
rotation=270,
2727
origin={0,120})));
28+
initial equation
29+
o.z = i.z "Elevation propagation: gate at same elevation";
2830
equation
2931
mu_A = psi/sqrt(1+psi*a/h_0);
3032
if sluice then
@@ -51,7 +53,6 @@ equation
5153
mdot = Vdot * data.rho "Mass flow rate through the gate";
5254
i.p = h_0 * data.g * data.rho + data.p_a "Inlet water pressure";
5355
o.p = h_2 * data.g * data.rho + data.p_a "Outlet water pressure";
54-
o.z = i.z "Elevation propagation: gate at same elevation";
5556
annotation (
5657
preferredView="info",
5758
Documentation(info="<html>

OpenHPL/Waterway/Gate_HR.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ protected
3333
SI.VolumeFlowRate Vdot_full "Fully submerged base volume flow rate through the gate";
3434
Real Cdx "Discharge coefficient tuned for a smooth transition between partially and fully submerged";
3535

36+
initial equation
37+
o.z = i.z "Elevation propagation: gate at same elevation";
3638
equation
3739
i.mdot+o.mdot = 0 "Mass balance";
3840
mdot = i.mdot "Inlet direction for mdot";
@@ -50,7 +52,6 @@ equation
5052
mdot = Vdot * data.rho "Mass flow rate through the gate";
5153
i.p = h_i * data.g * data.rho + data.p_a "Inlet water pressure";
5254
o.p = h_o * data.g * data.rho + data.p_a "Outlet water pressure";
53-
o.z = i.z "Elevation propagation: gate at same elevation";
5455
annotation (
5556
preferredView="info",
5657
Documentation(info="<html>

OpenHPL/Waterway/OpenChannel.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ model OpenChannel "Open channel model (use KP scheme)"
3030
boundaryValues=[h_0[1] + H[1],Vdot_i/W; h_0[N] + H[2],Vdot_o/W],
3131
boundaryCondition=BoundaryCondition,
3232
SteadyState=SteadyState) annotation (Placement(transformation(extent={{-10,-8},{10,12}})));
33+
initial equation
34+
o.z = i.z - (H[1] - H[2]) "Elevation propagation: channel bed drops from H[1] to H[2]";
3335
equation
3436
// define a vector of the water depth in the channel
3537
h = openChannel.h;
@@ -39,7 +41,6 @@ equation
3941
// presurre boundaries
4042
i.p = h[1] * data.g * data.rho + data.p_a;
4143
o.p = h[N] * data.g * data.rho + data.p_a;
42-
o.z = i.z - (H[1] - H[2]) "Elevation propagation: channel bed drops from H[1] to H[2]";
4344
annotation (preferredView="info",
4445
Documentation(info="<html>
4546
<p style=\"color: #ff0000;\"><em>Note: Currently under investigation for plausibility.</em></p>

0 commit comments

Comments
 (0)