问题
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
回答1:
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 valueModelica.Blocks.Interfaces.partialBooleanSO
shows how to change line- and fill colors of iconsModelica.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.
来源:https://stackoverflow.com/questions/52608262/displaying-parameter-in-annotation-in-dymola