#2624 closed defect (fixed)
missing elseif branch
Reported by: | vwaurich | Owned by: | perost |
---|---|---|---|
Priority: | normal | Milestone: | 1.16.0 |
Component: | New Instantiation | Version: | trunk |
Keywords: | elseif | Cc: | perost, adrpo, cschubert, jfrenkel, lochel |
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 Changed 10 years ago by lochel
- Cc lochel added
comment:2 follow-up: ↓ 3 Changed 10 years ago by perost
comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 10 years ago by 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.
comment:4 in reply to: ↑ 3 Changed 10 years ago by perost
- Owner changed from somebody to perost
- Status changed from new to 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 Changed 10 years ago by perost
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 follow-up: ↓ 7 Changed 10 years ago by jfrenkel
Hopefully this affect only statements and not equations. Otherwise the preOptModule "simplifyIfEquations" will run in trouble.
comment:7 in reply to: ↑ 6 Changed 10 years ago by perost
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 Changed 10 years ago by vwaurich
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 Changed 9 years ago by sjoelund.se
- Milestone changed from 1.9.1 to 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 Changed 9 years ago by sjoelund.se
- Milestone changed from 1.9.2 to 1.9.3
Milestone changed to 1.9.3 since 1.9.2 was released.
comment:11 Changed 9 years ago by sjoelund.se
- Milestone changed from 1.9.3 to 1.9.4
Moved to new milestone 1.9.4
comment:12 Changed 8 years ago by sjoelund.se
- Milestone changed from 1.9.4 to 1.9.5
Milestone pushed to 1.9.5
comment:13 Changed 8 years ago by sjoelund.se
- Milestone changed from 1.9.5 to 1.10.0
Milestone renamed
comment:14 Changed 7 years ago by sjoelund.se
- Milestone changed from 1.10.0 to 1.11.0
Ticket retargeted after milestone closed
comment:15 Changed 7 years ago by sjoelund.se
- Milestone changed from 1.11.0 to 1.12.0
Milestone moved to 1.12.0 due to 1.11.0 already being released.
comment:16 Changed 6 years ago by casella
- Milestone changed from 1.12.0 to 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 Changed 3 years ago by perost
- Component changed from Frontend to New Instantiation
- Resolution set to fixed
- Status changed from assigned to closed
The new frontend removes the whole if-statement now, so I guess this is fixed.
comment:18 Changed 3 years ago by casella
- Milestone changed from Future to 1.16.0
Do you have an example model that uses this function?