Menu

Unit Conversion

2017-10-13
2017-10-21
  • Carl Schneiders

    Carl Schneiders - 2017-10-13

    Hello!
    I was wondering if anyone could tell me whether MasterSim supports unit conversion when a BaseUnit and DisplayUnits are stated for a variable in the modelDescription.xml of an FMU. I tried to test this using this code in the modelDescription:

    <UnitDefinitions>
        <Unit name="m">
            <BaseUnit m="1" />
            <DisplayUnit name="2m" factor= "2"/>
            <DisplayUnit name="1m" factor= "1"/>
        </Unit>
    </UnitDefinitions>
    

    .
    .
    .

    <!-- Index of variable = "7" -->
        <ScalarVariable
            name="y"
            valueReference="6"
            description="Current Distance"
            variability="continuous"
            causality="output"
            initial="exact">
            <Real start="0.0" unit="m" displayUnit="2m"/>
        </ScalarVariable>
    

    MasterSimulator recognizes the unit "m" since it names the output file appropriately. But it does not matter whether I set the displayUnit of the variable to "1m" or "2m", the resulting values do not change, which I would expect. It might of course also be that there is an error in my code or that there is another way for MasterSim to recognize units.
    Thanks for any ideas!

     
  • Andreas Nicolai

    Andreas Nicolai - 2017-10-16

    Unit conversion is not handled by MasterSim. That means:

    • unit attribute of ScalarVariable specifies the base unit, which shall be used for any input/output quantities set/read by the master
    • in the MasterSim output files, the base unit is used in the table caption, thus postprocessing has to do the conversion between, for example, from K to degC

    To my knowledge the FMI standard expects DisplayUnit property as something for user interfaces; start attribute is expected to have a value of the baseunit.

    Suggestion/workaround:

    as part of the postprocessing, you could use a simply python script that reads in the CSV-files generated by MasterSim using pandas, scaling/transforming values and dumping data out again.

     

    Last edit: Andreas Nicolai 2017-11-21
    • Carl Schneiders

      Carl Schneiders - 2017-10-21

      Thank you very much! Yes, the workaround with the python script will probably be the way to go for me.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.