Opened 13 years ago

Closed 10 years ago

#1679 closed defect (fixed)

Equations in certain order cause errors

Reported by: Teemu Lempinen Owned by: Lennart Ochel
Priority: high Milestone: 1.9.3
Component: Backend Version:
Keywords: removeSimpleEquations Cc: Teemu Lempinen, Frenkel, TUD

Description (last modified by Martin Sjölund)

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 by Martin Sjölund, 13 years ago

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

comment:2 by Martin Sjölund, 13 years ago

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 by Martin Sjölund, 11 years ago

Cc: Frenkel TUD added; Jens Frenkel removed
Component: Backend
Description: modified (diff)
Owner: changed from Teemu Lempinen to Lennart Ochel
Status: acceptedassigned

This is still not working. Neither of the examples.

comment:4 by Lennart Ochel, 10 years ago

Keywords: removeSimpleEquations added
Milestone: 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 by Lennart Ochel, 10 years ago

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

comment:6 by Per Östlund, 10 years ago

Resolution: fixed
Status: assignedclosed

It seems this is working fine now.

Note: See TracTickets for help on using tickets.