Opened 4 years ago

Closed 4 years ago

#4905 closed defect (fixed)

Bad handling of switches in solved initial equations

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

Description (last modified by Jonathan Kämpe)

When generating C code for a solved initial equation containing a relational expression, then an UnsupportedOperationException is thrown with the message "Unknown switch index for relational operator, not in list of switches".

This is due to FEquation.genBlock_C() using the result of FExp.solution() (that creates a new FExp) to generate code from, and this calls FRelExp.printSwitchMacro_C(), that uses FRelExp.relExpInInitialEquationsIndex(), that in turn depends on a list of expressions generated from the FClass. Thus the FRelExp is not found in the list, and does not get an index.

Example:

        parameter Real p1(fixed=false);
        parameter Boolean p2 = p1*p1 > time;
initial equation
        p1 = if p2 then 1 else 2;

Change History (3)

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

Description: modified (diff)

comment:2 Changed 4 years ago by Jonathan Kämpe

changeset:8702

Fixes bug in code generation of switches

comment:3 Changed 4 years ago by Jonathan Kämpe

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.