Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

dymola - 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

question from:https://stackoverflow.com/questions/65853621/how-to-set-the-dynamicselect-expression-in-modelica-models

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • 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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...