Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4834 closed defect (fixed)

Problem with conditional equation involving structural parameters

Reported by: Francesco Casella Owned by: Per Östlund
Priority: high Milestone: 2.0.0
Component: New Instantiation Version:
Keywords: Cc:

Description

Please check Modelica.Thermal.HeatTransfer.Examples.Motor.

The model contains the following equation:

final parameter Real p_offset[nout]=
  (if size(offset, 1) == 1 then ones(nout)*offset[1] else offset)

The NF complains that:

Type mismatch in if-expression in component.
True branch: {1.0, 1.0} .* (lossTable.offset[1]) has type Real[2],
false branch: lossTable.offset has type Real[1].

As far as I understand, in the case of if-expressions depending on structural parameters, it would make sense to only evaluate the active branch and just ignore the other one. I guess the old FE just did that.

Change History (3)

comment:1 by Per Östlund, 7 years ago

Resolution: fixed
Status: newclosed

Fixed in 8338ce6.

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

As far as I understand, in the case of if-expressions depending on structural parameters, it would make sense to only evaluate the active branch and just ignore the other one. I guess the old FE just did that.

There is a special case for if-expressions where the sizes of dimensions do not need to be equal in each branch (in order for branch selection to be possible).

in reply to:  2 comment:3 by Per Östlund, 7 years ago

Replying to sjoelund.se:

As far as I understand, in the case of if-expressions depending on structural parameters, it would make sense to only evaluate the active branch and just ignore the other one. I guess the old FE just did that.

There is a special case for if-expressions where the sizes of dimensions do not need to be equal in each branch (in order for branch selection to be possible).

Yes, 3.6.5 in the spec says that the branches must be type compatible, which is why I first implemented it like that. But the definition of type compatible in 6.6 says that the type is based on the branch selected (without saying when a branch can be selected).

The way it's implemented now is to always do branch selection if the condition is a constant or structural parameter expression, without even typing the not selected branch (because that's what Dymola does). Otherwise we type both branches, and if they match we return a typed if-expression. If the types don't match and the condition is a parameter expression we do branch selection, otherwise an error is given.

Note: See TracTickets for help on using tickets.