#2940 closed defect (fixed)
OMC API: getComponents[i] and getNthComponent(i) does not return the same component for some models
Reported by: | Adrian Pop | Owned by: | Adrian Pop |
---|---|---|---|
Priority: | high | Milestone: | 1.19.0 |
Component: | Interactive Environment | Version: | trunk |
Keywords: | Cc: | jklingler@… |
Description
Bug report from James Klingler:
loadModel(Modelica); getComponents(Modelica.Electrical.Analog.Examples.CauerLowPassOPV); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 1); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 2); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 3); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 50); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 51); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 52); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 53); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 54); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 55); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 56); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 57); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 58); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 59); // Error expected getComponents(Modelica.Electrical.Analog.Examples.CauerLowPassSC); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassSC, 57); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassSC, 58); getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassSC, 59); // Error expected
If you run:
getComponents(Modelica.Electrical.Analog.Examples.CauerLowPassOPV);
(line 3 of the script), the array returned has length 58. The final object in the array is Modelica.Electrical.Analog.Interfaces.NegativePin
with name “n14”
but running
getNthComponent(Modelica.Electrical.Analog.Examples.CauerLowPassOPV, 58);
(line 15 of the script) returns info about Modelica.Electrical.Analog.Basic.Ground
with name “Ground1”
.
Change History (6)
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
I agree, getNthComponent behaves intuitively, and getComponents should not sort the elements.
comment:4 by , 3 years ago
Milestone: | Future → 1.18.1 |
---|---|
Resolution: | → fixed |
Status: | accepted → closed |
Fixed with PR: https://github.com/OpenModelica/OpenModelica/pull/7709
comment:5 by , 3 years ago
Milestone: | 1.18.1 → 1.19.0 |
---|
@adrpo, the PR is on master, so it goes to 1.19.0. For 1.18.1 (or actually 1.18.0) it needs to be cherry picked into the 1.18 maintenance branch
The problem is
getComponents
first lists all the public elements then all the protected elements so the list is not according to the elements as listed in the model. ThegetNthComponent
fetches the component correctly.In the above testcase
getComponents
lists the first 34 elements correctly as they are all in public section andgetNthComponent
also works fine. But the element 35 ofgetComponents
isModelica.Electrical.Analog.Basic.Ground
with nameG2
whereas it should beModelica.Electrical.Analog.Interfaces.NegativePin
with namen1
.In my opinion
getNthComponent
is working fine.getComponents
should not sort the elements based on public and protected sections.