Opened 8 years ago

Last modified 3 years ago

#4391 new defect

Weird behaviour with event detection

Reported by: Francesco Casella Owned by: somebody
Priority: high Milestone:
Component: Run-time Version:
Keywords: Cc: andrea.bartolini@…

Description

Please consider the following test model

model Test
  Real a, b;
  discrete Real flag;
algorithm
  when a > 0 and b > 0 then
    flag := 1;
  end when;
initial algorithm
  if (a > 0) then
    flag := -1;
  end if;
equation
  a = 1+time;
  b = if time < (-1) then -1 else time;
annotation(experiment(StartTime=-2, StopTime=2));
end Test;

When simulating, the variable flag starts at -1, but only switches to +1 when time = 2, as if the event at time 0 was not caught.

Why does this happen?

Attachments (1)

Test.mo (327 bytes ) - added by Francesco Casella 8 years ago.

Download all attachments as: .zip

Change History (11)

by Francesco Casella, 8 years ago

Attachment: Test.mo added

comment:1 by Andrea Bartolini, 8 years ago

Cc: andrea.bartolini@… added

comment:2 by Lennart Ochel, 8 years ago

No zero crossings are generated for the algorithm section.

in reply to:  2 comment:3 by Francesco Casella, 8 years ago

Replying to lochel:

No zero crossings are generated for the algorithm section.

Why not? Is this due to the language specification, or a missing implementation?

BTW, if I remove the condition a > 0 from the when statement, the event is triggered at time = 0 as expected

model Test
  Real a, b;
  discrete Real flag;
algorithm
  when b > 0 then
    flag := 1;
  end when;
initial algorithm
  if (a > 0) then
    flag := -1;
  end if;
equation
  a = 1+time;
  b = if time < (-1) then -1 else time;
annotation(experiment(StartTime=-2, StopTime=2));
end Test;

comment:4 by Francesco Casella, 8 years ago

Modelica 3.3r1, page 9

Algorithm sections where every section is treated as a set of equations which involves the variables occurring in the algorithm section

Modelica 3.3r1 page 92

The integration, is halted and an event occurs whenever a Real elementary relation, e.g. “ x > 2 ”, changes its value. The value of such a relation can only be changed at event instants [in other words, Real elementary relations induce state or time events].

As far as I understand, whether the when clause is contained in algorithm or equation section doesn't make any difference.

comment:5 by Francesco Casella, 7 years ago

Milestone: 1.12.01.13.0

Milestone changed to 1.13.0 since 1.12.0 was released

comment:6 by Francesco Casella, 6 years ago

Milestone: 1.13.01.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:7 by Francesco Casella, 5 years ago

Milestone: 1.14.01.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:8 by Francesco Casella, 4 years ago

Milestone: 1.16.01.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:9 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:10 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.