From 8584e8030b602fec7da07b682bf8dd750e57e5e3 Mon Sep 17 00:00:00 2001 From: Antoine Gautier Date: Wed, 28 Aug 2024 01:53:11 +0200 Subject: [PATCH 01/40] Fix TrueFalseHold with unit impulse input signal (#3967) * Fix issue with Dirac delta, update validation model * Update results * Split vector expression into 2 separate elsewhen clauses This is for https://github.com/lbl-srg/modelica-buildings/pull/3967#issuecomment-2311927171 * Update results --- .../Controls/OBC/CDL/Logical/TrueFalseHold.mo | 33 +++++++++++--- .../CDL/Logical/Validation/TrueFalseHold.mo | 19 +++++++- ...amples_OptimalStart_ConventionalSpring.txt | 10 ++--- ...amples_OptimalStart_ConventionalSummer.txt | 10 ++--- ...amples_OptimalStart_ConventionalWinter.txt | 4 +- ...xamples_OptimalStart_Guideline36Spring.txt | 10 ++--- ...xamples_OptimalStart_Guideline36Summer.txt | 10 ++--- ...xamples_OptimalStart_Guideline36Winter.txt | 10 ++--- ...C_CDL_Logical_Validation_TrueFalseHold.txt | 18 ++++---- ...xamples_OptimalStart_Guideline36Winter.txt | 10 ++--- ..._Examples_SmallOffice_ASHRAE2006Spring.txt | 44 +++++++++---------- ..._Examples_SmallOffice_ASHRAE2006Summer.txt | 42 +++++++++--------- ...Examples_SmallOffice_Guideline36Winter.txt | 16 +++---- ..._SmallOffice_IdealHeatingCoolingSummer.txt | 2 +- ...6_0_Examples_SmallOffice_Unconditioned.txt | 2 +- .../CDL/Logical/Validation/TrueFalseHold.mos | 1 + ...C.CDL.Logical.Validation.TrueFalseHold.mos | 4 +- .../UsersGuide/ReleaseNotes/Version_12_0_0.mo | 3 +- 18 files changed, 144 insertions(+), 104 deletions(-) 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="