是否可以使用连接器作为函数输入参数?不知何故,我无法运行以下最小示例。
在我的f.mo文件中
function f
input Modelica.Electrical.Analog.Interfaces.Pin t;
output Real p;
algorithm
p:=t.i*t.v;
end f;
在test.mo我有
model test
Modelica.Electrical.Analog.Interfaces.Pin t;
Real V = f(t);
end test;
当我运行 test.mo 检查时,我收到错误消息
[1] 11:15:38 Translation Error
[f: 2:3-2:52]: Invalid type .Modelica.Electrical.Analog.Interfaces.Pin for function component t.
[2] 11:15:38 Translation Error
[test: 5:3-5:16]: Class f not found in scope test (looking for a function or record).
[3] 11:15:38 Translation Error
Error occurred while flattening model test
谢谢!
最佳答案
以前的答案很好并且有效,但是在 Modelica 3.4 的第 12.6.1 节中。添加了另一种更接近原始的可能性。
record R
Real i,v;
end R;
function f
input R t;
output Real p;
algorithm
p:=t.i*t.v;
end f;
model test
Modelica.Electrical.Analog.Interfaces.Pin t;
Real V = f(R(t));
end test;
这主要是受具有更多元素的模型的插入,列出所有元素变得乏味。由于它是 Modelica 3.4 中的新功能,如果您设置标志 Advanced.RecordModelConstructor = true;
关于function - 连接器作为模型中的函数输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52756479/