OMPython使用自定义模型与外部包



我正在尝试使用外部包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:

最后一个错误是由于使用了"time"@adrian-pop

指出modelica中不允许的命名组件

您似乎有一个名为"time"在MainModel中。在第12行?


旧答案如下(问题已更改)。

有几个问题。如果你加载包。整个库将被加载,所以你不需要在库列表中再次给出它。另外,如果你在库列表中给出了库ModPowerSystems,你不应该在列表中给出任何其他内部包ModPowerSystems. x.y。

代码应该是这样的:

mod=ModelicaSystem(str(source_dir)+"/simulator/ModPowerSystems/package.mo",
"ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel",
["Modelica"])

另一个问题是"Error: Cannot instantiate ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel due to class specialization PACKAGE"。这意味着您试图模拟的类:ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel不是一个模型,而是一个不能模拟的包。也许包中有你需要选择的模型。

还有其他问题,比如包中缺少名称。命令库中的文件,但这些只是警告,我们现在忽略它们。

最新更新