Search code examples
modelicadymola

How to add unit conversions using Dymola


In Modelica Standard Library, the unit of SpecificEnergy and SpecificEnthalpy is "J/kg", but I'd like to use "kJ/kg" as the display unit, my first thought is to modify the Modelica Standard Library, but I am not sure if it will cause unexpectable issues, so I want to find a way to customize my own Modelica Standard Library. In this way, I could choose to use my own version or the standard one.

My question is: Is there some way like this?

enter image description here enter image description here


Solution

  • There are multiple possibilities to extend the unit conversions in Dymola. Probably the best is the one for the question asked is mentioned by Hans Olsson below, but you can as well

    1. Create a function like this:

    function unitConversions "Define unit conversions, which are currently not pre-defined by Dymola"
      extends DymolaModels.Icons.Basic.Function;
    
    algorithm 
    
      defineUnitConversion("J/kg", "kJ/kg", 1e-3);
      // more conversions could be added here
    
    end unitConversions;
    

    After the function is executed, the conversion should be available for the current session of Dymola. So you need to run the function manually every time Dymola is started. This is actually one reason I asked this question - but there seems to be no answer until now.

    1. As an alternative, you can modify E:\[Dymola_InstallPath]\insert\displayunit.mos and add the same line. This will be usable until you install a new version of Dymola, for which you will have to do the same modification...