Opened 11 years ago

Closed 4 years ago

Last modified 4 years ago

#2624 closed defect (fixed)

missing elseif branch

Reported by: Volker Waurich Owned by: Per Östlund
Priority: normal Milestone: 1.16.0
Component: New Instantiation Version: trunk
Keywords: elseif Cc: Per Östlund, Adrian Pop, Christian Schubert, Jens Frenkel, Lennart Ochel

Description

I have some problems when evaluating (I want to implement a partially function evaluation module) the function Modelica.Electrical.Spice3.Internal.Mos.mosCalcNoBypassCode which occurs in the Inverter model from the msl.(find a smaller version of this model in testsuite\modelica\functions_eval\Inverter2.mo)

There are 3 if statements including an elseif in this function. the first one is:

  if ( SpiceRoot.useInitialConditions())    and (in_m.m_dICVBSIsGiven >0.5) then
    int_c.m_vbs := in_m_type * in_m.m_dICVBS;
  elseif ( SpiceRoot.initJunctionVoltages()) then
    int_c.m_vbs := if (in_m.m_off >0.5) then 0. else int_c.m_VBScrit;
  end if;

The DAE.Statement.STMT_IF is correct but there is a DAE.Else.NOELSE instead of an DAE.Else.ELSEIF. So the elseif branch is ignored. Also in the *_functions.c you'll only find:

tmp2 = omc_Modelica_Electrical_Spice3_Internal_SpiceRoot_useInitialConditions(threadData);
  if((tmp2.c1 && (_in_m._m_dICVBSIsGiven > 0.5)))
  {
    _int_c._m_vbs = (((modelica_real)(modelica_integer)_in_m_type) * _in_m._m_dICVBS);
  }

This occurs already in SimCodeMain.translateModel in the Env.Cache.functions structure. So this is possibly a frontend issue.

Could somebody have a look on that or give me a hint where to fix this?

Change History (18)

comment:1 by Lennart Ochel, 11 years ago

Cc: Lennart Ochel added

comment:2 by Per Östlund, 11 years ago

Do you have an example model that uses this function?

in reply to:  2 ; comment:3 by Volker Waurich, 11 years ago

Replying to perost:

Do you have an example model that uses this function?

Unfortunately, there is only the inverter model, mentioned above. This is still quite big but I could not yet reproduce this error with a simple model.

in reply to:  3 comment:4 by Per Östlund, 11 years ago

Owner: changed from somebody to Per Östlund
Status: newassigned

Replying to vwaurich:

Replying to perost:

Do you have an example model that uses this function?

Unfortunately, there is only the inverter model, mentioned above. This is still quite big but I could not yet reproduce this error with a simple model.

Sorry, I somehow missed that in your description. Anyway, the elseifs are missing also in the flattened code, so it's an issue in the frontend. I'll take a look at it tomorrow.

comment:5 by Per Östlund, 11 years ago

Ok, I've had a proper look at the model now, and it boils down to something like this:

function useInitialConditions  
  output Boolean ret;
algorithm
  ret := false;
end useInitialConditions;

function initJunctionVoltages  
  output Boolean ret;
algorithm
  ret := false;
end initJunctionVoltages;

function mosCalcNoBypassCode  
  input Real in_m;
  output Real out_cc;
algorithm
  if useInitialConditions() and in_m > 0.5 then
    out_cc := 1.0; 
  elseif initJunctionVoltages() then
    out_cc := 2.0; 
  end if;
end mosCalcNoBypassCode;

model Inverter2  
  Real m;
  Real cc = mosCalcNoBypassCode(m);
end Inverter2;

useInitialConditions and initJunctionVoltages have not been simplified, they actually look like that in the MSL (sans annotations). I haven't yet looked at exactly what the compiler does, but from what I can see there's nothing wrong in removing the elseif-branch since it's condition will always be false. The only thing that looks weird to me is that not the whole if-statement is removed, but I'm guessing that whatever part of the compiler that does these optimization is written to only rewrite statements, not remove them completely.

So unless you have some objections I suggest we just leave this as it is for now.

comment:6 by Jens Frenkel, 11 years ago

Hopefully this affect only statements and not equations. Otherwise the preOptModule "simplifyIfEquations" will run in trouble.

in reply to:  6 comment:7 by Per Östlund, 11 years ago

Replying to jfrenkel:

Hopefully this affect only statements and not equations. Otherwise the preOptModule "simplifyIfEquations" will run in trouble.

Yes, it seems only to affect statements in functions.

comment:8 by Volker Waurich, 11 years ago

Ok. I could simply not imagine why the elseif is evaluated and removed an the if is left at it is. Thanks for the advice.

comment:9 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:10 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

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

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:12 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:13 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:14 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:15 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:16 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

comment:17 by Per Östlund, 4 years ago

Component: FrontendNew Instantiation
Resolution: fixed
Status: assignedclosed

The new frontend removes the whole if-statement now, so I guess this is fixed.

comment:18 by Francesco Casella, 4 years ago

Milestone: Future1.16.0
Note: See TracTickets for help on using tickets.