Opened 7 years ago
Last modified 3 years ago
#4391 new defect
Weird behaviour with event detection
Reported by: | 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)
Changed 7 years ago by casella
comment:1 Changed 7 years ago by Andrea.Bartolini
- Cc andrea.bartolini@… added
comment:2 follow-up: ↓ 3 Changed 7 years ago by lochel
comment:3 in reply to: ↑ 2 Changed 7 years ago by casella
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 Changed 7 years ago by casella
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 Changed 7 years ago by casella
- Milestone changed from 1.12.0 to 1.13.0
Milestone changed to 1.13.0 since 1.12.0 was released
comment:6 Changed 6 years ago by casella
- Milestone changed from 1.13.0 to 1.14.0
Rescheduled to 1.14.0 after 1.13.0 releasee
comment:7 Changed 5 years ago by casella
- Milestone changed from 1.14.0 to 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:8 Changed 4 years ago by casella
- Milestone changed from 1.16.0 to 1.17.0
Retargeted to 1.17.0 after 1.16.0 release
comment:9 Changed 4 years ago by casella
- Milestone changed from 1.17.0 to 1.18.0
Retargeted to 1.18.0 because of 1.17.0 timed release.
comment:10 Changed 3 years ago by casella
- Milestone 1.18.0 deleted
Ticket retargeted after milestone closed
No zero crossings are generated for the algorithm section.