From 1760b49bfc221b72ce85b651cc5874185f0c7c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjarne=20B=C3=B8rresen?= Date: Wed, 18 Feb 2026 11:59:41 +0100 Subject: [PATCH 1/2] Corrected initialization of pipe for case when SteadyState is not true. Added one more test in OpenHPLTest/TestPipe --- OpenHPL/Waterway/Pipe.mo | 2 ++ OpenHPLTest/TestPipe.mo | 58 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/OpenHPL/Waterway/Pipe.mo b/OpenHPL/Waterway/Pipe.mo index 43bb94f..4d7a7e5 100644 --- a/OpenHPL/Waterway/Pipe.mo +++ b/OpenHPL/Waterway/Pipe.mo @@ -58,6 +58,8 @@ protected initial equation if SteadyState then der(mdot) = 0; + else + Vdot=Vdot_0; end if; algorithm assert( phi < 1.0, "Change in pipe diameter is too large. (angle= "+String(phi)+" )",AssertionLevel.warning); diff --git a/OpenHPLTest/TestPipe.mo b/OpenHPLTest/TestPipe.mo index 724539e..2ea2315 100644 --- a/OpenHPLTest/TestPipe.mo +++ b/OpenHPLTest/TestPipe.mo @@ -48,11 +48,11 @@ end Test01; model Test02 extends AbstractTest; - OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = 0.8*Dn, D_o = 1.2*Dn) annotation( + OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = 0.8*Dn, D_o = 1.2*Dn, SteadyState = false, Vdot_0 = 0) annotation( Placement(transformation(origin = {2, 68}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, D_o = Dn) annotation( + OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, D_o = Dn, SteadyState = false, Vdot_0 = 0) annotation( Placement(transformation(origin = {2, 40}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = 1.2*Dn, D_o = 0.8*Dn) annotation( + OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = 1.2*Dn, D_o = 0.8*Dn, SteadyState = false, Vdot_0 = 0) annotation( Placement(transformation(origin = {0, 8}, extent = {{-10, -10}, {10, 10}}))); equation error=sqrt((pipe1.mdot-pipe2.mdot)^2 + (pipe2.mdot-pipe3.mdot)^2 + (pipe3.mdot-pipe1.mdot)^2); @@ -70,6 +70,56 @@ end Test01; Line(points = {{-44, 32}, {-32, 32}, {-32, 8}, {-10, 8}}, color = {0, 128, 255})); annotation( experiment(StartTime = 0, StopTime = 20, Tolerance = 1e-06, Interval = 0.004)); -end Test02; + end Test02; + + model Test03 + extends AbstractTest; + + OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = Dn, SteadyState = true) annotation( + Placement(transformation(origin = {2, 68}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, SteadyState = true) annotation( + Placement(transformation(origin = {2, 40}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = Dn, SteadyState = true) annotation( Placement(transformation(origin = {0, 8}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Valve valve1(ValveCapacity = false, H_n = 100, Vdot_n = 1) annotation( + Placement(transformation(origin = {34, 68}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Valve valve2(ValveCapacity = false, H_n = 100, Vdot_n = 1) annotation( + Placement(transformation(origin = {30, 40}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Valve valve3(ValveCapacity = false, H_n = 100, Vdot_n = 1) annotation( + Placement(transformation(origin = {30, 8}, extent = {{-10, 10}, {10, -10}}, rotation = -0))); + Modelica.Blocks.Sources.Ramp ramp1(height = 1, duration = 5, offset = 0, startTime = 2) annotation( + Placement(transformation(origin = {-8, 100}, extent = {{-10, -10}, {10, 10}}))); + Modelica.Blocks.Sources.Ramp ramp2(duration = 5, height = 0.5, offset = 0.5, startTime = 2) annotation( + Placement(transformation(origin = {82, 50}, extent = {{10, -10}, {-10, 10}}, rotation = -0))); + Modelica.Blocks.Sources.Ramp ramp3(duration = 5, height = -1, offset = 1, startTime = 2) annotation( + Placement(transformation(origin = {58, -28}, extent = {{10, -10}, {-10, 10}}))); + equation + error=sqrt((pipe1.mdot-pipe2.mdot)^2 + (pipe2.mdot-pipe3.mdot)^2 + (pipe3.mdot-pipe1.mdot)^2); + connect(Upstream.o, pipe1.i) annotation( + Line(points = {{-44, 32}, {-38, 32}, {-38, 68}, {-8, 68}}, color = {0, 128, 255})); + connect(Upstream.o, pipe2.i) annotation( + Line(points = {{-44, 32}, {-30, 32}, {-30, 40}, {-8, 40}}, color = {0, 128, 255})); + connect(Upstream.o, pipe3.i) annotation( + Line(points = {{-44, 32}, {-34, 32}, {-34, 8}, {-10, 8}}, color = {0, 128, 255})); + connect(pipe1.o, valve1.i) annotation( + Line(points = {{12, 68}, {24, 68}}, color = {0, 128, 255})); + connect(pipe2.o, valve2.i) annotation( + Line(points = {{12, 40}, {20, 40}}, color = {0, 128, 255})); + connect(pipe3.o, valve3.i) annotation( + Line(points = {{10, 8}, {20, 8}}, color = {0, 128, 255})); + connect(ramp1.y, valve1.opening) annotation( + Line(points = {{4, 100}, {34, 100}, {34, 76}}, color = {0, 0, 127})); + connect(valve1.o, Downstream.o) annotation( + Line(points = {{44, 68}, {54, 68}, {54, 10}, {62, 10}}, color = {0, 128, 255})); + connect(valve2.o, Downstream.o) annotation( + Line(points = {{40, 40}, {52, 40}, {52, 10}, {62, 10}}, color = {0, 128, 255})); + connect(ramp3.y, valve3.opening) annotation( + Line(points = {{48, -28}, {30, -28}, {30, 0}}, color = {0, 0, 127})); + connect(ramp2.y, valve2.opening) annotation( + Line(points = {{72, 50}, {51, 50}, {51, 48}, {30, 48}}, color = {0, 0, 127})); + connect(valve3.o, Downstream.o) annotation( + Line(points = {{40, 8}, {44, 8}, {44, 10}, {62, 10}}, color = {0, 128, 255})); + annotation( + experiment(StartTime = 0, StopTime = 30, Tolerance = 1e-06, Interval = 0.001)); +end Test03; end TestPipe; From 65b396f98f1ccce1d9addc3209e3161ae0863eef Mon Sep 17 00:00:00 2001 From: Dietmar Winkler Date: Thu, 19 Feb 2026 12:47:40 +0100 Subject: [PATCH 2/2] Cleaner implementation of the test models Try to avoid code duplication. --- OpenHPLTest/TestPipe.mo | 124 ++++++++++++++++---------------------- OpenHPLTest/package.order | 2 +- 2 files changed, 53 insertions(+), 73 deletions(-) diff --git a/OpenHPLTest/TestPipe.mo b/OpenHPLTest/TestPipe.mo index 2ea2315..1148e23 100644 --- a/OpenHPLTest/TestPipe.mo +++ b/OpenHPLTest/TestPipe.mo @@ -7,119 +7,99 @@ package TestPipe extends Modelica.Icons.Example; // inner OpenHPL.Data data(Vdot_0 = 0.0, p_a = 0.0, p_eps = 0.0) annotation( - Placement(transformation(origin = {-72, 80}, extent = {{-10, -10}, {10, 10}}))); + Placement(transformation(origin = {-70, 70}, extent = {{-10, -10}, {10, 10}}))); // parameter Modelica.Units.SI.Length Ln = 1000.; parameter Modelica.Units.SI.Length Dn = sqrt(A*4/Modelica.Constants.pi); Real error; OpenHPL.Waterway.Reservoir Upstream(h_0 = 100, constantLevel = true) annotation( - Placement(transformation(origin = {-54, 32}, extent = {{-10, -10}, {10, 10}}))); + Placement(transformation(origin = {-50, 30}, extent = {{-10, -10}, {10, 10}}))); OpenHPL.Waterway.Reservoir Downstream(constantLevel = true, h_0 = 0) annotation( - Placement(transformation(origin = {72, 10}, extent = {{10, -10}, {-10, 10}}, rotation = -0))); + Placement(transformation(origin = {70, 10}, extent = {{10, -10}, {-10, 10}}))); protected constant Modelica.Units.SI.Area A = 0.1; end AbstractTest; model Test01 extends AbstractTest; - OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = 0.8*Dn, D_o = 1.2*Dn, SteadyState = true) annotation( - Placement(transformation(origin = {2, 68}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, D_o = Dn, SteadyState = true) annotation( - Placement(transformation(origin = {2, 40}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = 1.2*Dn, D_o = 0.8*Dn, SteadyState = true) annotation( - Placement(transformation(origin = {0, 8}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = 0.8*Dn, D_o = 1.2*Dn) annotation( + Placement(transformation(origin = {0, 60}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, D_o = Dn) annotation( + Placement(transformation(origin = {0, 30}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = 1.2*Dn, D_o = 0.8*Dn) annotation( + Placement(transformation(extent = {{-10, -10}, {10, 10}}))); equation error=sqrt((pipe1.mdot-pipe2.mdot)^2 + (pipe2.mdot-pipe3.mdot)^2 + (pipe3.mdot-pipe1.mdot)^2); - connect(Upstream.o, pipe1.i) annotation( - Line(points = {{-44, 32}, {-34, 32}, {-34, 68}, {-8, 68}}, color = {0, 128, 255})); - connect(pipe1.o, Downstream.o) annotation( - Line(points = {{12, 68}, {38, 68}, {38, 10}, {62, 10}}, color = {0, 128, 255})); - connect(pipe2.o, Downstream.o) annotation( - Line(points = {{12, 40}, {26, 40}, {26, 10}, {62, 10}}, color = {0, 128, 255})); - connect(pipe3.o, Downstream.o) annotation( - Line(points = {{10, 8}, {20, 8}, {20, 10}, {62, 10}}, color = {0, 128, 255})); - connect(Upstream.o, pipe2.i) annotation( - Line(points = {{-44, 32}, {-26, 32}, {-26, 40}, {-8, 40}}, color = {0, 128, 255})); - connect(Upstream.o, pipe3.i) annotation( - Line(points = {{-44, 32}, {-32, 32}, {-32, 8}, {-10, 8}}, color = {0, 128, 255})); + connect(Upstream.o, pipe1.i) annotation( + Line(points = {{-40, 30}, {-20, 30}, {-20, 60}, {-10, 60}}, color = {0, 128, 255})); + connect(pipe2.i, Upstream.o) annotation( + Line(points = {{-10, 30}, {-40, 30}}, color = {0, 128, 255})); + connect(Upstream.o, pipe3.i) annotation( + Line(points = {{-40, 30}, {-20, 30}, {-20, 0}, {-10, 0}}, color = {0, 128, 255})); + connect(pipe1.o, Downstream.o) annotation( + Line(points = {{10, 60}, {50, 60}, {50, 10}, {60, 10}}, color = {0, 128, 255})); + connect(pipe2.o, Downstream.o) annotation( + Line(points = {{10, 30}, {50, 30}, {50, 10}, {60, 10}}, color = {0, 128, 255})); + connect(pipe3.o, Downstream.o) annotation( + Line(points = {{10, 0}, {50, 0}, {50, 10}, {60, 10}}, color = {0, 128, 255})); annotation( experiment(StartTime = 0, StopTime = 1, Tolerance = 1e-06, Interval = 0.002)); end Test01; model Test02 - extends AbstractTest; - OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = 0.8*Dn, D_o = 1.2*Dn, SteadyState = false, Vdot_0 = 0) annotation( - Placement(transformation(origin = {2, 68}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, D_o = Dn, SteadyState = false, Vdot_0 = 0) annotation( - Placement(transformation(origin = {2, 40}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = 1.2*Dn, D_o = 0.8*Dn, SteadyState = false, Vdot_0 = 0) annotation( - Placement(transformation(origin = {0, 8}, extent = {{-10, -10}, {10, 10}}))); + extends OpenHPLTest.TestPipe.Test01(data(SteadyState = true)); equation - error=sqrt((pipe1.mdot-pipe2.mdot)^2 + (pipe2.mdot-pipe3.mdot)^2 + (pipe3.mdot-pipe1.mdot)^2); - connect(Upstream.o, pipe1.i) annotation( - Line(points = {{-44, 32}, {-34, 32}, {-34, 68}, {-8, 68}}, color = {0, 128, 255})); - connect(pipe1.o, Downstream.o) annotation( - Line(points = {{12, 68}, {38, 68}, {38, 10}, {62, 10}}, color = {0, 128, 255})); - connect(pipe2.o, Downstream.o) annotation( - Line(points = {{12, 40}, {26, 40}, {26, 10}, {62, 10}}, color = {0, 128, 255})); - connect(pipe3.o, Downstream.o) annotation( - Line(points = {{10, 8}, {20, 8}, {20, 10}, {62, 10}}, color = {0, 128, 255})); - connect(Upstream.o, pipe2.i) annotation( - Line(points = {{-44, 32}, {-26, 32}, {-26, 40}, {-8, 40}}, color = {0, 128, 255})); - connect(Upstream.o, pipe3.i) annotation( - Line(points = {{-44, 32}, {-32, 32}, {-32, 8}, {-10, 8}}, color = {0, 128, 255})); - annotation( - experiment(StartTime = 0, StopTime = 20, Tolerance = 1e-06, Interval = 0.004)); + end Test02; model Test03 - extends AbstractTest; + extends AbstractTest(data(SteadyState = true)); - OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = Dn, SteadyState = true) annotation( - Placement(transformation(origin = {2, 68}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn, SteadyState = true) annotation( - Placement(transformation(origin = {2, 40}, extent = {{-10, -10}, {10, 10}}))); - OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = Dn, SteadyState = true) annotation( Placement(transformation(origin = {0, 8}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe1(H = 0, L = Ln, D_i = Dn) annotation( + Placement(transformation(origin = {0, 60}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe2(H = 0, L = Ln, D_i = Dn) annotation( + Placement(transformation(origin = {0, 30}, extent = {{-10, -10}, {10, 10}}))); + OpenHPL.Waterway.Pipe pipe3(H = 0, L = Ln, D_i = Dn) annotation( Placement(transformation(extent = {{-10, -10}, {10, 10}}))); OpenHPL.Waterway.Valve valve1(ValveCapacity = false, H_n = 100, Vdot_n = 1) annotation( - Placement(transformation(origin = {34, 68}, extent = {{-10, -10}, {10, 10}}))); + Placement(transformation(origin = {30, 60}, extent = {{-10, -10}, {10, 10}}))); OpenHPL.Waterway.Valve valve2(ValveCapacity = false, H_n = 100, Vdot_n = 1) annotation( - Placement(transformation(origin = {30, 40}, extent = {{-10, -10}, {10, 10}}))); + Placement(transformation(origin = {30, 30}, extent = {{-10, -10}, {10, 10}}))); OpenHPL.Waterway.Valve valve3(ValveCapacity = false, H_n = 100, Vdot_n = 1) annotation( - Placement(transformation(origin = {30, 8}, extent = {{-10, 10}, {10, -10}}, rotation = -0))); + Placement(transformation(origin = {30, 0}, extent = {{-10, 10}, {10, -10}}))); Modelica.Blocks.Sources.Ramp ramp1(height = 1, duration = 5, offset = 0, startTime = 2) annotation( - Placement(transformation(origin = {-8, 100}, extent = {{-10, -10}, {10, 10}}))); + Placement(transformation(origin = {80, 80}, extent = {{10, -10}, {-10, 10}}, rotation = -0))); Modelica.Blocks.Sources.Ramp ramp2(duration = 5, height = 0.5, offset = 0.5, startTime = 2) annotation( - Placement(transformation(origin = {82, 50}, extent = {{10, -10}, {-10, 10}}, rotation = -0))); + Placement(transformation(origin = {80, 50}, extent = {{10, -10}, {-10, 10}}))); Modelica.Blocks.Sources.Ramp ramp3(duration = 5, height = -1, offset = 1, startTime = 2) annotation( - Placement(transformation(origin = {58, -28}, extent = {{10, -10}, {-10, 10}}))); + Placement(transformation(origin = {80, -20}, extent = {{10, -10}, {-10, 10}}))); equation error=sqrt((pipe1.mdot-pipe2.mdot)^2 + (pipe2.mdot-pipe3.mdot)^2 + (pipe3.mdot-pipe1.mdot)^2); - connect(Upstream.o, pipe1.i) annotation( - Line(points = {{-44, 32}, {-38, 32}, {-38, 68}, {-8, 68}}, color = {0, 128, 255})); - connect(Upstream.o, pipe2.i) annotation( - Line(points = {{-44, 32}, {-30, 32}, {-30, 40}, {-8, 40}}, color = {0, 128, 255})); - connect(Upstream.o, pipe3.i) annotation( - Line(points = {{-44, 32}, {-34, 32}, {-34, 8}, {-10, 8}}, color = {0, 128, 255})); connect(pipe1.o, valve1.i) annotation( - Line(points = {{12, 68}, {24, 68}}, color = {0, 128, 255})); + Line(points = {{10, 60}, {20, 60}}, color = {0, 128, 255})); connect(pipe2.o, valve2.i) annotation( - Line(points = {{12, 40}, {20, 40}}, color = {0, 128, 255})); + Line(points = {{10, 30}, {20, 30}}, color = {0, 128, 255})); connect(pipe3.o, valve3.i) annotation( - Line(points = {{10, 8}, {20, 8}}, color = {0, 128, 255})); + Line(points = {{10, 0}, {20, 0}}, color = {0, 128, 255})); connect(ramp1.y, valve1.opening) annotation( - Line(points = {{4, 100}, {34, 100}, {34, 76}}, color = {0, 0, 127})); + Line(points = {{69, 80}, {30, 80}, {30, 68}}, color = {0, 0, 127})); connect(valve1.o, Downstream.o) annotation( - Line(points = {{44, 68}, {54, 68}, {54, 10}, {62, 10}}, color = {0, 128, 255})); + Line(points = {{40, 60}, {52, 60}, {52, 10}, {62, 10}}, color = {0, 128, 255})); connect(valve2.o, Downstream.o) annotation( - Line(points = {{40, 40}, {52, 40}, {52, 10}, {62, 10}}, color = {0, 128, 255})); + Line(points = {{40, 30}, {52, 30}, {52, 10}, {62, 10}}, color = {0, 128, 255})); connect(ramp3.y, valve3.opening) annotation( - Line(points = {{48, -28}, {30, -28}, {30, 0}}, color = {0, 0, 127})); - connect(ramp2.y, valve2.opening) annotation( - Line(points = {{72, 50}, {51, 50}, {51, 48}, {30, 48}}, color = {0, 0, 127})); + Line(points = {{69, -20}, {30, -20}, {30, -8}}, color = {0, 0, 127})); connect(valve3.o, Downstream.o) annotation( - Line(points = {{40, 8}, {44, 8}, {44, 10}, {62, 10}}, color = {0, 128, 255})); + Line(points = {{40, 0}, {52, 0}, {52, 10}, {62, 10}}, color = {0, 128, 255})); + connect(valve2.opening, ramp2.y) annotation( + Line(points = {{30, 38}, {30, 50}, {70, 50}}, color = {0, 0, 127})); + connect(Upstream.o, pipe2.i) annotation( + Line(points = {{-40, 30}, {-10, 30}}, color = {0, 128, 255})); + connect(Upstream.o, pipe1.i) annotation( + Line(points = {{-40, 30}, {-20, 30}, {-20, 60}, {-10, 60}}, color = {0, 128, 255})); + connect(Upstream.o, pipe3.i) annotation( + Line(points = {{-40, 30}, {-20, 30}, {-20, 0}, {-10, 0}}, color = {0, 128, 255})); annotation( experiment(StartTime = 0, StopTime = 30, Tolerance = 1e-06, Interval = 0.001)); end Test03; -end TestPipe; +end TestPipe; \ No newline at end of file diff --git a/OpenHPLTest/package.order b/OpenHPLTest/package.order index 8962113..3310500 100644 --- a/OpenHPLTest/package.order +++ b/OpenHPLTest/package.order @@ -1,3 +1,4 @@ +TestPipe OpenChannel Reservoir TestMCB @@ -70,4 +71,3 @@ HPSTSimple HPSTAirCushion HPSTSharpOrifice HPSTThrottleValve -TestPipe