如何在块中使用未指定的数组维度?

How to use unspecified array dimensions in blocks?

使用未指定的数组维度 (:) 是设计灵活组件以供重用的基本特征。我很好 实际尺寸必须在编译模型时固定。据我所知,将具有未指定数组维度的变量绑定到具有明确定义维度的变量就足够了。

所以我有点困惑为什么下面的 model Test 不会在 OpenModelicaWolfram System Modeler 中验证:

package VectorFunctions

  model Test
      VectorSum converter "Component taking the sum of a vector input";
      InformationSource source "Vector input";
    equation
      connect( source.y, converter.u );
  end Test;

  block VectorSum "Take the sum of an input with unspecified dimension"
      Modelica.Blocks.Interfaces.RealInput u[:];
      Modelica.Blocks.Interfaces.RealOutput y;
    equation
      y = sum(u);
  end VectorSum;

  block InformationSource "Provide some vector output"
      Modelica.Blocks.Interfaces.RealOutput y[3];
    equation
      y = ones( 3 );
  end InformationSource;

end VectorFunctions;

这样的事情怎么办?

我的猜测是 Modelica 规范没有指定可以从连接中自动检测矢量大小,因此工具不支持它。

我认为你必须自己设置矢量大小,例如使用在您的测试模型中设置的参数如下:

  model Test
      VectorSum converter(nu=size(source.y, 1)) "Pass in the vector size";
      InformationSource source "Vector input";
  equation 
      connect(source.y, converter.u);
  end Test;

  block VectorSum "Take the sum of an input with unspecified dimension"
      Modelica.Blocks.Interfaces.RealInput u[nu];
      parameter Integer nu(min=0)=0;
      output Real y;
  equation 
      y = sum(u);
  end VectorSum;

请注意,Dymola 在您的示例代码中抱怨连接语句只能应用于连接器。因此,我将 input Real 更改为 Modelica.Blocks.Interfaces.RealInput(与 InformationSource 中的类似)

Wolfram MathCore 的某个人(例如 System Modeler 的开发人员)给了我(非官方的)feedback on Wolfram Community

Hi, I agree with your interpretation, I think we should support it. I have filed a bug to keep track of this issue internally, unfortunately I do not see any work around. We will come back to you when we have fixed this problem.

因此,希望 blocks 能够像 functions.

一样支持 flexbile 数组大小