ModelicaStandardLibrary icon indicating copy to clipboard operation
ModelicaStandardLibrary copied to clipboard

Invalid access of protected elements in SmoothStep example

Open maltelenz opened this issue 10 months ago • 2 comments

This:

https://github.com/modelica/ModelicaStandardLibrary/blob/a877f527e29c47e344d2c05e393b65c6c4eee01b/Modelica/Electrical/Analog/Examples/Lines/SmoothStep.mo#L92-L97

Accesses these protected elements:

https://github.com/modelica/ModelicaStandardLibrary/blob/a877f527e29c47e344d2c05e393b65c6c4eee01b/Modelica/Electrical/Analog/Lines/OLine.mo#L57-L65

and is hence illegal, as reported by System Modeler:

Error: Modelica.Electrical.Analog.Examples.Lines.SmoothStep Invalid lookup of protected element. When looking up oLine50.L.i in scope Modelica.Electrical.Analog.Examples.Lines.SmoothStep, L is protected. Protected elements can only appear as the first part of a component reference or path, and cannot be imported.

Error: Modelica.Electrical.Analog.Examples.Lines.SmoothStep Invalid lookup of protected element. When looking up oLine50.C.v in scope Modelica.Electrical.Analog.Examples.Lines.SmoothStep, C is protected. Protected elements can only appear as the first part of a component reference or path, and cannot be imported.

Error: Modelica.Electrical.Analog.Examples.Lines.SmoothStep Invalid lookup of protected element. When looking up oLine5.L.i in scope Modelica.Electrical.Analog.Examples.Lines.SmoothStep, L is protected. Protected elements can only appear as the first part of a component reference or path, and cannot be imported.

Error: Modelica.Electrical.Analog.Examples.Lines.SmoothStep Invalid lookup of protected element. When looking up oLine5.C.v in scope Modelica.Electrical.Analog.Examples.Lines.SmoothStep, C is protected. Protected elements can only appear as the first part of a component reference or path, and cannot be imported.

Error: Modelica.Electrical.Analog.Examples.Lines.SmoothStep Invalid lookup of protected element. When looking up oLine1.L.i in scope Modelica.Electrical.Analog.Examples.Lines.SmoothStep, L is protected. Protected elements can only appear as the first part of a component reference or path, and cannot be imported.

Error: Modelica.Electrical.Analog.Examples.Lines.SmoothStep Invalid lookup of protected element. When looking up oLine1.C.v in scope Modelica.Electrical.Analog.Examples.Lines.SmoothStep, C is protected. Protected elements can only appear as the first part of a component reference or path, and cannot be imported.

maltelenz avatar Apr 11 '24 09:04 maltelenz

Same thing here:

https://github.com/modelica/ModelicaStandardLibrary/blob/a877f527e29c47e344d2c05e393b65c6c4eee01b/Modelica/Electrical/Analog/Examples/Lines/CompareLineTrunks.mo#L91-L98

maltelenz avatar Apr 11 '24 09:04 maltelenz

Broken by 839ab4de9c84a4a9bcbf070708f982969c84b484 for #4306. Not sure if the protected section was modified on purpose or accident. Given the commit message it does not look a necessary change.

beutlich avatar Apr 11 '24 13:04 beutlich

I confirm also OpenModelica complains about that:

  • https://libraries.openmodelica.org/branches/master/Modelica_trunk/files/Modelica_trunk_Modelica.Electrical.Analog.Examples.Lines.SmoothStep.err
  • https://libraries.openmodelica.org/branches/master/Modelica_trunk/files/Modelica_trunk_Modelica.Electrical.Analog.Examples.Lines.CompareLineTrunks.err

As I understand, 839ab4d made the sub-components of OLine protected to avoid excessive simulation data output and mirrored the current and voltage variables to public alias variables. The commit fixed the initial equations of LightningSegmentedTransmissionLine accordingly, but not the ones of SmoothStep and CompareLineTrunk.

If we had a proper CI in place, this would have been caught immediately 😃

I'll make a PR to fix this.

casella avatar Jun 18 '24 20:06 casella

Will be fixed by #4422 on master, then we need to back-port it to maint/4.1.x

casella avatar Jun 18 '24 21:06 casella

Reopening until it is back-ported to maint/4.1.x

casella avatar Jul 31 '24 12:07 casella

#4446 back-ported #4422, all set.

casella avatar Aug 16 '24 22:08 casella