Commit f04c7563 authored by Jorn Baayen's avatar Jorn Baayen

Merge branch 'example_fixes' into 'master'

get mixed_integer working again

See merge request !67
parents 0fae3cd5 f0cc96ca
......@@ -45,8 +45,8 @@ represents a simple water system with the following elements:
``Deltares.ChannelFlow.Hydraulic.BoundaryConditions.Level``,
* a pump
``Deltares.ChannelFlow.Hydraulic.Structures.Pump``
* an orifice
``Deltares.ChannelFlow.Hydraulic.Structures.BooleanSubmergedOrifice``
* an orifice modeled as a pump
``Deltares.ChannelFlow.Hydraulic.Structures.Pump``
.. image:: ../../images/orifice_vs_pump_openmodelica.png
......@@ -70,9 +70,8 @@ connector ``HQPort``.
In addition to elements, the input variables ``Q_in``, ``H_sea``, ``Q_pump``,
and ``Q_orifice`` are also defined. Because we want to view the water levels in
the storage element in the output file, we also define output
variables ``storage_level`` and ``sea_level``. In the ``equation`` section,
equations are defined to relate the inputs and outputs to the appropriate water
system elements.
variables ``storage_level`` and ``sea_level``. It is usually easiest to set input
and output variables equal to their corresponding model variable in the same line.
To maintain the linearity of the model, we input the Boolean ``is_downhill`` as
a way to keep track of whether water can flow by gravity to the sea. This
......
model Example
// Declare Model Elements
Deltares.ChannelFlow.Hydraulic.Storage.Linear storage(A=1.0e6, H_b=0.0, HQ.H(min=0.0, max=0.5)) annotation(Placement(visible = true, transformation(origin = {32.022, -0}, extent = {{-10, -10}, {10, 10}}, rotation = -270)));
Deltares.ChannelFlow.Hydraulic.BoundaryConditions.Discharge discharge annotation(Placement(visible = true, transformation(origin = {60, -0}, extent = {{10, -10}, {-10, 10}}, rotation = 270)));
Deltares.ChannelFlow.Hydraulic.BoundaryConditions.Level level annotation(Placement(visible = true, transformation(origin = {-52.7, 0}, extent = {{-10, -10}, {10, 10}}, rotation = -270)));
Deltares.ChannelFlow.Hydraulic.Structures.Pump pump annotation(Placement(visible = true, transformation(origin = {0, -20}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Deltares.ChannelFlow.Hydraulic.Structures.Pump orifice annotation(Placement(visible = true, transformation(origin = {0, 20}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
input Modelica.SIunits.VolumeFlowRate Q_in(fixed=true);
input Modelica.SIunits.Position H_sea(fixed=true);
input Modelica.SIunits.VolumeFlowRate Q_pump(fixed=false, min=0.0, max=7.0);
input Modelica.SIunits.VolumeFlowRate Q_orifice(fixed=false, min=0.0, max=10.0);
// Define Input/Output Variables and set them equal to model variables
input Modelica.SIunits.VolumeFlowRate Q_pump(fixed=false, min=0.0, max=7.0) = pump.Q;
input Boolean is_downhill;
output Modelica.SIunits.Position storage_level;
output Modelica.SIunits.Position sea_level;
input Modelica.SIunits.VolumeFlowRate Q_in(fixed=true) = discharge.Q;
input Modelica.SIunits.Position H_sea(fixed=true) = level.H;
input Modelica.SIunits.VolumeFlowRate Q_orifice(fixed=false, min=0.0, max=10.0) = orifice.Q;
output Modelica.SIunits.Position storage_level = storage.HQ.H;
output Modelica.SIunits.Position sea_level = level.H;
equation
// Connect Model Elements
connect(orifice.HQDown, level.HQ) annotation(Line(visible = true, origin = {-33.025, 10}, points = {{25.025, 10}, {-6.675, 10}, {-6.675, -10}, {-11.675, -10}}, color = {0, 0, 255}));
connect(storage.HQ, orifice.HQUp) annotation(Line(visible = true, origin = {43.737, 48.702}, points = {{-3.715, -48.702}, {-3.737, -28.702}, {-35.737, -28.702}}, color = {0, 0, 255}));
connect(storage.HQ, pump.HQUp) annotation(Line(visible = true, origin = {4.669, -31.115}, points = {{35.353, 31.115}, {35.331, 11.115}, {3.331, 11.115}}, color = {0, 0, 255}));
connect(discharge.HQ, storage.HQ) annotation(Line(visible = true, origin = {46.011, -0}, points = {{5.989, 0}, {-5.989, -0}}, color = {0, 0, 255}));
connect(pump.HQDown, level.HQ) annotation(Line(visible = true, origin = {-33.025, -10}, points = {{25.025, -10}, {-6.675, -10}, {-6.675, 10}, {-11.675, 10}}, color = {0, 0, 255}));
discharge.Q = Q_in;
level.H = H_sea;
pump.Q = Q_pump;
orifice.Q = Q_orifice;
storage_level = storage.HQ.H;
sea_level = H_sea;
annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end Example;
time,Q_orifice,Q_pump,is_downhill,sea_level,storage_level
2013-05-19 22:00:00,0.000000,0.000000,1.000000,0.000000,0.400000
2013-05-19 23:00:00,0.000000,0.000000,1.000000,0.100000,0.418000
2013-05-20 00:00:00,1.672747,0.000000,1.000000,0.200000,0.429978
2013-05-20 01:00:00,3.889150,0.000000,1.000000,0.300000,0.433977
2013-05-20 02:00:00,2.125131,1.201018,1.000000,0.400000,0.440003
2013-05-20 03:00:00,0.000000,5.038647,0.000000,0.500000,0.439864
2013-05-20 04:00:00,0.000000,5.022802,0.000000,0.600000,0.439782
2013-05-20 05:00:00,0.000000,5.014486,0.000000,0.700000,0.439730
2013-05-20 06:00:00,0.000000,5.009141,0.000000,0.800000,0.439697
2013-05-20 07:00:00,0.000000,5.005138,0.000000,0.900000,0.439678
2013-05-20 08:00:00,0.000000,5.001728,0.000000,1.000000,0.439672
2013-05-20 09:00:00,0.000000,4.998489,0.000000,0.900000,0.439677
2013-05-20 10:00:00,0.000000,4.995079,0.000000,0.800000,0.439695
2013-05-20 11:00:00,0.000000,4.991072,0.000000,0.700000,0.439727
2013-05-20 12:00:00,0.000000,4.985678,0.000000,0.600000,0.439779
2013-05-20 13:00:00,0.000000,4.977065,0.000000,0.500000,0.439861
2013-05-20 14:00:00,2.125128,2.835581,1.000000,0.400000,0.440003
2013-05-20 15:00:00,3.975648,1.024338,1.000000,0.300000,0.440003
2013-05-20 16:00:00,5.197601,0.000000,1.000000,0.200000,0.439292
2013-05-20 17:00:00,6.150614,0.000000,1.000000,0.100000,0.435149
2013-05-20 18:00:00,6.436143,0.000000,1.000000,0.000000,0.429979
2013-05-20 00:00:00,1.671714,0.000000,1.000000,0.200000,0.429982
2013-05-20 01:00:00,3.889201,0.000000,1.000000,0.300000,0.433981
2013-05-20 02:00:00,2.125117,1.202160,1.000000,0.400000,0.440003
2013-05-20 03:00:00,0.000000,6.046332,0.000000,0.500000,0.436236
2013-05-20 04:00:00,0.000000,5.318681,0.000000,0.600000,0.435088
2013-05-20 05:00:00,0.000000,5.062000,0.000000,0.700000,0.434865
2013-05-20 06:00:00,0.000000,5.009117,0.000000,0.800000,0.434832
2013-05-20 07:00:00,0.000000,5.000202,0.000000,0.900000,0.434832
2013-05-20 08:00:00,0.000000,4.999319,0.000000,1.000000,0.434834
2013-05-20 09:00:00,0.000000,5.000742,0.000000,0.900000,0.434831
2013-05-20 10:00:00,0.000000,5.000108,0.000000,0.800000,0.434831
2013-05-20 11:00:00,0.000000,4.992524,0.000000,0.700000,0.434858
2013-05-20 12:00:00,0.000000,4.944152,0.000000,0.600000,0.435059
2013-05-20 13:00:00,0.000000,4.622809,0.000000,0.500000,0.436417
2013-05-20 14:00:00,2.125114,1.878932,1.000000,0.400000,0.440002
2013-05-20 15:00:00,3.975640,1.024350,1.000000,0.300000,0.440002
2013-05-20 16:00:00,5.105053,0.000000,1.000000,0.200000,0.439624
2013-05-20 17:00:00,5.543917,0.000000,1.000000,0.100000,0.437666
2013-05-20 18:00:00,5.286357,0.000000,1.000000,0.000000,0.436635
model Example
// Declare Model Elements
Deltares.ChannelFlow.Hydraulic.Storage.Linear storage(A=1.0e6, H_b=0.0, HQ.H(min=0.0, max=0.5)) annotation(Placement(visible = true, transformation(origin = {32.022, -0}, extent = {{-10, -10}, {10, 10}}, rotation = -270)));
Deltares.ChannelFlow.Hydraulic.BoundaryConditions.Discharge discharge annotation(Placement(visible = true, transformation(origin = {60, -0}, extent = {{10, -10}, {-10, 10}}, rotation = 270)));
Deltares.ChannelFlow.Hydraulic.BoundaryConditions.Level level annotation(Placement(visible = true, transformation(origin = {-52.7, 0}, extent = {{-10, -10}, {10, 10}}, rotation = -270)));
Deltares.ChannelFlow.Hydraulic.Structures.Pump pump annotation(Placement(visible = true, transformation(origin = {0, -20}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
Deltares.ChannelFlow.Hydraulic.Structures.BooleanSubmergedOrifice orifice(width = 3.0, height = 0.8) annotation(Placement(visible = true, transformation(origin = {0, 20}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
input Modelica.SIunits.VolumeFlowRate Q_in(fixed=true);
input Modelica.SIunits.Position H_sea(fixed=true);
input Modelica.SIunits.VolumeFlowRate Q_pump(fixed=false, min=0.0, max=7.0);
input Modelica.SIunits.VolumeFlowRate Q_orifice(fixed=false, min=0.0, max=10.0);
Deltares.ChannelFlow.Hydraulic.Structures.Pump orifice annotation(Placement(visible = true, transformation(origin = {0, 20}, extent = {{10, -10}, {-10, 10}}, rotation = 0)));
// Define Input/Output Variables and set them equal to model variables
input Modelica.SIunits.VolumeFlowRate Q_pump(fixed=false, min=0.0, max=7.0) = pump.Q;
input Boolean is_downhill;
output Modelica.SIunits.Position storage_level;
output Modelica.SIunits.Position sea_level;
input Modelica.SIunits.VolumeFlowRate Q_in(fixed=true) = discharge.Q;
input Modelica.SIunits.Position H_sea(fixed=true) = level.H;
input Modelica.SIunits.VolumeFlowRate Q_orifice(fixed=false, min=0.0, max=10.0) = orifice.Q;
output Modelica.SIunits.Position storage_level = storage.HQ.H;
output Modelica.SIunits.Position sea_level = level.H;
equation
// Connect Model Elements
connect(orifice.HQDown, level.HQ) annotation(Line(visible = true, origin = {-33.025, 10}, points = {{25.025, 10}, {-6.675, 10}, {-6.675, -10}, {-11.675, -10}}, color = {0, 0, 255}));
connect(storage.HQ, orifice.HQUp) annotation(Line(visible = true, origin = {43.737, 48.702}, points = {{-3.715, -48.702}, {-3.737, -28.702}, {-35.737, -28.702}}, color = {0, 0, 255}));
connect(storage.HQ, pump.HQUp) annotation(Line(visible = true, origin = {4.669, -31.115}, points = {{35.353, 31.115}, {35.331, 11.115}, {3.331, 11.115}}, color = {0, 0, 255}));
connect(discharge.HQ, storage.HQ) annotation(Line(visible = true, origin = {46.011, -0}, points = {{5.989, 0}, {-5.989, -0}}, color = {0, 0, 255}));
connect(pump.HQDown, level.HQ) annotation(Line(visible = true, origin = {-33.025, -10}, points = {{25.025, -10}, {-6.675, -10}, {-6.675, 10}, {-11.675, 10}}, color = {0, 0, 255}));
discharge.Q = Q_in;
level.H = H_sea;
pump.Q = Q_pump;
orifice.Q = Q_orifice;
storage_level = storage.HQ.H;
sea_level = H_sea;
annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5})));
end Example;
\ No newline at end of file
time,Q_orifice,Q_pump,is_downhill,sea_level,storage_level
2013-05-19 22:00:00,3.661655,0.000000,1.000000,0.000000,0.400000
2013-05-19 22:00:00,0.000000,0.000000,1.000000,0.000000,0.400000
2013-05-19 23:00:00,5.791971,0.000000,1.000000,0.100000,0.397149
2013-05-20 00:00:00,4.729408,0.000000,1.000000,0.200000,0.398123
2013-05-20 01:00:00,3.423235,0.000000,1.000000,0.300000,0.403799
2013-05-20 02:00:00,1.378672,0.000000,1.000000,0.400000,0.416836
2013-05-20 03:00:00,0.000000,4.622680,0.000000,0.500000,0.418195
2013-05-20 04:00:00,0.000000,4.228897,0.000000,0.600000,0.420970
2013-05-20 05:00:00,0.000000,3.904761,0.000000,0.700000,0.424913
2013-05-20 06:00:00,0.000000,3.586908,0.000000,0.800000,0.430000
2013-05-20 07:00:00,0.000000,3.263765,0.000000,0.900000,0.436251
2013-05-20 08:00:00,0.000000,2.934204,0.000000,1.000000,0.443688
2013-05-20 09:00:00,0.000000,2.600447,0.000000,0.900000,0.452326
2013-05-20 10:00:00,0.000000,2.254012,0.000000,0.800000,0.462212
2013-05-20 11:00:00,0.000000,1.897100,0.000000,0.700000,0.473382
2013-05-20 12:00:00,0.000000,1.521407,0.000000,0.600000,0.485905
2013-05-20 13:00:00,0.001503,1.083248,1.000000,0.500000,0.500000
2013-05-20 03:00:00,0.000000,4.476889,0.000000,0.500000,0.418719
2013-05-20 04:00:00,0.000000,4.103700,0.000000,0.600000,0.421946
2013-05-20 05:00:00,0.000000,3.817639,0.000000,0.700000,0.426203
2013-05-20 06:00:00,0.000000,3.544285,0.000000,0.800000,0.431443
2013-05-20 07:00:00,0.000000,3.265951,0.000000,0.900000,0.437686
2013-05-20 08:00:00,0.000000,2.976000,0.000000,1.000000,0.444972
2013-05-20 09:00:00,0.000000,2.671708,0.000000,0.900000,0.453354
2013-05-20 10:00:00,0.000000,2.340619,0.000000,0.800000,0.462928
2013-05-20 11:00:00,0.000000,1.983423,0.000000,0.700000,0.473787
2013-05-20 12:00:00,0.000000,1.592914,0.000000,0.600000,0.486053
2013-05-20 13:00:00,0.000315,1.125490,1.000000,0.500000,0.500000
2013-05-20 14:00:00,3.360000,1.640000,1.000000,0.400000,0.500000
2013-05-20 15:00:00,4.751758,0.248242,1.000000,0.300000,0.500000
2013-05-20 16:00:00,5.442400,0.000000,1.000000,0.200000,0.498407
2013-05-20 17:00:00,5.779148,0.000000,1.000000,0.100000,0.495602
2013-05-20 18:00:00,5.461580,0.000000,1.000000,0.000000,0.493941
2013-05-20 16:00:00,5.475820,0.000000,1.000000,0.200000,0.498287
2013-05-20 17:00:00,5.815266,0.000000,1.000000,0.100000,0.495352
2013-05-20 18:00:00,5.494218,0.000000,1.000000,0.000000,0.493573
......@@ -41,14 +41,19 @@ class Example(CSVMixin, ModelicaMixin, CollocatedIntegratedOptimizationProblem):
constraints.append((self.state('H_sea') - self.state('storage.HQ.H') +
self.state('is_downhill') * M, 0.0, inf))
# Orifice flow upper bound. Uses the equation:
# Q = width * C * height * (2 * g * (HQUp.H - HQDown.H)) ^ 0.5
# orifice.LHS is the left-hand-side of this equation in standard form:
# ((Q / (width * height * C)) ^ 2) / (g * 2) + HQDown.H - HQUp.H = 0
# Orifice flow constraint. Uses the equation:
# Q(HUp, HDown, d) = width * C * d * (2 * g * (HUp - HDown)) ^ 0.5
# Note that this equation is only valid for orifices that are submerged
# units: description:
w = 3.0 # m width of orifice
d = 0.8 # m hight of orifice
C = 1.0 # none orifice constant
g = 9.8 # m/s^2 gravitational acceleration
constraints.append(
(self.state('orifice.LHS') - M * (1.0 - self.state('is_downhill')),
(((self.state('Q_orifice') / (w * C * d)) ** 2) / (2 * g) +
self.state('orifice.HQDown.H') - self.state('orifice.HQUp.H') -
M * (1 - self.state('is_downhill')),
-inf, 0.0))
# Note that this element is only valid for orifices that are submerged!
return constraints
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment