Opened 13 years ago

Closed 9 years ago

#1679 closed defect (fixed)

Equations in certain order cause errors

Reported by: lempinen Owned by: lochel
Priority: high Milestone: 1.9.3
Component: Backend Version:
Keywords: removeSimpleEquations Cc: lempinen, Frenkel, TUD

Description (last modified by sjoelund.se)

As far as I know, the order of equations in equation block should not matter. However, the following code causes an error:

class Model
    Real BUGTEST[2];
    Real Var1[2, 5, 2, 3];
    Real Var2[2, 5, 2, 3]; 
    Real Var3[2, 5, 2, 3] = zeros(2, 5, 2, 3);
equation
    Var2 = Var1;
    BUGTEST = {sum(Var2[i,:,:,:]) for i in 1:2};
    Var1 = ones(2,5,2,3);
end Model;
Error: Error building simulator. Buildlog: gcc  -O3 -falign-functions -msse2 -mf
pmath=sse   -I\"C:/OpenModelica1.8.0//include/omc\" -I.    -c -o Model.o Model.c

Model.c: In function 'eqFunction_0':
Model.c:1704: error: '$PVar2' undeclared (first use in this function)
Model.c:1704: error: (Each undeclared identifier is reported only once
Model.c:1704: error: for each function it appears in.)
Model.c: In function 'eqFunction_1':
Model.c:1714: error: '$PVar2' undeclared (first use in this function)
mingw32-make: *** [Model.o] Error 1

But the model simulates if you change the order of the equations to:

equation
    Var1 = ones(2,5,2,3);
    Var2 = Var1;
    BUGTEST = {sum(Var2[i,:,:,:]) for i in 1:2};

Reducing the dimensions to Var[[2,5,2] causes the following error:

Error: Error building simulator. Buildlog: gcc  -O3 -falign-functions -msse2 -mf
pmath=sse   -I\"C:/OpenModelica1.8.0//include/omc\" -I.    -c -o Model.o Model.c

Model.c: In function 'eqFunction_0':
Model.c:804: error: '$PVar2' undeclared (first use in this function)
Model.c:804: error: (Each undeclared identifier is reported only once
Model.c:804: error: for each function it appears in.)
Model.c:823: error: invalid operands to binary + (have 'real_array' and 'real_ar
ray')
Model.c: In function 'eqFunction_1':
Model.c:852: error: '$PVar2' undeclared (first use in this function)
Model.c:871: error: invalid operands to binary + (have 'real_array' and 'real_ar
ray')
mingw32-make: *** [Model.o] Error 1

And finally the simulation is OK when dimensions are reduced to Var[[2,5].

Simulations have been run with the latest Windows nightly build (revision 10787)

Change History (6)

comment:1 Changed 13 years ago by sjoelund.se

This is a problem with alias elimination, similar to #1671.

comment:2 Changed 13 years ago by sjoelund.se

The Problem is the incidence Matrix for equations

{{{121 : BUGTEST[1] = sum(Var2[1,:,:,:])
122 : BUGTEST[2] = sum(Var2[2,:,:,:])

Incidence Matrix (row == equation)
====================================
number of rows: 183
...
121:182
122:181

Variables (183)
=========
...
181: BUGTEST[2]:VARIABLE() .Model, .Real type: Real [2] indx = -1
182: BUGTEST[1]:VARIABLE() .Model, .Real type: Real [2] indx = -1
}}}
The function BackendDAEUtil.traversingincidenceRowExpFinder does not handle the expression sum(Var2[1,:,:,:]). Because of that in the incidence matrix of equation 121 and 122 the variables Var2[1,:,:,:] and Var2[2,:,:,:] are missing.

comment:3 Changed 11 years ago by sjoelund.se

  • Cc Frenkel TUD added; Frenkel TUD removed
  • Component set to Backend
  • Description modified (diff)
  • Owner changed from lempinen to lochel
  • Status changed from accepted to assigned

This is still not working. Neither of the examples.

comment:4 Changed 10 years ago by lochel

  • Keywords removeSimpleEquations added
  • Milestone set to 2.0.0

The problem is connected to the "remove-simple-equations" module. If it is deactivated, then the model is working fine and the simulation results seem to be correct.

comment:5 Changed 10 years ago by lochel

BTW: The order of the equations seem to not affect the processing anymore.

comment:6 Changed 9 years ago by perost

  • Resolution set to fixed
  • Status changed from assigned to closed

It seems this is working fine now.

Note: See TracTickets for help on using tickets.