如果我有一个没有输入和输出的非modelica函数,比如
void foo(void)
{
variable1;
variable2;
for loop
{
if conditions
}
variable2=foobar(); // another function call, foobar() is not modelica function
}那么我可以在modelica中像下面这样建模吗?
model foo
variable1;
variable2;
algorithm
for loop
{
if conditions
}
variable2 :=foobar(); //foobar here is modelica function
end foo;发布于 2013-11-21 09:09:17
实际上,你的描述有点麻烦。如果你的函数没有输入和输出,那么调用它有什么意义呢?
我猜你的函数有side effects。但是,如果您从Modelica调用有副作用的函数,则需要非常小心,因为一般来说,您无法控制何时调用它们。例如,它们将被称为所谓的“候选解决方案”以及实际的模拟步骤。
所以你最好多解释一下这个函数的作用。这不仅有助于决定如何在Modelica中表达它,还可以证明您的函数最好保留为C代码,并通过Modelica中的外部函数接口进行调用。
发布于 2013-11-21 06:20:49
您可能想快速查看一下漂亮的小抄http://modref.xogeny.com/,以了解如何执行for-循环。此外,在算法部分中,您必须使用赋值而不是公式:
algorithm
...
variable2 := foobar(); //foobar here is modelica functionhttps://stackoverflow.com/questions/20099100
复制相似问题