Opened 10 years ago

Closed 3 years ago

Last modified 3 years ago

#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 Adrian Pop, 10 years ago

Owner: changed from somebody to Adrian Pop
Status: newaccepted

comment:2 by Adeel Asghar, 10 years ago

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. The getNthComponent fetches the component correctly.

In the above testcase getComponents lists the first 34 elements correctly as they are all in public section and getNthComponent also works fine. But the element 35 of getComponents is Modelica.Electrical.Analog.Basic.Ground with name G2 whereas it should be Modelica.Electrical.Analog.Interfaces.NegativePin with name n1.

model CauerLowPassOPV "Cauer low pass filter with operational amplifiers"
  extends Modelica.Icons.Example;
  parameter Modelica.SIunits.Capacitance l1 = 1.304 "filter coefficient i1";
  parameter Modelica.SIunits.Capacitance l2 = 0.8586 "filter coefficient i2";
  parameter Modelica.SIunits.Capacitance c1 = 1.072 "filter coefficient c1";
  parameter Modelica.SIunits.Capacitance c2 = 1 / (1.704992 ^ 2 * l1) "filter coefficient c2";
  parameter Modelica.SIunits.Capacitance c3 = 1.682 "filter coefficient c3";
  parameter Modelica.SIunits.Capacitance c4 = 1 / (1.179945 ^ 2 * l2) "filter coefficient c4";
  parameter Modelica.SIunits.Capacitance c5 = 0.7262 "filter coefficient c5";
  Modelica.Electrical.Analog.Basic.Capacitor C1(C = c1 + c2, v(start = 0, fixed = true)) annotation(Placement(transformation(extent = {{-192, 10}, {-172, 30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C2(C = c2, v(start = 0, fixed = true)) annotation(Placement(transformation(extent = {{-240, -90}, {-220, -70}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C3(C = l1, v(start = 0, fixed = true)) annotation(Placement(transformation(extent = {{-90, 10}, {-70, 30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C4(C = c4, v(start = 0, fixed = true)) annotation(Placement(transformation(extent = {{-30, 30}, {-10, 50}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C5(C = c2) annotation(Placement(transformation(extent = {{-30, -120}, {-10, -100}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R1(R = 1) annotation(Placement(transformation(extent = {{-240, -50}, {-220, -30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R2(R = 1) annotation(Placement(transformation(extent = {{-240, -10}, {-220, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R3(R = 1) annotation(Placement(transformation(extent = {{-193, 50}, {-173, 70}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op1 annotation(Placement(transformation(extent = {{-200, -70}, {-160, -30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Ground G annotation(Placement(transformation(extent = {{-188, -96}, {-174, -80}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R4(R = -1) annotation(Placement(transformation(extent = {{-140, -60}, {-120, -40}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R5(R = -1) annotation(Placement(transformation(extent = {{-140, -100}, {-120, -80}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op2 annotation(Placement(transformation(extent = {{-100, -70}, {-60, -30}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op3 annotation(Placement(transformation(extent = {{4, -72}, {46, -30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Ground G1 annotation(Placement(transformation(extent = {{-87, -96}, {-73, -80}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R6(R = 1) annotation(Placement(transformation(extent = {{-31, -10}, {-11, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R7(R = 1) annotation(Placement(transformation(extent = {{-31, -60}, {-11, -40}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C6(C = c2 + c3 + c4) annotation(Placement(transformation(extent = {{9, 10}, {29, 30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R8(R = -1) annotation(Placement(transformation(extent = {{60, -10}, {80, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R9(R = -1) annotation(Placement(transformation(extent = {{60, -60}, {80, -40}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R10(R = 1) annotation(Placement(transformation(extent = {{160, -60}, {180, -40}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op4 annotation(Placement(transformation(extent = {{100, -70}, {140, -30}}, rotation = 0)));
  Modelica.Electrical.Analog.Ideal.IdealOpAmp3Pin Op5 annotation(Placement(transformation(extent = {{200, -70}, {240, -30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C7(C = l2, v(start = 0, fixed = true)) annotation(Placement(transformation(extent = {{110, 10}, {130, 30}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C8(C = c4) annotation(Placement(transformation(extent = {{160, -150}, {180, -130}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Capacitor C9(C = c4 + c5) annotation(Placement(transformation(extent = {{208, -10}, {228, 10}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Resistor R11(R = 1) annotation(Placement(transformation(extent = {{209, 30}, {229, 50}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n1 annotation(Placement(transformation(extent = {{-214, -42}, {-210, -38}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n2 annotation(Placement(transformation(extent = {{-214, -2}, {-210, 2}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n3 annotation(Placement(transformation(extent = {{-214, 18}, {-210, 22}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n4 annotation(Placement(transformation(origin = {-160, 20}, extent = {{2, 2}, {-2, -2}}, rotation = 180)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n5 annotation(Placement(transformation(extent = {{-114, -52}, {-110, -48}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p1 annotation(Placement(transformation(extent = {{-154, -142}, {-148, -138}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n6 annotation(Placement(transformation(extent = {{-62, 18}, {-58, 22}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n7 annotation(Placement(transformation(extent = {{-6, -52}, {-2, -48}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n8 annotation(Placement(transformation(extent = {{-6, -2}, {-2, 2}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p2 annotation(Placement(transformation(extent = {{-6, 18}, {-2, 22}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin out1 annotation(Placement(transformation(extent = {{44, -142}, {48, -138}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p3 annotation(Placement(transformation(extent = {{58, 58}, {62, 62}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n9 annotation(Placement(transformation(extent = {{86, -2}, {90, 2}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n10 annotation(Placement(transformation(extent = {{86, -52}, {90, -48}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n11 annotation(Placement(transformation(extent = {{138, 18}, {142, 22}}, rotation = 0)));
public
  Modelica.Electrical.Analog.Basic.Ground G2 annotation(Placement(transformation(extent = {{12, -96}, {26, -80}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n12 annotation(Placement(transformation(extent = {{238, 38}, {242, 42}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n13 annotation(Placement(transformation(extent = {{238, -2}, {242, 2}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.PositivePin p4 annotation(Placement(transformation(extent = {{188, -2}, {194, 2}}, rotation = 0)));
protected
  Modelica.Electrical.Analog.Interfaces.NegativePin n14 annotation(Placement(transformation(extent = {{188, -52}, {194, -48}}, rotation = 0)));
public
  Modelica.Electrical.Analog.Basic.Ground G3 annotation(Placement(transformation(extent = {{113, -96}, {127, -80}}, rotation = 0)));
  Modelica.Electrical.Analog.Basic.Ground G4 annotation(Placement(transformation(extent = {{213, -96}, {227, -80}}, rotation = 0)));
  Modelica.Electrical.Analog.Sources.StepVoltage V(startTime = 1, V = 1) annotation(Placement(transformation(origin = {-240, -170}, extent = {{-10, -10}, {10, 10}}, rotation = 90)));
  Modelica.Electrical.Analog.Basic.Ground Ground1 annotation(Placement(transformation(extent = {{-246, -202}, {-234, -190}}, rotation = 0)));

In my opinion getNthComponent is working fine. getComponents should not sort the elements based on public and protected sections.

comment:3 by jklingler@…, 10 years ago

I agree, getNthComponent behaves intuitively, and getComponents should not sort the elements.

comment:4 by Adrian Pop, 3 years ago

Milestone: Future1.18.1
Resolution: fixed
Status: acceptedclosed

comment:5 by Francesco Casella, 3 years ago

Milestone: 1.18.11.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

comment:6 by Adrian Pop, 3 years ago

I will do that tomorrow.

Note: See TracTickets for help on using tickets.