diff --git a/Buildings/Controls/OBC/CDL/Logical/TrueFalseHold.mo b/Buildings/Controls/OBC/CDL/Logical/TrueFalseHold.mo index 76eac861d93..de1091d2759 100644 --- a/Buildings/Controls/OBC/CDL/Logical/TrueFalseHold.mo +++ b/Buildings/Controls/OBC/CDL/Logical/TrueFalseHold.mo @@ -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") @@ -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", @@ -132,6 +145,12 @@ alt=\"Input and output of the block\"/> revisions="