【问题标题】:How to use unspecified array dimensions in blocks?如何在块中使用未指定的数组维度?
【发布时间】:2019-06-18 14:13:09
【问题描述】:

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

所以我有点困惑为什么下面的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;

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

【问题讨论】:

  • 请注意,我在Wolfram Community 上交叉发布了一个类似的问题。
  • 我更新了我的代码以提供 connectors 以获得干净的 connect 声明。

标签: modelica openmodelica systemmodeler


【解决方案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 Real 更改为Modelica.Blocks.Interfaces.RealInput(在InformationSource 中类似)

【讨论】:

  • 其实Modelica specs 在我看来并不清楚这一点:Section 10.2 Flexible Array Sizes 只是指向 Section 12.4.5 这在哪里讨论functions(允许使用此处介绍的输入)。由于blocksfunctions 有一些熟悉,正如规范中所指出的那样,我仍然没有看到一个很好的理由为什么这不应该成功。
【解决方案2】:

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

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

因此,希望 blocksfunctions 一样支持灵活的数组大小。

【讨论】:

    猜你喜欢
    • 2015-05-25
    • 1970-01-01
    • 2012-05-14
    • 2023-03-29
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-07-06
    相关资源
    最近更新 更多