Search code examples
modelicadymola

How to set the DynamicSelect expression in Modelica models


I plan to show a variable's quantity in a text string, so I checked the usage of DynamicSelect expression in Modelica Specification, as shown below:

enter image description here

Here is an example I make, it only contains one Modelica.Blocks.Sources.Sine component and a text label, but I am not sure why the text doesn't change during the simulation. It seems like the DynamicSelect expression doesn't work at all.
My question is:
How should I set the DynamicSelect expression to make it work?

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;

enter image description here


Solution

    • Please use String() for conversion of numeric values to string.
    • Browse the Modelica Standard Library which uses DynamicSelect in various places.
    • Here is an improved example for Modelica Standard Library version 4 with slowed down simulation:
    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;