问题描述
我们通过 C/Python API 从 Dymola 执行 Python 代码。因此我们使用了 tutorial。本教程的工作原理如图所示,但是当我们结合 Dymolas 内置时间变量和 Pythons Numpy 库时,会出现段错误。
function pyString
input String s;
output Real o;
external "C" o = pyRunString(s)
annotation(Include="
#include <Python.h>
double pyRunString(const char *str)
{
Py_Initialize();
PyRun_SimpleString(str);
Py_Finalize();
return 0.0;
}
");
end pyString;
model CallPython
Real value;
equation
value = pyString("print(" + String(time) + ")");
end CallPython;
这个模型也适用于模拟:
model CallPython
Real value;
equation
value = pyString("import numpy \nprint(" + String(0.0) + ")");
end CallPython;
model CallPython
Real value;
equation
value = pyString("import numpy \nprint(" + String(time) + ")");
end CallPython;
我们使用 Ubuntu20.04 和 Dymola 2021 版(64 位)、2020-04-17、python3.8 和 Numpy 1.21.0
有人知道为什么这不起作用或我们如何解决吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)