Insert Dynamic Expressions and Dynamic Single Variables and Parameters in Text
Areas
You can insert dynamic expressons in text areas. You can also insert dynamic single
variables and parameters.
-
In a cockpit, from the Cockpit section of the action bar,
click Create Text Area
.
-
To activate the text area, click it.
A toolbar appears, with common text creating options, including PDF file
creation, and adding of links, images, tables, and expressions.
-
To display dynamic single variables or parameters, you can reference them by adding a
% character before the variable or parameter name.
An example is to enter current = %R2.i.
When you run the simulation, the reference is replaced by the value of the
variable or parameter, including the unit, for example current = 0.5764
A.
-
To insert dynamic expressions, from the toolbar, select Insert Expression
F(x). You can select any of:
| Expression Name |
Expression in Text |
Example |
| FinalValue |
%(FinalValue(%variable)) |
%(FinalValue(%tank1.level)) |
| Min |
%(Min(%variable,minTime,MaxTime)) |
%(Min(%tank1.level,1,100)) |
| Max |
%(Max(%variable,minTime,MaxTime)) |
%(Max(%tank1.level)) |
| AritmeticMean |
%(AritmeticMean(%variable,minTime,MaxTime)) |
%(AritmeticMean(%tank1.level,MaxTime=50)) |
| LesserThan |
%(LesserThan(%variable,variable2, 1, 0)) |
For example and additional information, see Comparing Variable and Parameter Values in Text Areas
below. |
| GreaterThan |
%(GreaterThan(%variable,variable2, 1, 0)) |
For example and additional information, see Comparing Variable and Parameter Values in Text Areas
below. |
Notes:
- You can also enter dynamic directly, without using the Insert
Expression F(x) command.
- If you pause over a dynamic expression in the toolbar, a tooltip displays the
text that appears if you select this alternative.
- The default values for
minTime and maxTime are
the start time and stop time of the simulation.
- You can combine values using the arithmetic operators +, -, *, and /.
- The value is always returned as a number in MKS units, without any unit
suffix.
- You can specify the number of decimals shown for the resulting value. You do
that by adding an argument
decimals=n to the expression, after a
comma separator (where "n" is the wanted number). An example:
%(FinalValue(%tank1.level),decimals=2).
Apply Dynamic Color to Dynamic Expression Texts
You can apply dynamic color to dynamic expressions, that is, you can let the value
of dynamic expressions change color depending on the values of the displayed
variables.
You do this by adding, for any dynamic expression %(...), the optional
argument color. The syntax is:
%(..., color="<html color 1> <value 1> <html color 2> <value 2> ...
<html color n>")
The below scenario illustrates an example with three colors.
Before you begin: To have some variables to work with, do the following:
- Create a study template for the model
Modelica.Blocks.Examples.PID_Controller from the Modelica Standard
Library.
- Create a cockpit in this study template, and add a text area.
-
From the parameters of inertia 1, drop
phi in the text area.
The line inertia1.phi: %inertia1.phi appears in the text
area. This line is for comparing with the line created in the next step.
-
Repeat the previous step, but this time, enhance the resulting line to:
inertia1.phi value (red until 0.5, then blue until 1.5, then green):
%(%inertia1.phi, color="#FF0000 0.5 #0000FF 1.5 #00FF00")
-
Simulate and play the animation to see the result.
The color of the value in the second line changes color according to the color
argument. Note:
Another way to state the color selection, as a description, for clarity:
- If inertia1.phi < 0.5, display the color #FF0000 (red)
- If 0.5 <= inertia1.phi < 1.5, display the color #0000FF (blue)
- Otherwise, display the last color #00FF00 (green)
Comparing Variable and Parameter Values in Text Areas
You can compare variable and parameter values in text areas using the functions
LesserThan and GreaterThan. Below you use a
comparison to switch between two static texts, as an example. For detailed information about
LesserThan and GreaterThan, see the note in
the result of the last step below.
Before you begin: To have some variables to work with, do the following:
- Create a study template for the model
Modelica.Blocks.Examples.PID_Controller from the Modelica Standard
Library.
- Create a cockpit in this study template, and add a text area.
-
From the parameters of inertia 1, drop
phi in the text area.
The line inertia1.phi: %inertia1.phi appears in the text
area. This line is for comparing with the lines created in the next step.
-
Enter the below lines for studying comparison:
inertia1.phi value (red until 0.5, then blue until 1.5, then green):
%(%inertia1.phi, color="#FF0000 0.5 #0000FF 1.5 #00FF00")
Is inertia1.phi lesser than 0.5? %(LesserThan(%inertia1.phi, 0.5, "Yes", "No"))
Is inertia1.phi greater than 1.5? %(GreaterThan(%inertia1.phi, 1.5, "Yes", "No"))
-
Simulate and play the animation to see the result.
An example of the result (with the value of intertia1.phi at the time 1 s and
dynamic text values indicated by bold) is: inertia1.phi:
0.122 rad Is inertia1.phi greater lesser than 0.5?
Yes Is inertia1.phi greater than 1.5?
No The Yes and
No corresponds to the value of inertia1.phi. Note:
To fully use
LesserThan and GreaterThan, the
detailed description is:
- LesserThan can be described
as:
LesserThan(variable1, variable2 [, value_true,
value_false]) where:
- variable1 and variable2 are
compared. They can be result variables (like %tank1.level) or numerical
values.
- value_true and value_false
are optional arguments. They can be of type string, integer, or real.
- The behavior of LesserThan with optional arguments is:
- If variable1 <
variable2 then
value_true is returned. If
value_true is not specified, the value
1 is returned.
- If variable1 = or >
variable2 then
value_false is returned. If
value_false is not specified, the value
0 is returned.
- GreaterThan can be described
as:
GreaterThan(variable1, variable2 [, value_true,
value_false]) where:
- variable1 and variable2 are
compared. They can be result variables (like %tank1.level) or numerical
values.
- value_true and value_false
are optional arguments. They can be of type string, integer, or real.
- The behavior of GreaterThan with optional arguments is:
- If variable1 > variable2
then value_true is returned. If
value_true is not specified, the value
1 is returned.
- If variable1 = or <
variable2 then
value_false is returned. If
value_false is not specified, the value
0 is returned.
|