#3530 closed defect (fixed)
"comSubExp" introduces bad alias variables in certain cases
Reported by: | lochel | Owned by: | vwaurich |
---|---|---|---|
Priority: | high | Milestone: | 1.9.4 |
Component: | Backend | Version: | |
Keywords: | Cc: | vwaurich |
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 Changed 9 years ago by vwaurich
- Owner changed from lochel to vwaurich
- Status changed from new to assigned
comment:2 Changed 9 years ago by lochel
comment:3 Changed 9 years ago by lochel
- Resolution set to fixed
- Status changed from assigned to closed
Thanks, this is now working.
comment:4 follow-up: ↓ 5 Changed 9 years ago by lochel
Should this get integrated into the removeSimpleEquation module? This could reduce the back end time slightly.
comment:5 in reply to: ↑ 4 Changed 9 years ago by vwaurich
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 Changed 9 years ago by vwaurich
The model is now in the testsuite.
comment:7 Changed 8 years ago by sjoelund.se
- Milestone changed from 1.9.4 to 1.9.4-1.9.x
Milestone renamed
comment:8 Changed 8 years ago by sjoelund.se
- Milestone changed from 1.9.4-1.9.x to 1.9.4
Milestone renamed
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.