Opened 10 years ago

Closed 4 years ago

#3280 closed defect (fixed)

Strange things happening when size of array in a record depends on a value in a constant record of the same record

Reported by: Gustaf Thorslund Owned by: somebody
Priority: high Milestone: 1.16.0
Component: New Instantiation Version: trunk
Keywords: array, constant, record Cc: Mahder Alemseged Gebremedhin, Adrian Pop, Per Östlund

Description

When flattening the following model M, strange things are happening with array sizes.

package RecordArraySizeFromConstant
  record Range
    Real first = 0.0;
    Real last = 0.0;
    Integer n = 0;
  end Range;

  record RecIntegerIndex
    constant Range r[3];
    Real x[r[1].n,r[2].n,r[3].n];
  end RecIntegerIndex;

  type EnumIndex = enumeration (x1, x2, x3);

  record RecEnumIndex
    constant Range r[EnumIndex];
    Real x[r[EnumIndex.x1].n, r[EnumIndex.x2].n, r[EnumIndex.x3].n];
  end RecEnumIndex;

  model M
    RecIntegerIndex ri(r.n={2,3,5}, x(each start=0, each fixed=true));
    RecEnumIndex re(r.n={2,3,5}, x(each start=0, each fixed=true));
    RecIntegerIndex ri10(r.n={10,1,1}, x(each start=0, each fixed=true));
    RecEnumIndex re10(r.n={10,1,1}, x(each start=0, each fixed=true));

  algorithm
    when sample(0, 0.1) then
      ri.x := ri.x * 10;
      re.x := re.x * 10;
      ri10.x := ri10.x * 10;
      re10.x := re10.x * 10;
    end when;
  end M;
end RecordArraySizeFromConstant;

Just looking at ri it get the constant Range r set correctly, but the size depending on r appears to just become a mess:

class RecordArraySizeFromConstant.M
  constant Real ri.r[1].first = 0.0;
  constant Real ri.r[1].last = 0.0;
  constant Integer ri.r[1].n = 2;
  constant Real ri.r[2].first = 0.0;
  constant Real ri.r[2].last = 0.0;
  constant Integer ri.r[2].n = 3;
  constant Real ri.r[3].first = 0.0;
  constant Real ri.r[3].last = 0.0;
  constant Integer ri.r[3].n = 5;
  Real ri.x[1,1,1](start = 0.0, fixed = true);
  Real ri.x[1,1,2](start = 0.0, fixed = true);
  Real ri.x[1,2,1](start = 0.0, fixed = true);
  Real ri.x[1,2,2](start = 0.0, fixed = true);
  Real ri.x[2,1,1](start = 0.0, fixed = true);
  Real ri.x[2,1,2](start = 0.0, fixed = true);
  Real ri.x[2,2,1](start = 0.0, fixed = true);
  Real ri.x[2,2,2](start = 0.0, fixed = true);
// all of ri

re results in an array of size 5*5*5, ri10 10*10*10, and finally re10 1*1*1.

I'll attach the full output too. I built OMC using r25516 earlier today.

Attachments (1)

RecordArraySizeFromConstant-flat.mo (85.3 KB ) - added by Gustaf Thorslund 10 years ago.
Flattening of test case

Download all attachments as: .zip

Change History (3)

by Gustaf Thorslund, 10 years ago

Flattening of test case

comment:1 by Per Östlund, 10 years ago

This is probably at least partially a duplicate of #1628.

comment:2 by Per Östlund, 4 years ago

Component: FrontendNew Instantiation
Milestone: Future1.16.0
Resolution: fixed
Status: newclosed

Still an issue in the old frontend, but seems to work fine in the new.

Note: See TracTickets for help on using tickets.