【发布时间】:2021-09-22 08:04:20
【问题描述】:
我正在尝试使用外部包 ModPowerSystems 模拟自定义模型,并使用 OMPython 进行一些自动化。
我的代码是:
from OMPython import OMCSessionZMQ
from OMPython import ModelicaSystem
from pathlib import Path
omc = OMCSessionZMQ()
source_path = Path(__file__).resolve()
source_dir = source_path.parent
mod=ModelicaSystem(str(source_dir)+"/simulator/ModPowerSystems/package.mo",
"ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel",
["ModPowerSystems","Modelica","ModPowerSystems.CustomModule.Loads.DependentModel1","ModPowerSystems.CustomModule.Generation.DependentModel2"])
mod.buildModel()
但是当我运行它时,我得到了:
2021-09-22 09:39:04,743 - OMPython - INFO - OMC Server is up and running at
2021-09-22 09:39:05,017 - OMPython - INFO - OMC Server is up and running at
[<interactive>:1:9-1:13:writable] Warning: Lexer treating \ as \\, since \U is not a valid Modelica escape sequence.
[<interactive>:1:9-1:19:writable] Warning: Lexer treating \ as \\, since \A is not a valid Modelica escape sequence.
[<interactive>:1:9-1:33:writable] Warning: Lexer treating \ as \\, since \P is not a valid Modelica escape sequence.
[<interactive>:1:9-1:42:writable] Warning: Lexer treating \ as \\, since \T is not a valid Modelica escape sequence.
Notification: Automatically loaded package Modelica 3.2.3 due to uses annotation.
Notification: Automatically loaded package Complex 3.2.3 due to uses annotation.
Notification: Automatically loaded package ModelicaServices 3.2.3 due to uses annotation.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
[C:/Program Files/OpenModelica1.16.0-64bit/lib/omlibrary/ModPowerSystems/EmtThreePhase/Examples/BasicGrids/package.order:0:0-0:0:readonly] Warning: The package.order file does not list all .mo files and directories (containing package.mo) present in its directory.
Missing names are:
SynGen_Park_UnitTest_FullModel
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
[C:/Program Files/OpenModelica1.16.0-64bit/lib/omlibrary/ModPowerSystems/EmtThreePhase/Examples/BasicGrids/package.order:0:0-0:0:readonly] Warning: The package.order file does not list all .mo files and directories (containing package.mo) present in its directory.
Missing names are:
SynGen_Park_UnitTest_FullModel
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
[C:/Program Files/OpenModelica1.16.0-64bit/lib/omlibrary/ModPowerSystems/EmtThreePhase/Examples/BasicGrids/package.order:0:0-0:0:readonly] Warning: The package.order file does not list all .mo files and directories (containing package.mo) present in its directory.
Missing names are:
SynGen_Park_UnitTest_FullModel
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Error: Cannot instantiate ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel due to class specialization PACKAGE.
Error: Class ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel not found in scope <TOP>.
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Error: Cannot instantiate ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel due to class specialization PACKAGE.
Error: Class ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel not found in scope <TOP>.
我是 openmodelica 的超级新手,所以我不确定这里缺少什么。 有什么建议吗?
更新 1:
我正在关注@adrian-pop 的建议,但遇到了这个新错误:
2021-09-22 10:46:32,128 - OMPython - INFO - OMC Server is up and running at
[<interactive>:1:9-1:13:writable] Warning: Lexer treating \ as \\, since \U is not a valid Modelica escape sequence.
[<interactive>:1:9-1:19:writable] Warning: Lexer treating \ as \\, since \A is not a valid Modelica escape sequence.
[<interactive>:1:9-1:33:writable] Warning: Lexer treating \ as \\, since \P is not a valid Modelica escape sequence.
[<interactive>:1:9-1:42:writable] Warning: Lexer treating \ as \\, since \T is not a valid Modelica escape sequence.
Notification: Automatically loaded package Modelica 3.2.3 due to uses annotation.
Notification: Automatically loaded package Complex 3.2.3 due to uses annotation.
Notification: Automatically loaded package ModelicaServices 3.2.3 due to uses annotation.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/Base/Interfaces/ComplexPhasor/ThreePhase/OnePortGrounded.mo:7:5-7:45:writable] Warning: No corresponding 'inner' declaration found for component .ModPowerSystems.Base.System DependentModel2.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: ModPowerSystems.CustomModel.Generation.DependentModel2.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/CustomModel/Generation/DependentModel2.mo:11:3-11:43:writable] Warning: No corresponding 'inner' declaration found for component .ModPowerSystems.Base.System DependentModel2.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: ModPowerSystems.CustomModel.Generation.DependentModel2.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/Base/Interfaces/ComplexPhasor/ThreePhase/OnePortGrounded.mo:7:5-7:45:writable] Warning: No corresponding 'inner' declaration found for component .ModPowerSystems.Base.System DependentModel1.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: ModPowerSystems.CustomModel.Loads.DependentModel1.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/CustomModel/Examples/BasicGrids/MainModel.mo:12:3-12:32:writable] Error: Identifier time is reserved for the built-in element with the same name.
Error: Error occurred while flattening model ModPowerSystems.CustomModel.Examples.BasicGrids.MainModel
Notification: ModPowerSystems requested package Modelica of version 3.2.2. Modelica 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package Complex of version 3.2.2. Complex 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
Notification: ModPowerSystems requested package ModelicaServices of version 3.2.2. ModelicaServices 3.2.3 is used instead which states that it is fully compatible without conversion script needed.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/Base/Interfaces/ComplexPhasor/ThreePhase/OnePortGrounded.mo:7:5-7:45:writable] Warning: No corresponding 'inner' declaration found for component .ModPowerSystems.Base.System DependentModel2.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: ModPowerSystems.CustomModel.Generation.DependentModel2.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/CustomModel/Generation/DependentModel2.mo:11:3-11:43:writable] Warning: No corresponding 'inner' declaration found for component .ModPowerSystems.Base.System DependentModel2.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: ModPowerSystems.CustomModel.Generation.DependentModel2.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/Base/Interfaces/ComplexPhasor/ThreePhase/OnePortGrounded.mo:7:5-7:45:writable] Warning: No corresponding 'inner' declaration found for component .ModPowerSystems.Base.System DependentModel1.system declared as 'outer '.
The existing 'inner' components are:
There are no 'inner' components defined in the model in any of the parent scopes of 'outer' component's scope: ModPowerSystems.CustomModel.Loads.DependentModel1.
Check if you have not misspelled the 'outer' component name.
Please declare an 'inner' component with the same name in the top scope.
Continuing flattening by only considering the 'outer' component declaration.
[C:/Users/Administrator/Projects/Proj/simulator/ModPowerSystems/CustomModel/Examples/BasicGrids/MainModel.mo:12:3-12:32:writable] Error: Identifier time is reserved for the built-in element with the same name.
Error: Error occurred while flattening model ModPowerSystems.CustomModel.Examples.BasicGrids.MainModel
不确定这里发生了什么,但“无法实例化 PACKAGE”错误消失了。扁平化模型时发生的错误是什么意思?
更新 2:
最后一个错误是由于使用了@adrian-pop指出的modelica中不允许的“时间”命名组件
【问题讨论】:
-
我猜你的模型中有一个名为 time 的组件(或类)。这是不允许的。
-
谢谢指出,错误消失了,
mod.buildModel()没问题!
标签: python-3.x modelica openmodelica