Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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 Francesco Casella, 5 years ago

Summary: Weird behaviour with OMC and eventsProblem with findZeroCrossings

comment:2 by Francesco Casella, 5 years ago

Cc: Karim Adbdelhak Andreas Heuermann added

I carried out some further investigations with -d=optdaedump.

With x <= 1e-32 we get

Zero Crossings (4) 
======================================== 
time >= tfill with index = 0 in equations [1] 
fill and x >= 1.0 in equations [1] 
time >= tempty with index = 2 in equations [1] 
empty and x <= 1e-032 in equations [1] 

while with x <= 0 we get

Zero Crossings (3) 
======================================== 
time >= tfill with index = 0 in equations [1] 
fill and x >= 1.0 in equations [1] 
time >= tempty with index = 2 in equations [1] 

For 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?

in reply to:  2 comment:3 by Karim Adbdelhak, 5 years ago

Replying to casella:

Can you please investigate why this happens?

Some oversight in using fake dummy variables, should be fixed in PR464.

comment:4 by Karim Adbdelhak, 5 years ago

It is pushed, feel free to test and report @Francesco. :)

comment:5 by Francesco Casella, 5 years ago

Will do ASAP, thanks 1e6!

comment:6 by Francesco Casella, 5 years ago

Resolution: fixed
Status: newclosed

Works like a charm.

I'm just curious, what exactly are "fake dummy variables"? Is it not enough to be dummy?

in reply to:  6 comment:7 by Karim Adbdelhak, 5 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.

Note: See TracTickets for help on using tickets.