#5651 closed defect (fixed)
Problem with findZeroCrossings
| Reported by: | Francesco Casella | Owned by: | Lennart Ochel |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.14.0 |
| Component: | Backend | Version: | |
| Keywords: | Cc: | Karim Adbdelhak, Andreas Heuermann, alberto.leva@…, chiara.cimino@… |
Description
Please consider the following test model
model foo
parameter Real tfill=1;
parameter Real tempty=5;
parameter Real empty_level = 0;
Real x(start=0,fixed=true);
Boolean fill(start=false,fixed=true);
Boolean empty(start=false,fixed=true);
equation
der(x) = if fill and not empty then 1 elseif empty and not fill then -1 else 0;
algorithm
when time>=tfill then fill := true; end when;
when fill and x>=1 then fill := false; end when;
when time>=tempty then empty := true; end when;
when empty and x<=empty_level then empty := false;
end when;
annotation(experiment(StartTime = 0, StopTime = 10,
Tolerance = 1e-6, Interval = 0.02));
end foo;
The expected solution is that x starts growing at time = 1, stops at time = 2, starts going down at time = 4, and stops again when it hits zero. That's in fact what is obtained.
If you replace the last statement in the algorithm with
when empty and x<=0 then empty := false; end when;
the last event is completely missed, and the level goes down forever.
However, if you replace the 0 with any non-zero constant, no matter how small, e.g,
when empty and x<=1e-32 then empty := false; end when;
the correct behaviour is restored.
This is a serious issue, because we get plain wrong results.
Change History (7)
comment:1 by , 6 years ago
| Summary: | Weird behaviour with OMC and events → Problem with findZeroCrossings |
|---|
follow-up: 3 comment:2 by , 6 years ago
| Cc: | added |
|---|
comment:3 by , 6 years ago
follow-up: 7 comment:6 by , 6 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Works like a charm.
I'm just curious, what exactly are "fake dummy variables"? Is it not enough to be dummy?
comment:7 by , 6 years ago
Replying to casella:
Works like a charm.
I'm just curious, what exactly are "fake dummy variables"? Is it not enough to be dummy?
There is a routine designed for for-loops that searches for zero-crossings. To reuse it someone called it with a dummy-iterator which was represented by a constant real value of 0.0. This caused problems because all equations containing iterators are excluded from this routine and therefore all equations containing a constant real value of 0.0. I replaced it with a constant string value of "$$$" which should never occur.
This is only applied on algorithms, because without the need of causalization everything can be processed by the same routine. Was just some oversight on choosing this dummy value.

I carried out some further investigations with
-d=optdaedump.With
x <= 1e-32we getwhile with
x <= 0we getFor some reason, in the latter case one zero-crossing relation is lost, hence the event is also lost. I gues there is some issue with findZeroCrossings.
Can you please investigate why this happens?