#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 , 11 years ago
Cc: | added |
---|
follow-up: 3 comment:2 by , 11 years ago
follow-up: 4 comment:3 by , 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.
comment:4 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
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 , 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.
follow-up: 7 comment:6 by , 11 years ago
Hopefully this affect only statements and not equations. Otherwise the preOptModule "simplifyIfEquations" will run in trouble.
comment:7 by , 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 , 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 , 10 years ago
Milestone: | 1.9.1 → 1.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 , 10 years ago
Milestone: | 1.9.2 → 1.9.3 |
---|
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:15 by , 8 years ago
Milestone: | 1.11.0 → 1.12.0 |
---|
Milestone moved to 1.12.0 due to 1.11.0 already being released.
comment:16 by , 7 years ago
Milestone: | 1.12.0 → Future |
---|
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 , 4 years ago
Component: | Frontend → New Instantiation |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
The new frontend removes the whole if-statement now, so I guess this is fixed.
comment:18 by , 4 years ago
Milestone: | Future → 1.16.0 |
---|
Do you have an example model that uses this function?