Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2368 closed defect (fixed)

Record with 0-length array

Reported by: c.schulze@… Owned by: Martin Sjölund
Priority: blocker Milestone: 1.9.0
Component: Code Generation Version: 1.9.0Beta
Keywords: Cc:

Description (last modified by Martin Sjölund)

model emptyVector4
  record R
    constant Boolean fixedMixingRatio;
    constant Integer nc_propertyCalculation(min=1);
    final constant Integer nc=if fixedMixingRatio then 1 else nc_propertyCalculation;
    constant Real[nc_propertyCalculation] mixingRatio_propertyCalculation;
    constant Real[nc] defaultMixingRatio = if fixedMixingRatio then {1} else mixingRatio_propertyCalculation;
    constant Real xi_default[nc-1] = defaultMixingRatio[1:end-1]/sum(defaultMixingRatio); 
  end R;
  record R2=R(nc_propertyCalculation=1,fixedMixingRatio=false,mixingRatio_propertyCalculation={1});
  R2 r2;
end emptyVector4;

The type of xi_default cannot be determined. Unusable source code is generated. (r15030)

Change History (7)

comment:1 by Martin Sjölund, 11 years ago

Description: modified (diff)

comment:2 by Martin Sjölund, 11 years ago

Owner: changed from probably noone to Martin Sjölund
Status: newassigned
Summary: Record, inheritance and real vectorsRecord with 0-length array

No, type of xi_default is determined. It is just that it has zero-dimensions, which requires special care when generating code (the empty array has unknown/uninteresting type).

comment:3 by Martin Sjölund, 11 years ago

Component: BackendCode Generation

comment:4 by Martin Sjölund, 11 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r17404

comment:5 by c.schulze@…, 11 years ago

new seems to work, but i cannot access the variables properly

model emptyVector4

record R

constant Boolean fixedMixingRatio;
constant Integer nc_propertyCalculation(min=1);
final constant Integer nc=if fixedMixingRatio then 1 else nc_propertyCalculation;
constant Real[nc_propertyCalculation] mixingRatio_propertyCalculation;
constant Real[nc] defaultMixingRatio = if fixedMixingRatio then {1} else mixingRatio_propertyCalculation;
constant Real xi_default[nc-1] = defaultMixingRatio[1:end-1]/sum(defaultMixingRatio);

end R;
record R2=R(nc_propertyCalculation=1,fixedMixingRatio=false,mixingRatio_propertyCalculation={1});
R2 r2;

Real x[r2.nc-1]=r2.defaultMixingRatio[1:end-1]/sum(r2.defaultMixingRatio);

end emptyVector4;

Version 0, edited 11 years ago by c.schulze@… (next)

comment:6 by Adrian Pop, 11 years ago

What do you mean you cannot access variables properly?
OpenModelica removes zero size arrays from the DAE and
they do not appear in the .mat file.

comment:7 by c.schulze@…, 11 years ago

I'm talking about the "Real x[r2.nc-1]=r2.defaultMixingRatio[1:end-1]/sum(r2.defaultMixingRatio);" line.

The x vector in global scope should be a Real[0], but the model cannot be translated. In this case the vector could be removed completely, but it should translate.

Note: See TracTickets for help on using tickets.