Opened 14 years ago

Closed 10 years ago

#1367 closed defect (fixed)

Constants that are arrays in packages should be copied in the flattened model

Reported by: Adrian Pop Owned by: Adrian Pop
Priority: critical Milestone: 1.9.3
Component: Instantiation Version: trunk
Keywords: Cc: Adrian Pop

Description

See for example flattening of: Modelica.Electrical.Digital.Examples.Multiplexer.
It contains equations:

MUX.Not1.auxiliary = D.Tables.NotTable[MUX.Not1.x];

but D.Tables.NotTable is nowhere to be found in the flattened model
as is a package constant that is an array which is indexed by a variable\\

We should copy the array constant from the package in the local model and
replace all references to it to the local constant which should become part
of the DAE\\
See for example /trunk/libraries/msl31/simulate/Modelica.Electrical.Digital.Examples.mos

Change History (5)

comment:1 by Adrian Pop, 14 years ago

Seems this happens only for arrays of enums.
Arrays of other basic types are copied in the flattened DAE.

comment:2 by Adrian Pop, 14 years ago

An easier example:

package P
  type E = enumeration('A', 'B', 'C', 'D');
  constant E x[4] = {E.'D', E.'C', E.'B', E.'A'};
  constant Real y[4] = {1, 2, 3, 4};
end P;

model ArrayEnums
  Real a = P.x[integer(time)];
  Real b = P.y[integer(time)];
end ArrayEnums;

which wrongly generates:

adrpo@kafka ~/dev/OpenModelicaBackend/build/bin/enums
$ ../omc ArrayEnums.mo 
class ArrayEnums
  Real a = Real(P.x[integer(time)]);
  Real b = P.y[integer(time)];
end ArrayEnums;

comment:3 by Adrian Pop, 14 years ago

Another example:

package P
  type E = enumeration('A', 'B', 'C', 'D');
  constant E x[4] = {E.'D', E.'C', E.'B', E.'A'};
  constant Real y[4] = {1, 2, 3, 4};
end P;

function getArrayFromPackage
  output P.E x[4];
algorithm
  x := P.x;
end getArrayFromPackage;

model ArrayEnums
  P.E a = P.x[integer(time)];
  Real b = P.y[integer(time)];
  P.E[4] c = getArrayFromPackage();
end ArrayEnums;

which gives:

adrpo@kafka ~/dev/OpenModelicaBackend/build/bin/enums
$ ../omc ArrayEnums.mo 
function getArrayFromPackage
  output enumeration('A', 'B', 'C', 'D')[4] x;
algorithm
  x := {P.E.'D',P.E.'C',P.E.'B',P.E.'A'};
end getArrayFromPackage;

class ArrayEnums
  enumeration('A', 'B', 'C', 'D') a = P.x[integer(time)];
  Real b = P.y[integer(time)];
  enumeration('A', 'B', 'C', 'D') c[1] = P.E.'D';
  enumeration('A', 'B', 'C', 'D') c[2] = P.E.'C';
  enumeration('A', 'B', 'C', 'D') c[3] = P.E.'B';
  enumeration('A', 'B', 'C', 'D') c[4] = P.E.'A';
end ArrayEnums;

comment:4 by Henning Kiel, 10 years ago

Cc: adrpo, adrpo → adrpo
Milestone: White December1.9.3

comment:5 by Adrian Pop, 10 years ago

Resolution: fixed
Status: newclosed

Duplicate of #2858.

Note: See TracTickets for help on using tickets.