Displaying parameter in annotation in DYMOLA
Asked Answered
U

1

5

I have a simulation model using different components. In order to get a quick overview of the used parameters I use the functionality of annotations to display certain model parameters (e.g. m_flow_nominal) via:

textString="Nominal Flow Rate = %m_flow_nominal"

in the annotation dialog. Which will give out something like

Nominal Flow Rate = 5

This is working perfectly fine for parameters that are integers.


I also have a parameter that is calculated from other values. Like, let's say the Volume of a body. When I try to display this parameters via:

textString="Volume = %volume"

Instead of the final value I will be given the formula the volume is calculated with. For example

Volume = a * b * c

How can I display the final value of the volume in this case, instead of the formula?


Here is the actual problem:

  parameter Modelica.SIunits.Length xBorFie = 10 "Borefield length";
  parameter Modelica.SIunits.Length yBorFie = 30 "Borefield width";
  parameter Modelica.SIunits.Length dBorHol = 5 "Distance between two boreholes";

  parameter Integer nXBorHol = integer((xBorFie+dBorHol)/dBorHol) "Number of boreholes in x-direction";
  parameter Integer nYBorHol = integer((yBorFie+dBorHol)/dBorHol) "Number of boreholes in y-direction";
  final parameter Integer nBorHol = nXBorHol*nYBorHol "Number of boreholes";

When using

textString="Number of boreholes = %nBorHol"

I get

Number of boreholes = nXBorHol*nYBorHol

Underwear answered 2/10, 2018 at 12:23 Comment(0)
M
7

I think the only possibility is to use the DynamicSelect() function. This can be used to show a changing value within e.g. an icon. To use it you will have to manually adapt the Icon annotation. It is documented in the Modelica Language Specification 3.4, Section 18.6.6.

Some good examples of how this DynamicSelect() can be used are:

  • Modelica.Blocks.Interaction.Show.RealValue shows how to display a value
  • Modelica.Blocks.Interfaces.partialBooleanSO shows how to change line- and fill colors of icons
  • Modelica.StateGraph.Examples.Utilities.Tank shows how to change the size of a rectangle to display the level within a tank

The disadvantage of DynamicSelect() is that it will sometimes need to initialize/simulate the model before showing a value (I think if it is not computed from literals or parameters). The advantage is that they are updated during the simulation when looking at the model.

For your case the implementation of the icon could look like:

    annotation (Icon(graphics={Text(
      extent={{-100,-20},{100,20}},
      lineColor={0,0,0},
      textString="NoB=" + DynamicSelect("?", String(nBorHol)))}));

which results in the icon showing

NoB=21

For me it also immediately adapts when changing one of the respective parameters.

Maculate answered 2/10, 2018 at 12:45 Comment(4)
In deed the parameter consists of other calculated parameters. Trying the Modelica.Blocks.Interaction.Show.RealValue actually returns the value, but only after I started the simulation. I guess there is no "online" solution?Underwear
The value I want to display is pretty much concatenated. There are 3-4 calculations made beforehand.Underwear
I updated the question with the actual code I am using, to show the problem. Am I just missing something?Underwear
You are right, it then only shows the string that is used to compute the final parameter. I'll edit my answer and delete the misleading comments...Maculate

© 2022 - 2024 — McMap. All rights reserved.