Skip to content

Commit

Permalink
Merge pull request #1222 from ibpsa/issue1221_limiterHomotopy
Browse files Browse the repository at this point in the history
disabled homotopy for #1221
  • Loading branch information
mwetter committed Nov 19, 2019
2 parents bdbbb9c + 7b83a6a commit e17ca51
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 5 deletions.
97 changes: 95 additions & 2 deletions IBPSA/Controls/Continuous/LimPID.mo
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ protected
annotation (
Placement(transformation(extent={{60,-80},{40,-60}})));

Modelica.Blocks.Nonlinear.Limiter limiter(
Limiter limiter(
final uMax=yMax,
final uMin=yMin,
final strict=strict) "Output limiter"
final strict=strict)
"Output limiter"
annotation (Placement(transformation(extent={{70,-10},{90,10}})));


Expand All @@ -191,6 +192,91 @@ protected
"Signal source for integrator reset"
annotation (Placement(transformation(extent={{-80,-90},{-60,-70}})));

// The block Limiter below has been implemented as it is introduced in MSL 3.2.3, but
// not all tools include MSL 3.2.3.
// See https://github.com/ibpsa/modelica-ibpsa/pull/1222#issuecomment-554114617
block Limiter "Limit the range of a signal"
parameter Real uMax(start=1) "Upper limits of input signals";
parameter Real uMin= -uMax "Lower limits of input signals";
parameter Boolean strict=false "= true, if strict limits with noEvent(..)"
annotation (Evaluate=true, choices(checkBox=true), Dialog(tab="Advanced"));
parameter Boolean limitsAtInit=true
"Has no longer an effect and is only kept for backwards compatibility (the implementation uses now the homotopy operator)"
annotation (Dialog(tab="Dummy"),Evaluate=true, choices(checkBox=true));
extends Modelica.Blocks.Interfaces.SISO;

equation
assert(uMax >= uMin, "Limiter: Limits must be consistent. However, uMax (=" + String(uMax) +
") < uMin (=" + String(uMin) + ")");

if strict then
y = smooth(0, noEvent(if u > uMax then uMax else if u < uMin then uMin else u));
else
y = smooth(0,if u > uMax then uMax else if u < uMin then uMin else u);
end if;
annotation (
Icon(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Line(points={{0,-90},{0,68}}, color={192,192,192}),
Polygon(
points={{0,90},{-8,68},{8,68},{0,90}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-90,0},{68,0}}, color={192,192,192}),
Polygon(
points={{90,0},{68,-8},{68,8},{90,0}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-80,-70},{-50,-70},{50,70},{80,70}}),
Text(
extent={{-150,-150},{150,-110}},
textString="uMax=%uMax"),
Line(
visible=strict,
points={{50,70},{80,70}},
color={255,0,0}),
Line(
visible=strict,
points={{-80,-70},{-50,-70}},
color={255,0,0})}),
Diagram(coordinateSystem(
preserveAspectRatio=true,
extent={{-100,-100},{100,100}}), graphics={
Line(points={{0,-60},{0,50}}, color={192,192,192}),
Polygon(
points={{0,60},{-5,50},{5,50},{0,60}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-60,0},{50,0}}, color={192,192,192}),
Polygon(
points={{60,0},{50,-5},{50,5},{60,0}},
lineColor={192,192,192},
fillColor={192,192,192},
fillPattern=FillPattern.Solid),
Line(points={{-50,-40},{-30,-40},{30,40},{50,40}}),
Text(
extent={{46,-6},{68,-18}},
lineColor={128,128,128},
textString="u"),
Text(
extent={{-30,70},{-5,50}},
lineColor={128,128,128},
textString="y"),
Text(
extent={{-58,-54},{-28,-42}},
lineColor={128,128,128},
textString="uMin"),
Text(
extent={{26,40},{66,56}},
lineColor={128,128,128},
textString="uMax")}));
end Limiter;


