如何在 Modelica 模型中设置 DynamicSelect 表达式

How to set the DynamicSelect expression in Modelica models

我打算在文本字符串中显示一个变量的数量,所以我检查了Modelica Specification中DynamicSelect表达式的用法,如下所示:

这是我做的一个例子,它只包含一个Modelica.Blocks.Sources.Sine组件和一个文本标签,但我不确定为什么文本在模拟过程中没有变化。 DynamicSelect 表达式似乎根本不起作用。
我的问题是:
我应该如何设置 DynamicSelect 表达式以使其工作?

model fsdaf

  Modelica.Blocks.Sources.Sine sine(amplitude=100, freqHz=1)
    annotation (Placement(transformation(extent={{-124,-10},{-104,10}})));
equation 

  annotation (Diagram(graphics={
          Text(
          extent={{-22,60},{98,10}},
          lineColor={28,108,200},
          fillColor={238,46,47},
          fillPattern=FillPattern.None,
          textString=DynamicSelect(10,string(sine.y)))}),
          uses(Modelica(version="3.2.3")));
end fsdaf;

  • 请使用 String() 将数值转换为字符串。
  • 浏览 Modelica Standard Library 在各个地方使用 DynamicSelect。
  • 这里是 Modelica 标准库版本 4 的一个改进示例,它的仿真速度变慢了:
model TestDynamicSelect
  Modelica.Blocks.Sources.Sine sine(amplitude=100, f=1) annotation(Placement(transformation(extent={{-80,40},{-60,60}})));
  Modelica_DeviceDrivers.Blocks.OperatingSystem.RealtimeSynchronize realtimeSynchronize annotation(Placement(transformation(extent={{-80,0},{-60,20}})));
  annotation(experiment(StopTime=10), Diagram(graphics={
   Text(
     extent={{-22,60},{98,10}},
     lineColor={28,108,200},
     fillColor={238,46,47},
     fillPattern=FillPattern.None,
     textString=DynamicSelect(10,String(sine.y)))}),
   uses(Modelica(version="4.0.0"), Modelica_DeviceDrivers(version="2.0.0")));
end TestDynamicSelect;