Opened 3 years ago

Last modified 3 years ago

#6345 reopened defect

displayUnit of inverse time "d-1", "h-1", ''min-1" not working

Reported by: pierre.haessig@… Owned by: sjoelund.se
Priority: normal Milestone:
Component: OMEdit Version: 1.16.2
Keywords: Cc:

Description

Dear OM devs,

With OM 1.16.2, I can't get variables representing a rate in per second ("s-1") to display as per day, per hour or per minute (i.e. unit="s-1" and displayUnit="d-1" or "h-1", "min-1"). See example model attached.

I've checked that the displayUnit="d" for a time works. For a rate, displayUnit="ks-1" (per 1000 seconds) also works fine, i.e. displays the value multiplied by 1000. So the problem does not concerns the conversion of all units with a -1 exponent.

I've found the implementation of the "day" unit was discussed in issue #2250 (https://trac.openmodelica.org/OpenModelica/ticket/2250#comment:27) and is visible in the code at https://github.com/OpenModelica/OpenModelica/blob/master/OMCompiler/Compiler/runtime/unitparser.cpp#L1152.

About the application: I gave students a modeling project about SIR epidemy models. Quite fashionable these days! I think infection rates are often given per day.

Best,
Pierre

Attachments (1)

timeUnitDay.mo (555 bytes) - added by pierre.haessig@… 3 years ago.
model to test displayUnit="d-1"

Download all attachments as: .zip

Change History (13)

Changed 3 years ago by pierre.haessig@…

model to test displayUnit="d-1"

comment:1 Changed 3 years ago by pierre.haessig@…

Further digging into the problem: displayUnit="1/d" does work ("1/ks" as well). So there is some specific interaction between the day/hour/minute unit and the "-1" unit exponent.

comment:2 Changed 3 years ago by sjoelund.se

>>> convertUnits("s-1", "d-1")
(false,86400.0,0.0)
>>> convertUnits("s-1", "1/d")
(true,1.157407407407407e-05,0.0)
>>> getDerivedUnits("1/s")
{"Bq","Hz","rpm"}
>>> getDerivedUnits("1/d")
{"Bq","Hz","rpm"}

So there is indeed something fishy going on with that conversion...

comment:3 Changed 3 years ago by casella

  • Component changed from *unknown* to OMEdit
  • Owner changed from somebody to adeas31
  • Status changed from new to assigned

I'll assign this to @adeas31

Adeel, feel free to reassing it if there is a dependency of OMEdit on some other module that you cannot fix.

comment:4 Changed 3 years ago by sjoelund.se

s-1 has unit s-1
d-1 has unit s
s has unit s
d has unit s

This seems... wrong

Last edited 3 years ago by sjoelund.se (previous) (diff)

comment:5 Changed 3 years ago by sjoelund.se

So, the error is that Unit::pow gives an error if the scale factor is not 1 when you try to add an exponent. And this is silently ignored.

The actual thing that should happen is that the scale factor should also be affected by this operation as far as I can tell.

This seems to only be supported for prefixExpo (Exponent value for the prefix. E.g. if [mm] is defined, it is 10^-3*[m], e.g. prefixExpo = -3), but not (Scalar factor including both SI prefix and unit scalar factors (e.g. feet -> meter)).

comment:6 follow-up: Changed 3 years ago by sjoelund.se

So... The problem is this is all using rational factors, and pow was never implemented. They even added an error code for this, instead of fixing the problem :)

comment:7 in reply to: ↑ 6 Changed 3 years ago by casella

Replying to sjoelund.se:

They even added an error code for this, instead of fixing the problem :)

Who was "they"?

comment:8 Changed 3 years ago by sjoelund.se

  • Owner changed from adeas31 to sjoelund.se

comment:9 Changed 3 years ago by sjoelund.se

  • Milestone changed from NeedsInput to 1.17.0
  • Resolution set to fixed
  • Status changed from assigned to closed

comment:10 Changed 3 years ago by casella

  • Resolution fixed deleted
  • Status changed from closed to reopened

@sjoelund.se, PR 7132 is already on 1.18.0-dev, would you mind pushing it also to 1.17.0 maintenance?

comment:11 Changed 3 years ago by casella

  • Milestone changed from 1.17.0 to 1.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:12 Changed 3 years ago by casella

  • Milestone 1.18.0 deleted

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.