From af3434bbfd072b18dac0040edb54cbb60a97704e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaudia=20Horv=C3=A1th?= Date: Wed, 10 Sep 2025 09:56:36 +0200 Subject: [PATCH 1/2] Correct missing files from package order. --- .../Deltares/ChannelFlow/Hydraulic/Reservoir/package.order | 2 ++ .../Deltares/ChannelFlow/SimpleRouting/Reservoir/package.order | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/Hydraulic/Reservoir/package.order b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/Hydraulic/Reservoir/package.order index f8aae11..0cbe280 100644 --- a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/Hydraulic/Reservoir/package.order +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/Hydraulic/Reservoir/package.order @@ -1,2 +1,4 @@ Internal Linear +HomotopicVolume +HomotopicPower \ No newline at end of file diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/SimpleRouting/Reservoir/package.order b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/SimpleRouting/Reservoir/package.order index a24fdd0..5f0e774 100644 --- a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/SimpleRouting/Reservoir/package.order +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/SimpleRouting/Reservoir/package.order @@ -1,2 +1,3 @@ Reservoir -Reservoir_turbine_out \ No newline at end of file +Reservoir_turbine_out +Reservoir_multi_io \ No newline at end of file From 21761ec0e261dbef29276a88cb287db5da8c3d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaudia=20Horv=C3=A1th?= Date: Wed, 10 Sep 2025 09:57:07 +0200 Subject: [PATCH 2/2] Add modelica blocks of hydraulic structures. --- .../HydraulicStructures/Orifice/Orifice.mo | 8 +++ .../HydraulicStructures/Orifice/package.mo | 4 ++ .../HydraulicStructures/Orifice/package.order | 1 + .../PumpingStation/Pump.mo | 56 +++++++++++++++++++ .../PumpingStation/PumpingStation.mo | 26 +++++++++ .../PumpingStation/Resistance.mo | 22 ++++++++ .../PumpingStation/package.mo | 4 ++ .../PumpingStation/package.order | 3 + .../HydraulicStructures/Weir/Weir.mo | 21 +++++++ .../HydraulicStructures/Weir/package.mo | 4 ++ .../HydraulicStructures/Weir/package.order | 1 + .../HydraulicStructures/package.mo | 4 ++ .../Deltares/ChannelFlow/package.order | 1 + 13 files changed, 155 insertions(+) create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/Orifice.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.order create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Pump.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/PumpingStation.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Resistance.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.order create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/Weir.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.mo create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.order create mode 100644 src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/package.mo diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/Orifice.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/Orifice.mo new file mode 100644 index 0000000..ccc4292 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/Orifice.mo @@ -0,0 +1,8 @@ +within Deltares.ChannelFlow.HydraulicStructures.Orifice; + +model Orifice "Orifice that only allows flow when HQDown.H < HQUp.H" + extends Deltares.ChannelFlow.Hydraulic.Structures.DischargeControlledStructure(Q(min=0.0)); + parameter Modelica.Units.SI.Length dH_max = 10.0; + parameter Modelica.Units.SI.Area area = 1.0; + parameter Real discharge_coefficient = 0.61; +end Orifice; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.mo new file mode 100644 index 0000000..9b062e1 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.mo @@ -0,0 +1,4 @@ +within Deltares.ChannelFlow.HydraulicStructures; + +package Orifice +end Orifice; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.order b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.order new file mode 100644 index 0000000..5426293 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Orifice/package.order @@ -0,0 +1 @@ +Orifice diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Pump.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Pump.mo new file mode 100644 index 0000000..4a53313 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Pump.mo @@ -0,0 +1,56 @@ +within Deltares.ChannelFlow.HydraulicStructures.PumpingStation; + +partial model Pump "Pump with QHP relationship" + extends Deltares.ChannelFlow.Hydraulic.Structures.Pump; + + // Increasing row number is increasing H power (staring at 0th power). + // Increasing column number is increasing Q power (staring at 0th power). + parameter Real power_coefficients[:, :, :]; + parameter Real speed_coefficients[:, :] = {{0.0}}; + + + // Array of working area polynomials, each a function of Q and H. The + // coefficients of each polynomial are like the power coefficients, in that + // increasing row (second index) is increasing power of H, and increasing + // column (third index) is increasing power of Q. + parameter Real working_area[:, :, :]; + + // For each of the polynomials in the working area we have to specify whether + // the expression should evaluate to a positive expression (=1), or a + // negative expression (=-1). + // NOTE: May become unnecessary to specify this in the future, if we can + // figure out a way to determine this automatically based on the working + // area. + parameter Real working_area_direction[:]; + + // Pump's minimum on and off time. + parameter Modelica.Units.SI.Duration minimum_on = 0.0; + parameter Modelica.Units.SI.Duration minimum_off = 0.0; + + // NOTE: Enumerations are not supported in JModelica's CasADi interface. We + // therefore resort to an integer. + // What head to use for the pump head. This can be + // -1: The upstream head + // 0: The differential head (i.e. downstream head minus upstream head) + // 1: The downstream head. + parameter Integer head_option = 0; + + parameter Modelica.Units.SI.Energy start_up_energy = 0.0; + parameter Real start_up_cost = 0.0; + + parameter Modelica.Units.SI.Energy shut_down_energy = 0.0; + parameter Real shut_down_cost = 0.0; + + // NOTE: The equality constraint setting dH to some combination of HQUp and + // HQDown (based on head_option) will be added in the Mixin. + Modelica.Units.SI.Distance dH; + +equation + if head_option == -1 then + dH = HQUp.H; + elseif head_option == 1 then + dH = HQDown.H; + else + dH = HQDown.H - HQUp.H; + end if; +end Pump; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/PumpingStation.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/PumpingStation.mo new file mode 100644 index 0000000..b4710a8 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/PumpingStation.mo @@ -0,0 +1,26 @@ +within Deltares.ChannelFlow.HydraulicStructures.PumpingStation; + +model PumpingStation + extends Deltares.ChannelFlow.Internal.HQTwoPort; + import SI = Modelica.Units.SI; + parameter Integer n_pumps = 0; + + // FIXME: For some reason JModelica/CasADi returns {1, 2} for the expression + // 1:3 if we store it as an Integer, whereas it returns {1, 2, 3} if we + // store it as a Real. The weird thing is that JModelica does not complain + // about any size mismatches. Furthermore, transposes also do not seem to + // work well. + // To work around these issues, we detect the -999 default array, and + // overwrite it in Python with the correct one. + parameter Integer pump_switching_matrix[n_pumps, n_pumps] = fill(-999, n_pumps, n_pumps); + parameter Integer pump_switching_constraints[n_pumps, 2] = fill(-999, n_pumps, 2); + + SI.VolumeFlowRate Q; +equation + // Discharge + Q = HQUp.Q; + + HQUp.M = -HQDown.M; + + // TODO: Annotation / pretty picture. Currently inheriting TwoPort. +end PumpingStation; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Resistance.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Resistance.mo new file mode 100644 index 0000000..55af1ec --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/Resistance.mo @@ -0,0 +1,22 @@ +within Deltares.ChannelFlow.HydraulicStructures.PumpingStation; + +// TODO: Negative flows (from down to up) are not supported. Do we want to support them? +model Resistance "Quadratic resistance of form dH=C*Q^2" + extends Deltares.ChannelFlow.Internal.HQTwoPort; + + parameter Real C = 0.0; + + // Head loss + input Modelica.Units.SI.Distance dH; +equation + // Head + HQDown.H = HQUp.H - dH; + + // Discharge + HQUp.Q + HQDown.Q = 0; + + // Substances + HQUp.M = -HQDown.M; + + // TODO: Annotation / pretty picture. Currently inheriting TwoPort. +end Resistance; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.mo new file mode 100644 index 0000000..cd428f6 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.mo @@ -0,0 +1,4 @@ +within Deltares.ChannelFlow.HydraulicStructures; + +package PumpingStation +end PumpingStation; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.order b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.order new file mode 100644 index 0000000..401cbaa --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/PumpingStation/package.order @@ -0,0 +1,3 @@ +Resistance +PumpingStation +Pump diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/Weir.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/Weir.mo new file mode 100644 index 0000000..4f62cd2 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/Weir.mo @@ -0,0 +1,21 @@ +within Deltares.ChannelFlow.HydraulicStructures.Weir; + +model Weir + import SI = Modelica.Units.SI; + extends Deltares.ChannelFlow.Internal.HQTwoPort; + + // Inputs + input SI.VolumeFlowRate Q; + + // Parameters + parameter SI.Length width "Width of the weir"; + parameter SI.VolumeFlowRate q_min "Minimum flow of the weir; has to be positive"; + parameter SI.VolumeFlowRate q_max "Maximum flow of the weir. Should be as low as possible."; + parameter SI.Length hw_min "Minimum height of the weir"; + parameter SI.Length hw_max "Maximum height of the weir"; + parameter Real weir_coef=0.61 "Weir discharge coefficient"; +equation + HQUp.Q + HQDown.Q = 0; // Negative comes in, positive out, so in a branch positive goes in + HQUp.Q = Q; + annotation(Icon(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}), graphics = {Polygon(visible = true, origin = {0, -16.667}, fillColor = {255, 128, 0}, fillPattern = FillPattern.Solid, lineThickness = 2, points = {{0, 66.667}, {-50, -33.333}, {50, -33.333}})}), Diagram(coordinateSystem(extent = {{-100, -100}, {100, 100}}, preserveAspectRatio = true, initialScale = 0.1, grid = {10, 10}))); +end Weir; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.mo new file mode 100644 index 0000000..c43fbb0 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.mo @@ -0,0 +1,4 @@ +within Deltares.ChannelFlow.HydraulicStructures; + +package Weir +end Weir; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.order b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.order new file mode 100644 index 0000000..8a5e444 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/Weir/package.order @@ -0,0 +1 @@ +Weir diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/package.mo b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/package.mo new file mode 100644 index 0000000..31be5e5 --- /dev/null +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/HydraulicStructures/package.mo @@ -0,0 +1,4 @@ +within Deltares.ChannelFlow; + +package HydraulicStructures +end HydraulicStructures; diff --git a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/package.order b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/package.order index d031e2c..749963a 100644 --- a/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/package.order +++ b/src/rtctools_channel_flow/modelica/Deltares/ChannelFlow/package.order @@ -3,3 +3,4 @@ Interfaces Internal SimpleRouting Hydraulic +HydraulicStructures