initial equation
if initType==Modelica.Blocks.Types.InitPID.InitialOutput then
gainPID.y = y_start;
Expand Down Expand Up @@ -336,6 +422,13 @@ Some parameters assignments in the instances have been made final.
revisions="<html>
<ul>
<li>
October 19, 2019, by Filip Jorissen:<br/>
Disabled homotopy to ensure bounded outputs
by copying the implementation from MSL 3.2.3 and by
hardcoding the implementation for <code>homotopyType=NoHomotopy</code>.
See <a href=\"https://github.com/ibpsa/modelica-ibpsa/issues/1221\">issue 1221</a>.
</li>
<li>
September 29, 2016, by Michael Wetter:<br/>
Refactored model.
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
last-generated=2018-06-22
last-generated=2019-11-09
statistics-simulation=
{
"linear": " ",
"nonlinear": " ",
"number of continuous time states": "2",
"numerical Jacobians": "0"
}
con.u_m=[2.931499938964844e+02, 2.898402099609375e+02, 2.868109436035156e+02, 2.840455017089844e+02, 2.815281677246094e+02, 2.792446899414062e+02, 2.771823425292969e+02, 2.753295288085938e+02, 2.736747131347656e+02, 2.722072448730469e+02, 2.709170227050781e+02, 2.697947387695312e+02, 2.717220458984375e+02, 2.772921752929688e+02, 2.824770812988281e+02, 2.873129577636719e+02, 2.918327026367188e+02, 2.96066162109375e+02, 3.000403747558594e+02, 3.037797546386719e+02, 3.073062744140625e+02, 3.106398315429688e+02, 3.132925109863281e+02, 3.131466674804688e+02, 3.131512145996094e+02, 3.131510925292969e+02, 3.131510925292969e+02, 3.131510925292969e+02, 3.131510620117188e+02, 3.131510620117188e+02, 3.131510314941406e+02, 3.131510009765625e+02, 3.131510009765625e+02, 3.131509704589844e+02, 3.131509094238281e+02, 3.1315087890625e+02, 3.131508483886719e+02, 3.131507873535156e+02, 3.131507568359375e+02, 3.131506958007812e+02, 3.131525268554688e+02, 3.131973266601562e+02, 3.132941284179688e+02, 3.134329528808594e+02, 3.136045227050781e+02, 3.138001098632812e+02, 3.140115966796875e+02, 3.134809265136719e+02, 3.117776794433594e+02, 3.102276611328125e+02, 3.088117065429688e+02, 3.075130310058594e+02, 3.063161315917969e+02, 3.052058715820312e+02, 3.041682739257812e+02, 3.031909484863281e+02, 3.022622680664062e+02, 3.013719482421875e+02, 3.005109252929688e+02, 3.049744567871094e+02, 3.103306274414062e+02, 3.134226379394531e+02, 3.133167724609375e+02, 3.131485900878906e+02, 3.131491394042969e+02, 3.131491088867188e+02, 3.131490783691406e+02, 3.131490478515625e+02, 3.131490173339844e+02, 3.131489868164062e+02, 3.131489562988281e+02, 3.131489562988281e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.131488952636719e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.131489562988281e+02, 3.131489562988281e+02, 3.131489868164062e+02, 3.131490173339844e+02, 3.131490478515625e+02, 3.131490783691406e+02, 3.131491088867188e+02, 3.13149169921875e+02, 3.131492004394531e+02, 3.131492614746094e+02, 3.131492919921875e+02, 3.131493530273438e+02, 3.131494140625e+02, 3.131494750976562e+02, 3.131495361328125e+02, 3.131495971679688e+02, 3.13149658203125e+02, 3.131497192382812e+02, 3.131497802734375e+02, 3.131498718261719e+02, 3.131499328613281e+02, 3.131499938964844e+02]
con.u_m=[2.931499938964844e+02, 2.898402099609375e+02, 2.868109436035156e+02, 2.840455017089844e+02, 2.815281677246094e+02, 2.792446899414062e+02, 2.771823425292969e+02, 2.753295288085938e+02, 2.736747131347656e+02, 2.722072448730469e+02, 2.709170227050781e+02, 2.697947387695312e+02, 2.717220458984375e+02, 2.772921752929688e+02, 2.824770812988281e+02, 2.873129577636719e+02, 2.918327026367188e+02, 2.96066162109375e+02, 3.000403747558594e+02, 3.037797546386719e+02, 3.073062744140625e+02, 3.106398315429688e+02, 3.132925109863281e+02, 3.131466674804688e+02, 3.131512145996094e+02, 3.131510925292969e+02, 3.131510925292969e+02, 3.131510925292969e+02, 3.131510620117188e+02, 3.131510620117188e+02, 3.131510314941406e+02, 3.131510009765625e+02, 3.131510009765625e+02, 3.131509704589844e+02, 3.131509094238281e+02, 3.1315087890625e+02, 3.131508483886719e+02, 3.131507873535156e+02, 3.131507568359375e+02, 3.131506958007812e+02, 3.131525268554688e+02, 3.131973266601562e+02, 3.132941284179688e+02, 3.134329528808594e+02, 3.136045227050781e+02, 3.138001403808594e+02, 3.140116577148438e+02, 3.134803466796875e+02, 3.117771301269531e+02, 3.102271728515625e+02, 3.088112487792969e+02, 3.075126037597656e+02, 3.063157653808594e+02, 3.052055358886719e+02, 3.041679382324219e+02, 3.03190673828125e+02, 3.022620239257812e+02, 3.013717346191406e+02, 3.005107116699219e+02, 3.049763488769531e+02, 3.103323669433594e+02, 3.134226379394531e+02, 3.133167724609375e+02, 3.131486206054688e+02, 3.131491394042969e+02, 3.131491394042969e+02, 3.131490783691406e+02, 3.131490478515625e+02, 3.131490173339844e+02, 3.131489868164062e+02, 3.131489562988281e+02, 3.131489562988281e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.131488952636719e+02, 3.131488952636719e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.1314892578125e+02, 3.131489562988281e+02, 3.131489868164062e+02, 3.131490173339844e+02, 3.131490478515625e+02, 3.131490783691406e+02, 3.131491088867188e+02, 3.13149169921875e+02, 3.131492004394531e+02, 3.131492614746094e+02, 3.131492919921875e+02, 3.131493530273438e+02, 3.131494140625e+02, 3.131494750976562e+02, 3.131495361328125e+02, 3.131495971679688e+02, 3.13149658203125e+02, 3.131497192382812e+02, 3.131497802734375e+02, 3.131498413085938e+02, 3.131499328613281e+02, 3.131499938964844e+02]
con.u_s=[3.131499938964844e+02, 3.131499938964844e+02]
time=[0e+00, 8.64e+04]
con.y=[0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 4.000964462757111e-01, 5.353429913520813e-01, 5.156108736991882e-01, 5.000187754631042e-01, 4.843146800994873e-01, 4.686800539493561e-01, 4.53165590763092e-01, 4.378383457660675e-01, 4.227559566497803e-01, 4.07978892326355e-01, 3.9356330037117e-01, 3.795678317546844e-01, 3.660500049591064e-01, 3.530589044094086e-01, 3.406482636928558e-01, 3.288666605949402e-01, 3.177599310874939e-01, 3.073725998401642e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 1e+00, 1e+00, 3.00000011920929e-01, 3.00000011920929e-01, 3.027593493461609e-01, 3.414360582828522e-01, 3.530188202857971e-01, 3.660250306129456e-01, 3.795422911643982e-01, 3.93537998199463e-01, 4.079533219337462e-01, 4.227307140827178e-01, 4.378128945827484e-01, 4.531392753124237e-01, 4.686513245105743e-01, 4.842873513698578e-01, 4.99985545873642e-01, 5.156839489936829e-01, 5.313203930854797e-01, 5.468342900276184e-01, 5.621618628501892e-01, 5.77243983745575e-01, 5.920221209526062e-01, 6.064366698265076e-01, 6.204313039779663e-01, 6.339501738548279e-01, 6.46941602230072e-01, 6.593520045280457e-01, 6.711337566375732e-01, 6.822402477264404e-01, 6.926271915435791e-01, 7.022541165351868e-01, 7.110830545425415e-01, 7.190787792205811e-01, 7.262097597122192e-01, 7.324482798576355e-01, 7.37769603729248e-01, 7.421529293060303e-01, 7.455797791481018e-01, 7.480376958847046e-01, 7.495173811912537e-01, 7.500106692314148e-01]
con.y=[0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 1e+00, 4.00081992149353e-01, 5.35348653793335e-01, 5.156134963035583e-01, 5.000161528587341e-01, 4.843102991580963e-01, 4.686746001243591e-01, 4.53165054321289e-01, 4.378353655338287e-01, 4.227547347545624e-01, 4.079819321632385e-01, 3.935560584068298e-01, 3.795717358589172e-01, 3.660544455051422e-01, 3.530621230602265e-01, 3.406396806240082e-01, 3.288702964782715e-01, 3.177606463432312e-01, 3.07371973991394e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 3.00000011920929e-01, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 0e+00, 1e+00, 1e+00, 3.00000011920929e-01, 3.00000011920929e-01, 3.027577102184296e-01, 3.414410054683685e-01, 3.530088365077972e-01, 3.660304546356201e-01, 3.795446455478668e-01, 3.935376703739167e-01, 4.079526066780089e-01, 4.227280616760253e-01, 4.378052353858948e-01, 4.531471133232117e-01, 4.68649297952652e-01, 4.842866957187653e-01, 4.999865591526031e-01, 5.156813263893127e-01, 5.313149690628052e-01, 5.468428730964661e-01, 5.621551275253296e-01, 5.772404074668884e-01, 5.920273065567017e-01, 6.064383387565613e-01, 6.204272508621216e-01, 6.339491009712219e-01, 6.469439268112183e-01, 6.593599319458008e-01, 6.711235046386719e-01, 6.822413206100464e-01, 6.92631721496582e-01, 7.022591829299927e-01, 7.110856771469116e-01, 7.190799713134766e-01, 7.262053489685059e-01, 7.324503064155579e-01, 7.377764582633972e-01, 7.421417236328125e-01, 7.455839514732361e-01, 7.480451464653015e-01, 7.495126128196716e-01, 7.499999403953552e-01]

0 comments on commit e17ca51

Please sign in to comment.