Opened 11 years ago

Closed 11 years ago

#1943 closed defect (fixed)

Wrong equation count for enum in when equations

Reported by: cschubert Owned by: jfrenkel
Priority: critical Milestone: 1.9.0
Component: Backend Version: trunk
Keywords: equation count Cc: adrpo, sjoelund.se

Description

if an enum is set using an if equation inside a when equation, the OpenModelica Compiler the number of equations is set the possible states the enum can have rather than the dimensionality of the variable itself. Thus such models seem to be unbalanced.
Consider the model

model WhenCount
  type EnumA = enumeration(
      Value1,
      Value2);
  
  EnumA a;

equation 
  when (time > 0.5) then
    if (time < 1) then
      a = EnumA.Value1;
    else
      a = EnumA.Value2;
    end if;
  end when;

end WhenCount;

OMC reports:
Too many equations, overdetermined system. The model has 2 equation(s) and 1 variable(s).

Attachments (2)

WhenCount.mo (314 bytes) - added by cschubert 11 years ago.
WhenCount.mos (85 bytes) - added by cschubert 11 years ago.

Download all attachments as: .zip

Change History (7)

Changed 11 years ago by cschubert

Changed 11 years ago by cschubert

comment:1 Changed 11 years ago by jfrenkel

  • Cc adrpo sjoelund.se added

The Problem is that in the Backend the type of the ComponentRef is used. But the Type is Enumeration and there is the size the number of Elements in the Enumeration. If we use the right hand side the size would be zero because there the list of Elements is thero. This is maybe a bad implementation.

comment:2 Changed 11 years ago by jfrenkel

change

case (DAE.ENUM_LITERAL(name = p)) then DAE.T_ENUMERATION(NONE(), p, {}, {}, {}, DAE.emptyTypeSource);

to

case (DAE.ENUM_LITERAL(name = p, index=i)) then DAE.T_ENUMERATION(SOME(i), p, {}, {}, {}, DAE.emptyTypeSource);

comment:3 Changed 11 years ago by sjoelund.se

I fail to see the problem for the equation counting. Isn't the number of equations/vars always one for enumeration literals?

comment:4 Changed 11 years ago by sjoelund.se

Was this fixed in r13973?

comment:5 Changed 11 years ago by sjoelund.se

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.