Opened 15 years ago

Last modified 15 years ago

#1111 closed defect (fixed)

wrong results due to mix up in matrices!

Reported by: Schubert TUD Owned by: Schubert TUD
Priority: high Milestone:
Component: Simulation Code Generation Version: 1.4.5
Keywords: Cc: Schubert TUD,

Description

Hi,

I found another problem which I consider critical, since it causes the results to be corrupted.
It is best illustrated by the following model:

model MatrixMixUp

Real[2,2] A;
parameter Real t=3;

equation

A = {{1,0},

{0,sin(t)}};

end MatrixMixUp;

Simulating the model gives no error and the result seems to be fine until you look closer at the generated C-code:

#define $A$lB2$c1$rB localData->algebraics[3] A[2,1]
#define $A$lB1$c2$rB localData->algebraics[2]
A[1,2]
#define $A$lB1$c1$rB localData->algebraics[1] A[1,1]
#define $A localData->algebraics[1]
#define $t localData->parameters[0]
#define $A$lB2$c2$rB localData->algebraics[0]
A[2,2]

Surprisingly, within the array "algebraics", the element A[2,2] comes before all the other elements of the same matrices.
While this does not cause problems in this simple model, it is fatal in a complexer one. Sometimes, OpenModelica carries out calculations using matrices directly. The corresponding command looks like

real_array tmp0;
real_array tmp1;
real_array tmp2;
real_array_create(&tmp0, &$A, 2, 2, 2);
...
mul_alloc_real_matrix_product_smart(&tmp2, &tmp0, &tmp1);

The real array structure requires all matrix elements to be aligned properly, otherwise they will be mixed up (which is what happened in my case)
Supposedly, these matrix elements are treated differently since they contain constants and expressions respectively.

Regards,

Christian Schubert

Change History (0)

Note: See TracTickets for help on using tickets.