Skip to content

Commit

Permalink
Fix TrueFalseHold with unit impulse input signal (#3967)
Browse files Browse the repository at this point in the history
* Fix issue with Dirac delta, update validation model

* Update results

* Split vector expression into 2 separate elsewhen clauses

This is for #3967 (comment)

* Update results
  • Loading branch information
AntoineGautier authored Aug 27, 2024
1 parent 424a30c commit 8584e80
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 104 deletions.
33 changes: 26 additions & 7 deletions Buildings/Controls/OBC/CDL/Logical/TrueFalseHold.mo
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ protected
parameter Boolean pre_u_start=false
"Value of pre(u) at initial time"
annotation (Evaluate=true);
Boolean not_u = not u
"Opposite of u";
Boolean not_y = not y
"Opposite of y";
discrete Real entryTimeTrue(
final quantity="Time",
final unit="s")
Expand All @@ -37,20 +41,29 @@ initial equation
pre(entryTimeTrue) = -Modelica.Constants.inf;
pre(entryTimeFalse) = -Modelica.Constants.inf;
pre(u) = pre_u_start;
pre(not_u) = not pre_u_start;
pre(y) = u;
pre(not_y) = not u;
equation
when initial() then
y = u;
entryTimeTrue = if y then time else pre(entryTimeTrue);
entryTimeFalse = if not y then time else pre(entryTimeFalse);
elsewhen {change(u),
time >= pre(entryTimeFalse) + falseHoldDuration and
time >= pre(entryTimeTrue) + trueHoldDuration} then
y=if time >= pre(entryTimeFalse) + falseHoldDuration and
time >= pre(entryTimeTrue) + trueHoldDuration then u
/*
The two elsewhen clauses below are kept separate to address an issue
with event handling in the CVODE solver.
*/
elsewhen {edge(u), edge(not_u)} then
y = if time >= pre(entryTimeFalse) + falseHoldDuration and
time >= pre(entryTimeTrue) + trueHoldDuration then u
else pre(y);
entryTimeTrue = if change(y) and y then time else pre(entryTimeTrue);
entryTimeFalse = if change(y) and not y then time else pre(entryTimeFalse);
entryTimeTrue = if edge(y) then time else pre(entryTimeTrue);
entryTimeFalse = if edge(not_y) then time else pre(entryTimeFalse);
elsewhen time >= pre(entryTimeFalse) + falseHoldDuration and
time >= pre(entryTimeTrue) + trueHoldDuration then
y = u;
entryTimeTrue = if edge(y) then time else pre(entryTimeTrue);
entryTimeFalse = if edge(not_y) then time else pre(entryTimeFalse);
end when;
annotation (
defaultComponentName="truFalHol",
Expand Down Expand Up @@ -132,6 +145,12 @@ alt=\"Input and output of the block\"/>
revisions="<html>
<ul>
<li>
August 26, 2024, by Antoine Gautier:<br/>
Resolved an issue with unit impulse signals.<br/>
This is for
<a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3966\">issue 3966</a>.
</li>
<li>
June 13, 2024, by Antoine Gautier:<br/>
Refactored with synchronous language elements.<br/>
This is for
Expand Down
19 changes: 17 additions & 2 deletions Buildings/Controls/OBC/CDL/Logical/Validation/TrueFalseHold.mo
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,18 @@ model TrueFalseHold
trueHoldDuration=1000)
"The block introduces a minimal offset between the input signal rising and falling edge"
annotation (Placement(transformation(extent={{120,-60},{140,-40}})));
Buildings.Controls.OBC.CDL.Logical.Not not2
"Negation of input signal"
Buildings.Controls.OBC.CDL.Logical.Not not2 "Negation of input signal"
annotation (Placement(transformation(extent={{70,-20},{90,0}})));
Buildings.Controls.OBC.CDL.Logical.Not not4
"Negation of input signal"
annotation (Placement(transformation(extent={{70,-60},{90,-40}})));

Buildings.Controls.OBC.CDL.Logical.TrueFalseHold truFalHol8(trueHoldDuration=
0, falseHoldDuration=1000)
"Hold only false value of unit impulse signal"
annotation (Placement(transformation(extent={{120,-90},{140,-70}})));
Buildings.Controls.OBC.CDL.Logical.Edge edg "Generate unit impulse signal"
annotation (Placement(transformation(extent={{70,-90},{90,-70}})));
equation
connect(booPul.y,truFalHol.u)
annotation (Line(points={{-118,70},{-118,70},{-42,70}},color={255,0,255}));
Expand All @@ -115,6 +120,10 @@ equation
annotation (Line(points={{42,-50},{68,-50}},color={255,0,255}));
connect(not4.y,truFalHol7.u)
annotation (Line(points={{92,-50},{118,-50}},color={255,0,255}));
connect(edg.y, truFalHol8.u)
annotation (Line(points={{92,-80},{118,-80}}, color={255,0,255}));
connect(booPul6.y, edg.u) annotation (Line(points={{42,-10},{60,-10},{60,-80},
{68,-80}}, color={255,0,255}));
annotation (
experiment(
StopTime=7200.0,
Expand All @@ -136,6 +145,12 @@ of the input pulse, and different initial values for the input signal.
revisions="<html>
<ul>
<li>
August 26, 2024, by Antoine Gautier:<br/>
Added a case with a unit impulse signal.<br/>
This is for
<a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3966\">issue 3966</a>.
</li>
<li>
June 14, 2017, by Michael Wetter:<br/>
Added more tests for different initial signals and different hold values.
</li>
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
last-generated=2023-06-16
last-generated=2024-08-27
statistics-initialization=
{
"linear": "0, 0, 0, 0, 0, 0, 0, 0",
"nonlinear": "42, 42, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1",
"nonlinear": "0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 42, 42",
"numerical Jacobians": "0"
}
statistics-simulation=
Expand Down
Loading

0 comments on commit 8584e80

Please sign in to comment.