Function modelica中作为函数输入参数的连接器

Function modelica中作为函数输入参数的连接器,function,modelica,openmodelica,Function,Modelica,Openmodelica,是否可以将连接器用作函数输入参数?不知何故,我无法运行下面的最小示例 在我的f.mo文件中 function f input Modelica.Electrical.Analog.Interfaces.Pin t; output Real p; algorithm p:=t.i*t.v; end f; 在测试中,我有 model test Modelica.Electrical.Analog.Interfaces.Pin t; Real V = f(t); en

是否可以将连接器用作函数输入参数?不知何故,我无法运行下面的最小示例

在我的f.mo文件中

function f
  input Modelica.Electrical.Analog.Interfaces.Pin t;
  output Real p;
  algorithm
    p:=t.i*t.v;
end f;
在测试中,我有

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

谢谢

连接器不能用作功能输入。但是,您可以执行以下操作:

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;

前面的答案是好的,有效的,但在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时,它才在Dymola中处于活动状态

非常感谢您的澄清!我在介绍性书籍中看到过这样的评论:模型和块不能用作输入参数,但我对连接器不太确定。在迪莫拉,这似乎奏效了。我只得到一个警告。是的,Dymola不那么严格,除非你激活学究模式进行检查。Modelica规范3.4在第12.2章中阐明了允许的组件类型:函数只能包含受限类类型、记录、操作员记录和函数的组件;i、 e.无模型或块组件。感谢您的跟进!