Skip to content
Last updated

Unit handling

In order to better align with Petromod unit handling, units in the Open Simulator (for example, pmpy.Overlay.unit) are now pmpy.Unit objects, rather than simple strings. When specifying units (for a new overlay, for example) it is still possible to use a string, but it is recommended that pmpy.Unit objects are used instead.

For example, instead of assigning: my_new_overlay.unit = "Kelvin"

Use: my_new_overlay.unit = pmpy.Unit("Kelvin", pmpy.UnitGroup.Temperature)

Because Petromod distinguishes units by their context (for example: temperature versus temperature difference, pressure versus capillary pressure, and so on), the second form is safer. This is because there is no chance of unintentionally assigning the Kelvin unit in the TemperatureDifference group, and then having the Petromod viewers display your overlay as if it were a temperature difference.

For a list of unit groups enter help(pmpy.UnitGroup) in the python interpreter. Similarly, enter help(pmpy.Unit) to see a list of defined Petromod (PM) and SI units. In this instance, pmpy.Unit.SITemperature could be used instead of pmpy.Unit("Kelvin", pmpy.UnitGroup.Temperature) for example.

Note: A pmpy.Unit is not a string, therefore it may be necessary to explicitly convert it to one in some contexts (for example: when your script writes messages to the console).

If “u” was a pmpy.Unit this could be done using:

str(u)

Or equivalently, by referring to the string:

u.name

Parent topic:Get started