From ce126f8a7dcefcaae0639444a0aff7db3053d7ba Mon Sep 17 00:00:00 2001 From: HOS Date: Fri, 23 May 2025 10:32:03 +0200 Subject: [PATCH 1/3] Updated --- Modelica/Blocks/Discrete.mo | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Modelica/Blocks/Discrete.mo b/Modelica/Blocks/Discrete.mo index 30f4b108e0..180d30e46e 100644 --- a/Modelica/Blocks/Discrete.mo +++ b/Modelica/Blocks/Discrete.mo @@ -112,13 +112,17 @@ values of the last two sampled input signals. parameter Real y_start=0 "Initial value of output signal"; extends Interfaces.DiscreteSISO; + protected + Real u_internal; equation when sampleTrigger then - y = pre(u); + y = pre(u_internal); + u_internal = u; end when; initial equation - y = y_start; + y = y_start; + u_internal = y_start; annotation ( Documentation(info="

@@ -135,6 +139,8 @@ previous sample instant. Before the second sample instant, the output y is identical to parameter yStart.

+", revisions=" +

May 23, 2025 - updated to work without requiring a sampled input, but work the same if the input was sampled.

"), Icon( coordinateSystem(preserveAspectRatio=true, extent={{-100.0,-100.0},{100.0,100.0}}), From 9a741caf503047b09c6ba1b1e8932800e1bd910a Mon Sep 17 00:00:00 2001 From: HOS Date: Fri, 23 May 2025 10:32:33 +0200 Subject: [PATCH 2/3] AddTestShowingIt --- ModelicaTest/Blocks.mo | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ModelicaTest/Blocks.mo b/ModelicaTest/Blocks.mo index d1629a24ea..55c7774077 100644 --- a/ModelicaTest/Blocks.mo +++ b/ModelicaTest/Blocks.mo @@ -1843,6 +1843,8 @@ This shows the improvements in the numerics when balance=true is set. annotation (Placement(transformation(extent={{0,40},{20,60}}))); Modelica.Blocks.Discrete.TriggeredMax triggeredMax annotation (Placement(transformation(extent={{60,70},{80,90}}))); + Modelica.Blocks.Discrete.UnitDelay unitDelay1(samplePeriod=samplePeriod) + annotation (Placement(transformation(extent={{0,0},{20,20}}))); equation connect(sine.y, sampler.u) annotation (Line(points={{-59,80},{-42,80}}, color={0,0,127})); @@ -1864,6 +1866,8 @@ This shows the improvements in the numerics when balance=true is set. {-52,80},{-52,96},{54,96},{54,80},{58,80}}, color={0,0,127})); connect(booleanPulse.y, triggeredMax.trigger) annotation (Line(points={{21,50},{70,50},{70,68.2}}, color={255,0,255})); + connect(sampler.y, unitDelay1.u) annotation (Line(points={{-19,80},{-12,80}, + {-12,10},{-2,10}}, color={0,0,127})); annotation (experiment(StopTime=1.1)); end Discrete; From 776052ef11403afc5ce040c5461743a4e1e5a92a Mon Sep 17 00:00:00 2001 From: HOS Date: Fri, 23 May 2025 12:52:31 +0200 Subject: [PATCH 3/3] TestFunctionality --- ModelicaTest/Blocks.mo | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ModelicaTest/Blocks.mo b/ModelicaTest/Blocks.mo index 55c7774077..b8b73acec5 100644 --- a/ModelicaTest/Blocks.mo +++ b/ModelicaTest/Blocks.mo @@ -1867,7 +1867,8 @@ This shows the improvements in the numerics when balance=true is set. connect(booleanPulse.y, triggeredMax.trigger) annotation (Line(points={{21,50},{70,50},{70,68.2}}, color={255,0,255})); connect(sampler.y, unitDelay1.u) annotation (Line(points={{-19,80},{-12,80}, - {-12,10},{-2,10}}, color={0,0,127})); + {-12,10},{-2,10}}, color={0,0,127})); + assert(abs(unitDelay.y-unitDelay1.y)<1e-3, "Should be the same"); annotation (experiment(StopTime=1.1)); end Discrete;