2

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

所以我有点困惑为什么以下内容在任何一个或以下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;

这样的事情怎么能做到呢?

4

2 回答 2

1

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

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

  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 RealModelica.Blocks.Interfaces.RealInput和类似的InformationSource

于 2019-06-18T15:21:53.963 回答
1

Wolfram MathCore 的某个人(例如 System Modeler 的开发人员)向我提供了关于 Wolfram 社区的(非官方)反馈:

你好,我同意你的解释,我认为我们应该支持它。我已经提交了一个错误来在内部跟踪这个问题,不幸的是我没有看到任何解决方法。解决此问题后,我们会回复您。

因此,希望 flexbile 数组大小能够blocksfunctions.

于 2019-07-03T16:36:26.157 回答