是否可以使用连接器作为函数输入参数?不知何故,我无法获得以下最小的例子来运行。
在我的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谢谢!
发布于 2018-10-11 11:47:15
连接器不能用作函数输入。但是,您可以这样做:
function f
input Real i;
input Real v;
output Real p;
algorithm
p:=i*v;
end f;
model test
Modelica.Electrical.Analog.Interfaces.Pin t;
Real V = f(t.i, t.v);
end test;发布于 2018-10-12 10:07:14
前面的答案是好的,有效的,但在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;这主要是由有更多元素的模型驱动的,列出所有元素变得很乏味。因为它是Modelica3.4中的新功能,所以只有在设置标志Advanced.RecordModelConstructor = true;时,它才是在Dymola中活动的。
https://stackoverflow.com/questions/52756479
复制相似问题