OMPython 使用带有外部包的自定义模型
OMPython using custom model with external package
我正在尝试使用外部包 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
不确定这里发生了什么,但“无法实例化包”错误消失了。扁平化模型时发生错误是什么意思?
更新 2:
最后一个错误是由于使用了名为“time”的组件,正如 @adrian-pop 所指出的那样,modelica 中不允许使用该组件
您似乎在第 12 行的 MainModel.mo 中有一个名为“time”的组件?
下面是旧答案(问题已更改)。
有几个问题。如果你加载 package.mo 整个库将被加载,所以你不需要在库列表中再次给它。此外,如果您在库列表中提供库 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"
。这意味着您要模拟的 class:ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel
不是模型,是无法模拟的包。也许该包中有您需要 select.
的模型
还有其他问题,例如库中的 package.order 文件中缺少名称,但这些只是警告,我们暂时忽略它们。
我正在尝试使用外部包 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
不确定这里发生了什么,但“无法实例化包”错误消失了。扁平化模型时发生错误是什么意思?
更新 2:
最后一个错误是由于使用了名为“time”的组件,正如 @adrian-pop 所指出的那样,modelica 中不允许使用该组件
您似乎在第 12 行的 MainModel.mo 中有一个名为“time”的组件?
下面是旧答案(问题已更改)。
有几个问题。如果你加载 package.mo 整个库将被加载,所以你不需要在库列表中再次给它。此外,如果您在库列表中提供库 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"
。这意味着您要模拟的 class:ModPowerSystems.CustomModule.Examples.BasicGrids.MainModel
不是模型,是无法模拟的包。也许该包中有您需要 select.
还有其他问题,例如库中的 package.order 文件中缺少名称,但这些只是警告,我们暂时忽略它们。