尝试编译Dymola中零尺寸的记录变量时的错误

发布于 2025-01-30 18:59:50 字数 896 浏览 3 评论 0原文

我正在创建一系列记录,取决于组件中的端口连接数量。当连接数为1或更多时,实际组件正常工作,但是在没有连接时不起作用。寻找有关如何解决或解决方法的输入。

这是错误:

“在此处输入图像说明”

下面是MWE:

model RecordIssue
  record Record
    Real a=1;
  end Record;

  parameter Integer nPorts=0 annotation (Dialog(connectorSizing=true));

  Modelica.Fluid.Interfaces.FluidPorts_a ports_a[nPorts];

  // declare record array instance for each port connection
  parameter Record[nPorts] recordInstance={Record() for i in 1:nPorts};

  // this next line is an issue only when nPorts = 0 or no connections made
  Real test[:]=recordInstance[:].a;
end RecordIssue;

nports = 0时,变量test不存在的预期/所需行为将是不存在的。 ,这是真实测试[:] = {1.0 in 1:nports}};之类的正常行为

I'm creating an array of records dependent on the number of port connections made in a component. The actual component works fine when the number of connections is 1 or more, but does not work when no connections are made. Looking for input on how to resolve or workaround.

Here is the error:

enter image description here

Below is a MWE:

model RecordIssue
  record Record
    Real a=1;
  end Record;

  parameter Integer nPorts=0 annotation (Dialog(connectorSizing=true));

  Modelica.Fluid.Interfaces.FluidPorts_a ports_a[nPorts];

  // declare record array instance for each port connection
  parameter Record[nPorts] recordInstance={Record() for i in 1:nPorts};

  // this next line is an issue only when nPorts = 0 or no connections made
  Real test[:]=recordInstance[:].a;
end RecordIssue;

The expected/desired behavior would be for the variable test to not exist when nPorts=0, which is the normal behavior for something like Real test[:] = {1.0 for i in 1:nPorts};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的他你的她 2025-02-06 18:59:50

解决方法是确保记录变量永远不会空,并在nports为零时避免访问。

model RecordIssue
  record Record
    Real a=1;
  end Record;

  record Dummy
    extends Record(a=Modelica.Constants.inf);
  end Dummy;

  parameter Integer nPorts = 0 annotation (Dialog(connectorSizing=true));

  Modelica.Fluid.Interfaces.FluidPorts_a ports_a[nPorts];

  // declare record array and ensure that at least one exists
  parameter Record[max(nPorts, 1)] recordInstance = if nPorts > 0 then {Record() for i in 1:nPorts} else {Dummy()};
  
  // decide here if recordInstance shall be used
  Real test[nPorts] = if nPorts > 0 then recordInstance[:].a else fill(0, 0);
end RecordIssue;

A workaround would be to ensure that the record variable is never empty and avoid access when nPorts is zero.

model RecordIssue
  record Record
    Real a=1;
  end Record;

  record Dummy
    extends Record(a=Modelica.Constants.inf);
  end Dummy;

  parameter Integer nPorts = 0 annotation (Dialog(connectorSizing=true));

  Modelica.Fluid.Interfaces.FluidPorts_a ports_a[nPorts];

  // declare record array and ensure that at least one exists
  parameter Record[max(nPorts, 1)] recordInstance = if nPorts > 0 then {Record() for i in 1:nPorts} else {Dummy()};
  
  // decide here if recordInstance shall be used
  Real test[nPorts] = if nPorts > 0 then recordInstance[:].a else fill(0, 0);
end RecordIssue;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文