function - 连接器作为模型中的函数输入参数

标签 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;

在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;

,它目前仅在 Dymola 中有效

关于function - 连接器作为模型中的函数输入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52756479/

相关文章:

modelica - 作为除数的导数在 Dymola 初始化期间除以零

modelica - 在 State-Space block OpenModelica 中使用连续变量

php - 如何从周数、天数和年份中获取日期?

javascript - 我需要评估吗?

modelica - 如何为作为数组一部分从函数返回的 modelica 参数设置起始值

python - FMU异常 : Failed to setup the experiment

dll - 来自 MapleSim/Modelica 的 FORTRAN DLL 调用约定

php - 是否有一个 PHP 函数可以在不切割单词的情况下将字符串切割成多个部分?

python - (代码)OpenERP v7中product.product中的id是什么?

modelica - 在仿真期间暂停 JModelica 并传递增量输入