如何使用某个库中的组件

gfa*_*fan 2 modelica openmodelica

如何使用某个库(Modelica 除外)中的组件并从 OM Shell 运行模型?例如,

model myModel
   Modelica.Electrical.Analog.Sources.ConstantVoltage cv(V=9) .... // Standard component
   SomeLibrary.Components.SomeComponent myComponent ....           // Some specific component
...
end myModel

Run Code Online (Sandbox Code Playgroud)

如果我想使用 loadFile("mymodel.mo") 命令从 OM Shell 运行此模型,我通常会收到一条消息,提示无法构建模型,因为它找不到“SomeLibrary”。

我想编写命令以在脚本 (.mos) 中加载模型,并使用 omc 从 .bat 文件调用该脚本。

谢谢你!

sjo*_*.se 6

向模型添加使用注释(应该适用于任何工具):

model myModel
   Modelica.Electrical.Analog.Sources.ConstantVoltage cv(V=9) .... // Standard component
   SomeLibrary.Components.SomeComponent myComponent ....           // Some specific component
...
   annotation(uses(SomeLibrary(version="1.0.0")));
end myModel;
Run Code Online (Sandbox Code Playgroud)

或者在你的 mos 脚本中:

loadFile("myModel.mo");getErrorString();
loadModel(SomeLibrary);getErrorString();
loadModel(SomeLibrary, {"1.0.0"});getErrorString(); // Or with a specific version
Run Code Online (Sandbox Code Playgroud)

或者使用 OpenModelica 1.19.0 或更高版本(如果它位于 MODELICAPATH 上,它应该自动加载该库)。

如果未安装该库,请使用 OMEdit 安装该软件包,或从 OMShell/mos-script 中安装:

updatePackageIndex();
installPackage(SomeLibrary);
installPackage(SomeLibrary, "1.0.0"); // Or with a specific version
Run Code Online (Sandbox Code Playgroud)