modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
452 stars 165 forks source link

Invalid access of protected elements in SmoothStep example #4383

Closed maltelenz closed 4 days ago

maltelenz commented 2 months ago

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 commented 2 months ago

Same thing here:

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

beutlich commented 2 months ago

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.

casella commented 2 weeks ago

I confirm also OpenModelica complains about that:

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 commented 2 weeks ago

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