I noted numerical issues integrating a pulse input that is delayed by a fixed amount of time in Modelica (using Wolfram System Modeler 4.3):
model PulseTest "Test FixedDelay with Pulse Input";
Modelica.Blocks.Sources.Pulse pulse(
startTime = 1,
width = 100,
period = 1/32,
amplitude = 32,
nperiod = 1
);
Modelica.Blocks.Nonlinear.FixedDelay fixedDelay( delayTime = 5 );
Modelica.Blocks.Continuous.Integrator x; // integrator for the undelayed pulse
Modelica.Blocks.Continuous.Integrator y; // integrator for the delayed pulse
equation
connect( pulse.y, fixedDelay.u );
connect( fixedDelay.y, y.u );
connect( pulse.y, x.u );
end PulseTest;
Integrating a pulse with period = 1/a, amplitude = a, and width = 100 % should give 1.0. But as can be seen from the plot, this is not what I get for the delayed pulse:
Only the undelayed signal gives the correct value using DASSL. The numerical integration error will appear already for period = 1/a = 1/8 and (naturally) grow as a grows.
What is the best remedy?
The problem is, as Markus A wrote, that that delay does not propagate the discontinuity from input to output and therefore the simulation does not handle the delayed step-change in the same way as a normal step-change, i.e. with event-detection and event-handling.
From a tool-perspective smoothly interpolation the delayed signal is not merely the simplest solution - but also avoids a cascade of events if the delayed signal is fed back.
I cannot see any simple reliable workaround when using any variable step-size solver.
As Ankit posted at the Wolfram Forum, the problem is that the signal is discrete but the delay block is unaware of that. It can be fixed with a different delay block:
model DiscreteFixedDelay
discrete input Modelica.Blocks.Interfaces.RealInput u ;
discrete output Modelica.Blocks.Interfaces.RealOutput y ;
parameter Modelica.SIunits.Time delayTime(start = 5) = 5 "Delay time of output with respect to input signal";
equation
y = delay(u, delayTime);
end DiscreteFixedDelay;
Regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With