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)
Change History (11)
by , 8 years ago
comment:1 by , 8 years ago
Cc: | added |
---|
follow-up: 3 comment:2 by , 8 years ago
comment:3 by , 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 , 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 , 7 years ago
Milestone: | 1.12.0 → 1.13.0 |
---|
Milestone changed to 1.13.0 since 1.12.0 was released
comment:7 by , 5 years ago
Milestone: | 1.14.0 → 1.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:9 by , 4 years ago
Milestone: | 1.17.0 → 1.18.0 |
---|
Retargeted to 1.18.0 because of 1.17.0 timed release.
No zero crossings are generated for the algorithm section.