Opened 10 years ago

Last modified 7 years ago

#3213 closed defect

Failure with arrays composed of arrays if at least one index is of enumeration type — at Version 1

Reported by: Gustaf Thorslund Owned by: somebody
Priority: high Milestone: 1.9.4
Component: Backend Version: trunk
Keywords: array, enumeration, index, algorithm Cc: Per Östlund, Lennart Ochel, Willi Braun

Description (last modified by Gustaf Thorslund)

This is more or less ticket #3212 reloaded (revolutions might come later)

Instead of just indexing a real valued array with enumeration types, one may want to take the abstraction one step further and create arrays of arrays. Now (using r25040) if one of the indexes happens to be of enumeration type one will run into trouble.

package ArrayArrayTest
  constant Integer N = 3;
  type E = enumeration (e1, e2, e3);
  type AI = Real[N];
  type AE = Real[E];
  type AEAE = AE[E];
  type AEAI = AI[E];
  type AIAE = AE[N];
  type AIAI = AI[N];

  model AEAETest
    AEAE x(each start=0, each fixed=true);
  algorithm
    when sample(0,0.1) then
      for i loop
  for j loop
    x[i, j] := time;
  end for;
      end for;
    end when;
  end AEAETest;

  model AEAITest
    AEAI x(each start=0, each fixed=true);
  algorithm
    when sample(0,0.1) then
      for i loop
  for j loop
    x[i, j] := time;
  end for;
      end for;
    end when;
  end AEAITest;

  model AIAETest
    AIAE x(each start=0, each fixed=true);
  algorithm
    when sample(0,0.1) then
      for i loop
  for j loop
    x[i, j] := time;
  end for;
      end for;
    end when;
  end AIAETest;

  model AIAITest
    AIAI x(each start=0, each fixed=true);
  algorithm
    when sample(0,0.1) then
      for i loop
  for j loop
    x[i, j] := time;
  end for;
      end for;
    end when;
  end AIAITest;
end ArrayArrayTest;

Now when trying to generate code of AEAETest, AEAITest or AIAETest all fail in the same way, so to save some space I'm just posting the result of AEAETest:

build$ omc ../ArrayArrayTest.mo -i=ArrayArrayTest.AEAETest -s
class ArrayArrayTest.AEAETest
  Real x[ArrayArrayTest.E.e1,ArrayArrayTest.E.e1];
  Real x[ArrayArrayTest.E.e1,ArrayArrayTest.E.e2];
  Real x[ArrayArrayTest.E.e1,ArrayArrayTest.E.e3];
  Real x[ArrayArrayTest.E.e2,ArrayArrayTest.E.e1];
  Real x[ArrayArrayTest.E.e2,ArrayArrayTest.E.e2];
  Real x[ArrayArrayTest.E.e2,ArrayArrayTest.E.e3];
  Real x[ArrayArrayTest.E.e3,ArrayArrayTest.E.e1];
  Real x[ArrayArrayTest.E.e3,ArrayArrayTest.E.e2];
  Real x[ArrayArrayTest.E.e3,ArrayArrayTest.E.e3];
algorithm
  when sample(0.0, 0.1) then
    for i in ArrayArrayTest.E.e1:ArrayArrayTest.E.e3 loop
      for j in ArrayArrayTest.E.e1:ArrayArrayTest.E.e3 loop
        x[i,j] := time;
      end for;
    end for;
  end when;
end ArrayArrayTest.AEAETest;
Error processing file: ../ArrayArrayTest.mo
Error: Model is structurally singular, error found sorting equations 
 1: algorithm
  when sample(1, 0.0, 0.1) then
    for i in ArrayArrayTest.E.e1:ArrayArrayTest.E.e3 loop
      for j in ArrayArrayTest.E.e1:ArrayArrayTest.E.e3 loop
        x[i,j] := time;
      end for;
    end for;
  end when;
;
 for variables 
 x[ArrayArrayTest.E.e3,ArrayArrayTest.E.e3](1), x[ArrayArrayTest.E.e3,ArrayArrayTest.E.e2](2), x[ArrayArrayTest.E.e3,ArrayArrayTest.E.e1](3), x[ArrayArrayTest.E.e2,ArrayArrayTest.E.e3](4), x[ArrayArrayTest.E.e2,ArrayArrayTest.E.e2](5), x[ArrayArrayTest.E.e2,ArrayArrayTest.E.e1](6), x[ArrayArrayTest.E.e1,ArrayArrayTest.E.e3](7), x[ArrayArrayTest.E.e1,ArrayArrayTest.E.e2](8), x[ArrayArrayTest.E.e1,ArrayArrayTest.E.e1](9)
Error: Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

# Error encountered! Exiting...
# Please check the error message and the flags.

Execution failed!

If just using integer indexes it works fine (apart of variables not being initialized, but let's blame that on the guy who wrote the model (hint: the guy at my keyboard)).

build$ omc ../ArrayArrayTest.mo -i=ArrayArrayTest.AIAITest -s
class ArrayArrayTest.AIAITest
  Real x[1,1];
  Real x[1,2];
  Real x[1,3];
  Real x[2,1];
  Real x[2,2];
  Real x[2,3];
  Real x[3,1];
  Real x[3,2];
  Real x[3,3];
algorithm
  when sample(0.0, 0.1) then
    for i in 1:3 loop
      for j in 1:3 loop
        x[i,j] := time;
      end for;
    end for;
  end when;
end ArrayArrayTest.AIAITest;

Building and simulation worked fine too.

$ omc --version
1.9.2+dev (r25040)

Change History (1)

comment:1 by Gustaf Thorslund, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.