Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 741
Jay_At_Play Avatar asked Jul 16 '14 08:07

Jay_At_Play


1 Answers

@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.)

like image 90
kdavies4 Avatar answered Sep 28 '22 01:09

kdavies4