Despite SI units being the recognized scientific standard, other units and unit systems are widely used to this day. Even within the metric unit scheme there are often more typical units which are preferred to match a user’s model type or preference.
In addition to common alternate metric units such as centimetres or millimetres, there are other complete systems such as the Imperial standard which is still widely used in the United States.
Personal experience and developed intuition are extremely helpful in model development / debugging. This intuition (especially for many US based users) is often deeply rooted in a system other than SI.
Dymola users are encouraged to use whatever display unit system they wish. Dymola supports this with inbuilt functions enabling the user to define display unit conversions; it even provides pre-defined schemes to help make this task easier.
It should be noted that Dymola undertakes all calculations in the base unit (generally SI), and what we are discussing in this blog post is how to set up alternative conversions for the display unit.
Existing display unit conversions
Included in the Dymola installation, there are two supplemental pre-defined sets of unit conversions. These conversions are contained in two files:
- Program Files\Dymola 2021x\insert\displayunit.mos
- Program Files\Dymola 2021x\insert\displayunit_us.mos
The first file, displayunit.mos defines some common conversions between the SI unit and various non-standard metric units.
The latter file is similar in nature but contains various conversions from SI to Imperial units. Neither, one, or both of these script files can be executed by Dymola at start-up.
Editing/creating the start-up script
As explained in an earlier blog post, execution of script files can be automatically triggered by Dymola at startup via modification of the dymola.mos file.
By default, neither of the previously discussed display unit scripts are executed as their lines are commented in the dymola.mos file.
If a user wishes to add the unit conversions contained in one of these files during Dymola startup, all they need to do is remove the comment character (//) at the beginning of these lines in the dymola.mos file.
The user can also open these two display unit script files in a text editor to gain some understanding as to how alternative units may be implemented. Viewing these files in a text editor will also allow the user to determine the alternative units that are created in these files. Users can then add their own units or set default display units by either editing the existing display unit scripts directly or creating a new script similar to these which can then be executed on startup by the dymola.mos file.
Within the script there are two key commands that are used. The first command defines the numerical conversion between an existing SI unit and a new unit:
defineUnitConversion(unit, derived unit , scale, optional offset);
This command teaches Dymola a “new” unit as an optional conversion to be used in Dymola dialog boxes or plots. In this command, both the unit and derived unit are string variables. The unit defines the existing unit to be converted, with derived unit specifying the new unit name. Scale defines a multiplier to be applied to the original unit. The optional offset variable allows the user to add or subtract a value to achieve their desired conversion (Note: there are some caveats to the behavior of the optional offset which are explained in the Dymola User Manual 1B starting on page 238).
The second command will define the default display unit:
defineDefaultDisplayUnit(unit, derived unit);
Once again both unit and derived unit are string variables. By using this command, Dymola’s default display unit for variables of this type will be set to the one specified in the command.
Adding a third argument, true, will force Dymola to use the defined display unit conversion for not only parameter dialog windows, but also for plots:
defineDefaultDisplayUnit(unit, derived unit, true);
Defining your own display units for use in Dymola is a relatively simple task, and Dymola is built to support the use of alternative units for display purposes. Hopefully this blog post enables you to adapt Dymola’s display units to more closely align with your intuition. For additional information please see the Dymola User Manual 1B page 238.
Nate Horn – Vice President
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.