Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3530 closed defect (fixed)

"comSubExp" introduces bad alias variables in certain cases

Reported by: Lennart Ochel Owned by: Volker Waurich
Priority: high Milestone: 1.9.4
Component: Backend Version:
Keywords: Cc: Volker Waurich

Description

The following model can be used to illustrate the issue:

model test
  Real x[2];
  Real a[2];
  Real z;
  parameter Real t0 = 0.5;
  Boolean b[2];
  Integer j;
  Real t[2];
equation
  x[1] = t[2];
  x[2] = t[1];
  a[1] = if time<t0 then 1.0 else sin(time);
  a[2] = if time<t0 then 1.0 else time^2;
  x[1] = a[1]+a[2];
  x[2]-a[2] = a[1];
  der(z) = x[1]/x[2];
  j = 1+integer(time);
algorithm
  if t[j] < time then
    b[j] := true;
  end if;
end test;

The module "comSubExp" introduces t[1] as alias variable, which makes the generated c code invalid, since it occurs in an if condition where it cannot be substituted.

Change History (8)

comment:1 by Volker Waurich, 9 years ago

Owner: changed from Lennart Ochel to Volker Waurich
Status: newassigned

comment:2 by Lennart Ochel, 9 years ago

Maybe we could just do the substitution to benefit from the symbolic optimization but keep the variables and alias equations in the equation system. That shouldn't affect the performance much.

comment:3 by Lennart Ochel, 9 years ago

Resolution: fixed
Status: assignedclosed

Thanks, this is now working.

comment:4 by Lennart Ochel, 9 years ago

Should this get integrated into the removeSimpleEquation module? This could reduce the back end time slightly.

in reply to:  4 comment:5 by Volker Waurich, 9 years ago

Replying to lochel:

Should this get integrated into the removeSimpleEquation module? This could reduce the back end time slightly.

It should be since the purpose is similar. I will think about this, but the algorithm is different to removeSimpleEquations.

comment:6 by Volker Waurich, 9 years ago

The model is now in the testsuite.

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

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

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

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.