Title: calculate_unit_scale applies SI prefix linearly for SQUARE_METRE/CUBIC_METRE (DECI CUBIC_METRE = litre → volumes ×100) · Issue #9278 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: calculate_unit_scale applies SI prefix linearly for SQUARE_METRE/CUBIC_METRE (DECI CUBIC_METRE = litre → volumes ×100) · Issue #9278 · IfcOpenShell/IfcOpenShell
X Title: calculate_unit_scale applies SI prefix linearly for SQUARE_METRE/CUBIC_METRE (DECI CUBIC_METRE = litre → volumes ×100) · Issue #9278 · IfcOpenShell/IfcOpenShell
Description: Bug Description ifcopenshell.util.unit.calculate_unit_scale(model, unit_type) applies the SI prefix linearly, ignoring that for SQUARE_METRE / CUBIC_METRE the prefix attaches to the metre and is therefore raised to the power of the dimen...
Open Graph Description: Bug Description ifcopenshell.util.unit.calculate_unit_scale(model, unit_type) applies the SI prefix linearly, ignoring that for SQUARE_METRE / CUBIC_METRE the prefix attaches to the metre and is th...
X Description: Bug Description ifcopenshell.util.unit.calculate_unit_scale(model, unit_type) applies the SI prefix linearly, ignoring that for SQUARE_METRE / CUBIC_METRE the prefix attaches to the metre and is th...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9278
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"calculate_unit_scale applies SI prefix linearly for SQUARE_METRE/CUBIC_METRE (DECI CUBIC_METRE = litre → volumes ×100)","articleBody":"### Bug Description\n\n`ifcopenshell.util.unit.calculate_unit_scale(model, unit_type)` applies the SI prefix\n**linearly**, ignoring that for `SQUARE_METRE` / `CUBIC_METRE` the prefix attaches to the\n*metre* and is therefore raised to the power of the dimension.\n\nFor `IFCSIUNIT(*,.VOLUMEUNIT.,.DECI.,.CUBIC_METRE.);` — a cubic decimetre, i.e. a **litre**,\nwhich real-world MEP exports declare as the project volume unit — it returns `0.1` instead of\n`0.1**3 = 0.001`, so every volume read through this scale factor is inflated **×100**.\n`AREAUNIT` is affected the same way (the error factor is 1/prefix: ×10 for DECI, ×100 for CENTI).\n\nIn SI, a prefix attached to a unit symbol forms a new inseparable symbol which is raised to\nthe power as a whole: dm³ means (dm)³ = 10⁻³ m³, not 0.1 m³. There is no SI construct meaning\n\"0.1 m³\", so the linear interpretation maps `DECI CUBIC_METRE` to a unit that does not exist.\n\nThe rest of `util/unit.py` already follows the exponent interpretation, so the module is\ninternally inconsistent:\n\n- `named_dimensions[\"VOLUMEUNIT\"] == (3, 0, 0, 0, 0, 0, 0)` ([unit.py#L178](https://github.com/IfcOpenShell/IfcOpenShell/blob/048242783eafe097eb9733eee9c99a4ded235682/src/ifcopenshell-python/ifcopenshell/util/unit.py#L178))\n- `convert()` multiplies the prefix multiplier twice for `SQUARE` and three times for `CUBIC`\n unit names ([unit.py#L666-L684](https://github.com/IfcOpenShell/IfcOpenShell/blob/048242783eafe097eb9733eee9c99a4ded235682/src/ifcopenshell-python/ifcopenshell/util/unit.py#L666-L684))\n- `get_unit_symbol()` renders this exact unit as `dm3` ([unit.py#L624](https://github.com/IfcOpenShell/IfcOpenShell/blob/048242783eafe097eb9733eee9c99a4ded235682/src/ifcopenshell-python/ifcopenshell/util/unit.py#L624))\n\ni.e. the library *displays* the unit as dm³ (one litre) but *scales* it as 0.1 m³ (100 litres).\n\n### Minimal reproduction\n\n`minimal.ifc`:\n\n```\nISO-10303-21;\nHEADER;\nFILE_DESCRIPTION((''),'2;1');\nFILE_NAME('minimal.ifc','2026-08-07T00:00:00',(''),(''),'','','');\nFILE_SCHEMA(('IFC4'));\nENDSEC;\nDATA;\n#1=IFCPROJECT('0000000000000000000000',$,'UnitScaleRepro',$,$,$,$,$,#2);\n#2=IFCUNITASSIGNMENT((#3,#4,#5));\n#3=IFCSIUNIT(*,.LENGTHUNIT.,.MILLI.,.METRE.);\n#4=IFCSIUNIT(*,.AREAUNIT.,.DECI.,.SQUARE_METRE.);\n#5=IFCSIUNIT(*,.VOLUMEUNIT.,.DECI.,.CUBIC_METRE.);\nENDSEC;\nEND-ISO-10303-21;\n```\n\n```python\nimport ifcopenshell\nimport ifcopenshell.util.unit as uu\n\nmodel = ifcopenshell.open(\"minimal.ifc\")\nfor unit_type in (\"LENGTHUNIT\", \"AREAUNIT\", \"VOLUMEUNIT\"):\n print(unit_type, uu.calculate_unit_scale(model, unit_type))\n```\n\n### Expected vs actual (ifcopenshell 0.8.5)\n\n| unit_type | declaration | meaning | expected scale | actual scale | error |\n| ---------- | ----------------- | ----------- | ------------------ | ------------ | ----- |\n| LENGTHUNIT | MILLI METRE | mm | 1e-3 | 1e-3 | OK |\n| AREAUNIT | DECI SQUARE_METRE | dm² | (1e-1)² = **1e-2** | 1e-1 | ×10 |\n| VOLUMEUNIT | DECI CUBIC_METRE | dm³ = litre | (1e-1)³ = **1e-3** | 1e-1 | ×100 |\n\n### Root cause\n\n[`calculate_unit_scale`, unit.py#L723 on current master](https://github.com/IfcOpenShell/IfcOpenShell/blob/048242783eafe097eb9733eee9c99a4ded235682/src/ifcopenshell-python/ifcopenshell/util/unit.py#L723)\n(line 718 in the 0.8.5 wheel):\n\n```python\nif unit.is_a(\"IfcSIUnit\"):\n unit_scale *= get_prefix_multiplier(unit.Prefix)\n```\n\nThe prefix multiplier is applied to the first power regardless of `unit_type` / unit name.\n(The `IfcConversionBasedUnit` part of the chain is fine — the conversion factor carries the\nfull multiplier; a prefixed SI unit terminating the chain hits the same line above.)\n\n### Suggested fix\n\nMirror the logic `convert()` in the same module already uses:\n\n```python\nif unit.is_a(\"IfcSIUnit\"):\n multiplier = get_prefix_multiplier(unit.Prefix) # 1 when Prefix is None\n if \"CUBIC\" in unit.Name:\n multiplier **= 3\n elif \"SQUARE\" in unit.Name:\n multiplier **= 2\n unit_scale *= multiplier\n```\n\nKeying on the unit *Name* (rather than on `named_dimensions[unit_type]`) keeps prefixed\nderived units such as KILO PASCAL or MEGA NEWTON linear, which is correct — there the prefix\nattaches to the derived unit itself, not to the metre.\n\n### Real-world impact\n\nIFC4 MEP exports (e.g. MagiCAD for Revit) declare\n`IFCSIUNIT(*,.VOLUMEUNIT.,.DECI.,.CUBIC_METRE.);` with quantity values in litres. Reading any\n`IfcQuantityVolume` through `calculate_unit_scale(model, \"VOLUMEUNIT\")` then inflates every\nvolume ×100 (confirmed on production files; caught by cross-validating quantities against an\nindependent source).\n\n### Environment\n\n- ifcopenshell 0.8.5 (PyPI wheel), Python 3.12, Linux\n- The same code is present on current master (`0482427`, permalink above)\n\n---\n\nI'm happy to submit a PR with the fix above plus a regression test for\n`calculate_unit_scale` with prefixed `SQUARE_METRE`/`CUBIC_METRE` units, if the\napproach looks right.","author":{"url":"https://github.com/RobertSigmundsson","@type":"Person","name":"RobertSigmundsson"},"datePublished":"2026-08-07T17:29:21Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9278"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f26dd436-2734-e6a9-01ef-148af9516379 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E9D4:1CF439:37E00C:4A0F62:6B04B9E3 |
| html-safe-nonce | 44b7af4de7e7c2905f8e2963e69f393c2fa1ecdaaf4bea553cff0687843bba99 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUQ0OjFDRjQzOTozN0UwMEM6NEEwRjYyOjZCMDRCOUUzIiwidmlzaXRvcl9pZCI6IjIwMTc4NjMxNDMxMTk5NjA1NDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dac687b21bedd100293dac25a22e7b7c563d8b7946457cc93c8e18da400fa12e |
| hovercard-subject-tag | issue:5092525623 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/9278/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d61899cab374767fe3dd9612f397974ac86ab65d5cf9c9951b2797a51b3b230/IfcOpenShell/IfcOpenShell/issues/9278 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d61899cab374767fe3dd9612f397974ac86ab65d5cf9c9951b2797a51b3b230/IfcOpenShell/IfcOpenShell/issues/9278 |
| og:image:alt | Bug Description ifcopenshell.util.unit.calculate_unit_scale(model, unit_type) applies the SI prefix linearly, ignoring that for SQUARE_METRE / CUBIC_METRE the prefix attaches to the metre and is th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RobertSigmundsson |
| hostname | github.com |
| expected-hostname | github.com |
| None | 378bd702ac792b3550e484ad39d9a898fcd25bb52ba6962b0c9cc457c1ea71c7 |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b032e77f1ea437ede6c115446a0a467709b468e7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width