Jay_At_Play
Jay_At_Play

Reputation: 146

Teaching Modelica Medical Non-SI Units

I want to use non-SI units in a Modelica model in a medical context. I am using Modelica in Dymola. Being an engineer I prefer the SI units. But my model parameters are sourced from medical publications and I want to avoid conversion mistakes. Medical units also simplify communication with doctors.

For example, the unit "mmHg" (millimetres of mercury) is used instead of "Pa" for pressure. Pressure variables are defined in the model as follows:

type Pressure_mmHg = Real (final quantity="Pressure", final unit="mmHg")

Translating the model for simulation yields the following warning for every single non-SI variable in the model (~300 warnings in total):

Could not decode the unit symbol "mmHg" appearing in the unit string "mmHg"

If changes to the model cause a new warning it is near impossible to detect. Therefore I need to teach Modelica the unit "mmHg".

My current knowledge on the topic:
- Modelica Language Specification 3.3, Chapter 19 Unit Expressions: "It is possible to support user defined unit symbols." However the document does not elaborate on this.
- users may define display units (Real attribute "displayUnit") for use in the simulation GUI, as long as a conversion factor is defined in the "displayunit.mos" file in the Dymola directory as follows:

defineUnitConversion("Pa", "mmHg", 760/101325);

This is not an option because it diminishes portability of the model. It has to be performed manually on every computer that runs the model and requires administrator rights (which I don't have).

Thanks in advance for your help, it is much appreciated!

EDIT (might be helpful to anyone coming across this in the future):
Versions at time of posting: Modelica Standard Library 3.2, Dymola Version 2014 (64-bit) 2013-03-25

I forgot to add the following to my current knowledge on the topic: The Physiolibrary 2.1.1 defines displayUnits for the GUI. For coding, the authors use the following trick:

type Pressure =  Modelica.SIunits.Pressure(displayUnit="mmHg", nominal=133.322387415);

This way Modelica handles variables of type Pressure as having the unit Pascal (N/m2), but divides every value entered in code by the given nominal.

CORRECTION:
In this section, I previously stated that the Physiolibrary uses the Real attribute nominal for unit conversion. This is NOT the case. Thank you Marek Matejak (author of the Physiolibrary) for correcting me. The sole purpose of the attribute nominal is scaling of the numerical problem for stability reasons.

Upvotes: 7

Views: 1228

Answers (3)

Marek Matejak
Marek Matejak

Reputation: 31

Modelica Medical Non-SI (display) Units in Dymola:

  1. To have a suport for medical non-SI (display) units try to extend the Dymola file "C:\Program Files*\Dymola*\insert\displayunit.mos" such as https://github.com/MarekMatejak/Physiolibrary/blob/master/Physiolibrary/Resources/DisplayUnits/displayunit.mos

  2. definition of parameter or variable should have the attribute unit always set to SI unit and displayUnit can be everything what have defined conversion in Dymola file "displayunit.mos":

for example:

parameter Real systolicPressure(final unit="Pa", displayUnit="mmHg") = 16000;

parameter Real diastolicPressure(final unit="Pa", displayUnit="torr") = 10000;

Modelica will always calculate the models in SI units, but the parameter dialogs and output plots in Dymola will be in display units. So be carefull - every value in text code must be in SI unit.

Nominals are not directly connected with conversions.They are only for relative tolerances in numerical mathemathics behind.

If you find any mistake in Physiolibrary display units, please do not hesitate to report that. Thank you!

Upvotes: 3

kdavies4
kdavies4

Reputation: 178

@Jay_At_Play, you may want to take another look at the Modelica Trac site that @MichaelTiller shared. I just discussed an approach that may help. However, as a warning, is is nonstandard and not directly compatible with the Modelica Standard Library.

(I wanted to add this to the comments under the original question, but I don't have the reputation points.)

Upvotes: 4

Adrian Pop
Adrian Pop

Reputation: 4231

As far as I know there is no good way to do this in a portable way.

The Modelica specification does not say how to handle user defined units so each tool does it (or not) its own way.

The best way I think is to do as you did by defining types in your model or library even if you have warnings in some tools.

In Dymola you might get rid of the warnings via:

Advanced.CheckUnits = false

in the command window.

Upvotes: 3

Related Questions