﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3213	Failure with arrays composed of arrays if at least one index is of enumeration type	Gustaf Thorslund	somebody	"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.

{{{#!mo
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;
  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;
  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;
  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;
  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;
Warning: The initial conditions are not fully specified. Use +d=initialization for more information.
}}}

Building and simulation worked fine too.

$ omc --version
1.9.2+dev (r25040)
"	defect	new	high	Future	Backend	trunk		array, enumeration, index, algorithm	Per Östlund Lennart Ochel Willi Braun
