Opened 11 years ago

Last modified 7 years ago

#2599 new defect

Handling of (tuple) = f(...) when solving non-linear

Reported by: Willi Braun Owned by: probably noone
Priority: high Milestone: Future
Component: Backend Version: trunk
Keywords: Cc:

Description (last modified by Willi Braun)

Examples like following were handled wrong in SimCodeUtil:

model TupleNonLinear
function ftest
  input Real a;
  output Real b;
  output Integer c;
algorithm
  b := 0;
  for i in {1} loop //prevent inlining
    b := b + sin(a);
    c := integer(a);
  end for;
end ftest;

  Real a;
  Integer c;
  Real x,z;
equation
  der(x) = sin(a + time);
  (x,c) = ftest(a);
  z = if c>=1 then 10 else 0;
  annotation (experiment(StopTime=2));
end TupleNonLinear;

We try to solve the equation
(x,c) = ftest(a) non-linear for
{a,c} but actually only a should be solved
non-linear and c can be calculated then directly.

Change History (12)

in reply to:  description comment:1 by Lennart Ochel, 11 years ago

Replying to wbraun:

We try to solve the equation
(x,c) = ftest(a) non-linear for
{a,c} but actually only a should be solved
non-linear and c can be calculated then directly.

Why? That is actually not an error. I think it is good enough to solve it non-linear.

Anyway, the model gets handled wrong. I changed the model a bit, so that OpenModelica produces wrong results:

model TupleNonLinear
  function ftest
    input Real a;
    output Real b;
    output Integer c;
  algorithm
    b := 0;
    for i in {1} loop //prevent inlining
      b := b + sin(a);
      c := i;
    end for;
  end ftest;

  Real a;
  Integer c;
  Real x;
equation
  der(x) = a + time;
  (x,c) = ftest(a);
end TupleNonLinear;

comment:2 by Willi Braun, 11 years ago

Yes, the code we would produce is wrong, since for all
non-linear systems we assume that the iteration variables
are Real and not Integer.

comment:3 by Martin Sjölund, 11 years ago

Are you actually allowed to output both a continuous-time and discrete-time expression for the same equation?

Spec 3.8.3 says:

For an equation expr1 = expr2 where neither expression is of base type Real, both expressions must be discrete-time expressions.

Exceptions are only made for records.

in reply to:  3 comment:4 by Willi Braun, 11 years ago

Description: modified (diff)

Replying to sjoelund.se:

Are you actually allowed to output both a continuous-time and discrete-time expression for the same equation?

Spec 3.8.3 says:

For an equation expr1 = expr2 where neither expression is of base type Real, both expressions must be discrete-time expressions.

Exceptions are only made for records.

That's a really good remark.
I changed the model a bit, so that the mode
has a discrete change of c while the
continues integration.

So I think you are right we need to handle
that whole equation as discrete.

comment:5 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:6 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:7 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:9 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:10 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:11 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:12 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

Note: See TracTickets for help on using tickets.