在JModelica中引用外部文件

时间:2016-08-24 21:42:44

标签: modelica openmodelica jmodelica

我有一个Modelica文件,通过外部库* .a文件在模拟过程中引用c代码。

例如:

model CallAdd
    input Real FirstInput(start=0);
    input Real SecondInput(start=0);
    output Real FMUOutput(start=0); 
    function CAdd
        input Real x(start=0);
        input Real y(start=0);
        output Real z(start=0);
        external "C"  annotation(Library = "CAdd", LibraryDirectory = "modelica://CallAdd");
    end CAdd;

equation
    FMUOutput = CAdd(FirstInput,SecondInput);
    annotation(uses(Modelica(version = "3.2.1")));
end CallAdd;

在OpenModelica中打开Modelica模型时,所需的文件似乎会自动加载,因为它会模拟并提供适当的结果。

但是,当我尝试使用JModelica-SDK-1.12编译Modelica文件时,我收到一个错误,即无法找到库* .a文件。

所以我的问题是:在JModelica中使用compile_fmu时引用其他文件的正确方法是什么?

没有成功,我试过了:

# Import the compiler function
from pymodelica import compile_fmu
model_name = "CallAdd"
mo_file = "CallAdd.mo"

# Compile the model and save the return argument, for use later if wanted
my_fmu = compile_fmu(model_name, mo_file, target="cs",compiler_options = {'extra_lib_dirs':'C:/ToFolderContainingLib/'})

奇怪的是,当我使用JModelica-1.17(非SDK)时,文件编译得很好,但结果没有意义。我建议尝试使用SDK版本,看看它是否修复了我之前发布的帖子here中的错误。

2 个答案:

答案 0 :(得分:2)

如果是一小段C代码,作为最后一种替代方案,您可以尝试将C文件直接包含在Modelica代码中:

external "C"  annotation(Include="
// the entire C code here
");

希望JModelica人员能尽快给你一个更好的答案。 您也可以尝试在他们的网站上询问: http://www.jmodelica.org/forum

答案 1 :(得分:2)

尝试将外部库放在名为您当前所在平台的子文件夹中。所以在你的例子中,我将库(libCAdd.a)放在名为linux64的子文件夹中,因为我在64位Linux机器上,然后运行代码。

相关问题