尝试编译Dymola中零尺寸的记录变量时的错误
我正在创建一系列记录,取决于组件中的端口连接数量。当连接数为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:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方法是确保记录变量永远不会空,并在
nports
为零时避免访问。A workaround would be to ensure that the record variable is never empty and avoid access when
nPorts
is zero.