Opened 6 years ago

Closed 5 years ago

#3532 closed defect (fixed)

Size of array in record depending on param in record

Reported by: Jesper Mattsson Owned by: Jonathan Kämpe
Priority: major Milestone: 1.15
Component: Modelica/FrontEnd Version: trunk
Keywords: Cc:

Description

When the size on an array in a record is determined by a parameter in the same record, and the parameter gets its value from the binding expression of the record instance, then the size becomes 0.

Example:

model Test
    record A
        parameter Integer n;
        Real x[n];
    end A;
    
    function f
        input Integer n;
        output A a(n=n);
    algorithm
        a.x := 1:n;
    end f;
    
    parameter Integer m = 2;
    parameter A a = f(m);
    Real y[m] = a.x;
end Test;

Change History (12)

comment:1 Changed 6 years ago by Jonathan Kämpe

Summary: Size of array in record derending on param in recordSize of array in record depending on param in record

comment:2 Changed 6 years ago by Jesper Mattsson

Milestone: Pending1.14.x

comment:3 Changed 6 years ago by Jesper Mattsson

Status: newaccepted

comment:4 Changed 6 years ago by Jesper Mattsson

Milestone: 1.14.xPending

changeset:6266

Fixed handling of size of array in record depending on parameter in record for simple cases.

Cases that still aren't handled:

model Test1
    record A
        parameter Integer n;
        Real x[n];
    end A;
    
    function f
        input Integer n;
        output A a(n=n);
    algorithm
        a.x := 1:n;
    end f;
    
    parameter Integer m = 2;
    A a[m] = f(1:m);
    Real y[m] = a[2].x;
end Test1;


model Test2
    record A
        parameter Integer n;
        Real x[n];
    end A;
    
    record B
        A a;
    end B;
    
    parameter Integer m = 2;
    B b = B(A(m, 1:m));
    Real y[m] = b.a.x;
end Test2;

comment:5 Changed 6 years ago by Jesper Mattsson

changeset:6279

Fixed tests broken by r6266.

comment:6 Changed 6 years ago by Jesper Mattsson

changeset:6306

Fixed evaluation of constants in records that was broken by r6279.

comment:7 Changed 5 years ago by Jesper Mattsson

Owner: changed from Jesper Mattsson to Jonathan Kämpe
Status: acceptedassigned

comment:8 Changed 5 years ago by Jonathan Kämpe

Some more test cases:

model Test
    record R
        parameter Integer n = 1;
        parameter Real x[n] =( 1:n);
    end R;
    
    R r1;
    R r2(x={9});
    R r3(n=2);
    R r4(n=2, x={8,7});
end Test;

model Test2
    record R
        parameter Integer n;
        parameter Real x[n] =( 1:n);
    end R;
    
    R r3(n=2);
    R r4(n=2, x={8,7});
end Test2;

model Test3
    record R
        parameter Integer n = 1;
        parameter Real x[n];
    end R;
    
    R r1;
    R r2(x={9});
    R r3(n=2);
    R r4(n=2, x={8,7});
end Test3;

model Test4
    record R
        parameter Integer n;
        parameter Real x[n];
    end R;
    
    R r3(n=2);
    R r4(n=2, x={8,7});
end Test4;

comment:9 Changed 5 years ago by Tove Bergdahl

Milestone: Pending1.15.x

comment:10 Changed 5 years ago by Jonathan Kämpe

changeset:6868

Scalarization of records with array size defined by modified component.

changeset:6869

Introducing composite variabilities to preserve variability of mixed records until scalarization.

comment:11 Changed 5 years ago by Jesper Mattsson

Milestone: 1.15.x1.15

Move remaining tickets to next milestone.

comment:12 Changed 5 years ago by Jonathan Kämpe

Resolution: fixed
Status: assignedclosed

This seems finished.

Note: See TracTickets for help on using tickets.