User-defined input dialogs in Dymola

Written by: Maura Gallarotti – Fluids Modelling Engineer

In this blog post we will go through the available options in Dymola to build user-defined input dialogs. In Dymola the user can edit the parameter dialogs adding tabs, groups, alternative forms of input fields such as combo boxes, radio buttons and many others.

1. Definition of a new parameter:

A new parameter can be defined by directly declaring it in the text layer or by using the New Variable dialog, that can be accessed in the text layer: right click -> Variables-> New Variables (or Ctrl + N).

The New Variable dialog can be very convenient to organise the GUI, however, it doesn’t contain all the possible options that can be defined in the text layer. We will give an overview of the two parameter defining and organising methods (which can be combined) in this post.

Figure 1: New Variable Dialog.

Let’s start by creating a new parameter using the New Variable dialog:

  • Create a package GUITutorial (File->New->Package or or Ctrl+Shift+P)
  • Create a new model MyModel (right click on GUITutorial->New->Model or Ctrl+Shift+M )
  • Open the New Variable tab from the text layer (Ctrl + N)
  • In the Declaration tab, set the type to parameter Modelica.SIunits.Length. Name it length and set the default value to 1 m. In the description write: Pipe length. In the Annotations tab write in Tab: Pipe and in Group: Geometry.

Now let’s change the unit displayed in the parameter dialog. In the Diagram layer: right click-> parameters-> Pipe tab. Click on the unit and change it to mm. This will modify the text in the text layer as follows:

parameter Modelica.SIunits.Length length(displayUnit=”mm”) = 1 ” Pipe length”

    annotation (Dialog(tab=”Pipe”, group=”Geometry”));

One can decide to show only the description in the GUI and not the actual parameter name, using the setting __Dymola_descriptionLabel =true as follows:

  parameter Modelica.SIunits.Length length(displayUnit=”mm”) = 1 “Pipe length” 

    annotation (Dialog(

      tab=”Pipe”,

      group=”Geometry”,

      __Dymola_descriptionLabel=true));

Figure 2: Use of the setting __Dymola_descriptionLabel=true.

Let’s create another parameter diameter, this time using the text layer directly:

  parameter Modelica.SIunits.Length diameter(displayUnit=”mm”) = 0.1 

    “Pipe diameter” annotation (Dialog(

      tab=”Pipe”,

      group=”Geometry”,

      __Dymola_descriptionLabel=true));

One can have the two parameters diameter and length in the same line using the setting __Dymola_joinNext=true in the annotation of the first parameter:

Figure 3: Use of the setting __Dymola_joinNext=true.

 2. Using records in the input dialog:

Let’s create a record to be used in the parameter dialog. In this example, we will create a record to allow the user to specify the characteristic curves for a pump for different pump speeds:

  • Create a new record in the package GUITutorial (Right click in the package -> New-> Record)
  • Define a parameter speed  and a table m_flowPressureRatioEfficiency containing values of mass flow rate, pressure ratio and efficiency

  parameter Modelica.SIunits.AngularVelocity speed=100 “Speed (rad/s)”;

 

  parameter Real m_flowPressureRatioEfficiency[:, :]=[0.01, 1.2, 0.5; 0.02, 1.3, 0.6; 0.03, 1.8, 0.7] “m_flow, pressure ratio, efficiency”;

Then, drag and drop the record in the model MyModel and call it pumpData. Define the size to be a vector, in order to be able to input different characteristics for different speeds. Define also a new tab called Pump using the annotation tab (in the text layer: right click-> variables-> pumpData) or by writing the required syntax directly into the text layer by hand:

parameter GUITutorial.PumpData pumpCharacteristics[:]={GUITutorial.PumpData(),  GUITutorial.PumpData()} annotation (Dialog(tab=”Pump”));

Figure 4: Data record in the parameter dialog.

 

3. Combo boxes and radio buttons:

Comboboxes and radiobuttons can be used to define a set of different choices in the dialog. Figure 5 shows an example using a combobox and a radio button.

4. Checkboxes:

In case there are only two options, a checkbox can be more convenient to use (lower example in figure 5):

Figure 5: Use of combo boxes, radio buttons and check boxes.

 

5. Defining the initial conditions

The New Variable window can also be used for the initialisation of variables. In MyModel, press Ctrl+N in the text layer and define a new variable pressureDrop with unit Modelica.SIunits.PressureDifference, default value 0.1 bar. In the Annotations tab, set the tab to Pipe and tick the options Show start. This will generate the parameter pressureDrop.start in the dialog box:

Figure 6: Use of the Show start option.

 

6. Illustrations in the parameter dialog box:

To make it easier to understand what the input data physically refers to, it’s possible to include a picture or diagram within a Group:

Figure 7: Use of pictures in the dialog.

 

7. HTML formatting

It is possible to include HTML formatting in labels and descriptions by including the text string in <html> … </html>.

As an example, let’s create a parameter alpha using the greek alphabet and some html tags:

parameter Modelica.SIunits.alpha alpha “<html><font face=\”Courier New, Courier,

  monospace\”>angle</font>  &alpha; <font size=\”+2\”>can be written</font> <font color=\”#ff0000\”>using</font> <font face=\”Blackadder ITC, 

  monospace\” font size=\”+2\”>greek </font> </font> <font face=\”Bauhaus 93, 

  monospace\” font size=\”+2\”> letters </font> </html>”

    annotation (Dialog(__Dymola_label=“<html>&alpha;</html>“));

Figure 8: Use of html tags and different font types in labels and descriptions.

 

The  package GUITutorial containing the code described in this blog post can be downloaded from here.

 

NB: these blog post examples use Dymola 2018

 

References:

Dymola User Manual Volume 2, Dymola 2018.

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2017 Claytex Services Ltd All Rights Reserved. | Designed by CMA Marketing

Log in with your credentials

Forgot your details?