Managing Display Units and Units

The Dymola Behavior Modeling app automatically converts the usual units to be displayed. For most cases, this is sufficient. However, if you are an expert user, you can define user-defined units and work with them.

This task shows you how to:

Manage Predefined Unit Types

Unit types that are declared in the Modelica Standard Library (in the SIunits package) are automatically converted into display units.

Whenever you use classes from this package, or extend from them, you take advantage of this automatic conversion.

These units are managed from Me > Preferences > App Preferences > 3D Modeling > Multi Discipline Automated Engineering > Knowledge Basics, the Units tab.

Manage User-defined Unit Types

You can manage user-defined unit types. You need to do this if you have not imported the Modelica Standard Library, or if you work with a library using a type that is not defined in the SIunits package.

You manage a user-defined unit type by two steps, detailed below. You first create a class defining the unit type, then you define display units for that type by defining conversion factors. You must also select a default display unit.

You can also import unit conversions and default display units from a file.

Important: It is recommended to use predefined units whenever possible, since all Modelica standard and commercial libraries use those units.

Declare the User-defined Unit Type

You can define user-defined unit type.

This scenario shows how to define, in your library, a class with a Type class type and a basic type extends (Real, for example).

The following Modelica code defines such a type (in this example, the 'bar' unit is chosen as unit):

 type MyPressure = Real (unit="bar");

Before you begin: Open the library where the class is to be used, for example MyUnitLib.
  1. From the Behavior Authoring section of the action bar, click Modelica Editor .
    The Modelica Editor dialog box appears.
  2. In the Modelica Editor dialog box, enter the code line:

     type MyPressure = Real (unit="bar");

  3. Click OK.

    In most other cases you can use the command New Modelica Class to create a new type, but in this case you can use the Modelica Editor to get a simpler code structure.

A user-defined unit type MyPressure with the unit "bar" is created.

Define Unit Conversions and Select Default Display Units

For a user-defined unit, you must define any corresponding display unit by defining a conversion factor.

Such units are managed from Me > Preferences > App Preferences > 3D Modeling > Systems Modeling and Execution > Dymola Behavior Modeling , the Authoring tab, Customized Units section.

Notes:
  • You can define unit conversions for units not yet defined as types.
  • You can import unit conversions and the default display unit from a file to work with, see Step 8 below.

Before you begin: For each unit you want to use, a corresponding type must be defined, see Declare the User-defined Unit Type above.
  1. Open the Me > Preferences > Systems > Behavior Modeling > Authoring tab.
  2. To add a unit in the conversion table:
    1. Click <Add unit> in the conversion table.
      The field is editable.
    2. Enter the exact name of the unit, as declared in the Modelica class (for example bar).
    3. Press Enter.
      The unit to be converted is added to the conversion table.
  3. To create a display unit for this unit:

    You can create several display units for the same unit.

    1. In the Conversion table, select this unit.
    2. In the Display Unit Management area, click Create Display Unit to create an empty line to edit.
    3. In the first field, enter the name of the display unit (for example Pa).
    4. Enter the conversion factor and offset.
    5. Click Apply.
      The result is:
      • The new display unit is added in the display unit value list.
      • The new display unit is selected as the default display unit in the column Display Unit.
  4. To edit a display unit:
    1. Select an existing display unit from the display unit value list.
    2. Modify the conversion factor and offset.
    3. Click Apply.
  5. To remove a display unit:
    1. Select a unit in the conversion table.
    2. From the display unit value list, select a display unit.
    3. Click Remove.
      The display unit is removed for this unit.
  6. To remove a unit with all its display units:
    1. Select a unit in the conversion table.
    2. From the display unit value list, select the No conversion display unit.
    3. Click Remove.
      The display unit is removed for this unit.
  7. To select a display unit as the default display unit, select it in the display unit value list for the corresponding unit.
    The display unit is selected as the default display unit in the Display Unit column.
  8. To import unit conversions and default display units from a file, do the following:

    Note: You cannot undo this action by clicking Cancel in the Preferences dialog box.

    1. Click Import Units.
      The Select a Modelica script file dialog box appears.
    2. Browse for the required file and click Open.
      The unit conversions and the default display units are imported from the file.
    The unit conversions and default units appear in the Conversion table.
    Notes:
    • If you import for example displayUnit.mos from the stand-alone application Dymola, you get numerous unit conversions and default display units, but most correspond to SI units. It is recommended not to use those, but use the predefined units instead. See Manage Predefined Unit Types above.
    • You cannot run a file as a script to import the content.
    • There is no link between the file and the imported content, any changes in the file afterward are not imported automatically.
    • Existing conversion rules are not removed when importing. However, in case of conflict between the imported content and the current content, the existing rules are replaced with the definitions from the file.
  9. Click OK.