Opened 16 years ago

Closed 10 years ago

#1048 closed defect (fixed)

delay gives wrong result for discrete signals (from MathCore)

Reported by: krsta Owned by: Willi Braun
Priority: critical Milestone: 1.9.1
Component: Run-time Version:
Keywords: Cc: krsta, Willi Braun

Description

When using delay on discrete signals, the delay-signal is no longer discrete, the interpolation does not take events into consideration.

Test example:

model delaytest
  Integer n;
  Integer n2;
  Integer n3;
  parameter Real delayMax=10;
equation 
  when sample(0,0.1) then
    n = pre(n) + 1;
  end when;
  n2 = integer(delay(n,0.34));
  n3 = integer(delay(n,1.0/(n2+0.01),delayMax));
end delaytest;

Note that n2 and n3 does not have discrete jumps as n does.

Please add this example to the testsuite once it is working.

Implementation note: I guess that in order to get this to work, the delay function must identlify when an event occurs and force an extra emit to occur.

Change History (5)

comment:1 by Jan Brugård, 15 years ago

http://intranet/trac/mathmodelica/ticket/1549

There are a couple of issues that complicates things:

  1. The current implementation writes to the delay buffer for every call to delay in order to also capture the internal solver steps. That means that we cannot distinguish between and event (two calls with the same t) and the solver stepping backwards.
  1. It is not as easy as performing a dual emit in the delay function since all the event handling code needs to be called.

Note: This does not work in Dymola 6, but it does in Dymola 7.

Delays where the result is stored in an integer seems to be completely broken so the test example above does not work. However, if we change n2,n3 to Real instead it works.

model delaytest
  Integer n;
  Real n2;
  Real n3;
  parameter Real delayMax=10;
equation 
  when sample(0, 0.1) then
    n=pre(n) + 1;
  end when;
  n2=delay(n, 0.34);
  n3=delay(n, 1.0/(n2 + 0.01), delayMax);
end delaytest;

The the missing feature is that we don't generate delayed events so n2 and n3 doesn't make discrete changes as they should.

comment:2 by Martin Sjölund, 11 years ago

Cc: Willi Braun added
Component: Run-time
Milestone: 1.9.0
Owner: changed from krsta to Lennart Ochel
Status: newassigned

Lennart: Is the following the correct result?

loadString("model M
  Integer n;
  Integer n2;
  Integer n3;
  parameter Real delayMax=10;
equation 
  when sample(0,0.1) then
    n = pre(n) + 1;
  end when;
  n2 = integer(delay(n,0.34));
  n3 = integer(delay(n,1.0/(n2+0.01),delayMax));
end M;");getErrorString();
simulate(M);getErrorString();
plot({n,n2,n3});getErrorString();

comment:3 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:4 by Lennart Ochel, 11 years ago

Owner: changed from Lennart Ochel to Willi Braun

I get the following message:

Simulation execution failed for model: M
assert            | debug   | Negative delay requested -4.65661e-010

There is something wrong with the delay handling.

comment:5 by Willi Braun, 10 years ago

Resolution: fixed
Status: assignedclosed

The result looks fine compared to dymola, so it seems that this is fixed in the meanwhile.

Note: See TracTickets for help on using tickets.